Search in sources :

Example 6 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId 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);
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with DimensionalItemId

use of org.hisp.dhis.common.DimensionalItemId 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);
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) 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 8 with DimensionalItemId

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

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

use of org.hisp.dhis.common.DimensionalItemId 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());
}
Also used : ParserException(org.hisp.dhis.antlr.ParserException) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

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