Search in sources :

Example 11 with ProgramRule

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();
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramRule(org.hisp.dhis.programrule.ProgramRule) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 12 with ProgramRule

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

Example 13 with ProgramRule

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();
}
Also used : ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) Program(org.hisp.dhis.program.Program) ProgramRule(org.hisp.dhis.programrule.ProgramRule)

Example 14 with ProgramRule

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;
}
Also used : 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