Search in sources :

Example 61 with DimensionalItemObject

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);
}
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 62 with DimensionalItemObject

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);
}
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 63 with DimensionalItemObject

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);
}
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 64 with DimensionalItemObject

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);
}
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 65 with DimensionalItemObject

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

DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)178 Test (org.junit.jupiter.api.Test)63 ArrayList (java.util.ArrayList)51 DimensionalObject (org.hisp.dhis.common.DimensionalObject)48 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)42 Period (org.hisp.dhis.period.Period)41 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)40 HashMap (java.util.HashMap)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)22 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)20 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)20 DataElement (org.hisp.dhis.dataelement.DataElement)20 List (java.util.List)17 Indicator (org.hisp.dhis.indicator.Indicator)17 Grid (org.hisp.dhis.common.Grid)16 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)16 ListMap (org.hisp.dhis.common.ListMap)15 QueryItem (org.hisp.dhis.common.QueryItem)15