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