use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ProgramInstancePreProcessorTest method verifyEnrollmentIsSetOnEventWhenOneProgramInstanceIsFound.
@Test
void verifyEnrollmentIsSetOnEventWhenOneProgramInstanceIsFound() {
//
// Tracked Entity Instance
//
TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
when(workContext.getTrackedEntityInstance(event.getUid())).thenReturn(Optional.of(tei));
ProgramInstance programInstance = new ProgramInstance();
programInstance.setUid(CodeGenerator.generateUid());
when(programInstanceStore.get(tei, program, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance));
event.setProgram(program.getUid());
//
// Method under test
//
subject.process(event, workContext);
assertThat(event.getEnrollment(), is(programInstance.getUid()));
assertThat(programInstanceMap.get(event.getUid()), is(programInstance));
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method testDeleteEnrollmentWithEvents.
@Test
void testDeleteEnrollmentWithEvents() {
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
eventService.addEvent(event, null, false);
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
enrollment.setEvents(Lists.newArrayList(event));
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
Enrollment retrievedEnrlollment = enrollmentService.getEnrollment(tei.getEnrollments().get(0).getEnrollment());
EventSearchParams params = new EventSearchParams();
params.setProgram(programA);
params.setOrgUnit(organisationUnitA);
params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
Event retrievedEvent = enrollment.getEvents().get(0);
assertNotNull(retrievedEnrlollment);
assertNotNull(retrievedEvent);
enrollmentService.deleteEnrollment(retrievedEnrlollment.getEnrollment());
assertNull(enrollmentService.getEnrollment(tei.getEnrollments().get(0).getEnrollment()));
assertEquals(1, eventService.getEvents(params).getEvents().size());
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testUpdateTeiByCompletingExistingEnrollmentAndAddNewEventsToSameEnrollment.
@Test
void testUpdateTeiByCompletingExistingEnrollmentAndAddNewEventsToSameEnrollment() {
TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
assertNotNull(trackedEntityInstance.getEnrollments());
assertEquals(1, trackedEntityInstance.getEnrollments().size());
Enrollment enrollment1 = trackedEntityInstance.getEnrollments().get(0);
enrollment1.setStatus(EnrollmentStatus.COMPLETED);
enrollment1.setCompletedBy("test");
enrollment1.setCompletedDate(new Date());
Event event1 = new Event();
event1.setEnrollment(enrollment1.getEnrollment());
event1.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
event1.setOrgUnit(organisationUnitA.getUid());
event1.setProgram(programA.getUid());
event1.setProgramStage(programStageA1.getUid());
event1.setStatus(EventStatus.COMPLETED);
event1.setTrackedEntityInstance(maleA.getUid());
Event event2 = new Event();
event2.setEnrollment(enrollment1.getEnrollment());
event2.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
event2.setOrgUnit(organisationUnitA.getUid());
event2.setProgram(programA.getUid());
event2.setProgramStage(programStageA2.getUid());
event2.setStatus(EventStatus.ACTIVE);
event2.setTrackedEntityInstance(maleA.getUid());
enrollment1.setEvents(Arrays.asList(event1, event2));
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testUpdateTeiByDeletingExistingEventAndAddNewEventForSameProgramStage.
@Test
void testUpdateTeiByDeletingExistingEventAndAddNewEventForSameProgramStage() {
// Making program stage repeatable
programStageA2.setRepeatable(true);
TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
assertNotNull(trackedEntityInstance.getEnrollments());
assertEquals(1, trackedEntityInstance.getEnrollments().size());
Enrollment enrollment1 = trackedEntityInstance.getEnrollments().get(0);
Event event1 = new Event();
event1.setEnrollment(enrollment1.getEnrollment());
event1.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
event1.setOrgUnit(organisationUnitA.getUid());
event1.setProgram(programA.getUid());
event1.setProgramStage(programStageA1.getUid());
event1.setStatus(EventStatus.COMPLETED);
event1.setTrackedEntityInstance(maleA.getUid());
Event event2 = new Event();
event2.setEnrollment(enrollment1.getEnrollment());
event2.setOrgUnit(organisationUnitA.getUid());
event2.setProgram(programA.getUid());
event2.setProgramStage(programStageA2.getUid());
event2.setStatus(EventStatus.SCHEDULE);
event2.setDueDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now().plusDays(10)));
event2.setTrackedEntityInstance(maleA.getUid());
enrollment1.setEvents(Arrays.asList(event1, event2));
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
manager.flush();
sessionFactory.getCurrentSession().clear();
trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
assertNotNull(trackedEntityInstance.getEnrollments());
assertEquals(1, trackedEntityInstance.getEnrollments().size());
assertNotNull(trackedEntityInstance.getEnrollments().get(0).getEvents());
assertEquals(2, trackedEntityInstance.getEnrollments().get(0).getEvents().size());
enrollment1 = trackedEntityInstance.getEnrollments().get(0);
event2 = enrollment1.getEvents().stream().filter(e -> e.getProgramStage().equals(programStageA2.getUid())).findFirst().get();
event2.setDeleted(true);
Event event3 = new Event();
event3.setEnrollment(enrollment1.getEnrollment());
event3.setOrgUnit(organisationUnitA.getUid());
event3.setProgram(programA.getUid());
event3.setProgramStage(programStageA2.getUid());
event3.setStatus(EventStatus.SCHEDULE);
event3.setDueDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now().plusDays(11)));
event3.setTrackedEntityInstance(maleA.getUid());
enrollment1.getEvents().add(event3);
ImportOptions importOptions = new ImportOptions();
importOptions.setImportStrategy(ImportStrategy.SYNC);
importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, importOptions, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getImportSummaries().get(0).getEvents().getStatus());
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testSyncTeiFutureDatesForEnrollmentAndIncident.
@Test
void testSyncTeiFutureDatesForEnrollmentAndIncident() {
TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(dateConflictsMaleA.getUid());
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, new ImportOptions().setImportStrategy(ImportStrategy.SYNC), true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(2, importSummary.getEnrollments().getImportSummaries().get(0).getConflictCount());
assertEquals(trackedEntityInstance.getEnrollments().get(0).getEnrollment(), importSummary.getEnrollments().getImportSummaries().get(0).getReference());
}
Aggregations