Search in sources :

Example 11 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId 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);
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ReportingRate(org.hisp.dhis.common.ReportingRate) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 12 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId 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 13 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId 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 14 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId 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)

Example 15 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.

the class DataDimensionExtractorTest method testGetAtomicIdsForDataElement.

@Test
void testGetAtomicIdsForDataElement() {
    // Given
    final DimensionalItemId dataElementItem = new DimensionalItemId(DATA_ELEMENT, "id0");
    final Set<DimensionalItemId> someItemIds = newHashSet(dataElementItem);
    // When
    final SetMap<Class<? extends IdentifiableObject>, String> result = new DataDimensionExtractor(null).getAtomicIds(someItemIds);
    // Then
    assertThat(result.size(), is(equalTo(1)));
    assertThat(result.get(DataElement.class), containsInAnyOrder(dataElementItem.getId0()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Aggregations

DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)46 Test (org.junit.jupiter.api.Test)32 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)21 DhisSpringTest (org.hisp.dhis.DhisSpringTest)13 Indicator (org.hisp.dhis.indicator.Indicator)12 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 HashMap (java.util.HashMap)11 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)9 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)9 IndicatorValue (org.hisp.dhis.indicator.IndicatorValue)8 IndicatorType (org.hisp.dhis.indicator.IndicatorType)6 DataElement (org.hisp.dhis.dataelement.DataElement)5 List (java.util.List)4 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)4 Period (org.hisp.dhis.period.Period)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AllArgsConstructor (lombok.AllArgsConstructor)3