Search in sources :

Example 1 with ProgramRuleVariable

use of org.hisp.dhis.programrule.ProgramRuleVariable in project dhis2-core by dhis2.

the class ProgramRuleVariableObjectBundleHook method getProgramRuleVariableQuery.

private Query<ProgramRuleVariable> getProgramRuleVariableQuery(ProgramRuleVariable programRuleVariable) {
    Session session = sessionFactory.getCurrentSession();
    Query<ProgramRuleVariable> query = session.createQuery(FROM_PROGRAM_RULE_VARIABLE, ProgramRuleVariable.class);
    query.setParameter("name", programRuleVariable.getName());
    query.setParameter("programUid", programRuleVariable.getProgram().getUid());
    return query;
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Session(org.hibernate.Session)

Example 2 with ProgramRuleVariable

use of org.hisp.dhis.programrule.ProgramRuleVariable in project dhis2-core by dhis2.

the class ProgramRuleVariableIntegrationTest method shouldAssignValueTypeFromTrackedEntityAttributeToProgramRuleVariable.

@Test
public void shouldAssignValueTypeFromTrackedEntityAttributeToProgramRuleVariable() {
    Program program = programService.getProgram("BFcipDERJne");
    TrackedEntityAttribute trackedEntityAttribute = trackedEntityAttributeService.getTrackedEntityAttribute("sYn3tkL3XKa");
    List<ProgramRuleVariable> ruleVariables = programRuleVariableService.getProgramRuleVariable(program);
    ProgramRuleVariable prv = ruleVariables.stream().filter(r -> ProgramRuleVariableSourceType.TEI_ATTRIBUTE == r.getSourceType()).findFirst().get();
    assertEquals(trackedEntityAttribute.getValueType(), prv.getValueType());
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Program(org.hisp.dhis.program.Program) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with ProgramRuleVariable

use of org.hisp.dhis.programrule.ProgramRuleVariable in project dhis2-core by dhis2.

the class ProgramRuleVariableIntegrationTest method shouldAssignDefaultValueTypeToProgramRuleVariable.

@Test
public void shouldAssignDefaultValueTypeToProgramRuleVariable() {
    Program program = programService.getProgram("BFcipDERJne");
    List<ProgramRuleVariable> ruleVariables = programRuleVariableService.getProgramRuleVariable(program);
    ProgramRuleVariable prv = ruleVariables.stream().filter(r -> ProgramRuleVariableSourceType.CALCULATED_VALUE == r.getSourceType()).findFirst().get();
    assertEquals(ValueType.TEXT, prv.getValueType());
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Program(org.hisp.dhis.program.Program) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with ProgramRuleVariable

use of org.hisp.dhis.programrule.ProgramRuleVariable 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);
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) Program(org.hisp.dhis.program.Program) ProgramRule(org.hisp.dhis.programrule.ProgramRule) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) List(java.util.List) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 5 with ProgramRuleVariable

use of org.hisp.dhis.programrule.ProgramRuleVariable in project dhis2-core by dhis2.

the class DhisConvenienceTest method createProgramRuleVariableWithDataElement.

public static ProgramRuleVariable createProgramRuleVariableWithDataElement(char uniqueCharacter, Program parentProgram, DataElement dataElement) {
    ProgramRuleVariable programRuleVariable = new ProgramRuleVariable();
    programRuleVariable.setAutoFields();
    programRuleVariable.setName(PROGRAM_RULE_VARIABLE + uniqueCharacter);
    programRuleVariable.setProgram(parentProgram);
    programRuleVariable.setDataElement(dataElement);
    programRuleVariable.setSourceType(ProgramRuleVariableSourceType.DATAELEMENT_CURRENT_EVENT);
    programRuleVariable.setValueType(dataElement.getValueType());
    return programRuleVariable;
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable)

Aggregations

ProgramRuleVariable (org.hisp.dhis.programrule.ProgramRuleVariable)14 Test (org.junit.jupiter.api.Test)6 Program (org.hisp.dhis.program.Program)5 ErrorReport (org.hisp.dhis.feedback.ErrorReport)4 List (java.util.List)3 Session (org.hibernate.Session)3 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)3 ImmutableList (com.google.common.collect.ImmutableList)2 Collections (java.util.Collections)2 SessionFactory (org.hibernate.SessionFactory)2 Query (org.hibernate.query.Query)2 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)2 PROGRAM_RULE_VARIABLE_NAME_INVALID_KEYWORDS (org.hisp.dhis.dxf2.Constants.PROGRAM_RULE_VARIABLE_NAME_INVALID_KEYWORDS)2 E4051 (org.hisp.dhis.feedback.ErrorCode.E4051)2 E4052 (org.hisp.dhis.feedback.ErrorCode.E4052)2 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2