use of org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString in project dhis2-core by dhis2.
the class JdbcDataAnalysisStore method getDeflatedDataValues.
private List<DeflatedDataValue> getDeflatedDataValues(DataElement dataElement, CategoryOptionCombo categoryOptionCombo, Collection<Period> periods, List<Long> organisationUnits, Map<Long, Integer> lowerBoundMap, Map<Long, Integer> upperBoundMap) {
String periodIds = TextUtils.getCommaDelimitedString(getIdentifiers(periods));
// @formatter:off
String sql = "select dv.dataelementid, dv.periodid, dv.sourceid, " + "dv.categoryoptioncomboid, dv.attributeoptioncomboid, dv.value, dv.storedby, dv.lastupdated, " + "dv.created, dv.comment, dv.followup, ou.name as sourcename, " + "? as dataelementname, pt.name as periodtypename, pe.startdate, pe.enddate, " + "? as categoryoptioncomboname " + "from datavalue dv " + "inner join period pe on dv.periodid = pe.periodid " + "inner join periodtype pt on pe.periodtypeid = pt.periodtypeid " + "inner join organisationunit ou on dv.sourceid = ou.organisationunitid " + "where dv.dataelementid = " + dataElement.getId() + " " + "and dv.categoryoptioncomboid = " + categoryOptionCombo.getId() + " " + "and dv.periodid in (" + periodIds + ") and (";
for (Long orgUnitUid : organisationUnits) {
sql += "(dv.sourceid = " + orgUnitUid + " " + "and (cast( dv.value as " + statementBuilder.getDoubleColumnType() + " ) < " + lowerBoundMap.get(orgUnitUid) + " " + "or cast(dv.value as " + statementBuilder.getDoubleColumnType() + ") > " + upperBoundMap.get(orgUnitUid) + ")) or ";
}
sql = TextUtils.removeLastOr(sql) + ") ";
sql += "and dv.deleted is false ";
PreparedStatementSetter pss = (ps) -> {
ps.setString(1, dataElement.getName());
ps.setString(2, categoryOptionCombo.getName());
};
return jdbcTemplate.query(sql, pss, new DeflatedDataValueNameMinMaxRowMapper(lowerBoundMap, upperBoundMap));
}
use of org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString 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;
}
use of org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString in project dhis2-core by dhis2.
the class JdbcDataAnalysisStore method getDeflatedDataValues.
private List<DeflatedDataValue> getDeflatedDataValues(DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, List<Integer> organisationUnits, Map<Integer, Integer> lowerBoundMap, Map<Integer, Integer> upperBoundMap) {
String periodIds = TextUtils.getCommaDelimitedString(getIdentifiers(periods));
String sql = "select dv.dataelementid, dv.periodid, dv.sourceid, dv.categoryoptioncomboid, dv.value, dv.storedby, dv.lastupdated, " + "dv.created, dv.comment, dv.followup, ou.name as sourcename, " + "'" + dataElement.getName() + "' as dataelementname, pt.name as periodtypename, pe.startdate, pe.enddate, " + "'" + categoryOptionCombo.getName() + "' as categoryoptioncomboname " + "from datavalue dv " + "join period pe on dv.periodid = pe.periodid " + "join periodtype pt on pe.periodtypeid = pt.periodtypeid " + "join organisationunit ou on dv.sourceid = ou.organisationunitid " + "where dv.dataelementid = " + dataElement.getId() + " " + "and dv.categoryoptioncomboid = " + categoryOptionCombo.getId() + " " + "and dv.periodid in (" + periodIds + ") and ( ";
for (Integer orgUnitUid : organisationUnits) {
sql += "( dv.sourceid = " + orgUnitUid + " " + "and ( cast( dv.value as " + statementBuilder.getDoubleColumnType() + " ) < " + lowerBoundMap.get(orgUnitUid) + " " + "or cast( dv.value as " + statementBuilder.getDoubleColumnType() + " ) > " + upperBoundMap.get(orgUnitUid) + " ) ) or ";
}
sql = TextUtils.removeLastOr(sql) + " ) ";
sql += "and dv.deleted is false ";
return jdbcTemplate.query(sql, new DeflatedDataValueNameMinMaxRowMapper(lowerBoundMap, upperBoundMap));
}
Aggregations