use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackerTest method deleteOneEnrollment.
public Enrollment deleteOneEnrollment(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance trackedEntityInstance) {
List<Enrollment> enrollments = trackedEntityInstance.getEnrollments();
assertThat(enrollments, is(not(empty())));
Enrollment enrollment = enrollments.get(0);
ImportSummary importSummary = enrollmentService.deleteEnrollment(enrollment.getEnrollment());
assertEquals(0, importSummary.getConflictCount());
return enrollment;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment 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.enrollment.Enrollment 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.enrollment.Enrollment 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.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testUpdateTeiByCompletingExistingEnrollmentAndOpeningNewEnrollment.
@Test
void testUpdateTeiByCompletingExistingEnrollmentAndOpeningNewEnrollment() {
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());
Enrollment enrollment2 = new Enrollment();
enrollment2.setTrackedEntityInstance(maleA.getUid());
enrollment2.setEnrollmentDate(new Date());
enrollment2.setOrgUnit(organisationUnitA.getUid());
enrollment2.setProgram(programA.getUid());
enrollment2.setStatus(EnrollmentStatus.ACTIVE);
trackedEntityInstance.getEnrollments().add(enrollment2);
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, null, true);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(ImportStatus.SUCCESS, importSummary.getEnrollments().getStatus());
}
Aggregations