use of org.hisp.dhis.system.objectmapper.DeflatedDataValueNameMinMaxRowMapper in project dhis2-core by dhis2.
the class JdbcDataAnalysisStore method getMinMaxViolations.
@Override
public List<DeflatedDataValue> getMinMaxViolations(Collection<DataElement> dataElements, Collection<DataElementCategoryOptionCombo> categoryOptionCombos, Collection<Period> periods, Collection<OrganisationUnit> parents, int limit) {
if (dataElements.isEmpty() || categoryOptionCombos.isEmpty() || periods.isEmpty() || parents.isEmpty()) {
return new ArrayList<>();
}
String dataElementIds = getCommaDelimitedString(getIdentifiers(dataElements));
String periodIds = getCommaDelimitedString(getIdentifiers(periods));
String categoryOptionComboIds = getCommaDelimitedString(getIdentifiers(categoryOptionCombos));
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, de.name as dataelementname, " + "pt.name as periodtypename, pe.startdate, pe.enddate, coc.name as categoryoptioncomboname, mm.minimumvalue, mm.maximumvalue " + "from datavalue dv " + "join minmaxdataelement mm on ( dv.dataelementid = mm.dataelementid and dv.categoryoptioncomboid = mm.categoryoptioncomboid and dv.sourceid = mm.sourceid ) " + "join dataelement de on dv.dataelementid = de.dataelementid " + "join period pe on dv.periodid = pe.periodid " + "join periodtype pt on pe.periodtypeid = pt.periodtypeid " + "join organisationunit ou on dv.sourceid = ou.organisationunitid " + "join categoryoptioncombo coc on dv.categoryoptioncomboid = coc.categoryoptioncomboid " + "where dv.dataelementid in (" + dataElementIds + ") " + "and dv.categoryoptioncomboid in (" + categoryOptionComboIds + ") " + "and dv.periodid in (" + periodIds + ") " + "and ( " + "cast( dv.value as " + statementBuilder.getDoubleColumnType() + " ) < mm.minimumvalue " + "or cast( dv.value as " + statementBuilder.getDoubleColumnType() + " ) > mm.maximumvalue ) " + "and (";
for (OrganisationUnit parent : parents) {
sql += "ou.path like '" + parent.getPath() + "%' or ";
}
sql = TextUtils.removeLastOr(sql) + ") ";
sql += "and dv.deleted is false ";
sql += statementBuilder.limitRecord(0, limit);
return jdbcTemplate.query(sql, new DeflatedDataValueNameMinMaxRowMapper(null, null));
}
use of org.hisp.dhis.system.objectmapper.DeflatedDataValueNameMinMaxRowMapper 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