Search in sources :

Example 66 with Enrollment

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

Example 67 with 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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Event(org.hisp.dhis.dxf2.events.event.Event) 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 68 with Enrollment

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());
}
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) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 69 with Enrollment

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());
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Arrays(java.util.Arrays) Date(java.util.Date) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) TextPattern(org.hisp.dhis.textpattern.TextPattern) Autowired(org.springframework.beans.factory.annotation.Autowired) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) EnrollmentStatus(org.hisp.dhis.dxf2.events.enrollment.EnrollmentStatus) Locale(java.util.Locale) SessionFactory(org.hibernate.SessionFactory) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) EventStatus(org.hisp.dhis.event.EventStatus) Collectors(java.util.stream.Collectors) Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) Event(org.hisp.dhis.dxf2.events.event.Event) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) TextPatternMethod(org.hisp.dhis.textpattern.TextPatternMethod) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgramType(org.hisp.dhis.program.ProgramType) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TrackedEntityTypeService(org.hisp.dhis.trackedentity.TrackedEntityTypeService) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) LocalDateTime(java.time.LocalDateTime) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Objects(org.hisp.dhis.common.Objects) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) DateTime(org.joda.time.DateTime) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ProgramStage(org.hisp.dhis.program.ProgramStage) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DateTimeFormatter(java.time.format.DateTimeFormatter) CodeGenerator(org.hisp.dhis.common.CodeGenerator) TextPatternSegment(org.hisp.dhis.textpattern.TextPatternSegment) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 70 with Enrollment

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());
}
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) Date(java.util.Date) 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