Search in sources :

Example 1 with ValidationAnalysisParams

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) ValidationAnalysisParams(org.hisp.dhis.validation.ValidationAnalysisParams) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ValidationRule(org.hisp.dhis.validation.ValidationRule) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ValidationAnalysisParams

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) ValidationResult(org.hisp.dhis.validation.ValidationResult) DateTime(org.joda.time.DateTime) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ValidationAnalysisParams(org.hisp.dhis.validation.ValidationAnalysisParams) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 3 with ValidationAnalysisParams

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;
    }
}
Also used : Objects(java.util.Objects) Period(org.hisp.dhis.period.Period) ValidationAnalysisParams(org.hisp.dhis.validation.ValidationAnalysisParams) Date(java.util.Date) MonitoringJobParameters(org.hisp.dhis.scheduling.parameters.MonitoringJobParameters) ValidationRule(org.hisp.dhis.validation.ValidationRule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ValidationAnalysisParams

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);
}
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 5 with ValidationAnalysisParams

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ValidationSummary(org.hisp.dhis.validation.ValidationSummary) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Period(org.hisp.dhis.period.Period) ValidationAnalysisParams(org.hisp.dhis.validation.ValidationAnalysisParams) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ValidationAnalysisParams (org.hisp.dhis.validation.ValidationAnalysisParams)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Period (org.hisp.dhis.period.Period)4 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 DataSet (org.hisp.dhis.dataset.DataSet)2 ValidationResult (org.hisp.dhis.validation.ValidationResult)2 ValidationRule (org.hisp.dhis.validation.ValidationRule)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 Date (java.util.Date)1 Objects (java.util.Objects)1 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)1 DeflatedDataValue (org.hisp.dhis.datavalue.DeflatedDataValue)1 I18nFormat (org.hisp.dhis.i18n.I18nFormat)1 MonitoringJobParameters (org.hisp.dhis.scheduling.parameters.MonitoringJobParameters)1 ValidationRuleGroup (org.hisp.dhis.validation.ValidationRuleGroup)1 ValidationSummary (org.hisp.dhis.validation.ValidationSummary)1 ValidationResultComparator (org.hisp.dhis.validation.comparator.ValidationResultComparator)1