Search in sources :

Example 1 with EventOutputType

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

the class JdbcEventAnalyticsManager method getAggregateClause.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
     * Returns the count clause based on value dimension and output type.
     * 
     * @param params the {@link EventQueryParams}.
     * 
     * TODO include output type if aggregation type is count
     */
private String getAggregateClause(EventQueryParams params) {
    EventOutputType outputType = params.getOutputType();
    if (// TODO && isNumeric
    params.hasValueDimension()) {
        Assert.isTrue(params.getAggregationTypeFallback().isAggregateable(), "Event query aggregation type must be aggregatable");
        String function = params.getAggregationTypeFallback().getValue();
        String expression = statementBuilder.columnQuote(params.getValue().getUid());
        return function + "(" + expression + ")";
    } else if (params.hasEventProgramIndicatorDimension()) {
        String function = params.getProgramIndicator().getAggregationTypeFallback().getValue();
        function = TextUtils.emptyIfEqual(function, AggregationType.CUSTOM.getValue());
        String expression = programIndicatorService.getAnalyticsSQl(params.getProgramIndicator().getExpression(), params.getProgramIndicator().getAnalyticsType(), params.getEarliestStartDate(), params.getLatestEndDate());
        return function + "(" + expression + ")";
    } else {
        if (EventOutputType.TRACKED_ENTITY_INSTANCE.equals(outputType) && params.isProgramRegistration()) {
            return "count(distinct " + statementBuilder.columnQuote("tei") + ")";
        } else if (EventOutputType.ENROLLMENT.equals(outputType)) {
            return "count(distinct " + statementBuilder.columnQuote("pi") + ")";
        } else // EVENT
        {
            return "count(" + statementBuilder.columnQuote("psi") + ")";
        }
    }
}
Also used : DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) EventOutputType(org.hisp.dhis.analytics.EventOutputType)

Example 2 with EventOutputType

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

the class JdbcEnrollmentAnalyticsManager method getAggregateClause.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
     * Returns the count clause based on value dimension and output type.
     * 
     * TODO include output type if aggregation type is count
     */
private String getAggregateClause(EventQueryParams params) {
    EventOutputType outputType = params.getOutputType();
    if (// && isNumeric
    params.hasValueDimension()) {
        String function = params.getAggregationTypeFallback().getValue();
        String expression = statementBuilder.columnQuote(params.getValue().getUid());
        return function + "(" + expression + ")";
    } else if (params.hasEnrollmentProgramIndicatorDimension()) {
        String function = params.getProgramIndicator().getAggregationTypeFallback().getValue();
        function = TextUtils.emptyIfEqual(function, AggregationType.CUSTOM.getValue());
        String expression = programIndicatorService.getAnalyticsSQl(params.getProgramIndicator().getExpression(), params.getProgramIndicator().getAnalyticsType(), params.getEarliestStartDate(), params.getLatestEndDate());
        return function + "(" + expression + ")";
    } else {
        if (EventOutputType.TRACKED_ENTITY_INSTANCE.equals(outputType) && params.isProgramRegistration()) {
            return "count(distinct tei)";
        } else // EVENT
        {
            return "count(pi)";
        }
    }
}
Also used : DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) EventOutputType(org.hisp.dhis.analytics.EventOutputType)

Example 3 with EventOutputType

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

the class AbstractJdbcEventAnalyticsManager method getAggregateClause.

/**
 * Returns the count clause based on value dimension and output type.
 *
 * @param params the {@link EventQueryParams}.
 *
 *        TODO include output type if aggregation type is count
 */
protected String getAggregateClause(EventQueryParams params) {
    EventOutputType outputType = params.getOutputType();
    if (// TODO && isNumeric
    params.hasValueDimension()) {
        Assert.isTrue(params.getAggregationTypeFallback().getAggregationType().isAggregatable(), "Event query aggregation type must be aggregatable");
        String function = params.getAggregationTypeFallback().getAggregationType().getValue();
        String expression = quoteAlias(params.getValue().getUid());
        return function + "(" + expression + ")";
    } else if (params.hasProgramIndicatorDimension()) {
        String function = params.getProgramIndicator().getAggregationTypeFallback().getValue();
        function = TextUtils.emptyIfEqual(function, AggregationType.CUSTOM.getValue());
        String expression = programIndicatorService.getAnalyticsSql(params.getProgramIndicator().getExpression(), params.getProgramIndicator(), params.getEarliestStartDate(), params.getLatestEndDate());
        return function + "(" + expression + ")";
    } else {
        if (params.hasEnrollmentProgramIndicatorDimension()) {
            if (EventOutputType.TRACKED_ENTITY_INSTANCE.equals(outputType) && params.isProgramRegistration()) {
                return "count(distinct tei)";
            } else // EVENT
            {
                return "count(pi)";
            }
        } else {
            if (EventOutputType.TRACKED_ENTITY_INSTANCE.equals(outputType) && params.isProgramRegistration()) {
                return "count(distinct " + quoteAlias("tei") + ")";
            } else if (EventOutputType.ENROLLMENT.equals(outputType)) {
                if (params.hasEnrollmentProgramIndicatorDimension()) {
                    return "count(" + quoteAlias("pi") + ")";
                }
                return "count(distinct " + quoteAlias("pi") + ")";
            } else // EVENT
            {
                return "count(" + quoteAlias("psi") + ")";
            }
        }
    }
}
Also used : EventOutputType(org.hisp.dhis.analytics.EventOutputType)

Aggregations

EventOutputType (org.hisp.dhis.analytics.EventOutputType)3 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)2