Search in sources :

Example 86 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class TrackerBundleParamsConverterTest method verifyUidIsAssignedWhenMissing.

@Test
void verifyUidIsAssignedWhenMissing() throws IOException {
    List<Relationship> relationships1 = createRelationships(2, null);
    List<Relationship> relationships2 = createRelationships(2, "rel2");
    List<Event> events1 = createEvent(3, null, null);
    List<Event> events2 = createEvent(7, null, null);
    List<Enrollment> enrollments = new ArrayList<>();
    Enrollment enrollment1 = createEnrollment(null, null, events1);
    Enrollment enrollment2 = createEnrollment(null, null, events2);
    enrollment1.setRelationships(relationships1);
    enrollment2.setRelationships(relationships2);
    enrollments.add(enrollment1);
    enrollments.add(enrollment2);
    TrackedEntity trackedEntity = createTrackedEntity(null, enrollments);
    trackedEntity.setRelationships(relationships1);
    TrackerBundleParams build = TrackerBundleParams.builder().trackedEntities(Collections.singletonList(trackedEntity)).build();
    String jsonPayload = toJson(build);
    TrackerBundleParams b2 = this.objectMapper.readValue(jsonPayload, TrackerBundleParams.class);
    // TEI has uid
    assertThat(b2.getTrackedEntities().get(0).getTrackedEntity(), is(notNullValue()));
    // Also check parent uid is set
    assertThat(b2.getEnrollments().get(0).getTrackedEntity(), is(b2.getTrackedEntities().get(0).getTrackedEntity()));
    assertThat(b2.getEnrollments().get(0).getEnrollment(), is(notNullValue()));
    // Also check parent uid is set
    assertThat(b2.getEnrollments().get(1).getTrackedEntity(), is(b2.getTrackedEntities().get(0).getTrackedEntity()));
    assertThat(b2.getEnrollments().get(1).getEnrollment(), is(notNullValue()));
    assertThat(b2.getEvents().get(0).getEvent(), is(notNullValue()));
    assertThat(b2.getEvents().get(1).getEvent(), is(notNullValue()));
    assertThat(b2.getRelationships(), hasSize(4));
    b2.getRelationships().stream().forEach(r -> assertThat(r.getRelationship(), is(notNullValue())));
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Relationship(org.hisp.dhis.tracker.domain.Relationship) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.tracker.domain.Event) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Test(org.junit.jupiter.api.Test)

Example 87 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class TrackerBundleParamsConverterTest method verifyNestedTeiStructureHasNestedDataClearedAfterFlattening.

@Test
void verifyNestedTeiStructureHasNestedDataClearedAfterFlattening() throws IOException {
    List<Relationship> relationships1 = createRelationships(2, "rel1");
    List<Relationship> relationships2 = createRelationships(2, "rel2");
    List<Event> events1 = createEvent(3, "ev1", "enr1");
    List<Event> events2 = createEvent(7, "ev2", "enr2");
    List<Enrollment> enrollments = new ArrayList<>();
    Enrollment enrollment1 = createEnrollment("enr1", "teiABC", events1);
    Enrollment enrollment2 = createEnrollment("enr2", "teiABC", events2);
    enrollment1.setRelationships(relationships2);
    enrollment2.setRelationships(relationships1);
    enrollments.add(enrollment1);
    enrollments.add(enrollment2);
    TrackedEntity trackedEntity = createTrackedEntity("teiABC", enrollments);
    trackedEntity.setRelationships(relationships1);
    TrackerBundleParams build = TrackerBundleParams.builder().trackedEntities(Collections.singletonList(trackedEntity)).build();
    String jsonPayload = toJson(build);
    TrackerBundleParams b2 = this.objectMapper.readValue(jsonPayload, TrackerBundleParams.class);
    assertThat(b2.getTrackedEntities().get(0).getEnrollments(), hasSize(0));
    assertThat(b2.getTrackedEntities().get(0).getRelationships(), hasSize(0));
    assertThat(b2.getEnrollments().get(0).getEvents(), hasSize(0));
    assertThat(b2.getEnrollments().get(0).getRelationships(), hasSize(0));
    assertThat(b2.getEvents().get(0).getRelationships(), hasSize(0));
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Relationship(org.hisp.dhis.tracker.domain.Relationship) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.tracker.domain.Event) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Test(org.junit.jupiter.api.Test)

Example 88 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class TrackerBundleParamsConverterTest method createEnrollment.

private Enrollment createEnrollment(String uid, String parent, List<Event> events) {
    Enrollment enrollment = rnd.nextObject(Enrollment.class);
    enrollment.setGeometry(null);
    enrollment.setEnrollment(uid);
    enrollment.setTrackedEntity(parent);
    enrollment.setEvents(events);
    return enrollment;
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment)

Aggregations

Enrollment (org.hisp.dhis.tracker.domain.Enrollment)88 Test (org.junit.jupiter.api.Test)67 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)53 Event (org.hisp.dhis.tracker.domain.Event)25 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)24 Program (org.hisp.dhis.program.Program)21 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)17 List (java.util.List)16 Optional (java.util.Optional)15 ProgramInstance (org.hisp.dhis.program.ProgramInstance)15 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)15 Sets (com.google.common.collect.Sets)14 Collectors (java.util.stream.Collectors)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Mockito.when (org.mockito.Mockito.when)14