Search in sources :

Example 6 with ProgramRule

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();
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) Program(org.hisp.dhis.program.Program) ProgramRule(org.hisp.dhis.programrule.ProgramRule) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Option(org.hisp.dhis.option.Option) ProgramStage(org.hisp.dhis.program.ProgramStage) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ProgramRule

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ProgramRule(org.hisp.dhis.programrule.ProgramRule) Matcher(java.util.regex.Matcher) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with ProgramRule

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);
}
Also used : ProgramRule(org.hisp.dhis.programrule.ProgramRule)

Example 9 with 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();
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ProgramRuleActionValidationResult(org.hisp.dhis.programrule.ProgramRuleActionValidationResult) ProgramRule(org.hisp.dhis.programrule.ProgramRule) Option(org.hisp.dhis.option.Option)

Example 10 with ProgramRule

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();
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ProgramRuleActionValidationResult(org.hisp.dhis.programrule.ProgramRuleActionValidationResult) OptionGroup(org.hisp.dhis.option.OptionGroup) ProgramRule(org.hisp.dhis.programrule.ProgramRule)

Aggregations

ProgramRule (org.hisp.dhis.programrule.ProgramRule)14 ErrorReport (org.hisp.dhis.feedback.ErrorReport)8 Program (org.hisp.dhis.program.Program)5 ProgramStage (org.hisp.dhis.program.ProgramStage)5 List (java.util.List)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 ProgramRuleAction (org.hisp.dhis.programrule.ProgramRuleAction)3 ProgramRuleActionValidationResult (org.hisp.dhis.programrule.ProgramRuleActionValidationResult)3 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)2 Option (org.hisp.dhis.option.Option)2 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 ObjectBundleParams (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams)1