Search in sources :

Example 31 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class LockExceptionController method getLockExceptionCombinations.

@GetMapping(value = "/combinations", produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getLockExceptionCombinations() {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<LockException> lockExceptions = this.dataSetService.getLockExceptionCombinations();
    I18nFormat format = this.i18nManager.getI18nFormat();
    for (LockException lockException : lockExceptions) {
        lockException.getPeriod().setName(format.formatPeriod(lockException.getPeriod()));
    }
    Collections.sort(lockExceptions, new LockExceptionNameComparator());
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.toCollectionNode(LockException.class, new FieldFilterParams(lockExceptions, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) LockExceptionNameComparator(org.hisp.dhis.dataset.comparator.LockExceptionNameComparator) LockException(org.hisp.dhis.dataset.LockException) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 32 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class DataAnalysisController method performValidationRulesAnalysis.

@PostMapping(value = "/validationRules", consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public List<ValidationResultView> performValidationRulesAnalysis(@RequestBody ValidationRulesAnalysisParams validationRulesAnalysisParams, HttpSession session) throws WebMessageException {
    I18nFormat format = i18nManager.getI18nFormat();
    ValidationRuleGroup group = null;
    if (validationRulesAnalysisParams.getVrg() != null) {
        group = validationRuleService.getValidationRuleGroup(validationRulesAnalysisParams.getVrg());
    }
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(validationRulesAnalysisParams.getOu());
    if (organisationUnit == null) {
        throw new WebMessageException(badRequest("No organisation unit defined"));
    }
    ValidationAnalysisParams params = validationService.newParamsBuilder(group, organisationUnit, format.parseDate(validationRulesAnalysisParams.getStartDate()), format.parseDate(validationRulesAnalysisParams.getEndDate())).withIncludeOrgUnitDescendants(true).withPersistResults(validationRulesAnalysisParams.isPersist()).withSendNotifications(validationRulesAnalysisParams.isNotification()).withMaxResults(ValidationService.MAX_INTERACTIVE_ALERTS).build();
    List<ValidationResult> validationResults = validationService.validationAnalysis(params);
    validationResults.sort(new ValidationResultComparator());
    session.setAttribute(KEY_VALIDATION_RESULT, validationResults);
    session.setAttribute(KEY_ORG_UNIT, organisationUnit);
    return validationResultsListToResponse(validationResults);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ValidationRuleGroup(org.hisp.dhis.validation.ValidationRuleGroup) ValidationAnalysisParams(org.hisp.dhis.validation.ValidationAnalysisParams) ValidationResult(org.hisp.dhis.validation.ValidationResult) ValidationResultComparator(org.hisp.dhis.validation.comparator.ValidationResultComparator) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 33 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat 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 34 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat 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 35 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class DataAnalysisController method generateValidationRulesReportGridFromResults.

private Grid generateValidationRulesReportGridFromResults(List<ValidationResult> results, OrganisationUnit orgUnit) {
    Grid grid = new ListGrid();
    if (results != null) {
        I18nFormat format = i18nManager.getI18nFormat();
        I18n i18n = i18nManager.getI18n();
        grid.setTitle(i18n.getString("data_quality_report"));
        if (orgUnit != null) {
            grid.setSubtitle(orgUnit.getName());
        }
        grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("validation_rule"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("importance"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("left_side_description"), false, true));
        grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
        grid.addHeader(new GridHeader(i18n.getString("operator"), false, false));
        grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
        grid.addHeader(new GridHeader(i18n.getString("right_side_description"), false, true));
        for (ValidationResult validationResult : results) {
            OrganisationUnit unit = validationResult.getOrganisationUnit();
            Period period = validationResult.getPeriod();
            Importance importance = validationResult.getValidationRule().getImportance();
            Operator operator = validationResult.getValidationRule().getOperator();
            grid.addRow();
            grid.addValue(unit.getName());
            grid.addValue(format.formatPeriod(period));
            grid.addValue(validationResult.getValidationRule().getName());
            grid.addValue(i18n.getString(importance.toString().toLowerCase()));
            grid.addValue(validationResult.getValidationRule().getLeftSide().getDescription());
            grid.addValue(String.valueOf(validationResult.getLeftsideValue()));
            grid.addValue(i18n.getString(operator.toString()));
            grid.addValue(String.valueOf(validationResult.getRightsideValue()));
            grid.addValue(validationResult.getValidationRule().getRightSide().getDescription());
        }
    }
    return grid;
}
Also used : Importance(org.hisp.dhis.validation.Importance) Operator(org.hisp.dhis.expression.Operator) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) 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) ValidationResult(org.hisp.dhis.validation.ValidationResult) ListGrid(org.hisp.dhis.system.grid.ListGrid) I18n(org.hisp.dhis.i18n.I18n) GridHeader(org.hisp.dhis.common.GridHeader)

Aggregations

I18nFormat (org.hisp.dhis.i18n.I18nFormat)37 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)24 Period (org.hisp.dhis.period.Period)19 ArrayList (java.util.ArrayList)10 Date (java.util.Date)8 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Grid (org.hisp.dhis.common.Grid)5 IdScheme (org.hisp.dhis.common.IdScheme)5 I18n (org.hisp.dhis.i18n.I18n)5 ListGrid (org.hisp.dhis.system.grid.ListGrid)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 DeflatedDataValue (org.hisp.dhis.datavalue.DeflatedDataValue)4 User (org.hisp.dhis.user.User)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 HashMap (java.util.HashMap)3