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