Search in sources :

Example 1 with RuleVariableAttribute

use of org.hisp.dhis.rules.models.RuleVariableAttribute in project dhis2-android-sdk by dhis2.

the class RuleVariableValueMapBuilder method buildRuleVariableValues.

private void buildRuleVariableValues(@Nonnull Map<String, RuleVariableValue> valueMap) {
    for (RuleVariable ruleVariable : ruleVariables) {
        if (ruleVariable instanceof RuleVariableAttribute) {
            RuleVariableAttribute ruleVariableAttribute = (RuleVariableAttribute) ruleVariable;
            createAttributeVariableValue(valueMap, ruleVariableAttribute);
        } else if (ruleVariable instanceof RuleVariableCurrentEvent) {
            RuleVariableCurrentEvent currentEventVariable = (RuleVariableCurrentEvent) ruleVariable;
            createCurrentEventVariableValue(valueMap, currentEventVariable);
        } else if (ruleVariable instanceof RuleVariablePreviousEvent) {
            RuleVariablePreviousEvent ruleVariablePreviousEvent = (RuleVariablePreviousEvent) ruleVariable;
            createPreviousEventVariableValue(valueMap, ruleVariablePreviousEvent);
        } else if (ruleVariable instanceof RuleVariableNewestEvent) {
            RuleVariableNewestEvent ruleVariableNewestEvent = (RuleVariableNewestEvent) ruleVariable;
            createNewestEventVariableValue(valueMap, ruleVariableNewestEvent);
        } else if (ruleVariable instanceof RuleVariableNewestStageEvent) {
            RuleVariableNewestStageEvent ruleVariableNewestEvent = (RuleVariableNewestStageEvent) ruleVariable;
            createNewestStageEventVariableValue(valueMap, ruleVariableNewestEvent);
        } else {
            throw new IllegalArgumentException("Unsupported RuleVariable type: " + ruleVariable.getClass());
        }
    }
}
Also used : RuleVariablePreviousEvent(org.hisp.dhis.rules.models.RuleVariablePreviousEvent) RuleVariableNewestStageEvent(org.hisp.dhis.rules.models.RuleVariableNewestStageEvent) RuleVariableAttribute(org.hisp.dhis.rules.models.RuleVariableAttribute) RuleVariableCurrentEvent(org.hisp.dhis.rules.models.RuleVariableCurrentEvent) RuleVariableNewestEvent(org.hisp.dhis.rules.models.RuleVariableNewestEvent) RuleVariable(org.hisp.dhis.rules.models.RuleVariable)

Example 2 with RuleVariableAttribute

use of org.hisp.dhis.rules.models.RuleVariableAttribute in project dhis2-core by dhis2.

the class ProgramRuleEntityMapperServiceTest method testMappedRuleVariableValues.

@Test
void testMappedRuleVariableValues() {
    when(programRuleVariableService.getAllProgramRuleVariable()).thenReturn(programRuleVariables);
    RuleVariableAttribute ruleVariableAttribute;
    RuleVariableCalculatedValue ruleVariableCalculatedValue;
    List<RuleVariable> ruleVariables = subject.toMappedProgramRuleVariables();
    assertEquals(ruleVariables.size(), 3);
    for (RuleVariable variable : ruleVariables) {
        if (variable instanceof RuleVariableAttribute) {
            ruleVariableAttribute = (RuleVariableAttribute) variable;
            assertEquals(ruleVariableAttribute.trackedEntityAttribute(), programRuleVariableB.getAttribute().getUid());
            assertEquals(ruleVariableAttribute.name(), programRuleVariableB.getName());
        }
        if (variable instanceof RuleVariableCalculatedValue) {
            ruleVariableCalculatedValue = (RuleVariableCalculatedValue) variable;
            assertEquals(ruleVariableCalculatedValue.name(), programRuleVariableA.getName());
        }
    }
}
Also used : RuleVariableAttribute(org.hisp.dhis.rules.models.RuleVariableAttribute) RuleVariableCalculatedValue(org.hisp.dhis.rules.models.RuleVariableCalculatedValue) RuleVariable(org.hisp.dhis.rules.models.RuleVariable) ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

RuleVariable (org.hisp.dhis.rules.models.RuleVariable)2 RuleVariableAttribute (org.hisp.dhis.rules.models.RuleVariableAttribute)2 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 ProgramRuleVariable (org.hisp.dhis.programrule.ProgramRuleVariable)1 RuleVariableCalculatedValue (org.hisp.dhis.rules.models.RuleVariableCalculatedValue)1 RuleVariableCurrentEvent (org.hisp.dhis.rules.models.RuleVariableCurrentEvent)1 RuleVariableNewestEvent (org.hisp.dhis.rules.models.RuleVariableNewestEvent)1 RuleVariableNewestStageEvent (org.hisp.dhis.rules.models.RuleVariableNewestStageEvent)1 RuleVariablePreviousEvent (org.hisp.dhis.rules.models.RuleVariablePreviousEvent)1 Test (org.junit.jupiter.api.Test)1