use of org.hisp.dhis.indicator.IndicatorValue 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.indicator.IndicatorValue in project dhis2-core by dhis2.
the class ExpressionService2Test method testGetNullWithoutNumeratorDataWithDenominatorData.
@Test
void testGetNullWithoutNumeratorDataWithDenominatorData() {
IndicatorType indicatorType = new IndicatorType("A", 100, false);
Indicator indicatorA = createIndicator('A', indicatorType);
indicatorA.setNumerator(expressionF);
indicatorA.setDenominator(expressionP);
Map<DimensionalItemObject, Object> valueMap = new HashMap<>();
valueMap.put(new DataElementOperand(deB, coc), 12d);
valueMap.put(new DataElementOperand(deC, coc), 18d);
Map<DimensionalItemId, DimensionalItemObject> itemMap = target.getIndicatorDimensionalItemMap(Arrays.asList(indicatorA));
IndicatorValue value = target.getIndicatorValueObject(indicatorA, null, itemMap, valueMap, null);
assertNull(value);
}
use of org.hisp.dhis.indicator.IndicatorValue in project dhis2-core by dhis2.
the class ExpressionService2Test method testGetNullWithNumeratorDataWithZeroDenominatorData.
@Test
void testGetNullWithNumeratorDataWithZeroDenominatorData() {
IndicatorType indicatorType = new IndicatorType("A", 100, false);
Indicator indicatorA = createIndicator('A', indicatorType);
indicatorA.setNumerator(expressionF);
indicatorA.setDenominator(expressionP);
Map<DimensionalItemObject, Object> valueMap = new HashMap<>();
valueMap.put(new DataElementOperand(deA, coc), 12d);
valueMap.put(new DataElementOperand(deB, coc), 0d);
Map<DimensionalItemId, DimensionalItemObject> itemMap = target.getIndicatorDimensionalItemMap(Arrays.asList(indicatorA));
IndicatorValue value = target.getIndicatorValueObject(indicatorA, null, itemMap, valueMap, null);
assertNull(value);
}
use of org.hisp.dhis.indicator.IndicatorValue 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.indicator.IndicatorValue 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