use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method createEnrollment.
// -------------------------------------------------------------------------
// Supportive tests
// -------------------------------------------------------------------------
private Enrollment createEnrollment(String program, String person) {
Enrollment enrollment = new Enrollment();
enrollment.setOrgUnit(organisationUnitA.getUid());
enrollment.setProgram(program);
enrollment.setTrackedEntityInstance(person);
enrollment.setEnrollmentDate(new Date());
enrollment.setIncidentDate(new Date());
return enrollment;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method testSaveRepeatableStageWithEventIdShouldNotCreateAdditionalEvents.
@Test
void testSaveRepeatableStageWithEventIdShouldNotCreateAdditionalEvents() {
ImportOptions importOptions = new ImportOptions();
importOptions.setImportStrategy(ImportStrategy.CREATE);
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
EventSearchParams params = new EventSearchParams();
params.setProgram(programA);
params.setOrgUnit(organisationUnitA);
params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
assertEquals(2, eventService.getEvents(params).getEvents().size());
event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
event.setEvent(importSummary.getReference());
importSummary = eventService.addEvent(event, importOptions, false);
assertEquals(ImportStatus.ERROR, importSummary.getStatus());
assertEquals(2, eventService.getEvents(params).getEvents().size());
event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
importSummary = eventService.addEvent(event, importOptions, false);
assertEquals(ImportStatus.ERROR, importSummary.getStatus());
assertEquals(2, eventService.getEvents(params).getEvents().size());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class RegistrationMultiEventsServiceTest method testSaveEventToCompletedEnrollment.
@Test
void testSaveEventToCompletedEnrollment() {
ImportOptions importOptions = new ImportOptions();
importOptions.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
EventSearchParams params = new EventSearchParams();
params.setProgram(programA);
params.setOrgUnit(organisationUnitA);
params.setOrgUnitSelectionMode(OrganisationUnitSelectionMode.SELECTED);
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
enrollment.setEnrollmentDate(new DateTime(2019, 1, 1, 0, 0, 0, 0).toDate());
enrollment.setIncidentDate(new DateTime(2019, 1, 1, 0, 0, 0, 0).toDate());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
enrollment = enrollmentService.getEnrollment(importSummary.getReference());
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
event.setEnrollment(enrollment.getEnrollment());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
enrollment.setStatus(EnrollmentStatus.COMPLETED);
enrollment.setCompletedDate(new DateTime(2019, 8, 20, 0, 0, 0, 0).toDate());
enrollmentService.updateEnrollment(enrollment, null);
importSummary = enrollmentService.updateEnrollment(enrollment, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
enrollment = enrollmentService.getEnrollment(enrollment.getEnrollment());
assertEquals(EnrollmentStatus.COMPLETED, enrollment.getStatus());
event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
event.setEnrollment(enrollment.getEnrollment());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(2, eventService.getEvents(params).getEvents().size());
enrollmentService.incompleteEnrollment(enrollment.getEnrollment());
enrollment = enrollmentService.getEnrollment(enrollment.getEnrollment());
assertEquals(EnrollmentStatus.ACTIVE, enrollment.getStatus());
event = createEvent(programA.getUid(), programStageB.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementB.getUid());
event.setEnrollment(enrollment.getEnrollment());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(3, eventService.getEvents(params).getEvents().size());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EventImportTest method testAddEventOnRepeatableProgramStageWithRegistration.
@Test
void testAddEventOnRepeatableProgramStageWithRegistration() throws IOException {
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
InputStream is = createEventJsonInputStream(programA.getUid(), programStageA2.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA2, "10");
ImportSummaries importSummaries = eventService.addEventsJson(is, null);
assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EventImportTest method testAddValidEnrollmentWithOneValidAndOneInvalidEvent.
@Test
void testAddValidEnrollmentWithOneValidAndOneInvalidEvent() {
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
Event validEvent = createEvent("eventUid004");
validEvent.setOrgUnit(organisationUnitA.getUid());
Event invalidEvent = createEvent("eventUid005");
invalidEvent.setOrgUnit("INVALID");
enrollment.setEvents(Lists.newArrayList(validEvent, invalidEvent));
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(1, importSummary.getImportCount().getImported());
assertEquals(0, importSummary.getImportCount().getIgnored());
assertEquals(0, importSummary.getImportCount().getDeleted());
assertEquals(0, importSummary.getImportCount().getUpdated());
ImportSummaries eventImportSummaries = importSummary.getEvents();
assertEquals(ImportStatus.ERROR, eventImportSummaries.getStatus());
assertEquals(1, eventImportSummaries.getImported());
assertEquals(1, eventImportSummaries.getIgnored());
assertEquals(0, eventImportSummaries.getDeleted());
assertEquals(0, eventImportSummaries.getUpdated());
}
Aggregations