use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class ExpressionServiceTest method testGetIndicatorDimensionalItemMap.
@Test
void testGetIndicatorDimensionalItemMap() {
Indicator indicatorA = createIndicator('A', indicatorTypeA);
indicatorA.setNumerator("#{dataElemenA.catOptCombB}*C{xxxxxxxxx05}");
indicatorA.setDenominator("#{dataElemenB.catOptCombA}");
Indicator indicatorB = createIndicator('B', indicatorTypeA);
indicatorB.setNumerator("R{dataSetUidA.REPORTING_RATE} * A{programUidA.trakEntAttA}");
indicatorB.setDenominator(null);
List<Indicator> indicators = Arrays.asList(indicatorA, indicatorB);
DimensionalItemId id1 = new DimensionalItemId(DimensionItemType.DATA_ELEMENT_OPERAND, dataElementA.getUid(), categoryOptionComboB.getUid());
DimensionalItemId id2 = new DimensionalItemId(DimensionItemType.DATA_ELEMENT_OPERAND, dataElementB.getUid(), categoryOptionComboA.getUid());
DimensionalItemId id3 = new DimensionalItemId(DimensionItemType.REPORTING_RATE, dataSetA.getUid(), "REPORTING_RATE");
DimensionalItemId id4 = new DimensionalItemId(DimensionItemType.PROGRAM_ATTRIBUTE, programA.getUid(), trackedEntityAttributeA.getUid());
Map<DimensionalItemId, DimensionalItemObject> expectedItemMap = ImmutableMap.of(id1, new DataElementOperand(dataElementA, categoryOptionComboB), id2, new DataElementOperand(dataElementB, categoryOptionComboA), id3, new ReportingRate(dataSetA), id4, new ProgramTrackedEntityAttributeDimensionItem(programA, trackedEntityAttributeA));
Map<DimensionalItemId, DimensionalItemObject> itemMap = expressionService.getIndicatorDimensionalItemMap(indicators);
assertMapEquals(expectedItemMap, itemMap);
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class ExpressionServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementE = createDataElement('E');
dataElementF = createDataElement('F');
dataElementG = createDataElement('G');
dataElementH = createDataElement('H');
dataElementA.setUid("dataElemenA");
dataElementB.setUid("dataElemenB");
dataElementC.setUid("dataElemenC");
dataElementD.setUid("dataElemenD");
dataElementE.setUid("dataElemenE");
dataElementF.setUid("dataElemenF");
dataElementG.setUid("dataElemenG");
dataElementH.setUid("dataElemenH");
dataElementA.setAggregationType(AggregationType.SUM);
dataElementB.setAggregationType(AggregationType.NONE);
dataElementC.setAggregationType(AggregationType.SUM);
dataElementD.setAggregationType(AggregationType.NONE);
dataElementE.setAggregationType(AggregationType.SUM);
dataElementF.setAggregationType(AggregationType.NONE);
dataElementG.setAggregationType(AggregationType.NONE);
dataElementH.setAggregationType(AggregationType.NONE);
dataElementF.setValueType(ValueType.TEXT);
dataElementG.setValueType(ValueType.DATE);
dataElementH.setValueType(ValueType.BOOLEAN);
dataElementC.setDomainType(DataElementDomain.TRACKER);
dataElementD.setDomainType(DataElementDomain.TRACKER);
dataElementA.setName("DeA");
dataElementB.setName("DeB");
dataElementC.setName("DeC");
dataElementD.setName("DeD");
dataElementE.setName("DeE");
dataElementF.setName("DeF");
dataElementG.setName("DeG");
dataElementH.setName("DeH");
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementE);
dataElementService.addDataElement(dataElementF);
dataElementService.addDataElement(dataElementG);
dataElementService.addDataElement(dataElementH);
indicatorTypeB = createIndicatorType('B');
indicatorService.addIndicatorType(indicatorTypeB);
indicatorA = createIndicator('A', indicatorTypeB);
indicatorA.setUid("mindicatorA");
indicatorService.addIndicator(indicatorA);
categoryOptionA = createCategoryOption('A');
categoryOptionB = createCategoryOption('B');
categoryService.addCategoryOption(categoryOptionA);
categoryService.addCategoryOption(categoryOptionB);
categoryA = createCategory('A', categoryOptionA, categoryOptionB);
categoryService.addCategory(categoryA);
categoryComboA = createCategoryCombo('A', categoryA);
categoryService.addCategoryCombo(categoryComboA);
categoryOptionComboA = createCategoryOptionCombo(categoryComboA, categoryOptionA);
categoryOptionComboB = createCategoryOptionCombo(categoryComboA, categoryOptionB);
categoryOptionComboA.setUid("catOptCombA");
categoryOptionComboB.setUid("catOptCombB");
categoryOptionComboA.setName("CocA");
categoryOptionComboB.setName("CocB");
categoryService.addCategoryOptionCombo(categoryOptionComboA);
categoryService.addCategoryOptionCombo(categoryOptionComboB);
dataElementOperandA = new DataElementOperand(dataElementA, categoryOptionComboB);
dataElementOperandB = new DataElementOperand(dataElementB, categoryOptionComboA);
dataElementOperandC = new DataElementOperand(dataElementA, categoryOptionComboA, categoryOptionComboB);
dataElementOperandD = new DataElementOperand(dataElementB, categoryOptionComboB, categoryOptionComboA);
dataElementOperandE = new DataElementOperand(dataElementA, null, categoryOptionComboB);
dataElementOperandF = new DataElementOperand(dataElementB, null, categoryOptionComboA);
programA = createProgram('A');
programB = createProgram('B');
programA.setUid("programUidA");
programB.setUid("programUidB");
programA.setName("PA");
programB.setName("PB");
manager.save(programA);
manager.save(programB);
programDataElementA = new ProgramDataElementDimensionItem(programA, dataElementC);
programDataElementB = new ProgramDataElementDimensionItem(programB, dataElementD);
trackedEntityAttributeA = createTrackedEntityAttribute('A', ValueType.NUMBER);
trackedEntityAttributeB = createTrackedEntityAttribute('B', ValueType.NUMBER);
trackedEntityAttributeA.setUid("trakEntAttA");
trackedEntityAttributeB.setUid("trakEntAttB");
trackedEntityAttributeA.setName("TeaA");
trackedEntityAttributeB.setName("TeaB");
trackedEntityAttributeA.setAggregationType(AggregationType.SUM);
trackedEntityAttributeB.setAggregationType(AggregationType.NONE);
manager.save(trackedEntityAttributeA);
manager.save(trackedEntityAttributeB);
programAttributeA = new ProgramTrackedEntityAttributeDimensionItem(programA, trackedEntityAttributeA);
programAttributeB = new ProgramTrackedEntityAttributeDimensionItem(programB, trackedEntityAttributeB);
programIndicatorA = createProgramIndicator('A', programA, "9.0", "");
programIndicatorB = createProgramIndicator('B', programA, "19.0", "");
programIndicatorA.setUid("programIndA");
programIndicatorB.setUid("programIndB");
programIndicatorA.setName("PiA");
programIndicatorB.setName("PiB");
programIndicatorA.setAggregationType(AggregationType.SUM);
programIndicatorB.setAggregationType(AggregationType.NONE);
manager.save(programIndicatorA);
manager.save(programIndicatorB);
orgUnitA = createOrganisationUnit('A');
orgUnitB = createOrganisationUnit('B', orgUnitA);
orgUnitC = createOrganisationUnit('C', orgUnitA);
orgUnitD = createOrganisationUnit('D', orgUnitA);
orgUnitE = createOrganisationUnit('E', orgUnitB);
orgUnitF = createOrganisationUnit('F', orgUnitC);
orgUnitG = createOrganisationUnit('G', orgUnitC);
orgUnitH = createOrganisationUnit('H', orgUnitC);
orgUnitI = createOrganisationUnit('I', orgUnitD);
orgUnitJ = createOrganisationUnit('J', orgUnitG);
orgUnitK = createOrganisationUnit('K', orgUnitG);
orgUnitL = createOrganisationUnit('L', orgUnitJ);
orgUnitA.setUid("OrgUnitUidA");
orgUnitB.setUid("OrgUnitUidB");
orgUnitC.setUid("OrgUnitUidC");
orgUnitD.setUid("OrgUnitUidD");
orgUnitE.setUid("OrgUnitUidE");
orgUnitF.setUid("OrgUnitUidF");
orgUnitG.setUid("OrgUnitUidG");
orgUnitH.setUid("OrgUnitUidH");
orgUnitI.setUid("OrgUnitUidI");
orgUnitJ.setUid("OrgUnitUidJ");
orgUnitK.setUid("OrgUnitUidK");
orgUnitL.setUid("OrgUnitUidL");
orgUnitA.setName("OuA");
orgUnitB.setName("OuB");
orgUnitC.setName("OuC");
orgUnitD.setName("OuD");
orgUnitE.setName("OuE");
orgUnitF.setName("OuF");
orgUnitG.setName("OuG");
orgUnitH.setName("OuH");
orgUnitI.setName("OuI");
orgUnitJ.setName("OuJ");
orgUnitK.setName("OuK");
orgUnitL.setName("OuL");
organisationUnitService.addOrganisationUnit(orgUnitA);
organisationUnitService.addOrganisationUnit(orgUnitB);
organisationUnitService.addOrganisationUnit(orgUnitC);
organisationUnitService.addOrganisationUnit(orgUnitD);
organisationUnitService.addOrganisationUnit(orgUnitE);
organisationUnitService.addOrganisationUnit(orgUnitF);
organisationUnitService.addOrganisationUnit(orgUnitG);
organisationUnitService.addOrganisationUnit(orgUnitH);
organisationUnitService.addOrganisationUnit(orgUnitI);
organisationUnitService.addOrganisationUnit(orgUnitJ);
organisationUnitService.addOrganisationUnit(orgUnitK);
organisationUnitService.addOrganisationUnit(orgUnitL);
orgUnitGroupA = createOrganisationUnitGroup('A');
orgUnitGroupB = createOrganisationUnitGroup('B');
orgUnitGroupC = createOrganisationUnitGroup('C');
orgUnitGroupA.setUid("orgUnitGrpA");
orgUnitGroupB.setUid("orgUnitGrpB");
orgUnitGroupC.setUid("orgUnitGrpC");
orgUnitGroupA.setCode("orgUnitGroupCodeA");
orgUnitGroupB.setCode("orgUnitGroupCodeB");
orgUnitGroupC.setCode("orgUnitGroupCodeC");
orgUnitGroupA.setName("OugA");
orgUnitGroupB.setName("OugB");
orgUnitGroupC.setName("OugC");
orgUnitGroupA.addOrganisationUnit(orgUnitB);
orgUnitGroupA.addOrganisationUnit(orgUnitC);
orgUnitGroupA.addOrganisationUnit(orgUnitE);
orgUnitGroupA.addOrganisationUnit(orgUnitF);
orgUnitGroupA.addOrganisationUnit(orgUnitG);
orgUnitGroupB.addOrganisationUnit(orgUnitF);
orgUnitGroupB.addOrganisationUnit(orgUnitG);
orgUnitGroupB.addOrganisationUnit(orgUnitH);
orgUnitGroupC.addOrganisationUnit(orgUnitC);
orgUnitGroupC.addOrganisationUnit(orgUnitD);
orgUnitGroupC.addOrganisationUnit(orgUnitG);
orgUnitGroupC.addOrganisationUnit(orgUnitH);
orgUnitGroupC.addOrganisationUnit(orgUnitI);
organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupA);
organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupB);
organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupC);
dataSetA = createDataSet('A');
dataSetB = createDataSet('B');
dataSetA.setUid("dataSetUidA");
dataSetB.setUid("dataSetUidB");
dataSetA.setName("DsA");
dataSetB.setName("DsB");
dataSetA.setCode("dataSetCodeA");
dataSetB.setCode("dataSetCodeB");
dataSetA.addOrganisationUnit(orgUnitE);
dataSetA.addOrganisationUnit(orgUnitH);
dataSetA.addOrganisationUnit(orgUnitI);
dataSetB.addOrganisationUnit(orgUnitF);
dataSetB.addOrganisationUnit(orgUnitG);
dataSetB.addOrganisationUnit(orgUnitI);
dataSetService.addDataSet(dataSetA);
dataSetService.addDataSet(dataSetB);
reportingRateA = new ReportingRate(dataSetA, REPORTING_RATE);
reportingRateB = new ReportingRate(dataSetA, REPORTING_RATE_ON_TIME);
reportingRateC = new ReportingRate(dataSetA, ACTUAL_REPORTS);
reportingRateD = new ReportingRate(dataSetA, ACTUAL_REPORTS_ON_TIME);
reportingRateE = new ReportingRate(dataSetA, EXPECTED_REPORTS);
reportingRateF = new ReportingRate(dataSetB);
indicatorTypeA = new IndicatorType("A", 100, false);
Constant constantA = new Constant("One half", 0.5);
Constant constantB = new Constant("One quarter", 0.25);
constantA.setUid("xxxxxxxxx05");
constantB.setUid("xxxxxxxx025");
constantService.saveConstant(constantA);
constantService.saveConstant(constantB);
valueMap = new ImmutableMap.Builder<DimensionalItemObject, Object>().put(dataElementA, 3.0).put(dataElementB, 13.0).put(dataElementF, "Str").put(dataElementG, "2022-01-15").put(dataElementH, true).put(dataElementOperandA, 5.0).put(dataElementOperandB, 15.0).put(dataElementOperandC, 7.0).put(dataElementOperandD, 17.0).put(dataElementOperandE, 9.0).put(dataElementOperandF, 19.0).put(programDataElementA, 101.0).put(programDataElementB, 102.0).put(programAttributeA, 201.0).put(programAttributeB, 202.0).put(programIndicatorA, 301.0).put(programIndicatorB, 302.0).put(reportingRateA, 401.0).put(reportingRateB, 402.0).put(reportingRateC, 403.0).put(reportingRateD, 404.0).put(reportingRateE, 405.0).put(reportingRateF, 406.0).put(indicatorA, 88.0).build();
samples = new MapMap<>();
samples.putEntries(samplePeriod1, new ImmutableMap.Builder<DimensionalItemObject, Object>().put(dataElementC, 2.0).build());
samples.putEntries(samplePeriod2, new ImmutableMap.Builder<DimensionalItemObject, Object>().put(dataElementB, 1.0).put(dataElementC, 3.0).build());
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class EventQueryPlannerTest method setUpTest.
@Override
public void setUpTest() {
prA = createProgram('A');
prA.setUid("programuida");
idObjectManager.save(prA);
deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
deB = createDataElement('B', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
deC = createDataElement('C', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT, DataElementDomain.TRACKER);
deD = createDataElement('D', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT, DataElementDomain.TRACKER);
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
idObjectManager.save(deD);
pdeA = new ProgramDataElementDimensionItem(prA, deA);
pdeB = new ProgramDataElementDimensionItem(prA, deB);
pdeC = new ProgramDataElementDimensionItem(prA, deC);
pdeD = new ProgramDataElementDimensionItem(prA, deD);
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', ouA);
ouC = createOrganisationUnit('C', ouA);
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
organisationUnitService.addOrganisationUnit(ouC);
lsA = createLegendSet('A');
idObjectManager.save(lsA);
osA = new OptionSet("OptionSetA", ValueType.TEXT);
idObjectManager.save(osA);
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class PredictionDataConsolidatorTest method initTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@BeforeEach
void initTest() {
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementX = createDataElement('X');
dataElementA.setId(1);
dataElementB.setId(2);
dataElementX.setId(3);
cocA = createCategoryOptionCombo('A');
cocB = createCategoryOptionCombo('B');
cocA.setId(4);
cocB.setId(5);
cocA.setUid("CatOptCombA");
cocB.setUid("CatOptCombB");
aocC = createCategoryOptionCombo('C');
aocD = createCategoryOptionCombo('D');
aocC.setId(6);
aocD.setId(7);
aocC.setUid("AttOptionCC");
aocD.setUid("AttOptionCD");
dataElementOperandA = new DataElementOperand(dataElementA, cocA);
dataElementOperandB = new DataElementOperand(dataElementB, cocB);
dataElementOperandX = new DataElementOperand(dataElementX, cocA);
periodA = createPeriod("202201");
periodB = createPeriod("202202");
periodC = createPeriod("202203");
periodA.setUid("Perio202201");
periodB.setUid("Perio202202");
periodC.setUid("Perio202203");
periodA.setId(10);
periodB.setId(11);
periodC.setId(12);
// OrgUnit hierarchy:
//
// Level 1 - Level 2
// -- A
// -- B ------ E
// -- C ------ F
// -- D ------ G
orgUnitA = createOrganisationUnit("A");
orgUnitB = createOrganisationUnit("B");
orgUnitC = createOrganisationUnit("C");
orgUnitD = createOrganisationUnit("D");
orgUnitE = createOrganisationUnit("E", orgUnitB);
orgUnitF = createOrganisationUnit("F", orgUnitC);
orgUnitG = createOrganisationUnit("G", orgUnitD);
orgUnitA.setId(20);
orgUnitB.setId(21);
orgUnitC.setId(22);
orgUnitD.setId(23);
orgUnitE.setId(24);
orgUnitF.setId(25);
orgUnitG.setId(26);
orgUnitA.setUid("orgUnitAAAA");
orgUnitB.setUid("orgUnitBBBB");
orgUnitC.setUid("orgUnitCCCC");
orgUnitD.setUid("orgUnitDDDD");
orgUnitE.setUid("orgUnitEEEE");
orgUnitF.setUid("orgUnitFFFF");
orgUnitG.setUid("orgUnitGGGG");
orgUnitA.setPath("/orgUnitAAAA");
orgUnitB.setPath("/orgUnitBBBB");
orgUnitC.setPath("/orgUnitCCCC");
orgUnitD.setPath("/orgUnitDDDD");
orgUnitE.setPath("/orgUnitBBBB/orgUnitEEEE");
orgUnitF.setPath("/orgUnitCCCC/orgUnitFFFF");
orgUnitG.setPath("/orgUnitDDDD/orgUnitGGGG");
currentUserOrgUnits = Sets.newHashSet(orgUnitA, orgUnitB, orgUnitC, orgUnitD);
levelOneOrgUnits = Lists.newArrayList(orgUnitA, orgUnitB, orgUnitC, orgUnitD);
// DataValue values:
foundValueA = new FoundDimensionItemValue(orgUnitB, periodA, aocC, dataElementA, 25.0);
foundValueB = new FoundDimensionItemValue(orgUnitC, periodA, aocC, dataElementB, 18.0);
foundValueC = new FoundDimensionItemValue(orgUnitB, periodB, aocC, dataElementOperandA, 10.0);
foundValueD = new FoundDimensionItemValue(orgUnitB, periodB, aocD, dataElementOperandX, 30.0);
foundValueE = new FoundDimensionItemValue(orgUnitB, periodC, aocC, dataElementOperandX, 50.0);
// Analytics values with attribute option combo:
foundValueF = new FoundDimensionItemValue(orgUnitB, periodA, aocC, programIndicatorA, 10.0);
foundValueG = new FoundDimensionItemValue(orgUnitB, periodB, aocC, programIndicatorB, 10.0);
foundValueH = new FoundDimensionItemValue(orgUnitB, periodA, aocD, trackedEntityAttributeA, 10.0);
foundValueI = new FoundDimensionItemValue(orgUnitD, periodA, aocC, programIndicatorA, 10.0);
// Analytics values without attribute option combo:
CategoryOptionCombo noAoc = null;
foundValueJ = new FoundDimensionItemValue(orgUnitD, periodA, noAoc, programAttributeA, 100.0);
foundValueK = new FoundDimensionItemValue(orgUnitD, periodA, noAoc, programAttributeB, 200.0);
foundValueL = new FoundDimensionItemValue(orgUnitD, periodB, noAoc, programAttributeA, 300.0);
// old predictor data values:
dataValueX = new DataValue(dataElementX, periodA, orgUnitB, cocA, aocD, "30.0", "Z", null, null, null, false);
dataValueY = new DataValue(dataElementX, periodC, orgUnitB, cocA, aocC, "40.0", "Z", null, null, null, true);
programA = createProgram('A');
programB = createProgram('B');
programA.setUid("ProgramAAAA");
programB.setUid("ProgramBBBB");
programIndicatorA = createProgramIndicator('A', programA, "expressionA", "filterA");
programIndicatorB = createProgramIndicator('B', programB, "expressionB", "filterB");
programIndicatorA.setUid("ProgramIndA");
programIndicatorB.setUid("ProgramIndB");
trackedEntityAttributeA = createTrackedEntityAttribute('A');
trackedEntityAttributeA.setUid("trackEntAtA");
programAttributeA = new ProgramTrackedEntityAttributeDimensionItem(programA, trackedEntityAttributeA);
programAttributeB = new ProgramTrackedEntityAttributeDimensionItem(programB, trackedEntityAttributeA);
programAttributeA.setUid(programA.getUid() + "." + trackedEntityAttributeA.getUid());
programAttributeA.setUid(programB.getUid() + "." + trackedEntityAttributeA.getUid());
items = Sets.newHashSet(// DataValues (always with AOC):
dataElementA, dataElementOperandA, dataElementOperandB, dataElementOperandX, // Analytics with AOC:
programIndicatorA, programIndicatorB, trackedEntityAttributeA, // Analytics without AOC:
programAttributeA, programAttributeB);
dataValueQueryPeriods = Sets.newHashSet(periodA, periodB, periodC);
analyticsQueryPeriods = Sets.newHashSet(periodA, periodB);
existingOutputPeriods = Sets.newHashSet(periodC);
outputDataElementOperand = dataElementOperandX;
when(dataValueFetcher.setIncludeDeleted(true)).thenReturn(dataValueFetcher);
when(dataValueFetcher.setIncludeDescendants(INCLUDE_DESCENDANTS)).thenReturn(dataValueFetcher);
consolidator = new PredictionDataConsolidator(items, INCLUDE_DESCENDANTS, dataValueFetcher, analyticsFetcher);
consolidator.setAnalyticsBatchFetchSize(3);
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class DefaultValidationService method getDimensionalItemObjects.
/**
* Gets all required DimensionalItemObjects from their UIDs.
*
* @param expressionIdMap UIDs of DimensionalItemObjects to get.
* @return map of the DimensionalItemObjects.
*/
private Map<String, DimensionalItemObject> getDimensionalItemObjects(SetMap<Class<? extends DimensionalItemObject>, String> expressionIdMap) {
// 1. Get ids for all the individual IdentifiableObjects within the DimensionalItemObjects:
SetMap<Class<? extends IdentifiableObject>, String> idsToGet = new SetMap<>();
getIdentifiableObjectIds(idsToGet, expressionIdMap, DataElementOperand.class, DataElement.class, DataElementCategoryOptionCombo.class);
getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramDataElementDimensionItem.class, Program.class, DataElement.class);
getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramTrackedEntityAttributeDimensionItem.class, Program.class, TrackedEntityAttribute.class);
getIdentifiableObjectIds(idsToGet, expressionIdMap, ProgramIndicator.class, ProgramIndicator.class);
// 2. Look up all the IdentifiableObjects (each class all together, for best performance):
MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> idMap = new MapMap<>();
for (Map.Entry<Class<? extends IdentifiableObject>, Set<String>> e : idsToGet.entrySet()) {
idMap.putEntries(e.getKey(), idObjectManager.get(e.getKey(), e.getValue()).stream().collect(Collectors.toMap(o -> o.getUid(), o -> o)));
}
// 3. Build the map of DimensionalItemObjects:
Map<String, DimensionalItemObject> dimObjects = new HashMap<>();
for (Map.Entry<Class<? extends DimensionalItemObject>, Set<String>> e : expressionIdMap.entrySet()) {
for (String id : e.getValue()) {
if (e.getKey() == DataElementOperand.class) {
DataElementOperand deo = new DataElementOperand((DataElement) idMap.getValue(DataElement.class, getIdPart(id, 0)), (DataElementCategoryOptionCombo) idMap.getValue(DataElementCategoryOptionCombo.class, getIdPart(id, 1)));
if (deo.getDataElement() != null && (deo.getCategoryOptionCombo() != null || getIdPart(id, 1) == null)) {
dimObjects.put(id, deo);
}
} else if (e.getKey() == ProgramDataElementDimensionItem.class) {
ProgramDataElementDimensionItem pde = new ProgramDataElementDimensionItem((Program) idMap.getValue(Program.class, getIdPart(id, 0)), (DataElement) idMap.getValue(DataElement.class, getIdPart(id, 1)));
if (pde.getProgram() != null && pde.getDataElement() != null) {
dimObjects.put(id, pde);
}
} else if (e.getKey() == ProgramTrackedEntityAttributeDimensionItem.class) {
ProgramTrackedEntityAttributeDimensionItem pa = new ProgramTrackedEntityAttributeDimensionItem((Program) idMap.getValue(Program.class, getIdPart(id, 0)), (TrackedEntityAttribute) idMap.getValue(TrackedEntityAttribute.class, getIdPart(id, 1)));
if (pa.getProgram() != null && pa.getAttribute() != null) {
dimObjects.put(id, pa);
}
} else if (e.getKey() == ProgramIndicator.class) {
ProgramIndicator pi = (ProgramIndicator) idMap.getValue(ProgramIndicator.class, id);
if (pi != null) {
dimObjects.put(id, pi);
}
}
}
}
return dimObjects;
}
Aggregations