Search in sources :

Example 31 with Enrollment

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

the class EventImportTest method testAddEventOnProgramWithRegistration.

@Test
void testAddEventOnProgramWithRegistration() throws IOException, ParseException {
    String lastupdateDateBefore = trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstanceMaleA.getTrackedEntityInstance()).getLastUpdated();
    Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    InputStream is = createEventJsonInputStream(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA, "10");
    ImportSummaries importSummaries = eventService.addEventsJson(is, null);
    assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
    cleanSession();
    assertTrue(simpleDateFormat.parse(trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstanceMaleA.getTrackedEntityInstance()).getLastUpdated()).getTime() > simpleDateFormat.parse(lastupdateDateBefore).getTime());
}
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 32 with Enrollment

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

the class EventImportTest 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 33 with Enrollment

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

the class RegistrationSingleEventServiceTest method testDeleteEventShouldReturnReference.

@Test
@Disabled("luciano -> re-enable after delete has been implemented")
void testDeleteEventShouldReturnReference() {
    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());
    TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    importSummary = eventService.deleteEvent(tei.getEnrollments().get(0).getEvents().get(0).getEvent());
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertNotNull(importSummary.getReference());
    assertEquals(tei.getEnrollments().get(0).getEvents().get(0).getEvent(), importSummary.getReference());
}
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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 34 with Enrollment

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

the class TrackedEntityInstanceAggregateTest method testTrackedEntityInstanceRelationshipsTei2Event.

@Test
void testTrackedEntityInstanceRelationshipsTei2Event() {
    final String[] relationshipItemsUid = new String[2];
    doInTransaction(() -> {
        org.hisp.dhis.trackedentity.TrackedEntityInstance t1 = this.persistTrackedEntityInstance();
        org.hisp.dhis.trackedentity.TrackedEntityInstance t2 = this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
        sessionFactory.getCurrentSession().flush();
        sessionFactory.getCurrentSession().clear();
        t2 = manager.getByUid(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, Collections.singletonList(t2.getUid())).get(0);
        ProgramInstance pi = t2.getProgramInstances().iterator().next();
        final ProgramStageInstance psi = pi.getProgramStageInstances().iterator().next();
        this.persistRelationship(t1, psi);
        relationshipItemsUid[0] = t1.getUid();
        relationshipItemsUid[1] = psi.getUid();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeRelationships(true);
    params.setIncludeEnrollments(true);
    params.setIncludeEvents(true);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    // Fetch the TEI which is the vertex of the relationship TEI <-->
    // ENROLLMENT
    Optional<TrackedEntityInstance> trackedEntityInstance = trackedEntityInstances.stream().filter(t -> t.getTrackedEntityInstance().equals(relationshipItemsUid[0])).findFirst();
    if (trackedEntityInstance.isPresent()) {
        assertThat(trackedEntityInstance.get().getRelationships(), hasSize(1));
        final Relationship relationship = trackedEntityInstance.get().getRelationships().get(0);
        assertThat(relationship.getFrom().getTrackedEntityInstance().getTrackedEntityInstance(), is(relationshipItemsUid[0]));
        assertThat(relationship.getTo().getEvent().getEvent(), is(relationshipItemsUid[1]));
    } else {
        fail();
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) QueryItem(org.hisp.dhis.common.QueryItem) Date(java.util.Date) ValueType(org.hisp.dhis.common.ValueType) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) DateTimeFormatMatcher.hasDateTimeFormat(org.hisp.dhis.matchers.DateTimeFormatMatcher.hasDateTimeFormat) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) EnrollmentStatus(org.hisp.dhis.dxf2.events.enrollment.EnrollmentStatus) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ProgramOwner(org.hisp.dhis.dxf2.events.trackedentity.ProgramOwner) User(org.hisp.dhis.user.User) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService) TrackedEntityProgramOwnerService(org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerService) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) SessionFactory(org.hibernate.SessionFactory) QueryOperator(org.hisp.dhis.common.QueryOperator) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Set(java.util.Set) AggregationType(org.hisp.dhis.analytics.AggregationType) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) EventStatus(org.hisp.dhis.event.EventStatus) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Event(org.hisp.dhis.dxf2.events.event.Event) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) FeatureType(org.hisp.dhis.organisationunit.FeatureType) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackerTest(org.hisp.dhis.dxf2.TrackerTest) Collections(java.util.Collections) DateUtils(org.hisp.dhis.util.DateUtils) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Example 35 with Enrollment

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

the class TrackedEntityInstanceAggregateTest method testEnrollmentFollowup.

@Test
void testEnrollmentFollowup() {
    Map<String, Object> enrollmentValues = new HashMap<>();
    enrollmentValues.put("followup", Boolean.TRUE);
    doInTransaction(() -> this.persistTrackedEntityInstanceWithEnrollmentAndEvents(enrollmentValues));
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeEnrollments(true);
    params.setIncludeEvents(true);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    TrackedEntityInstance tei = trackedEntityInstances.get(0);
    Enrollment enrollment = tei.getEnrollments().get(0);
    Event event = enrollment.getEvents().get(0);
    assertThat(enrollment.getFollowup(), is(true));
    assertThat(event.getFollowup(), is(true));
}
Also used : HashMap(java.util.HashMap) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) Event(org.hisp.dhis.dxf2.events.event.Event) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

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