Search in sources :

Example 1 with IndicatorValue

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);
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Period(org.hisp.dhis.period.Period) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with IndicatorValue

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);
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) IndicatorType(org.hisp.dhis.indicator.IndicatorType) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 3 with IndicatorValue

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);
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) IndicatorType(org.hisp.dhis.indicator.IndicatorType) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 4 with IndicatorValue

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);
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) IndicatorType(org.hisp.dhis.indicator.IndicatorType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with IndicatorValue

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);
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) IndicatorType(org.hisp.dhis.indicator.IndicatorType) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

IndicatorValue (org.hisp.dhis.indicator.IndicatorValue)11 Indicator (org.hisp.dhis.indicator.Indicator)10 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)9 HashMap (java.util.HashMap)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)8 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)8 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)8 IndicatorType (org.hisp.dhis.indicator.IndicatorType)7 Test (org.junit.jupiter.api.Test)7 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)6 Period (org.hisp.dhis.period.Period)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Map (java.util.Map)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)2 DimensionItem (org.hisp.dhis.analytics.DimensionItem)2 DimensionalObjectUtils.asTypedList (org.hisp.dhis.common.DimensionalObjectUtils.asTypedList)2 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1