use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class DimensionServiceTest method testGetIndicatorDataDimensionalItemMapWithQueryMods.
@Test
void testGetIndicatorDataDimensionalItemMapWithQueryMods() {
Map<DimensionalItemId, DimensionalItemObject> result;
// Given
Set<DimensionalItemId> dimensionalItemIds = new HashSet<>();
deA.setQueryMods(queryModsA);
deB.setQueryMods(queryModsB);
deC.setQueryMods(queryModsC);
DimensionalItemId itemIdA = new DimensionalItemId(DATA_ELEMENT, deA.getUid(), queryModsA);
DimensionalItemId itemIdB = new DimensionalItemId(DATA_ELEMENT, deB.getUid(), queryModsB);
DimensionalItemId itemIdC = new DimensionalItemId(DATA_ELEMENT, deC.getUid(), queryModsC);
dimensionalItemIds.add(itemIdA);
dimensionalItemIds.add(itemIdB);
dimensionalItemIds.add(itemIdC);
Map<DimensionalItemId, DimensionalItemObject> dimensionalItemMap = ImmutableMap.of(itemIdA, deA, itemIdB, deB, itemIdC, deC);
// When
result = dimensionService.getDataDimensionalItemObjectMap(dimensionalItemIds);
// Then
assertEquals(dimensionalItemMap, result);
}
use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.
the class ExpressionService2Test method testGetIndicatorDimensionalItemMap.
@Test
void testGetIndicatorDimensionalItemMap() {
Set<DimensionalItemId> itemIds = Sets.newHashSet(getId(opA), getId(opB), getId(deB), getId(pdeA), getId(pteaA), getId(piA));
ImmutableMap<DimensionalItemId, DimensionalItemObject> itemMap = ImmutableMap.<DimensionalItemId, DimensionalItemObject>builder().put(getId(opA), opA).put(getId(opB), opB).put(getId(deB), deB).put(getId(pdeA), pdeA).put(getId(pteaA), pteaA).put(getId(piA), piA).build();
when(dimensionService.getDataDimensionalItemObjectMap(itemIds)).thenReturn(itemMap);
mockConstantService();
Indicator indicator = createIndicator('A', null);
indicator.setNumerator(expressionI);
indicator.setDenominator(expressionA);
Set<Indicator> indicators = Sets.newHashSet(indicator);
Map<DimensionalItemId, DimensionalItemObject> result = target.getIndicatorDimensionalItemMap(indicators);
assertMapEquals(itemMap, result);
}
use of org.hisp.dhis.common.DimensionalItemObject 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.common.DimensionalItemObject 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.common.DimensionalItemObject in project dhis2-core by dhis2.
the class ExpressionServiceTest method eval.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Evaluates a test expression, against getExpressionDimensionalItemObjects
* and getExpressionValue. Returns a string containing first the returned
* value from getExpressionValue, and then the items returned from
* getExpressionDimensionalItemObjects, if any, separated by spaces.
*
* @param expr expression to evaluate
* @param parseType type of expression to parse
* @param missingValueStrategy strategy to use if item value is missing
* @param dataType data type that the expression should return
* @return result from testing the expression
*/
private String eval(String expr, ParseType parseType, MissingValueStrategy missingValueStrategy, DataType dataType) {
try {
expressionService.getExpressionDescription(expr, parseType, dataType);
} catch (ParserException ex) {
return ex.getMessage();
}
Map<DimensionalItemId, DimensionalItemObject> itemMap = new HashMap<>();
expressionService.getExpressionDimensionalItemMaps(expr, parseType, dataType, itemMap, itemMap);
Object value = expressionService.getExpressionValue(ExpressionParams.builder().expression(expr).parseType(parseType).dataType(dataType).itemMap(itemMap).valueMap(valueMap).orgUnitCountMap(ORG_UNIT_COUNT_MAP).days(DAYS).missingValueStrategy(missingValueStrategy).samplePeriods(TEST_SAMPLE_PERIODS).periodValueMap(samples).build());
return result(value, itemMap.values());
}
Aggregations