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