use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class EventTrackerConverterService method getProgramStageInstanceDataValues.
private List<EventDataValue> getProgramStageInstanceDataValues(TrackerPreheat preheat, Event event) {
List<EventDataValue> eventDataValues = new ArrayList<>();
ProgramStageInstance programStageInstance = preheat.getEvent(TrackerIdScheme.UID, event.getEvent());
if (programStageInstance == null) {
return eventDataValues;
}
Set<String> dataElements = event.getDataValues().stream().map(DataValue::getDataElement).collect(Collectors.toSet());
for (EventDataValue eventDataValue : programStageInstance.getEventDataValues()) {
if (!dataElements.contains(eventDataValue.getDataElement())) {
eventDataValues.add(eventDataValue);
}
}
return eventDataValues;
}
use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class FilteringOutUndeclaredDataElementsProcessorTest method testNotLinkedDataElementsAreRemovedFromEvent.
@Test
void testNotLinkedDataElementsAreRemovedFromEvent() {
Event event = new Event();
event.setProgramStage(PROGRAMSTAGE);
HashSet<DataValue> dataValues = Sets.newHashSet(new DataValue(DATA_ELEMENT_1, "whatever"), new DataValue(DATA_ELEMENT_2, "another value"));
event.setDataValues(dataValues);
WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).programsMap(getProgramMap()).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(ImmutableList.of(event), Collections.emptyMap(), ImportOptions.getDefaultImportOptions())).build();
preProcessor.process(event, ctx);
Set<String> allowedDataValues = ctx.getProgramStage(ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme(), PROGRAMSTAGE).getDataElements().stream().map(BaseIdentifiableObject::getUid).collect(Collectors.toSet());
Set<String> filteredEventDataValues = ctx.getEventDataValueMap().values().stream().flatMap(Collection::stream).map(EventDataValue::getDataElement).collect(Collectors.toSet());
assertTrue(allowedDataValues.containsAll(filteredEventDataValues));
}
use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class EventTrackerConverterServiceTest method fromForRuleEngineGivenNewEvent.
@Test
void fromForRuleEngineGivenNewEvent() {
setUpMocks();
DataElement dataElement = new DataElement();
dataElement.setUid(CodeGenerator.generateUid());
when(preheat.get(DataElement.class, dataElement.getUid())).thenReturn(dataElement);
DataValue dataValue = dataValue(dataElement.getUid(), "900");
Event event = event(dataValue);
ProgramStageInstance programStageInstance = converter.fromForRuleEngine(preheat, event);
assertNotNull(programStageInstance);
assertNotNull(programStageInstance.getProgramStage());
assertNotNull(programStageInstance.getProgramStage().getProgram());
assertNotNull(programStageInstance.getOrganisationUnit());
assertEquals(PROGRAM_UID, programStageInstance.getProgramStage().getProgram().getUid());
assertEquals(PROGRAM_STAGE_UID, programStageInstance.getProgramStage().getUid());
assertEquals(ORGANISATION_UNIT_UID, programStageInstance.getOrganisationUnit().getUid());
assertEquals(ORGANISATION_UNIT_UID, programStageInstance.getOrganisationUnit().getUid());
assertEquals(1, programStageInstance.getEventDataValues().size());
EventDataValue actual = programStageInstance.getEventDataValues().stream().findFirst().get();
assertEquals(dataValue.getDataElement(), actual.getDataElement());
assertEquals(dataValue.getValue(), actual.getValue());
assertTrue(actual.getProvidedElsewhere());
assertEquals(USERNAME, actual.getCreatedByUserInfo().getUsername());
assertEquals(USERNAME, actual.getLastUpdatedByUserInfo().getUsername());
}
use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class EventTrackerConverterServiceTest method fromForRuleEngineGivenExistingEventUpdatesValueOfExistingDataValueOnIdSchemeUID.
@Test
void fromForRuleEngineGivenExistingEventUpdatesValueOfExistingDataValueOnIdSchemeUID() {
setUpMocks();
DataElement dataElement = new DataElement();
dataElement.setUid(CodeGenerator.generateUid());
when(preheat.get(DataElement.class, dataElement.getUid())).thenReturn(dataElement);
ProgramStageInstance existingPsi = programStageInstance();
existingPsi.setEventDataValues(Set.of(eventDataValue(dataElement.getUid(), "658")));
// dataElement is of idScheme UID if the NTI dataElementIdScheme is set
// to UID
DataValue updatedValue = dataValue(dataElement.getUid(), "900");
Event event = event(existingPsi.getUid(), updatedValue);
when(preheat.getEvent(TrackerIdScheme.UID, event.getEvent())).thenReturn(existingPsi);
ProgramStageInstance programStageInstance = converter.fromForRuleEngine(preheat, event);
assertEquals(1, programStageInstance.getEventDataValues().size());
EventDataValue expect1 = new EventDataValue();
expect1.setDataElement(updatedValue.getDataElement());
expect1.setValue(updatedValue.getValue());
assertContainsOnly(programStageInstance.getEventDataValues(), expect1);
}
use of org.hisp.dhis.eventdatavalue.EventDataValue in project dhis2-core by dhis2.
the class EventTrackerConverterServiceTest method fromForRuleEngineGivenExistingEventMergesNewDataValuesWithDBOnes.
@Test
void fromForRuleEngineGivenExistingEventMergesNewDataValuesWithDBOnes() {
setUpMocks();
ProgramStageInstance existingPsi = programStageInstance();
EventDataValue existingDataValue = eventDataValue(CodeGenerator.generateUid(), "658");
existingPsi.setEventDataValues(Set.of(existingDataValue));
DataElement dataElement = new DataElement();
dataElement.setUid(CodeGenerator.generateUid());
when(preheat.get(DataElement.class, dataElement.getUid())).thenReturn(dataElement);
// event refers to a different dataElement then currently associated
// with the event in the DB; thus both
// dataValues will be merged
DataValue newDataValue = dataValue(dataElement.getUid(), "900");
Event event = event(existingPsi.getUid(), newDataValue);
when(preheat.getEvent(TrackerIdScheme.UID, existingPsi.getUid())).thenReturn(existingPsi);
ProgramStageInstance programStageInstance = converter.fromForRuleEngine(preheat, event);
assertEquals(2, programStageInstance.getEventDataValues().size());
EventDataValue expect1 = new EventDataValue();
expect1.setDataElement(existingDataValue.getDataElement());
expect1.setValue(existingDataValue.getValue());
EventDataValue expect2 = new EventDataValue();
expect2.setDataElement(newDataValue.getDataElement());
expect2.setValue(newDataValue.getValue());
assertContainsOnly(programStageInstance.getEventDataValues(), expect1, expect2);
}
Aggregations