use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class TrackerImporterServiceTest method setUp.
@BeforeEach
public void setUp() {
subject = new DefaultTrackerImportService(trackerBundleService, trackerValidationService, trackerPreprocessService, trackerUserService, notifier);
final List<Event> events = rnd.objects(Event.class, 3).collect(Collectors.toList());
params = TrackerImportParams.builder().events(events).enrollments(new ArrayList<>()).relationships(new ArrayList<>()).trackedEntities(new ArrayList<>()).userId("123").build();
TrackerBundleReport trackerBundleReport = TrackerBundleReport.builder().build();
when(trackerUserService.getUser(anyString())).thenReturn(getUser());
when(trackerBundleService.commit(any(TrackerBundle.class))).thenReturn(trackerBundleReport);
when(trackerValidationService.validate(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
when(trackerValidationService.validateRuleEngine(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
when(trackerPreprocessService.preprocess(any(TrackerBundle.class))).thenReturn(ParamsConverter.convert(params));
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class RepeatedEventsValidationHook method validate.
@Override
public void validate(ValidationErrorReporter reporter, TrackerImportValidationContext context) {
TrackerBundle bundle = context.getBundle();
Map<Pair<String, String>, List<Event>> eventsByEnrollmentAndNotRepeatableProgramStage = bundle.getEvents().stream().filter(e -> !reporter.isInvalid(e)).filter(e -> !context.getStrategy(e).isDelete()).filter(e -> {
ProgramStage programStage = context.getProgramStage(e.getProgramStage());
return programStage.getProgram().isRegistration() && !programStage.getRepeatable();
}).collect(Collectors.groupingBy(e -> Pair.of(e.getProgramStage(), e.getEnrollment())));
for (Map.Entry<Pair<String, String>, List<Event>> mapEntry : eventsByEnrollmentAndNotRepeatableProgramStage.entrySet()) {
if (mapEntry.getValue().size() > 1) {
for (Event event : mapEntry.getValue()) {
reporter.addError(event, TrackerErrorCode.E1039, mapEntry.getKey().getLeft());
}
}
}
bundle.getEvents().forEach(e -> validateNotMultipleEvents(reporter, context, e));
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class EventTrackerConverterServiceTest method event.
private Event event(String uid, DataValue dataValue) {
Event event = new Event();
event.setEvent(uid);
event.setProgramStage(PROGRAM_STAGE_UID);
event.setProgram(PROGRAM_UID);
event.setOrgUnit(ORGANISATION_UNIT_UID);
event.setDataValues(Sets.newHashSet(dataValue));
return event;
}
use of org.hisp.dhis.tracker.domain.Event 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.tracker.domain.Event 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);
}
Aggregations