Search in sources :

Example 91 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class ProgramInstancePreProcessorTest method verifyEnrollmentIsSetOnEventWhenOneProgramInstanceIsFound.

@Test
void verifyEnrollmentIsSetOnEventWhenOneProgramInstanceIsFound() {
    // 
    // Tracked Entity Instance
    // 
    TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
    when(workContext.getTrackedEntityInstance(event.getUid())).thenReturn(Optional.of(tei));
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setUid(CodeGenerator.generateUid());
    when(programInstanceStore.get(tei, program, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance));
    event.setProgram(program.getUid());
    // 
    // Method under test
    // 
    subject.process(event, workContext);
    assertThat(event.getEnrollment(), is(programInstance.getUid()));
    assertThat(programInstanceMap.get(event.getUid()), is(programInstance));
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) BasePreProcessTest(org.hisp.dhis.dxf2.events.importer.BasePreProcessTest) Test(org.junit.jupiter.api.Test)

Example 92 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance 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 93 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance 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 94 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance 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 95 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceServiceTest method testSyncTeiFutureDatesForEnrollmentAndIncident.

@Test
void testSyncTeiFutureDatesForEnrollmentAndIncident() {
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(dateConflictsMaleA.getUid());
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, new ImportOptions().setImportStrategy(ImportStrategy.SYNC), true);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(2, importSummary.getEnrollments().getImportSummaries().get(0).getConflictCount());
    assertEquals(trackedEntityInstance.getEnrollments().get(0).getEnrollment(), importSummary.getEnrollments().getImportSummaries().get(0).getReference());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) 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)

Aggregations

TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)61 Test (org.junit.jupiter.api.Test)57 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)50 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)37 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)34 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)29 Date (java.util.Date)26 TrackerTest (org.hisp.dhis.dxf2.TrackerTest)26 ArrayList (java.util.ArrayList)25 List (java.util.List)25 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)25 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)24 Event (org.hisp.dhis.dxf2.events.event.Event)23 Program (org.hisp.dhis.program.Program)22 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 Collectors (java.util.stream.Collectors)19 User (org.hisp.dhis.user.User)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)16 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)16