use of org.hisp.dhis.common.DimensionalItemObject 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.common.DimensionalItemObject 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.common.DimensionalItemObject in project dhis2-core by dhis2.
the class ExpressionServiceTest method testGetIndicatorDimensionalItemMap2.
@Test
void testGetIndicatorDimensionalItemMap2() {
Indicator indicatorA = createIndicator('A', indicatorTypeA);
indicatorA.setNumerator("#{dataElemenA.catOptCombB}*C{xxxxxxxxx05}");
indicatorA.setDenominator("#{dataElemenA.catOptCombB}");
Indicator indicatorB = createIndicator('B', indicatorTypeA);
indicatorB.setNumerator("#{dataElemenA.catOptCombB} + #{dataElemenB.catOptCombA}");
indicatorB.setDenominator("#{dataElemenA.catOptCombB}");
indicatorB.setAnnualized(true);
Period period = createPeriod("20010101");
List<Indicator> indicators = Arrays.asList(indicatorA, indicatorB);
Map<DimensionalItemId, DimensionalItemObject> itemMap = expressionService.getIndicatorDimensionalItemMap(indicators);
IndicatorValue value = expressionService.getIndicatorValueObject(indicatorA, singletonList(period), itemMap, valueMap, null);
assertEquals(value.getNumeratorValue(), DELTA, 2.5);
assertEquals(value.getDenominatorValue(), DELTA, 5.0);
assertEquals(value.getFactor(), DELTA, 100.0);
assertEquals(value.getMultiplier(), DELTA, 100);
assertEquals(value.getDivisor(), DELTA, 1);
assertEquals(value.getValue(), DELTA, 50.0);
value = expressionService.getIndicatorValueObject(indicatorB, singletonList(period), itemMap, valueMap, null);
assertEquals(value.getNumeratorValue(), DELTA, 20.0);
assertEquals(value.getDenominatorValue(), DELTA, 5.0);
assertEquals(value.getFactor(), DELTA, 36500.0);
assertEquals(value.getMultiplier(), DELTA, 36500);
assertEquals(value.getDivisor(), DELTA, 1);
assertEquals(value.getValue(), DELTA, 146000.0);
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class ExpressionService2Test method testAnnualizedIndicatorValueWhenHavingMultiplePeriods.
@Test
void testAnnualizedIndicatorValueWhenHavingMultiplePeriods() {
Set<DimensionalItemId> itemIds = Sets.newHashSet(getId(opA));
Map<DimensionalItemId, DimensionalItemObject> expectedItemMap = ImmutableMap.of(getId(opA), opA);
when(dimensionService.getDataDimensionalItemObjectMap(itemIds)).thenReturn(expectedItemMap);
mockConstantService();
List<Period> periods = new ArrayList<>(6);
periods.add(createPeriod("200001"));
periods.add(createPeriod("200002"));
periods.add(createPeriod("200003"));
periods.add(createPeriod("200004"));
periods.add(createPeriod("200005"));
periods.add(createPeriod("200006"));
IndicatorType indicatorType = new IndicatorType("A", 100, false);
Indicator indicatorA = createIndicator('A', indicatorType);
indicatorA.setAnnualized(true);
indicatorA.setNumerator(expressionE);
indicatorA.setDenominator(expressionF);
Map<DimensionalItemObject, Object> valueMap = new HashMap<>();
valueMap.put(new DataElementOperand(deA, coc), 12d);
valueMap.put(new DataElementOperand(deB, coc), 34d);
valueMap.put(new DataElementOperand(deA, cocA, cocB), 46d);
valueMap.put(new DataElementOperand(deB, cocA), 10d);
Map<DimensionalItemId, DimensionalItemObject> itemMap = target.getIndicatorDimensionalItemMap(Arrays.asList(indicatorA));
IndicatorValue value = target.getIndicatorValueObject(indicatorA, periods, itemMap, valueMap, null);
assertNotNull(value);
assertEquals(24d, value.getNumeratorValue(), DELTA);
assertEquals(12d, value.getDenominatorValue(), DELTA);
assertEquals(36500, value.getMultiplier());
assertEquals(182, value.getDivisor());
assertEquals(200.55d, Precision.round(value.getFactor(), 2), DELTA);
assertEquals(401.1d, Precision.round(value.getValue(), 2), DELTA);
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class ExpressionService2Test method testGetIndicatorDimensionalItemMap3.
@Test
void testGetIndicatorDimensionalItemMap3() {
Set<DimensionalItemId> itemIds = Sets.newHashSet(getId(opA), getId(opE), getId(opF));
Map<DimensionalItemId, DimensionalItemObject> expectedItemMap = ImmutableMap.of(getId(opA), opA, getId(opE), opE, getId(opF), opF);
when(dimensionService.getDataDimensionalItemObjectMap(itemIds)).thenReturn(expectedItemMap);
mockConstantService();
IndicatorType indicatorType = new IndicatorType("A", 100, false);
Indicator indicatorB = createIndicator('B', indicatorType);
indicatorB.setNumerator(expressionN);
indicatorB.setDenominator(expressionF);
indicatorB.setAnnualized(true);
List<Indicator> indicators = Arrays.asList(indicatorB);
Map<DimensionalItemId, DimensionalItemObject> itemMap = target.getIndicatorDimensionalItemMap(indicators);
Map<DimensionalItemObject, Object> valueMap = new HashMap<>();
valueMap.put(new DataElementOperand(deA, coc), 12d);
valueMap.put(new DataElementOperand(deB, coc), 34d);
valueMap.put(new DataElementOperand(deA, cocA, cocB), 46d);
valueMap.put(new DataElementOperand(deB, cocA), 10d);
IndicatorValue value = target.getIndicatorValueObject(indicatorB, Collections.singletonList(period), itemMap, valueMap, null);
assertNotNull(value);
assertEquals(36d, value.getNumeratorValue(), DELTA);
assertEquals(12d, value.getDenominatorValue(), DELTA);
assertEquals(36500, value.getMultiplier());
assertEquals(31, value.getDivisor());
assertEquals(1177.419, value.getFactor(), DELTA);
assertEquals(3532.258, value.getValue(), DELTA);
}
Aggregations