Search in sources :

Example 1 with DataAnalysisMeasures

use of org.hisp.dhis.dataanalysis.DataAnalysisMeasures in project dhis2-core by dhis2.

the class JdbcDataAnalysisStore method getDataAnalysisMeasures.

@Override
public List<DataAnalysisMeasures> getDataAnalysisMeasures(DataElement dataElement, Collection<CategoryOptionCombo> categoryOptionCombos, Collection<String> parentPaths, Date from) {
    List<DataAnalysisMeasures> measures = new ArrayList<>();
    if (categoryOptionCombos.isEmpty() || parentPaths.isEmpty()) {
        return measures;
    }
    String catOptionComboIds = TextUtils.getCommaDelimitedString(getIdentifiers(categoryOptionCombos));
    String matchPaths = "(";
    for (String path : parentPaths) {
        matchPaths += "ou.path like '" + path + "%' or ";
    }
    matchPaths = TextUtils.removeLastOr(matchPaths) + ") ";
    String sql = "select dv.sourceid, dv.categoryoptioncomboid, " + "avg(cast(dv.value as " + statementBuilder.getDoubleColumnType() + ")) as average, " + "stddev_pop(cast(dv.value as " + statementBuilder.getDoubleColumnType() + ")) as standarddeviation " + "from datavalue dv " + "inner join organisationunit ou on ou.organisationunitid = dv.sourceid " + "inner join period pe on dv.periodid = pe.periodid " + "where dv.dataelementid = " + dataElement.getId() + " " + "and dv.categoryoptioncomboid in (" + catOptionComboIds + ") " + "and pe.startdate >= '" + DateUtils.getMediumDateString(from) + "' " + "and " + matchPaths + "and dv.deleted is false " + "group by dv.sourceid, dv.categoryoptioncomboid";
    SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
    while (rowSet.next()) {
        int orgUnitId = rowSet.getInt(1);
        int categoryOptionComboId = rowSet.getInt(2);
        double average = rowSet.getDouble(3);
        double stdDev = rowSet.getDouble(4);
        if (stdDev != 0.0) {
            measures.add(new DataAnalysisMeasures(orgUnitId, categoryOptionComboId, average, stdDev));
        }
    }
    return measures;
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) ArrayList(java.util.ArrayList) TextUtils.getCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString) DataAnalysisMeasures(org.hisp.dhis.dataanalysis.DataAnalysisMeasures)

Aggregations

ArrayList (java.util.ArrayList)1 TextUtils.getCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString)1 DataAnalysisMeasures (org.hisp.dhis.dataanalysis.DataAnalysisMeasures)1 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)1