Search in sources :

Example 1 with AggregationType

use of org.hisp.dhis.analytics.AggregationType in project dhis2-core by dhis2.

the class QueryPlannerUtils method getAggregationTypeDataElementMap.

/**
     * Creates a mapping between the aggregation type and data element for the
     * given data elements and period type.
     * 
     * @param params the data query parameters.
     */
public static ListMap<AggregationType, DimensionalItemObject> getAggregationTypeDataElementMap(DataQueryParams params) {
    List<DimensionalItemObject> dataElements = params.getDataElements();
    PeriodType aggregationPeriodType = PeriodType.getPeriodTypeByName(params.getPeriodType());
    ListMap<AggregationType, DimensionalItemObject> map = new ListMap<>();
    for (DimensionalItemObject element : dataElements) {
        DataElement de = (DataElement) element;
        AggregationType type = ObjectUtils.firstNonNull(params.getAggregationType(), de.getAggregationType());
        AggregationType aggregationType = getAggregationType(de.getValueType(), type, aggregationPeriodType, de.getPeriodType());
        map.putValue(aggregationType, de);
    }
    return map;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) DataElement(org.hisp.dhis.dataelement.DataElement) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) AggregationType(org.hisp.dhis.analytics.AggregationType) ListMap(org.hisp.dhis.common.ListMap)

Example 2 with AggregationType

use of org.hisp.dhis.analytics.AggregationType in project dhis2-core by dhis2.

the class QueryPlannerUtils method getAggregationType.

/**
     * Puts the given element into the map according to the value type, aggregation
     * operator, aggregation period type and data period type.
     * 
     * @param valueType the value type.
     * @param aggregationType the aggregation operator.
     * @param aggregationPeriodType the aggregation period type.
     * @param dataPeriodType the data period type.
     */
public static AggregationType getAggregationType(ValueType valueType, AggregationType aggregationType, PeriodType aggregationPeriodType, PeriodType dataPeriodType) {
    AggregationType type;
    boolean disaggregation = isDisaggregation(aggregationPeriodType, dataPeriodType);
    boolean number = valueType.isNumeric();
    if (aggregationType.isAverage() && ValueType.BOOLEAN == valueType) {
        type = AggregationType.AVERAGE_BOOL;
    } else if (AggregationType.AVERAGE_SUM_ORG_UNIT == aggregationType && number && disaggregation) {
        type = AggregationType.AVERAGE_SUM_INT_DISAGGREGATION;
    } else if (AggregationType.AVERAGE_SUM_ORG_UNIT == aggregationType && number) {
        type = AggregationType.AVERAGE_SUM_INT;
    } else if (AggregationType.AVERAGE == aggregationType && number && disaggregation) {
        type = AggregationType.AVERAGE_INT_DISAGGREGATION;
    } else if (AggregationType.AVERAGE == aggregationType && number) {
        type = AggregationType.AVERAGE_INT;
    } else {
        type = aggregationType;
    }
    return type;
}
Also used : AggregationType(org.hisp.dhis.analytics.AggregationType)

Example 3 with AggregationType

use of org.hisp.dhis.analytics.AggregationType in project dhis2-core by dhis2.

the class FunctionAggregationType method evaluate.

@Override
public Object evaluate(ExprContext ctx, CommonExpressionVisitor visitor) {
    AggregationType aggregationType = parseAggregationType(ctx.aggregationType.getText());
    QueryModifiers queryMods = visitor.getState().getQueryModsBuilder().aggregationType(aggregationType).build();
    return visitor.visitWithQueryMods(ctx.expr(0), queryMods);
}
Also used : QueryModifiers(org.hisp.dhis.common.QueryModifiers) AggregationType(org.hisp.dhis.analytics.AggregationType)

Aggregations

AggregationType (org.hisp.dhis.analytics.AggregationType)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 ListMap (org.hisp.dhis.common.ListMap)1 QueryModifiers (org.hisp.dhis.common.QueryModifiers)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 PeriodType (org.hisp.dhis.period.PeriodType)1