use of org.hisp.dhis.programrule.ProgramRule in project dhis2-core by dhis2.
the class BaseProgramRuleActionValidator method handleDataElement.
private ProgramRuleActionValidationResult handleDataElement(ProgramRuleActionValidationContext validationContext, ProgramRuleAction programRuleAction, Program program) {
ProgramRule rule = validationContext.getProgramRule();
DataElement dataElement = validationContext.getDataElement();
if (dataElement == null) {
log.debug(String.format("DataElement: %s associated with program rule: %s does not exist", programRuleAction.getDataElement().getUid(), rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(DataElement.class, ErrorCode.E4045, programRuleAction.getDataElement().getUid(), rule.getName())).build();
}
List<ProgramStage> stages = validationContext.getProgramStages();
if (stages == null || stages.isEmpty()) {
stages = validationContext.getProgramRuleActionValidationService().getProgramStageService().getProgramStagesByProgram(program);
}
Set<String> dataElements = stages.stream().flatMap(s -> s.getDataElements().stream()).map(DataElement::getUid).collect(Collectors.toSet());
if (!dataElements.contains(dataElement.getUid())) {
log.debug(String.format("DataElement: %s is not linked to any ProgramStageDataElement", dataElement.getUid()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(DataElement.class, ErrorCode.E4047, dataElement.getUid(), rule.getName())).build();
}
return ProgramRuleActionValidationResult.builder().valid(true).build();
}
use of org.hisp.dhis.programrule.ProgramRule in project dhis2-core by dhis2.
the class HideSectionProgramRuleActionValidator method validate.
@Override
public ProgramRuleActionValidationResult validate(ProgramRuleAction programRuleAction, ProgramRuleActionValidationContext validationContext) {
ProgramRule rule = validationContext.getProgramRule();
if (!programRuleAction.hasProgramStageSection()) {
log.debug(String.format("ProgramStageSection cannot be null for program rule: %s ", rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(ProgramStageSection.class, ErrorCode.E4036, rule.getName())).build();
}
ProgramStageSection stageSection = validationContext.getProgramStageSection();
if (stageSection == null) {
stageSection = validationContext.getProgramRuleActionValidationService().getSectionService().getProgramStageSection(programRuleAction.getProgramStageSection().getUid());
}
if (stageSection == null) {
log.debug(String.format("ProgramStageSection: %s associated with program rule: %s does not exist", programRuleAction.getProgramStageSection().getUid(), rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(ProgramStageSection.class, ErrorCode.E4037, programRuleAction.getProgramStageSection().getUid(), rule.getName())).build();
}
return ProgramRuleActionValidationResult.builder().valid(true).build();
}
use of org.hisp.dhis.programrule.ProgramRule in project dhis2-core by dhis2.
the class TrackerProgramRuleBundleServiceTest method initTest.
@Override
protected void initTest() throws IOException {
ObjectBundle bundle = setUpMetadata("tracker/event_metadata.json");
ProgramRule programRule = createProgramRule('A', bundle.getPreheat().get(PreheatIdentifier.UID, Program.class, "BFcipDERJwr"));
programRuleService.addProgramRule(programRule);
ProgramRuleAction programRuleAction = createProgramRuleAction('A', programRule);
programRuleAction.setProgramRuleActionType(ProgramRuleActionType.SENDMESSAGE);
programRuleActionService.addProgramRuleAction(programRuleAction);
programRule.setProgramRuleActions(Sets.newHashSet(programRuleAction));
programRuleService.updateProgramRule(programRule);
manager.flush();
}
use of org.hisp.dhis.programrule.ProgramRule in project dhis2-core by dhis2.
the class DhisConvenienceTest method createProgramRule.
public static ProgramRule createProgramRule(char uniqueCharacter, Program parentProgram) {
ProgramRule programRule = new ProgramRule();
programRule.setAutoFields();
programRule.setName("ProgramRule" + uniqueCharacter);
programRule.setProgram(parentProgram);
programRule.setCondition("true");
return programRule;
}
Aggregations