Search in sources :

Example 26 with Enrollment

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;
}
Also used : Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Date(java.util.Date)

Example 27 with 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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 28 with Enrollment

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());
}
Also used : EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) DateTime(org.joda.time.DateTime) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 29 with Enrollment

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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 30 with Enrollment

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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)46 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)44 Test (org.junit.jupiter.api.Test)35 Event (org.hisp.dhis.dxf2.events.event.Event)31 Date (java.util.Date)28 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)23 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)20 ArrayList (java.util.ArrayList)18 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)18 ProgramInstance (org.hisp.dhis.program.ProgramInstance)18 List (java.util.List)17 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)17 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)14 Program (org.hisp.dhis.program.Program)14 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 Map (java.util.Map)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Lists (com.google.common.collect.Lists)11