Search in sources :

Example 1 with MeasureFilter

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

the class JdbcAnalyticsManager method getMeasureCriteriaSql.

/**
     * Returns a HAVING clause restricting the result based on the measure criteria
     */
private String getMeasureCriteriaSql(DataQueryParams params) {
    SqlHelper sqlHelper = new SqlHelper();
    String sql = " ";
    for (MeasureFilter filter : params.getMeasureCriteria().keySet()) {
        Double criterion = params.getMeasureCriteria().get(filter);
        sql += sqlHelper.havingAnd() + " " + getNumericValueColumn(params) + " " + OPERATOR_SQL_MAP.get(filter) + " " + criterion + " ";
    }
    return sql;
}
Also used : MeasureFilter(org.hisp.dhis.analytics.MeasureFilter) SqlHelper(org.hisp.dhis.commons.util.SqlHelper) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString)

Example 2 with MeasureFilter

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

the class JdbcAnalyticsManager method getPartitionSql.

/**
     * If preAggregationMeasureCriteria is specified, generates a query which
     * provides a filtered view of the data according to the criteria .If not, 
     * returns the full view of the partition.
     */
private String getPartitionSql(DataQueryParams params, String partition) {
    if (params.isDataType(DataType.NUMERIC) && !params.getPreAggregateMeasureCriteria().isEmpty()) {
        SqlHelper sqlHelper = new SqlHelper();
        String sql = "";
        sql += "(select * from " + partition + " ";
        for (MeasureFilter filter : params.getPreAggregateMeasureCriteria().keySet()) {
            Double criterion = params.getPreAggregateMeasureCriteria().get(filter);
            sql += sqlHelper.whereAnd() + " value " + OPERATOR_SQL_MAP.get(filter) + " " + criterion + " ";
        }
        sql += ") as " + partition;
        return sql;
    } else {
        return partition;
    }
}
Also used : MeasureFilter(org.hisp.dhis.analytics.MeasureFilter) SqlHelper(org.hisp.dhis.commons.util.SqlHelper) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString)

Aggregations

MeasureFilter (org.hisp.dhis.analytics.MeasureFilter)2 SqlHelper (org.hisp.dhis.commons.util.SqlHelper)2 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)2