Search in sources :

Example 36 with Enrollment

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

the class TrackedEntityInstanceAggregateTest method testEnrollmentMapping.

@Test
void testEnrollmentMapping() {
    final Date currentTime = new Date();
    doInTransaction(this::persistTrackedEntityInstanceWithEnrollmentAndEvents);
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeEnrollments(true);
    params.setIncludeEvents(false);
    final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
    Enrollment enrollment = trackedEntityInstances.get(0).getEnrollments().get(0);
    assertThat("Tracked Entity Type does not match", enrollment.getTrackedEntityType(), is(trackedEntityTypeA.getUid()));
    assertThat("Tracked Entity Instance UID does not match", enrollment.getTrackedEntityInstance(), is(trackedEntityInstances.get(0).getTrackedEntityInstance()));
    assertThat("Org Unit UID does not match", enrollment.getOrgUnit(), is(organisationUnitA.getUid()));
    assertThat("Org Unit Name does not match", enrollment.getOrgUnitName(), is(organisationUnitA.getName()));
    assertTrue(CodeGenerator.isValidUid(enrollment.getEnrollment()));
    assertThat(enrollment.getProgram(), is(programA.getUid()));
    assertThat(enrollment.getStatus(), is(EnrollmentStatus.COMPLETED));
    assertThat(enrollment.isDeleted(), is(false));
    assertThat(enrollment.getStoredBy(), is("system-process"));
    assertThat(enrollment.getFollowup(), is(nullValue()));
    // Dates
    checkDate(currentTime, enrollment.getCreated(), 200L);
    checkDate(currentTime, enrollment.getCreatedAtClient(), 200L);
    checkDate(currentTime, enrollment.getLastUpdatedAtClient(), 200L);
    checkDate(currentTime, enrollment.getLastUpdated(), 300L);
    checkDate(currentTime, enrollment.getEnrollmentDate(), 300L);
    checkDate(currentTime, enrollment.getIncidentDate(), 300L);
    checkDate(currentTime, enrollment.getCompletedDate(), 200L);
    assertThat(enrollment.getCompletedBy(), is("hello-world"));
    // The Enrollment ID is not serialized to JSON
    assertThat(enrollment.getId(), is(notNullValue()));
}
Also used : TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Date(java.util.Date) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Example 37 with Enrollment

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

the class TrackedEntityInstanceAggregateTest method testTrackedEntityInstanceRelationshipsTei2Enrollment.

@Test
void testTrackedEntityInstanceRelationshipsTei2Enrollment() {
    final String[] relationshipItemsUid = new String[2];
    doInTransaction(() -> {
        org.hisp.dhis.trackedentity.TrackedEntityInstance t1 = this.persistTrackedEntityInstance();
        org.hisp.dhis.trackedentity.TrackedEntityInstance t2 = this.persistTrackedEntityInstanceWithEnrollment();
        ProgramInstance pi = t2.getProgramInstances().iterator().next();
        this.persistRelationship(t1, pi);
        relationshipItemsUid[0] = t1.getUid();
        relationshipItemsUid[1] = pi.getUid();
    });
    TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
    queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    queryParams.setTrackedEntityType(trackedEntityTypeA);
    queryParams.setIncludeAllAttributes(true);
    TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
    params.setIncludeRelationships(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().getEnrollment().getEnrollment(), 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) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Example 38 with Enrollment

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

the class TrackedEntityInstanceAggregateTest method testEventMapping.

@Test
void testEventMapping() {
    final Date currentTime = new Date();
    doInTransaction(this::persistTrackedEntityInstanceWithEnrollmentAndEvents);
    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);
    assertNotNull(event);
    // The id is not serialized to JSON
    assertThat(event.getId(), is(notNullValue()));
    assertThat(event.getUid(), is(nullValue()));
    assertTrue(CodeGenerator.isValidUid(event.getEvent()));
    assertThat(event.getStatus(), is(EventStatus.COMPLETED));
    assertThat(event.getProgram(), is(programA.getUid()));
    assertThat(event.getProgramStage(), is(programStageA1.getUid()));
    assertThat(event.getEnrollment(), is(enrollment.getEnrollment()));
    assertThat(event.getEnrollmentStatus(), is(enrollment.getStatus()));
    assertThat(event.getOrgUnit(), is(organisationUnitA.getUid()));
    assertThat(event.getOrgUnitName(), is(organisationUnitA.getName()));
    assertThat(event.getTrackedEntityInstance(), is(tei.getTrackedEntityInstance()));
    assertThat(event.getAttributeOptionCombo(), is(DEF_COC_UID));
    assertThat(event.isDeleted(), is(false));
    assertThat(event.getStoredBy(), is("[Unknown]"));
    assertThat(event.getFollowup(), is(nullValue()));
    // Dates
    checkDate(currentTime, event.getCreated(), 500L);
    checkDate(currentTime, event.getLastUpdated(), 500L);
    assertThat(event.getEventDate(), is(notNullValue()));
    checkDate(currentTime, event.getDueDate(), 500L);
    checkDate(currentTime, event.getCreatedAtClient(), 500L);
    checkDate(currentTime, event.getLastUpdatedAtClient(), 500L);
    checkDate(currentTime, event.getCompletedDate(), 500L);
    assertThat(event.getCompletedBy(), is("[Unknown]"));
}
Also used : 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) Date(java.util.Date) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.dxf2.TrackerTest)

Example 39 with Enrollment

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

the class TrackerRelationshipCriteriaTest method getIdentifierNameThrowsIfAllParamsAreSet.

@Test
void getIdentifierNameThrowsIfAllParamsAreSet() {
    TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
    criteria.setTrackedEntity("Hq3Kc6HK4OZ");
    criteria.setTei("Hq3Kc6HK4OZ");
    criteria.setEnrollment("Hq3Kc6HK4OZ");
    criteria.setEvent("Hq3Kc6HK4OZ");
    WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierName);
    assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
    assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Test(org.junit.jupiter.api.Test)

Example 40 with Enrollment

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

the class TrackerRelationshipCriteriaTest method getIdentifierParamThrowsIfTeiAndEnrollmentAreSet.

@Test
void getIdentifierParamThrowsIfTeiAndEnrollmentAreSet() {
    TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
    criteria.setTei("Hq3Kc6HK4OZ");
    criteria.setEnrollment("Hq3Kc6HK4OZ");
    WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierParam);
    assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
    assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) 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