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);
}
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);
}
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);
}
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);
}
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()));
}
Aggregations