Search in sources :

Example 1 with RuleDataValue

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

the class RuleVariableValueMapBuilderShould method thrown_illegal_state_exception_on_duplicate_events.

@Test
public void thrown_illegal_state_exception_on_duplicate_events() {
    RuleEvent ruleEvent = RuleEvent.create("test_event_two", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), new ArrayList<RuleDataValue>());
    try {
        RuleVariableValueMapBuilder.target(ruleEvent).ruleVariables(new ArrayList<RuleVariable>()).ruleEvents(Arrays.asList(ruleEvent)).build();
        fail("IllegalStateException was expected, but nothing was thrown.");
    } catch (IllegalStateException illegalStateException) {
    // noop
    }
}
Also used : RuleDataValue(org.hisp.dhis.rules.models.RuleDataValue) RuleEvent(org.hisp.dhis.rules.models.RuleEvent) Date(java.util.Date) RuleVariable(org.hisp.dhis.rules.models.RuleVariable) Test(org.junit.Test)

Example 2 with RuleDataValue

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

the class RuleVariableValueMapBuilder method buildAllEventValues.

private void buildAllEventValues() {
    List<RuleEvent> events = new ArrayList<>(ruleEvents);
    if (ruleEvent != null) {
        // target event should be among the list of all
        // events in order to achieve correct behavior
        events.add(ruleEvent);
    }
    // sort list of events by eventDate:
    Collections.sort(events, RuleEvent.EVENT_DATE_COMPARATOR);
    // aggregating values by data element uid
    for (int i = 0; i < events.size(); i++) {
        RuleEvent ruleEvent = events.get(i);
        for (int j = 0; j < ruleEvent.dataValues().size(); j++) {
            RuleDataValue ruleDataValue = ruleEvent.dataValues().get(j);
            // push new list if it is not there for the given data element
            if (!allEventsValues.containsKey(ruleDataValue.dataElement())) {
                allEventsValues.put(ruleDataValue.dataElement(), // NOPMD
                new ArrayList<RuleDataValue>(events.size()));
            }
            // append data value to the list
            allEventsValues.get(ruleDataValue.dataElement()).add(ruleDataValue);
        }
    }
}
Also used : RuleDataValue(org.hisp.dhis.rules.models.RuleDataValue) ArrayList(java.util.ArrayList) RuleEvent(org.hisp.dhis.rules.models.RuleEvent)

Example 3 with RuleDataValue

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

the class RuleVariableValueMapBuilder method buildCurrentEventValues.

private void buildCurrentEventValues() {
    if (ruleEvent != null) {
        for (int index = 0; index < ruleEvent.dataValues().size(); index++) {
            RuleDataValue ruleDataValue = ruleEvent.dataValues().get(index);
            currentEventValues.put(ruleDataValue.dataElement(), ruleDataValue);
        }
    }
}
Also used : RuleDataValue(org.hisp.dhis.rules.models.RuleDataValue)

Example 4 with RuleDataValue

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

the class RuleVariableValueMapBuilder method createNewestStageEventVariableValue.

private void createNewestStageEventVariableValue(@Nonnull Map<String, RuleVariableValue> valueMap, @Nonnull RuleVariableNewestStageEvent variable) {
    List<RuleDataValue> stageRuleDataValues = new ArrayList<>();
    List<RuleDataValue> sourceRuleDataValues = allEventsValues.get(variable.dataElement());
    if (sourceRuleDataValues != null && !sourceRuleDataValues.isEmpty()) {
        // filter data values based on program stage
        for (int i = 0; i < sourceRuleDataValues.size(); i++) {
            RuleDataValue ruleDataValue = sourceRuleDataValues.get(i);
            if (variable.programStage().equals(ruleDataValue.programStage())) {
                stageRuleDataValues.add(ruleDataValue);
            }
        }
    }
    if (stageRuleDataValues.isEmpty()) {
        valueMap.put(variable.name(), create(variable.dataElementType()));
    } else {
        valueMap.put(variable.name(), create(stageRuleDataValues.get(0).value(), variable.dataElementType(), Utils.values(stageRuleDataValues)));
    }
}
Also used : RuleDataValue(org.hisp.dhis.rules.models.RuleDataValue) ArrayList(java.util.ArrayList)

Example 5 with RuleDataValue

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

the class RuleVariableValueMapBuilder method createCurrentEventVariableValue.

private void createCurrentEventVariableValue(@Nonnull Map<String, RuleVariableValue> valueMap, @Nonnull RuleVariableCurrentEvent variable) {
    if (ruleEvent == null) {
        return;
    }
    RuleVariableValue variableValue;
    if (currentEventValues.containsKey(variable.dataElement())) {
        RuleDataValue value = currentEventValues.get(variable.dataElement());
        variableValue = create(value.value(), variable.dataElementType(), Arrays.asList(value.value()));
    } else {
        variableValue = create(variable.dataElementType());
    }
    valueMap.put(variable.name(), variableValue);
}
Also used : RuleDataValue(org.hisp.dhis.rules.models.RuleDataValue)

Aggregations

RuleDataValue (org.hisp.dhis.rules.models.RuleDataValue)14 RuleEvent (org.hisp.dhis.rules.models.RuleEvent)10 Date (java.util.Date)7 Test (org.junit.Test)7 RuleVariable (org.hisp.dhis.rules.models.RuleVariable)6 RuleEngine (org.hisp.dhis.rules.RuleEngine)4 Rule (org.hisp.dhis.rules.models.Rule)4 RuleAction (org.hisp.dhis.rules.models.RuleAction)4 RuleEffect (org.hisp.dhis.rules.models.RuleEffect)4 ArrayList (java.util.ArrayList)3 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)2 Test (org.junit.jupiter.api.Test)2 RuleEnrollment (org.hisp.dhis.rules.models.RuleEnrollment)1