use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.
the class DataAnalysisController method performMinMaxOutlierAnalysis.
@PostMapping(value = "/minMaxOutlier", consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public List<DeflatedDataValue> performMinMaxOutlierAnalysis(@RequestBody DataAnalysisParams params, HttpSession session) throws WebMessageException {
I18nFormat format = i18nManager.getI18nFormat();
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(params.getOu());
if (organisationUnit == null) {
throw new WebMessageException(badRequest("No organisation unit defined"));
}
Collection<Period> periods = periodService.getPeriodsBetweenDates(format.parseDate(params.getStartDate()), format.parseDate(params.getEndDate()));
Set<DataElement> dataElements = new HashSet<>();
if (params.getDs() != null) {
for (String uid : params.getDs()) {
dataElements.addAll(dataSetService.getDataSet(uid).getDataElements());
}
}
Date from = new DateTime(format.parseDate(params.getStartDate())).minusYears(2).toDate();
log.info("From date: " + params.getStartDate() + ", To date: " + params.getEndDate() + ", Organisation unit: " + organisationUnit);
log.info("Nr of data elements: " + dataElements.size() + " Nr of periods: " + periods.size() + " for Min Max Outlier Analysis");
List<DeflatedDataValue> dataValues = new ArrayList<>(minMaxOutlierAnalysisService.analyse(Sets.newHashSet(organisationUnit), dataElements, periods, null, from));
session.setAttribute(KEY_ANALYSIS_DATA_VALUES, dataValues);
session.setAttribute(KEY_ORG_UNIT, organisationUnit);
return deflatedValuesListToResponse(dataValues);
}
use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.
the class DataAnalysisController method generateAnalysisReportGridFromResults.
private Grid generateAnalysisReportGridFromResults(List<DeflatedDataValue> results, OrganisationUnit orgUnit) {
Grid grid = new ListGrid();
if (results != null) {
I18nFormat format = i18nManager.getI18nFormat();
I18n i18n = i18nManager.getI18n();
grid.setTitle(i18n.getString("data_analysis_report"));
if (orgUnit != null) {
grid.setSubtitle(orgUnit.getName());
}
grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
grid.addHeader(new GridHeader(i18n.getString("min"), false, false));
grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
grid.addHeader(new GridHeader(i18n.getString("max"), false, false));
for (DeflatedDataValue dataValue : results) {
Period period = dataValue.getPeriod();
grid.addRow();
grid.addValue(dataValue.getDataElementName());
grid.addValue(dataValue.getSourceName());
grid.addValue(format.formatPeriod(period));
grid.addValue(dataValue.getMin());
grid.addValue(dataValue.getValue());
grid.addValue(dataValue.getMax());
}
}
return grid;
}
use of org.hisp.dhis.datavalue.DeflatedDataValue in project dhis2-core by dhis2.
the class DataAnalysisController method getXlsReport.
@GetMapping("/report.xls")
public void getXlsReport(HttpSession session, HttpServletResponse response) throws Exception {
@SuppressWarnings("unchecked") List<DeflatedDataValue> results = (List<DeflatedDataValue>) session.getAttribute(KEY_ANALYSIS_DATA_VALUES);
Grid grid = generateAnalysisReportGridFromResults(results, (OrganisationUnit) session.getAttribute(KEY_ORG_UNIT));
String filename = filenameEncode(grid.getTitle()) + ".xls";
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, false);
GridUtils.toXls(grid, response.getOutputStream());
}
Aggregations