Search in sources :

Example 11 with IndicatorValue

use of org.hisp.dhis.indicator.IndicatorValue in project dhis2-core by dhis2.

the class DefaultExpressionService method getIndicatorValueObject.

@Override
public IndicatorValue getIndicatorValueObject(Indicator indicator, List<Period> periods, Map<DimensionalItemId, DimensionalItemObject> itemMap, Map<DimensionalItemObject, Object> valueMap, Map<String, Integer> orgUnitCountMap) {
    if (indicator == null || indicator.getNumerator() == null || indicator.getDenominator() == null) {
        return null;
    }
    Integer days = periods != null ? getDaysFromPeriods(periods) : null;
    ExpressionParams params = ExpressionParams.builder().parseType(INDICATOR_EXPRESSION).itemMap(itemMap).valueMap(valueMap).orgUnitCountMap(orgUnitCountMap).days(days).missingValueStrategy(SKIP_IF_ALL_VALUES_MISSING).build();
    Double denominatorValue = castDouble(getExpressionValue(params.toBuilder().expression(indicator.getDenominator()).build()));
    Double numeratorValue = castDouble(getExpressionValue(params.toBuilder().expression(indicator.getNumerator()).build()));
    if (denominatorValue != null && denominatorValue != 0d && numeratorValue != null) {
        int multiplier = indicator.getIndicatorType().getFactor();
        int divisor = 1;
        if (indicator.isAnnualized() && periods != null) {
            final int daysInPeriod = getDaysFromPeriods(periods);
            multiplier *= DateUtils.DAYS_IN_YEAR;
            divisor = daysInPeriod;
        }
        return new IndicatorValue().setNumeratorValue(numeratorValue).setDenominatorValue(denominatorValue).setMultiplier(multiplier).setDivisor(divisor);
    }
    return null;
}
Also used : IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) AntlrParserUtils.castDouble(org.hisp.dhis.antlr.AntlrParserUtils.castDouble)

Aggregations

IndicatorValue (org.hisp.dhis.indicator.IndicatorValue)11 Indicator (org.hisp.dhis.indicator.Indicator)10 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)9 HashMap (java.util.HashMap)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)8 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)8 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)8 IndicatorType (org.hisp.dhis.indicator.IndicatorType)7 Test (org.junit.jupiter.api.Test)7 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)6 Period (org.hisp.dhis.period.Period)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Map (java.util.Map)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)2 DimensionItem (org.hisp.dhis.analytics.DimensionItem)2 DimensionalObjectUtils.asTypedList (org.hisp.dhis.common.DimensionalObjectUtils.asTypedList)2 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1