use of org.hisp.dhis.programrule.ProgramRuleAction in project dhis2-core by dhis2.
the class ProgramRuleIntegrationTest method setUpTest.
@Override
public void setUpTest() throws Exception {
renderService = _renderService;
userService = _userService;
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("tracker/simple_metadata.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
assertFalse(validationReport.hasErrorReports());
objectBundleService.commit(bundle);
Program program = bundle.getPreheat().get(PreheatIdentifier.UID, Program.class, "BFcipDERJnf");
Program programWithoutRegistration = bundle.getPreheat().get(PreheatIdentifier.UID, Program.class, "BFcipDERJne");
DataElement dataElement1 = bundle.getPreheat().get(PreheatIdentifier.UID, DataElement.class, "DATAEL00001");
DataElement dataElement2 = bundle.getPreheat().get(PreheatIdentifier.UID, DataElement.class, "DATAEL00002");
ProgramStage programStage = bundle.getPreheat().get(PreheatIdentifier.UID, ProgramStage.class, "NpsdDv6kKSO");
ProgramRuleVariable programRuleVariable = createProgramRuleVariableWithDataElement('A', program, dataElement2);
programRuleVariableService.addProgramRuleVariable(programRuleVariable);
ProgramRule programRuleA = createProgramRule('A', program);
programRuleA.setUid("ProgramRule");
programRuleService.addProgramRule(programRuleA);
ProgramRule programRuleWithoutRegistration = createProgramRule('W', programWithoutRegistration);
programRuleService.addProgramRule(programRuleWithoutRegistration);
ProgramRule programRuleB = createProgramRule('B', program);
programRuleB.setProgramStage(programStage);
programRuleService.addProgramRule(programRuleB);
ProgramRuleAction programRuleActionShowWarning = createProgramRuleAction('A', programRuleA);
programRuleActionShowWarning.setProgramRuleActionType(ProgramRuleActionType.SHOWWARNING);
programRuleActionShowWarning.setContent("WARNING");
programRuleActionService.addProgramRuleAction(programRuleActionShowWarning);
ProgramRuleAction programRuleActionAssign = createProgramRuleAction('C', programRuleA);
programRuleActionAssign.setProgramRuleActionType(ProgramRuleActionType.ASSIGN);
programRuleActionAssign.setData("#{ProgramRuleVariableA}");
programRuleActionAssign.setDataElement(dataElement1);
programRuleActionService.addProgramRuleAction(programRuleActionAssign);
ProgramRuleAction programRuleActionShowWarningForProgramStage = createProgramRuleAction('B', programRuleB);
programRuleActionShowWarningForProgramStage.setProgramRuleActionType(ProgramRuleActionType.SHOWWARNING);
programRuleActionShowWarningForProgramStage.setContent("PROGRAM STAGE WARNING");
programRuleActionService.addProgramRuleAction(programRuleActionShowWarningForProgramStage);
programRuleA.getProgramRuleActions().add(programRuleActionShowWarning);
programRuleA.getProgramRuleActions().add(programRuleActionAssign);
programRuleWithoutRegistration.getProgramRuleActions().add(programRuleActionShowWarning);
programRuleService.updateProgramRule(programRuleWithoutRegistration);
programRuleB.getProgramRuleActions().add(programRuleActionShowWarningForProgramStage);
programRuleService.updateProgramRule(programRuleB);
userA = userService.getUser("M5zQapPyTZI");
injectSecurityContext(userA);
}
use of org.hisp.dhis.programrule.ProgramRuleAction in project dhis2-core by dhis2.
the class BaseProgramRuleActionValidator method handleTrackedEntityAttribute.
private ProgramRuleActionValidationResult handleTrackedEntityAttribute(ProgramRuleActionValidationContext validationContext, ProgramRuleAction programRuleAction, Program program) {
ProgramRule rule = validationContext.getProgramRule();
TrackedEntityAttribute attribute = validationContext.getTrackedEntityAttribute();
if (attribute == null) {
log.debug(String.format("TrackedEntityAttribute: %s associated with program rule: %s does not exist", programRuleAction.getAttribute().getUid(), rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(TrackedEntityAttribute.class, ErrorCode.E4046, programRuleAction.getAttribute().getUid(), rule.getName())).build();
}
List<String> trackedEntityAttributes = program.getProgramAttributes().stream().map(att -> att.getAttribute().getUid()).collect(Collectors.toList());
if (!trackedEntityAttributes.contains(attribute.getUid())) {
log.debug(String.format("TrackedEntityAttribute: %s is not linked to any ProgramTrackedEntityAttribute", attribute.getUid()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(TrackedEntityAttribute.class, ErrorCode.E4048, attribute.getUid(), rule.getName())).build();
}
return ProgramRuleActionValidationResult.builder().valid(true).build();
}
use of org.hisp.dhis.programrule.ProgramRuleAction in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method setUpAssignValueAge.
private void setUpAssignValueAge() {
ProgramNotificationTemplate pnt = createNotification();
programNotificationTemplateStore.save(pnt);
ProgramRuleAction programRuleActionAssignValueAge = createProgramRuleAction('P', programRuleA2);
programRuleActionAssignValueAge.setProgramRuleActionType(ProgramRuleActionType.SENDMESSAGE);
programRuleActionAssignValueAge.setData(" d2:yearsBetween(#{AGE}, V{event_date})");
programRuleActionService.addProgramRuleAction(programRuleActionAssignValueAge);
programRuleA2.setProgramRuleActions(Sets.newHashSet(programRuleActionAssignValueAge));
programRuleService.updateProgramRule(programRuleA2);
}
use of org.hisp.dhis.programrule.ProgramRuleAction in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method setUpAssignValueDate.
private void setUpAssignValueDate() {
ProgramNotificationTemplate pnt = createNotification();
programNotificationTemplateStore.save(pnt);
ProgramRuleAction programRuleActionAssignValueDate = createProgramRuleAction('P', programRuleA2);
programRuleActionAssignValueDate.setProgramRuleActionType(ProgramRuleActionType.SENDMESSAGE);
programRuleActionAssignValueDate.setData(" d2:yearsBetween(#{DOB}, V{event_date})");
programRuleActionService.addProgramRuleAction(programRuleActionAssignValueDate);
programRuleA2.setProgramRuleActions(Sets.newHashSet(programRuleActionAssignValueDate));
programRuleA2.setCondition(" d2:hasValue(#{DOB})");
programRuleService.updateProgramRule(programRuleA2);
}
use of org.hisp.dhis.programrule.ProgramRuleAction in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method setUpScheduleMessage.
private void setUpScheduleMessage() {
scheduledDate = "2018-04-17";
pnt = createNotification();
programNotificationTemplateStore.save(pnt);
ProgramRuleAction programRuleActionForScheduleMessage = createProgramRuleAction('S', programRuleS);
programRuleActionForScheduleMessage.setProgramRuleActionType(ProgramRuleActionType.SCHEDULEMESSAGE);
programRuleActionForScheduleMessage.setTemplateUid(pnt.getUid());
programRuleActionForScheduleMessage.setContent("STATIC-TEXT-SCHEDULE");
programRuleActionForScheduleMessage.setData(dataExpression);
programRuleActionService.addProgramRuleAction(programRuleActionForScheduleMessage);
programRuleS.setProgramRuleActions(Sets.newHashSet(programRuleActionForScheduleMessage));
programRuleService.updateProgramRule(programRuleS);
}
Aggregations