Search in sources :

Example 76 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class RegistrationSingleEventServiceTest method createEnrollment.

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 77 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class RegistrationSingleEventServiceTest method testDeleteEnrollmentShouldReturnReference.

@Test
void testDeleteEnrollmentShouldReturnReference() {
    Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    importSummary = enrollmentService.deleteEnrollment(tei.getEnrollments().get(0).getEnrollment());
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertNotNull(importSummary.getReference());
    assertEquals(tei.getEnrollments().get(0).getEnrollment(), importSummary.getReference());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 78 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class RegistrationSingleEventServiceTest method testSavingMultipleEventsShouldOnlyUpdate.

@Test
@Disabled
void testSavingMultipleEventsShouldOnlyUpdate() {
    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());
    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(1, eventService.getEvents(params).getEvents().size());
    event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    importSummary = eventService.addEvent(event, null, false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(1, eventService.getEvents(params).getEvents().size());
    event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    importSummary = eventService.addEvent(event, null, false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(1, 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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 79 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class TrackerAccessManagerTest method createEnrollment.

private Enrollment createEnrollment(String program, String person) {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(CodeGenerator.generateUid());
    enrollment.setOrgUnit(organisationUnitA.getUid());
    enrollment.setProgram(program);
    enrollment.setTrackedEntityInstance(person);
    enrollment.setEnrollmentDate(new Date());
    enrollment.setIncidentDate(new Date());
    Event event1 = new Event();
    event1.setEnrollment(enrollment.getEnrollment());
    event1.setEventDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now()));
    event1.setProgram(programA.getUid());
    event1.setProgramStage(programStageA.getUid());
    event1.setStatus(EventStatus.COMPLETED);
    event1.setTrackedEntityInstance(maleA.getUid());
    event1.setOrgUnit(organisationUnitA.getUid());
    Event event2 = new Event();
    event2.setEnrollment(enrollment.getEnrollment());
    event2.setDueDate(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(LocalDateTime.now().plusDays(10)));
    event2.setProgram(programA.getUid());
    event2.setProgramStage(programStageB.getUid());
    event2.setStatus(EventStatus.SCHEDULE);
    event2.setTrackedEntityInstance(maleA.getUid());
    event2.setOrgUnit(organisationUnitB.getUid());
    enrollment.setEvents(Arrays.asList(event1, event2));
    return enrollment;
}
Also used : Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) Date(java.util.Date)

Example 80 with Enrollment

use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.

the class EnrollmentController method startAsyncImport.

// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
/**
 * Starts an asynchronous enrollment task.
 *
 * @param importOptions the ImportOptions.
 * @param enrollments the enrollments to import.
 */
private WebMessage startAsyncImport(ImportOptions importOptions, List<Enrollment> enrollments) {
    JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", ENROLLMENT_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    taskExecutor.executeTask(new ImportEnrollmentsTask(enrollments, enrollmentService, importOptions, jobId));
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + ENROLLMENT_IMPORT);
}
Also used : ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

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