Search in sources :

Example 1 with ProgramRuleIssue

use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue in project dhis2-core by dhis2.

the class AssignValueImplementer method applyToEnrollments.

@Override
public List<ProgramRuleIssue> applyToEnrollments(Map.Entry<String, List<EnrollmentActionRule>> enrollmentActionRules, TrackerBundle bundle) {
    List<ProgramRuleIssue> issues = Lists.newArrayList();
    Boolean canOverwrite = systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE);
    for (EnrollmentActionRule actionRule : enrollmentActionRules.getValue()) {
        if (!actionRule.getAttribute().isPresent() || Boolean.TRUE.equals(canOverwrite) || isTheSameValue(actionRule, bundle.getPreheat())) {
            addOrOverwriteAttribute(actionRule, bundle);
            issues.add(new ProgramRuleIssue(actionRule.getRuleUid(), TrackerErrorCode.E1310, Lists.newArrayList(actionRule.getField(), actionRule.getValue()), IssueType.WARNING));
        } else {
            issues.add(new ProgramRuleIssue(actionRule.getRuleUid(), TrackerErrorCode.E1309, Lists.newArrayList(actionRule.getField(), actionRule.getEnrollment()), IssueType.ERROR));
        }
    }
    return issues;
}
Also used : EnrollmentActionRule(org.hisp.dhis.tracker.programrule.EnrollmentActionRule) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue)

Example 2 with ProgramRuleIssue

use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue in project dhis2-core by dhis2.

the class ValidationUtils method addIssuesToReporter.

public static void addIssuesToReporter(ValidationErrorReporter reporter, TrackerDto dto, List<ProgramRuleIssue> programRuleIssues) {
    programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(ERROR)).forEach(issue -> {
        List<String> args = Lists.newArrayList(issue.getRuleUid());
        args.addAll(issue.getArgs());
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    });
    programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(WARNING)).forEach(issue -> {
        List<String> args = Lists.newArrayList(issue.getRuleUid());
        args.addAll(issue.getArgs());
        TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
        reporter.addWarning(warning);
    });
}
Also used : WARNING(org.hisp.dhis.tracker.programrule.IssueType.WARNING) DataValue(org.hisp.dhis.tracker.domain.DataValue) ERROR(org.hisp.dhis.tracker.programrule.IssueType.ERROR) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Note(org.hisp.dhis.tracker.domain.Note) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) EventStatus(org.hisp.dhis.event.EventStatus) Collectors(java.util.stream.Collectors) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) FeatureType(org.hisp.dhis.organisationunit.FeatureType) TrackerDto(org.hisp.dhis.tracker.domain.TrackerDto) Geometry(org.locationtech.jts.geom.Geometry) GEOMETRY_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.GEOMETRY_CANT_BE_NULL) ValidationStrategy(org.hisp.dhis.program.ValidationStrategy) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 3 with ProgramRuleIssue

use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue in project dhis2-core by dhis2.

the class EventRuleValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    List<ProgramRuleIssue> programRuleIssues = validators.stream().flatMap(v -> v.validateEvents(context.getBundle()).getOrDefault(event.getEvent(), Lists.newArrayList()).stream()).collect(Collectors.toList());
    addIssuesToReporter(reporter, event, programRuleIssues);
}
Also used : ValidationUtils.addIssuesToReporter(org.hisp.dhis.tracker.validation.hooks.ValidationUtils.addIssuesToReporter) Event(org.hisp.dhis.tracker.domain.Event) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Collectors(java.util.stream.Collectors) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue)

Example 4 with ProgramRuleIssue

use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue in project dhis2-core by dhis2.

the class EnrollmentRuleValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    List<ProgramRuleIssue> programRuleIssues = validators.stream().flatMap(v -> v.validateEnrollments(context.getBundle()).getOrDefault(enrollment.getEnrollment(), Lists.newArrayList()).stream()).collect(Collectors.toList());
    addIssuesToReporter(reporter, enrollment, programRuleIssues);
}
Also used : ValidationUtils.addIssuesToReporter(org.hisp.dhis.tracker.validation.hooks.ValidationUtils.addIssuesToReporter) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Collectors(java.util.stream.Collectors) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue)

Example 5 with ProgramRuleIssue

use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue in project dhis2-core by dhis2.

the class AssignValueImplementer method applyToEvents.

@Override
public List<ProgramRuleIssue> applyToEvents(Map.Entry<String, List<EventActionRule>> eventClasses, TrackerBundle bundle) {
    List<ProgramRuleIssue> issues = Lists.newArrayList();
    Boolean canOverwrite = systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE);
    for (EventActionRule actionRule : eventClasses.getValue()) {
        if (!actionRule.getDataValue().isPresent() || Boolean.TRUE.equals(canOverwrite) || isTheSameValue(actionRule, bundle.getPreheat())) {
            addOrOverwriteDataValue(actionRule, bundle);
            issues.add(new ProgramRuleIssue(actionRule.getRuleUid(), TrackerErrorCode.E1308, Lists.newArrayList(actionRule.getField(), actionRule.getEvent()), IssueType.WARNING));
        } else {
            issues.add(new ProgramRuleIssue(actionRule.getRuleUid(), TrackerErrorCode.E1307, Lists.newArrayList(actionRule.getField(), actionRule.getValue()), IssueType.ERROR));
        }
    }
    return issues;
}
Also used : EventActionRule(org.hisp.dhis.tracker.programrule.EventActionRule) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue)

Aggregations

ProgramRuleIssue (org.hisp.dhis.tracker.programrule.ProgramRuleIssue)5 Lists (com.google.common.collect.Lists)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)3 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)3 Event (org.hisp.dhis.tracker.domain.Event)2 RuleActionImplementer (org.hisp.dhis.tracker.programrule.RuleActionImplementer)2 ValidationUtils.addIssuesToReporter (org.hisp.dhis.tracker.validation.hooks.ValidationUtils.addIssuesToReporter)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 StringUtils.isNotEmpty (org.apache.commons.lang3.StringUtils.isNotEmpty)1 EventStatus (org.hisp.dhis.event.EventStatus)1 FeatureType (org.hisp.dhis.organisationunit.FeatureType)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1 ValidationStrategy (org.hisp.dhis.program.ValidationStrategy)1 DataValue (org.hisp.dhis.tracker.domain.DataValue)1