Search in sources :

Example 1 with ProgramTrackedEntityAttributeDimensionItem

use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.

the class DataQueryServiceTest method setUpTest.

@Override
public void setUpTest() {
    super.userService = internalUserService;
    prA = createProgram('A');
    programService.addProgram(prA);
    deA = createDataElement('A');
    deB = createDataElement('B');
    deC = createDataElement('C');
    deD = createDataElement('D');
    DataElement deE = createDataElement('E');
    DataElement deF = createDataElement('F');
    deE.setDomainType(DataElementDomain.TRACKER);
    deF.setDomainType(DataElementDomain.TRACKER);
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    dataElementService.addDataElement(deD);
    dataElementService.addDataElement(deE);
    dataElementService.addDataElement(deF);
    pdA = new ProgramDataElementDimensionItem(prA, deE);
    pdB = new ProgramDataElementDimensionItem(prA, deF);
    cocA = categoryService.getDefaultCategoryOptionCombo();
    DataSet dsA = createDataSet('A', monthly);
    DataSet dsB = createDataSet('B', monthly);
    dataSetService.addDataSet(dsA);
    dataSetService.addDataSet(dsB);
    rrA = new ReportingRate(dsA, ReportingRateMetric.REPORTING_RATE);
    rrB = new ReportingRate(dsB, ReportingRateMetric.REPORTING_RATE);
    rrC = new ReportingRate(dsB, ReportingRateMetric.ACTUAL_REPORTS);
    itA = createIndicatorType('A');
    idObjectManager.save(itA);
    inA = createIndicator('A', itA);
    inB = createIndicator('B', itA);
    idObjectManager.save(inA);
    idObjectManager.save(inB);
    inGroupA = createIndicatorGroup('A');
    inGroupA.getMembers().add(inA);
    inGroupA.getMembers().add(inB);
    idObjectManager.save(inGroupA);
    atA = createTrackedEntityAttribute('A');
    atB = createTrackedEntityAttribute('B');
    idObjectManager.save(atA);
    idObjectManager.save(atB);
    patA = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
    patB = new ProgramTrackedEntityAttributeDimensionItem(prA, atB);
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    ouD = createOrganisationUnit('D');
    ouE = createOrganisationUnit('E');
    ouB.updateParent(ouA);
    ouC.updateParent(ouA);
    ouD.updateParent(ouB);
    ouE.updateParent(ouB);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    organisationUnitService.addOrganisationUnit(ouD);
    organisationUnitService.addOrganisationUnit(ouE);
    ouGroupSetA = createOrganisationUnitGroupSet('A');
    organisationUnitGroupService.addOrganisationUnitGroupSet(ouGroupSetA);
    ouGroupA = createOrganisationUnitGroup('A');
    ouGroupA.setPublicAccess(AccessStringHelper.FULL);
    ouGroupB = createOrganisationUnitGroup('B');
    ouGroupB.setPublicAccess(AccessStringHelper.FULL);
    ouGroupC = createOrganisationUnitGroup('C');
    ouGroupC.setPublicAccess(AccessStringHelper.FULL);
    ouGroupA.addOrganisationUnit(ouA);
    ouGroupA.addOrganisationUnit(ouB);
    ouGroupA.addOrganisationUnit(ouC);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(ouGroupC);
    ouGroupSetA.addOrganisationUnitGroup(ouGroupA);
    ouGroupSetA.addOrganisationUnitGroup(ouGroupB);
    ouGroupSetA.addOrganisationUnitGroup(ouGroupC);
    organisationUnitGroupService.updateOrganisationUnitGroupSet(ouGroupSetA);
    deGroupSetA = createDataElementGroupSet('A');
    dataElementService.addDataElementGroupSet(deGroupSetA);
    deGroupA = createDataElementGroup('A');
    deGroupB = createDataElementGroup('B');
    deGroupC = createDataElementGroup('C');
    deGroupA.getGroupSets().add(deGroupSetA);
    deGroupB.getGroupSets().add(deGroupSetA);
    deGroupC.getGroupSets().add(deGroupSetA);
    deGroupA.getGroupSets().add(deGroupSetA);
    deGroupA.addDataElement(deA);
    deGroupA.addDataElement(deB);
    deGroupA.addDataElement(deC);
    dataElementService.addDataElementGroup(deGroupA);
    dataElementService.addDataElementGroup(deGroupB);
    dataElementService.addDataElementGroup(deGroupC);
    deGroupSetA.addDataElementGroup(deGroupA);
    deGroupSetA.addDataElementGroup(deGroupB);
    deGroupSetA.addDataElementGroup(deGroupC);
    dataElementService.updateDataElementGroupSet(deGroupSetA);
    // ---------------------------------------------------------------------
    // Inject user
    // ---------------------------------------------------------------------
    UserAuthorityGroup role = createUserAuthorityGroup('A', "ALL");
    userService.addUserAuthorityGroup(role);
    User user = createUser('A');
    user.addOrganisationUnit(ouA);
    user.getUserAuthorityGroups().add(role);
    saveAndInjectUserSecurityContext(user);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)

Example 2 with ProgramTrackedEntityAttributeDimensionItem

use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.

the class DataDimensionExtractor method getBaseDimensionalItemObject.

private BaseDimensionalItemObject getBaseDimensionalItemObject(final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects, final DimensionalItemId id) {
    BaseDimensionalItemObject dimensionalItemObject = null;
    switch(id.getDimensionItemType()) {
        case DATA_ELEMENT:
            DataElement dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            if (dataElement != null) {
                dimensionalItemObject = cloneIfNeeded(dataElement, id);
            }
            break;
        case INDICATOR:
            final Indicator indicator = (Indicator) atomicObjects.getValue(Indicator.class, id.getId0());
            if (indicator != null) {
                dimensionalItemObject = cloneIfNeeded(indicator, id);
            }
            break;
        case DATA_ELEMENT_OPERAND:
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            final CategoryOptionCombo categoryOptionCombo = id.getId1() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId1());
            final CategoryOptionCombo attributeOptionCombo = id.getId2() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId2());
            if (dataElement != null && (id.getId1() != null) == (categoryOptionCombo != null) && (id.getId2() != null) == (attributeOptionCombo != null)) {
                dimensionalItemObject = new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
            }
            break;
        case REPORTING_RATE:
            final DataSet dataSet = (DataSet) atomicObjects.getValue(DataSet.class, id.getId0());
            if (dataSet != null) {
                dimensionalItemObject = new ReportingRate(dataSet, ReportingRateMetric.valueOf(id.getId1()));
            }
            break;
        case PROGRAM_DATA_ELEMENT:
            Program program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId1());
            if (program != null && dataElement != null) {
                dimensionalItemObject = new ProgramDataElementDimensionItem(program, dataElement);
            }
            break;
        case PROGRAM_ATTRIBUTE:
            program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            final TrackedEntityAttribute attribute = (TrackedEntityAttribute) atomicObjects.getValue(TrackedEntityAttribute.class, id.getId1());
            if (program != null && attribute != null) {
                dimensionalItemObject = new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
            }
            break;
        case PROGRAM_INDICATOR:
            final ProgramIndicator programIndicator = (ProgramIndicator) atomicObjects.getValue(ProgramIndicator.class, id.getId0());
            if (programIndicator != null) {
                dimensionalItemObject = cloneIfNeeded(programIndicator, id);
            }
            break;
        default:
            log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getItemObjectMap");
            break;
    }
    return dimensionalItemObject;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Example 3 with ProgramTrackedEntityAttributeDimensionItem

use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.

the class DefaultDimensionService method getDataDimensionalItemObject.

@Override
public DimensionalItemObject getDataDimensionalItemObject(IdScheme idScheme, String dimensionItem) {
    if (DimensionalObjectUtils.isCompositeDimensionalObject(dimensionItem)) {
        String id0 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 0);
        String id1 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 1);
        String id2 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 2);
        DataElementOperand operand;
        ReportingRate reportingRate;
        ProgramDataElementDimensionItem programDataElement;
        ProgramTrackedEntityAttributeDimensionItem programAttribute;
        if ((operand = getDataElementOperand(idScheme, id0, id1, id2)) != null) {
            return operand;
        } else if ((reportingRate = dataDimensionExtractor.getReportingRate(idScheme, id0, id1)) != null) {
            return reportingRate;
        } else if ((programDataElement = dataDimensionExtractor.getProgramDataElementDimensionItem(idScheme, id0, id1)) != null) {
            return programDataElement;
        } else if ((programAttribute = dataDimensionExtractor.getProgramAttributeDimensionItem(idScheme, id0, id1)) != null) {
            return programAttribute;
        }
    } else if (!idScheme.is(IdentifiableProperty.UID) || CodeGenerator.isValidUid(dimensionItem)) {
        DimensionalItemObject itemObject = idObjectManager.get(DataDimensionItem.DATA_DIMENSION_CLASSES, idScheme, dimensionItem);
        if (itemObject != null) {
            return itemObject;
        }
    }
    return null;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ReportingRate(org.hisp.dhis.common.ReportingRate) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)

Example 4 with ProgramTrackedEntityAttributeDimensionItem

use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.

the class EventQueryParams method fromDataQueryParams.

public static EventQueryParams fromDataQueryParams(DataQueryParams dataQueryParams) {
    EventQueryParams params = new EventQueryParams();
    dataQueryParams.copyTo(params);
    EventQueryParams.Builder builder = new EventQueryParams.Builder(params);
    for (DimensionalItemObject object : dataQueryParams.getProgramDataElements()) {
        ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
        DataElement dataElement = element.getDataElement();
        QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItem(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getProgramAttributes()) {
        ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
        TrackedEntityAttribute attribute = element.getAttribute();
        QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItem(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getFilterProgramDataElements()) {
        ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
        DataElement dataElement = element.getDataElement();
        QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
        item.setProgram(element.getProgram());
        builder.addItemFilter(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getFilterProgramAttributes()) {
        ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
        TrackedEntityAttribute attribute = element.getAttribute();
        QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
        builder.addItemFilter(item);
    }
    for (DimensionalItemObject object : dataQueryParams.getProgramIndicators()) {
        ProgramIndicator programIndicator = (ProgramIndicator) object;
        builder.addItemProgramIndicator(programIndicator);
    }
    return builder.withAggregateData(true).removeDimension(DATA_X_DIM_ID).build();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) QueryItem(org.hisp.dhis.common.QueryItem) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) QueryParamsBuilder(org.hisp.dhis.analytics.QueryParamsBuilder) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 5 with ProgramTrackedEntityAttributeDimensionItem

use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.

the class DimensionServiceTest method testGetDimensionalItemObject.

@Test
void testGetDimensionalItemObject() {
    String idA = deA.getUid();
    String idB = prA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + deA.getUid();
    String idC = prA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + atA.getUid();
    String idD = dsA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + ReportingRateMetric.REPORTING_RATE.name();
    String idE = dsA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + "UNKNOWN_METRIC";
    String idF = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
    String idG = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD;
    String idH = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + "UNKNOWN_SYMBOL";
    String idI = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
    String idJ = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD;
    String idK = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
    ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
    ProgramTrackedEntityAttributeDimensionItem ptaA = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
    ReportingRate rrA = new ReportingRate(dsA, ReportingRateMetric.REPORTING_RATE);
    DataElementOperand deoA = new DataElementOperand(deA, cocA);
    DataElementOperand deoB = new DataElementOperand(deA, null);
    DataElementOperand deoC = new DataElementOperand(deA, cocA, cocA);
    DataElementOperand deoD = new DataElementOperand(deA, cocA, null);
    DataElementOperand deoE = new DataElementOperand(deA, null, cocA);
    assertNotNull(dimensionService.getDataDimensionalItemObject(idA));
    assertEquals(deA, dimensionService.getDataDimensionalItemObject(idA));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idB));
    assertEquals(pdeA, dimensionService.getDataDimensionalItemObject(idB));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idC));
    assertEquals(ptaA, dimensionService.getDataDimensionalItemObject(idC));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idD));
    assertEquals(rrA, dimensionService.getDataDimensionalItemObject(idD));
    assertNull(dimensionService.getDataDimensionalItemObject(idE));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idF));
    assertEquals(deoA, dimensionService.getDataDimensionalItemObject(idF));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idG));
    assertEquals(deoB, dimensionService.getDataDimensionalItemObject(idG));
    assertNull(dimensionService.getDataDimensionalItemObject(idH));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idI));
    assertEquals(deoC, dimensionService.getDataDimensionalItemObject(idI));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idJ));
    assertEquals(deoD, dimensionService.getDataDimensionalItemObject(idJ));
    assertNotNull(dimensionService.getDataDimensionalItemObject(idK));
    assertEquals(deoE, dimensionService.getDataDimensionalItemObject(idK));
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) ReportingRate(org.hisp.dhis.common.ReportingRate) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ProgramTrackedEntityAttributeDimensionItem (org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem)14 ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)10 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)8 ReportingRate (org.hisp.dhis.common.ReportingRate)7 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)6 Program (org.hisp.dhis.program.Program)5 DataElement (org.hisp.dhis.dataelement.DataElement)4 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)4 DataSet (org.hisp.dhis.dataset.DataSet)3 Test (org.junit.jupiter.api.Test)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)2 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 Indicator (org.hisp.dhis.indicator.Indicator)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Date (java.util.Date)1