use of org.hisp.dhis.rules.models.RuleEvent in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method return_immutable_map.
@Test
public void return_immutable_map() throws ParseException {
RuleEvent ruleEvent = mock(RuleEvent.class);
when(ruleEvent.event()).thenReturn("test_event_uid");
when(ruleEvent.eventDate()).thenReturn(dateFormat.parse("1994-02-03"));
when(ruleEvent.dueDate()).thenReturn(dateFormat.parse("1995-02-03"));
try {
RuleVariableValueMapBuilder.target(ruleEvent).ruleVariables(new ArrayList<RuleVariable>()).build().clear();
fail("UnsupportedOperationException expected, but nothing was thrown");
} catch (UnsupportedOperationException exception) {
// noop
}
}
use of org.hisp.dhis.rules.models.RuleEvent in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method propagate_to_map_correctly_the_given_rule_enrollment_values.
@Test
public void propagate_to_map_correctly_the_given_rule_enrollment_values() throws ParseException {
RuleVariable ruleVariableOne = RuleVariableAttribute.create("test_variable_one", "test_attribute_one", RuleValueType.NUMERIC);
RuleVariable ruleVariableTwo = RuleVariableAttribute.create("test_variable_two", "test_attribute_two", RuleValueType.TEXT);
RuleVariable ruleVariableThree = RuleVariableCurrentEvent.create("test_variable_three", "test_dataelement_one", RuleValueType.BOOLEAN);
String currentDate = dateFormat.format(new Date());
Date enrollmentDate = dateFormat.parse("2017-02-02");
Date incidentDate = dateFormat.parse("2017-04-02");
RuleEnrollment ruleEnrollment = RuleEnrollment.create("test_enrollment", incidentDate, enrollmentDate, RuleEnrollment.Status.ACTIVE, Arrays.asList(RuleAttributeValue.create("test_attribute_one", "test_attribute_value_one"), RuleAttributeValue.create("test_attribute_two", "test_attribute_value_two"), RuleAttributeValue.create("test_attribute_three", "test_attribute_value_three")));
RuleEvent ruleEventOne = RuleEvent.create("test_event_one", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), new ArrayList<RuleDataValue>());
RuleEvent ruleEventTwo = RuleEvent.create("test_event_two", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), new ArrayList<RuleDataValue>());
Map<String, RuleVariableValue> valueMap = RuleVariableValueMapBuilder.target(ruleEnrollment).ruleVariables(Arrays.asList(ruleVariableOne, ruleVariableTwo, ruleVariableThree)).ruleEvents(Arrays.asList(ruleEventOne, ruleEventTwo)).build();
assertThat(valueMap.size()).isEqualTo(9);
assertThatVariable(valueMap.get("current_date")).hasValue(wrap(currentDate)).isTypeOf(RuleValueType.TEXT).hasCandidates(currentDate);
assertThatVariable(valueMap.get("event_count")).hasValue("2").isTypeOf(RuleValueType.NUMERIC).hasCandidates("2");
assertThatVariable(valueMap.get("enrollment_date")).hasValue(wrap(dateFormat.format(enrollmentDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(enrollmentDate));
assertThatVariable(valueMap.get("enrollment_id")).hasValue("'test_enrollment'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_enrollment");
assertThatVariable(valueMap.get("enrollment_count")).hasValue("1").isTypeOf(RuleValueType.NUMERIC).hasCandidates("1");
assertThatVariable(valueMap.get("incident_date")).hasValue(wrap(dateFormat.format(incidentDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(incidentDate));
assertThatVariable(valueMap.get("tei_count")).hasValue("1").isTypeOf(RuleValueType.NUMERIC).hasCandidates("1");
assertThatVariable(valueMap.get("test_variable_one")).hasValue("test_attribute_value_one").isTypeOf(RuleValueType.NUMERIC).hasCandidates("test_attribute_value_one");
assertThatVariable(valueMap.get("test_variable_two")).isTypeOf(RuleValueType.TEXT).hasValue("'test_attribute_value_two'").hasCandidates("test_attribute_value_two");
}
use of org.hisp.dhis.rules.models.RuleEvent in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method contain_data_element_value_in_a_variable_when_create_multiple_rules.
@Test
public void contain_data_element_value_in_a_variable_when_create_multiple_rules() throws ParseException {
RuleVariable ruleVariableOne = RuleVariableCurrentEvent.create("test_variable_one", "test_dataelement_one", RuleValueType.TEXT);
RuleVariable ruleVariableTwo = RuleVariableCurrentEvent.create("test_variable_two", "test_dataelement_two", RuleValueType.TEXT);
Date eventDate = dateFormat.parse("2015-01-01");
Date dueDate = dateFormat.parse("2016-01-01");
// values from context ruleEvents should be ignored
RuleEvent contextEventOne = RuleEvent.create("test_context_event_one", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), Arrays.asList(RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_one", "test_context_value_one"), RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_two", "test_context_value_two")));
RuleEvent contextEventTwo = RuleEvent.create("test_context_event_two", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), Arrays.asList(RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_one", "test_context_value_three"), RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_two", "test_context_value_four")));
// values from current ruleEvent should be propagated to the variable values
RuleEvent currentEvent = RuleEvent.create("test_event_uid", "test_program_stage", RuleEvent.Status.ACTIVE, eventDate, dueDate, Arrays.asList(RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_one", "test_value_one"), RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_two", "test_value_two")));
Map<String, RuleVariableValue> valueMap = RuleVariableValueMapBuilder.target(currentEvent).ruleVariables(Arrays.asList(ruleVariableOne, ruleVariableTwo)).ruleEvents(Arrays.asList(contextEventOne, contextEventTwo)).build();
assertThat(valueMap.size()).isEqualTo(7);
assertThatVariable(valueMap.get("current_date")).hasValue(wrap(dateFormat.format(new Date()))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(new Date()));
assertThatVariable(valueMap.get("event_date")).hasValue(wrap(dateFormat.format(eventDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(eventDate));
// event count variable should respect current event
assertThatVariable(valueMap.get("event_count")).hasValue("3").isTypeOf(RuleValueType.NUMERIC).hasCandidates("3");
assertThatVariable(valueMap.get("event_id")).hasValue("'test_event_uid'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_event_uid");
assertThatVariable(valueMap.get("due_date")).hasValue(wrap(dateFormat.format(dueDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(dueDate));
assertThatVariable(valueMap.get("test_variable_one")).hasValue("'test_value_one'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_value_one");
assertThatVariable(valueMap.get("test_variable_two")).hasValue("'test_value_two'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_value_two");
}
use of org.hisp.dhis.rules.models.RuleEvent in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method not_contain_any_variable_values.
@Test
public void not_contain_any_variable_values() throws ParseException {
RuleVariable ruleVariable = RuleVariableNewestStageEvent.create("test_variable", "test_dataelement", "test_program_stage_one", RuleValueType.TEXT);
Date dateEventOne = dateFormat.parse("2014-03-03");
Date dateEventTwo = dateFormat.parse("2015-02-03");
RuleEvent ruleEventOne = RuleEvent.create("test_event_uid_one", "test_program_stage_two", RuleEvent.Status.ACTIVE, dateEventOne, dateEventOne, Arrays.asList(RuleDataValue.create(dateEventOne, "test_program_stage_two", "test_dataelement", "test_value_one")));
RuleEvent ruleEventTwo = RuleEvent.create("test_event_uid_two", "test_program_stage_two", RuleEvent.Status.ACTIVE, dateEventTwo, dateEventTwo, Arrays.asList(RuleDataValue.create(dateEventTwo, "test_program_stage_two", "test_dataelement", "test_value_two")));
Map<String, RuleVariableValue> valueMap = RuleVariableValueMapBuilder.target(ruleEventTwo).ruleVariables(Arrays.asList(ruleVariable)).ruleEvents(Arrays.asList(ruleEventOne)).build();
assertThat(valueMap.size()).isEqualTo(6);
assertThatVariable(valueMap.get("current_date")).hasValue(wrap(dateFormat.format(new Date()))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(new Date()));
assertThatVariable(valueMap.get("event_date")).hasValue(wrap(dateFormat.format(dateEventTwo))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(dateEventTwo));
assertThatVariable(valueMap.get("event_count")).hasValue("2").isTypeOf(RuleValueType.NUMERIC).hasCandidates("2");
assertThatVariable(valueMap.get("event_id")).hasValue("'test_event_uid_two'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_event_uid_two");
assertThatVariable(valueMap.get("due_date")).hasValue(wrap(dateFormat.format(dateEventTwo))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(dateEventTwo));
assertThatVariable(valueMap.get("test_variable")).hasValue(null).isTypeOf(RuleValueType.TEXT).hasCandidates();
}
use of org.hisp.dhis.rules.models.RuleEvent in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method contain_values_from_previous_event_on_previous_event_variable.
@Test
public void contain_values_from_previous_event_on_previous_event_variable() throws ParseException {
RuleVariable ruleVariable = RuleVariablePreviousEvent.create("test_variable", "test_dataelement", RuleValueType.TEXT);
Date dateEventOne = dateFormat.parse("2014-02-03");
Date dateEventTwo = dateFormat.parse("2014-03-03");
Date dateEventThree = dateFormat.parse("2015-02-03");
Date dateEventCurrent = dateFormat.parse("2014-05-03");
RuleEvent ruleEventOne = RuleEvent.create("test_event_uid_one", "test_program_stage", RuleEvent.Status.ACTIVE, dateEventOne, dateEventOne, Arrays.asList(RuleDataValue.create(dateEventOne, "test_program_stage_one", "test_dataelement", "test_value_one")));
RuleEvent ruleEventTwo = RuleEvent.create("test_event_uid_two", "test_program_stage", RuleEvent.Status.ACTIVE, dateEventTwo, dateEventTwo, Arrays.asList(RuleDataValue.create(dateEventTwo, "test_program_stage_two", "test_dataelement", "test_value_two")));
RuleEvent ruleEventThree = RuleEvent.create("test_event_uid_three", "test_program_stage", RuleEvent.Status.ACTIVE, dateEventThree, dateEventThree, Arrays.asList(RuleDataValue.create(dateEventThree, "test_program_stage_two", "test_dataelement", "test_value_three")));
RuleEvent ruleEventCurrent = RuleEvent.create("test_event_uid_current", "test_program_stage", RuleEvent.Status.ACTIVE, dateEventCurrent, dateEventCurrent, Arrays.asList(RuleDataValue.create(dateEventCurrent, "test_program_stage_one", "test_dataelement", "test_value_current")));
Map<String, RuleVariableValue> valueMap = RuleVariableValueMapBuilder.target(ruleEventCurrent).ruleVariables(Arrays.asList(ruleVariable)).ruleEvents(Arrays.asList(ruleEventOne, ruleEventTwo, ruleEventThree)).build();
assertThat(valueMap.size()).isEqualTo(6);
assertThatVariable(valueMap.get("current_date")).hasValue(wrap(dateFormat.format(new Date()))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(new Date()));
assertThatVariable(valueMap.get("event_date")).hasValue(wrap(dateFormat.format(dateEventCurrent))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(dateEventCurrent));
assertThatVariable(valueMap.get("event_count")).hasValue("4").isTypeOf(RuleValueType.NUMERIC).hasCandidates("4");
assertThatVariable(valueMap.get("event_id")).hasValue("'test_event_uid_current'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_event_uid_current");
assertThatVariable(valueMap.get("due_date")).hasValue(wrap(dateFormat.format(dateEventCurrent))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(dateEventCurrent));
assertThatVariable(valueMap.get("test_variable")).hasValue("'test_value_two'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_value_three", "test_value_current", "test_value_two", "test_value_one");
}
Aggregations