use of org.hisp.dhis.programrule.ProgramRule in project dhis2-core by dhis2.
the class ProgramRuleActionValidationContextLoader method load.
@Transactional(readOnly = true)
public ProgramRuleActionValidationContext load(Preheat preheat, PreheatIdentifier preheatIdentifier, ProgramRuleAction ruleAction) {
ProgramRule rule = preheat.get(preheatIdentifier, ProgramRule.class, ruleAction.getProgramRule());
Program program = preheat.get(preheatIdentifier, Program.class, rule.getProgram());
List<ProgramStage> stages = preheat.getAll(preheatIdentifier, new ArrayList<>(program.getProgramStages()));
return ProgramRuleActionValidationContext.builder().programRule(rule).program(program).programStages(stages).dataElement(ruleAction.hasDataElement() ? preheat.get(preheatIdentifier, DataElement.class, ruleAction.getDataElement()) : null).trackedEntityAttribute(ruleAction.hasTrackedEntityAttribute() ? preheat.get(preheatIdentifier, TrackedEntityAttribute.class, ruleAction.getAttribute()) : null).notificationTemplate(ruleAction.hasNotification() ? preheat.get(preheatIdentifier, ProgramNotificationTemplate.class, ruleAction.getTemplateUid()) : null).programStageSection(ruleAction.hasProgramStageSection() ? preheat.get(preheatIdentifier, ProgramStageSection.class, ruleAction.getProgramStageSection()) : null).programStage(ruleAction.hasProgramStage() ? preheat.get(preheatIdentifier, ProgramStage.class, ruleAction.getProgramStage()) : null).option(ruleAction.hasOption() ? preheat.get(preheatIdentifier, Option.class, ruleAction.getOption()) : null).optionGroup(ruleAction.hasOptionGroup() ? preheat.get(preheatIdentifier, OptionGroup.class, ruleAction.getOptionGroup()) : null).programRuleActionValidationService(validationService).build();
}
use of org.hisp.dhis.programrule.ProgramRule in project dhis2-core by dhis2.
the class SupplementaryDataProvider method getSupplementaryData.
public Map<String, List<String>> getSupplementaryData(List<ProgramRule> programRules) {
List<String> orgUnitGroups = new ArrayList<>();
for (ProgramRule programRule : programRules) {
Matcher matcher = PATTERN.matcher(StringUtils.defaultIfBlank(programRule.getCondition(), ""));
while (matcher.find()) {
orgUnitGroups.add(StringUtils.replace(matcher.group(1), "'", ""));
}
}
Map<String, List<String>> supplementaryData = Maps.newHashMap();
if (!orgUnitGroups.isEmpty()) {
supplementaryData = orgUnitGroups.stream().collect(Collectors.toMap(g -> g, g -> organisationUnitGroupService.getOrganisationUnitGroup(g).getMembers().stream().map(OrganisationUnit::getUid).collect(Collectors.toList())));
}
if (currentUserService.getCurrentUser() != null) {
supplementaryData.put(USER, currentUserService.getCurrentUser().getUserAuthorityGroups().stream().map(UserAuthorityGroup::getUid).collect(Collectors.toList()));
}
return supplementaryData;
}
use of org.hisp.dhis.programrule.ProgramRule in project dhis2-core by dhis2.
the class SupplementaryDataProviderTest method getProgramRules.
private List<ProgramRule> getProgramRules() {
ProgramRule programRule = createProgramRule('A', null);
programRule.setCondition("d2:inOrgUnitGroup('OrgUnitGroupId')");
return Lists.newArrayList(programRule);
}
use of org.hisp.dhis.programrule.ProgramRule in project dhis2-core by dhis2.
the class HideOptionProgramRuleActionValidator method validate.
@Override
public ProgramRuleActionValidationResult validate(ProgramRuleAction programRuleAction, ProgramRuleActionValidationContext validationContext) {
// First checking the validity of DataElement and TEA
ProgramRuleActionValidationResult result = super.validate(programRuleAction, validationContext);
ProgramRule rule = validationContext.getProgramRule();
if (!result.isValid()) {
return result;
}
if (!programRuleAction.hasOption()) {
log.debug(String.format("Option cannot be null for program rule: %s ", rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4040, rule.getName())).build();
}
Option option = validationContext.getOption();
if (option == null) {
log.debug(String.format("Option %s associated with program rule %s does not exist", programRuleAction.getOption().getUid(), rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4041, programRuleAction.getOption().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 ShowHideOptionGroupProgramRuleActionValidator method validate.
@Override
public ProgramRuleActionValidationResult validate(ProgramRuleAction programRuleAction, ProgramRuleActionValidationContext validationContext) {
ProgramRule rule = validationContext.getProgramRule();
// First checking the validity of DataElement and TEA
ProgramRuleActionValidationResult result = super.validate(programRuleAction, validationContext);
if (!result.isValid()) {
return result;
}
if (!programRuleAction.hasOptionGroup()) {
log.debug(String.format("OptionGroup cannot be null for program rule: %s ", rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4040, rule.getName())).build();
}
OptionGroup optionGroup = validationContext.getOptionGroup();
if (optionGroup == null) {
optionGroup = validationContext.getProgramRuleActionValidationService().getOptionService().getOptionGroup(programRuleAction.getOptionGroup().getUid());
}
if (optionGroup == null) {
log.debug(String.format("OptionGroup: %s associated with program rule: %s does not exist", programRuleAction.getOptionGroup().getUid(), rule.getName()));
return ProgramRuleActionValidationResult.builder().valid(false).errorReport(new ErrorReport(Option.class, ErrorCode.E4043, programRuleAction.getOptionGroup().getUid(), rule.getName())).build();
}
return ProgramRuleActionValidationResult.builder().valid(true).build();
}
Aggregations