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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations