use of org.hisp.dhis.validation.ValidationAnalysisParams in project dhis2-core by dhis2.
the class DataAnalysisController method getValidationRuleExpressionDetials.
@GetMapping("validationRulesExpression")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public ValidationRuleExpressionDetails getValidationRuleExpressionDetials(@RequestParam String validationRuleId, @RequestParam String periodId, @RequestParam String organisationUnitId, @RequestParam(required = false) String attributeOptionComboId) throws WebMessageException {
ValidationRule validationRule = validationRuleService.getValidationRule(validationRuleId);
if (validationRule == null) {
throw new WebMessageException(notFound("Can't find ValidationRule with id =" + validationRuleId));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
if (organisationUnit == null) {
throw new WebMessageException(notFound("Can't find OrganisationUnit with id =" + organisationUnitId));
}
Period period = periodService.getPeriod(periodId);
if (period == null) {
throw new WebMessageException(notFound("Can't find Period with id =" + periodId));
}
CategoryOptionCombo attributeOptionCombo;
if (attributeOptionComboId == null) {
attributeOptionCombo = categoryService.getDefaultCategoryOptionCombo();
} else {
attributeOptionCombo = categoryService.getCategoryOptionCombo(attributeOptionComboId);
if (attributeOptionCombo == null) {
throw new WebMessageException(notFound("Can't find AttributeOptionCombo with id = " + attributeOptionComboId));
}
}
ValidationAnalysisParams params = validationService.newParamsBuilder(Lists.newArrayList(validationRule), organisationUnit, Lists.newArrayList(period)).withAttributeOptionCombo(attributeOptionCombo).build();
return validationService.getValidationRuleExpressionDetails(params);
}
use of org.hisp.dhis.validation.ValidationAnalysisParams in project dhis2-core by dhis2.
the class ValidationAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
DataSet dataSet = dataSetService.getDataSet(ds);
Period selectedPeriod = PeriodType.getPeriodFromIsoString(pe);
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
attributeOptionCombo = dataElementCategoryService.getDefaultCategoryOptionCombo();
}
if (selectedPeriod == null || orgUnit == null || (multiOu && !orgUnit.hasChild())) {
return SUCCESS;
}
Period period = periodService.getPeriod(selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedPeriod.getPeriodType());
if (period == null) {
return SUCCESS;
}
List<OrganisationUnit> organisationUnits = new ArrayList<>();
if (!multiOu) {
organisationUnits.add(orgUnit);
} else {
organisationUnits.addAll(orgUnit.getChildren());
}
Collections.sort(organisationUnits);
Date from = new DateTime(period.getStartDate()).minusYears(2).toDate();
for (OrganisationUnit organisationUnit : organisationUnits) {
List<DeflatedDataValue> values = new ArrayList<>(minMaxOutlierAnalysisService.analyse(Sets.newHashSet(organisationUnit), dataSet.getDataElements(), Sets.newHashSet(period), null, from));
if (!values.isEmpty()) {
dataValues.put(organisationUnit.getUid(), values);
}
ValidationAnalysisParams params = validationService.newParamsBuilder(dataSet, organisationUnit, period).withAttributeOptionCombo(attributeOptionCombo).build();
List<ValidationResult> results = new ArrayList<>(validationService.validationAnalysis(params));
if (!results.isEmpty()) {
validationResults.put(organisationUnit.getUid(), results);
}
List<DataElementOperand> violations = validationService.validateRequiredComments(dataSet, period, organisationUnit, attributeOptionCombo);
log.info("Validation done for data set: '{}', period: '{}', org unit: '{}', validation rule count: {}, violations found: {}", dataSet.getUid(), period.getIsoDate(), organisationUnit.getUid(), params.getValidationRules().size(), violations.size());
if (!violations.isEmpty()) {
commentViolations.put(organisationUnit.getUid(), violations);
}
}
return dataValues.isEmpty() && validationResults.isEmpty() && commentViolations.isEmpty() ? SUCCESS : INPUT;
}
use of org.hisp.dhis.validation.ValidationAnalysisParams in project dhis2-core by dhis2.
the class MonitoringJob method execute.
@Override
@Transactional
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
notifier.clear(jobConfiguration).notify(jobConfiguration, "Monitoring data");
MonitoringJobParameters monitoringJobParameters = (MonitoringJobParameters) jobConfiguration.getJobParameters();
try {
List<Period> periods;
Collection<ValidationRule> validationRules;
List<String> groupUIDs = monitoringJobParameters.getValidationRuleGroups();
if (groupUIDs.isEmpty()) {
validationRules = validationRuleService.getValidationRulesWithNotificationTemplates();
} else {
validationRules = groupUIDs.stream().map(validationRuleService::getValidationRuleGroup).filter(Objects::nonNull).map(ValidationRuleGroup::getMembers).filter(Objects::nonNull).reduce(Sets.newHashSet(), SetUtils::union);
}
if (monitoringJobParameters.getRelativeStart() != 0 && monitoringJobParameters.getRelativeEnd() != 0) {
Date startDate = DateUtils.getDateAfterAddition(new Date(), monitoringJobParameters.getRelativeStart());
Date endDate = DateUtils.getDateAfterAddition(new Date(), monitoringJobParameters.getRelativeEnd());
periods = periodService.getPeriodsBetweenDates(startDate, endDate);
periods = ListUtils.union(periods, periodService.getIntersectionPeriods(periods));
} else {
periods = validationRules.stream().map(ValidationRule::getPeriodType).distinct().map((vr) -> Arrays.asList(vr.createPeriod(), vr.getPreviousPeriod(vr.createPeriod()))).reduce(Lists.newArrayList(), ListUtils::union);
}
ValidationAnalysisParams parameters = validationService.newParamsBuilder(validationRules, null, periods).withIncludeOrgUnitDescendants(true).withMaxResults(ValidationService.MAX_SCHEDULED_ALERTS).withSendNotifications(monitoringJobParameters.isSendNotifications()).withPersistResults(monitoringJobParameters.isPersistResults()).build();
validationService.validationAnalysis(parameters);
notifier.notify(jobConfiguration, INFO, "Monitoring process done", true);
} catch (RuntimeException ex) {
notifier.notify(jobConfiguration, ERROR, "Process failed: " + ex.getMessage(), true);
messageService.sendSystemErrorNotification("Monitoring process failed", ex);
throw ex;
}
}
use of org.hisp.dhis.validation.ValidationAnalysisParams 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.validation.ValidationAnalysisParams in project dhis2-core by dhis2.
the class ValidationController method validate.
@GetMapping("/dataSet/{ds}")
@ResponseBody
public ValidationSummary validate(@PathVariable String ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String aoc, HttpServletResponse response, Model model) throws WebMessageException {
DataSet dataSet = dataSetService.getDataSet(ds);
if (dataSet == null) {
throw new WebMessageException(conflict("Data set does not exist: " + ds));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(conflict("Period does not exist: " + pe));
}
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
if (orgUnit == null) {
throw new WebMessageException(conflict("Organisation unit does not exist: " + ou));
}
CategoryOptionCombo attributeOptionCombo = categoryService.getCategoryOptionCombo(aoc);
if (attributeOptionCombo == null) {
attributeOptionCombo = categoryService.getDefaultCategoryOptionCombo();
}
ValidationSummary summary = new ValidationSummary();
ValidationAnalysisParams params = validationService.newParamsBuilder(dataSet, orgUnit, period).withAttributeOptionCombo(attributeOptionCombo).build();
summary.setValidationRuleViolations(new ArrayList<>(validationService.validationAnalysis(params)));
summary.setCommentRequiredViolations(validationService.validateRequiredComments(dataSet, period, orgUnit, attributeOptionCombo));
return summary;
}
Aggregations