Search in sources :

Example 1 with EnrollmentActionRule

use of org.hisp.dhis.tracker.programrule.EnrollmentActionRule 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 EnrollmentActionRule

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

the class AssignValueImplementer method isTheSameValue.

private boolean isTheSameValue(EnrollmentActionRule actionRule, TrackerPreheat preheat) {
    TrackedEntityAttribute attribute = preheat.get(TrackedEntityAttribute.class, actionRule.getField());
    String value = actionRule.getValue();
    Optional<Attribute> optionalAttribute = actionRule.getAttributes().stream().filter(at -> at.getAttribute().equals(actionRule.getField())).findAny();
    if (optionalAttribute.isPresent()) {
        return areEquals(value, optionalAttribute.get().getValue(), attribute.getValueType());
    }
    return false;
}
Also used : DataValue(org.hisp.dhis.tracker.domain.DataValue) RuleActionAssign(org.hisp.dhis.rules.models.RuleActionAssign) ValueType(org.hisp.dhis.common.ValueType) Attribute(org.hisp.dhis.tracker.domain.Attribute) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DataElement(org.hisp.dhis.dataelement.DataElement) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Lists(com.google.common.collect.Lists) Map(java.util.Map) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) Event(org.hisp.dhis.tracker.domain.Event) EventActionRule(org.hisp.dhis.tracker.programrule.EventActionRule) EnrollmentActionRule(org.hisp.dhis.tracker.programrule.EnrollmentActionRule) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Set(java.util.Set) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Sets(com.google.common.collect.Sets) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) Component(org.springframework.stereotype.Component) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) IssueType(org.hisp.dhis.tracker.programrule.IssueType) SettingKey(org.hisp.dhis.setting.SettingKey) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute)

Example 3 with EnrollmentActionRule

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

the class AssignValueImplementer method addOrOverwriteAttribute.

private void addOrOverwriteAttribute(EnrollmentActionRule actionRule, TrackerBundle bundle) {
    Enrollment enrollment = bundle.getEnrollment(actionRule.getEnrollment()).get();
    Optional<TrackedEntity> trackedEntity = bundle.getTrackedEntity(enrollment.getTrackedEntity());
    List<Attribute> attributes;
    if (trackedEntity.isPresent()) {
        attributes = trackedEntity.get().getAttributes();
        Optional<Attribute> optionalAttribute = attributes.stream().filter(at -> at.getAttribute().equals(actionRule.getField())).findAny();
        if (optionalAttribute.isPresent()) {
            optionalAttribute.get().setValue(actionRule.getData());
            return;
        }
    }
    attributes = enrollment.getAttributes();
    Optional<Attribute> optionalAttribute = attributes.stream().filter(at -> at.getAttribute().equals(actionRule.getField())).findAny();
    if (optionalAttribute.isPresent()) {
        optionalAttribute.get().setValue(actionRule.getData());
    } else {
        attributes.add(createAttribute(actionRule.getField(), actionRule.getData()));
    }
}
Also used : DataValue(org.hisp.dhis.tracker.domain.DataValue) RuleActionAssign(org.hisp.dhis.rules.models.RuleActionAssign) ValueType(org.hisp.dhis.common.ValueType) Attribute(org.hisp.dhis.tracker.domain.Attribute) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DataElement(org.hisp.dhis.dataelement.DataElement) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Lists(com.google.common.collect.Lists) Map(java.util.Map) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) Event(org.hisp.dhis.tracker.domain.Event) EventActionRule(org.hisp.dhis.tracker.programrule.EventActionRule) EnrollmentActionRule(org.hisp.dhis.tracker.programrule.EnrollmentActionRule) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Set(java.util.Set) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Sets(com.google.common.collect.Sets) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) Component(org.springframework.stereotype.Component) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) IssueType(org.hisp.dhis.tracker.programrule.IssueType) SettingKey(org.hisp.dhis.setting.SettingKey) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) Attribute(org.hisp.dhis.tracker.domain.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Enrollment(org.hisp.dhis.tracker.domain.Enrollment)

Aggregations

EnrollmentActionRule (org.hisp.dhis.tracker.programrule.EnrollmentActionRule)3 ProgramRuleIssue (org.hisp.dhis.tracker.programrule.ProgramRuleIssue)3 Lists (com.google.common.collect.Lists)2 Sets (com.google.common.collect.Sets)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 NumberUtils (org.apache.commons.lang3.math.NumberUtils)2 ValueType (org.hisp.dhis.common.ValueType)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 RuleActionAssign (org.hisp.dhis.rules.models.RuleActionAssign)2 SettingKey (org.hisp.dhis.setting.SettingKey)2 SystemSettingManager (org.hisp.dhis.setting.SystemSettingManager)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)2 Attribute (org.hisp.dhis.tracker.domain.Attribute)2 DataValue (org.hisp.dhis.tracker.domain.DataValue)2 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)2