Search in sources :

Example 1 with EventActionRule

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

Example 2 with EventActionRule

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

the class AssignValueImplementer method isTheSameValue.

private boolean isTheSameValue(EventActionRule actionRule, TrackerPreheat preheat) {
    DataElement dataElement = preheat.get(DataElement.class, actionRule.getField());
    String dataValue = actionRule.getValue();
    Optional<DataValue> optionalDataValue = actionRule.getDataValues().stream().filter(dv -> dv.getDataElement().equals(actionRule.getField())).findAny();
    if (optionalDataValue.isPresent()) {
        return areEquals(dataValue, optionalDataValue.get().getValue(), dataElement.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) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue)

Aggregations

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