Search in sources :

Example 26 with DeflatedDataValue

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Date(java.util.Date) DateTime(org.joda.time.DateTime) DataElement(org.hisp.dhis.dataelement.DataElement) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) HashSet(java.util.HashSet) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 27 with DeflatedDataValue

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;
}
Also used : DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ListGrid(org.hisp.dhis.system.grid.ListGrid) I18n(org.hisp.dhis.i18n.I18n) GridHeader(org.hisp.dhis.common.GridHeader)

Example 28 with DeflatedDataValue

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());
}
Also used : DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) List(java.util.List) ArrayList(java.util.ArrayList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

DeflatedDataValue (org.hisp.dhis.datavalue.DeflatedDataValue)28 ArrayList (java.util.ArrayList)16 Period (org.hisp.dhis.period.Period)16 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)9 DataElement (org.hisp.dhis.dataelement.DataElement)9 List (java.util.List)7 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)6 DataExportParams (org.hisp.dhis.datavalue.DataExportParams)6 Grid (org.hisp.dhis.common.Grid)5 DataValue (org.hisp.dhis.datavalue.DataValue)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5 ListGrid (org.hisp.dhis.system.grid.ListGrid)5 DateTime (org.joda.time.DateTime)5 Date (java.util.Date)4 HashSet (java.util.HashSet)4 Slf4j (lombok.extern.slf4j.Slf4j)4 Collectors (java.util.stream.Collectors)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 MinMaxDataElement (org.hisp.dhis.minmax.MinMaxDataElement)3