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;
}
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;
}
Aggregations