Search in sources :

Example 31 with Enrollment

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

the class TrackerBundleParamsConverterTest method verifyNestedTeiStructureIsFlattenedDuringDeserialization.

@Test
void verifyNestedTeiStructureIsFlattenedDuringDeserialization() 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(), hasSize(1));
    assertThat(b2.getEnrollments(), hasSize(2));
    assertThat(b2.getEvents(), hasSize(10));
    assertThat(b2.getRelationships(), hasSize(4));
}
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 32 with Enrollment

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

the class TrackerBundleTest method testBasicSetup2.

@Test
void testBasicSetup2() {
    TrackerBundle trackerBundle = TrackerBundle.builder().atomicMode(AtomicMode.ALL).validationMode(ValidationMode.SKIP).trackedEntities(Arrays.asList(new TrackedEntity(), new TrackedEntity())).enrollments(Arrays.asList(new Enrollment(), new Enrollment())).events(Arrays.asList(new Event(), new Event())).build();
    assertEquals(AtomicMode.ALL, trackerBundle.getAtomicMode());
    assertSame(trackerBundle.getValidationMode(), ValidationMode.SKIP);
    assertEquals(2, trackerBundle.getTrackedEntities().size());
    assertEquals(2, trackerBundle.getEnrollments().size());
    assertEquals(2, trackerBundle.getEvents().size());
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Event(org.hisp.dhis.tracker.domain.Event) Test(org.junit.jupiter.api.Test)

Example 33 with Enrollment

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

the class LastUpdateImportTest method shouldUpdateTeiIfEnrollmentIsUpdated.

@Test
void shouldUpdateTeiIfEnrollmentIsUpdated() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/single_enrollment.json", user.getUid());
    Date lastUpdateBefore = trackedEntityInstanceService.getTrackedEntityInstance(trackedEntity.getTrackedEntity()).getLastUpdated();
    Enrollment enrollment = trackerImportParams.getEnrollments().get(0);
    enrollment.setStatus(EnrollmentStatus.COMPLETED);
    trackerImportParams.setImportStrategy(TrackerImportStrategy.UPDATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    manager.clear();
    assertTrue(manager.get(TrackedEntityInstance.class, trackedEntity.getTrackedEntity()).getLastUpdated().getTime() > lastUpdateBefore.getTime());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Date(java.util.Date) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 34 with Enrollment

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

the class PreCheckUpdatableFieldsValidationHookTest method verifyEnrollmentValidationSuccess.

@Test
void verifyEnrollmentValidationSuccess() {
    // given
    Enrollment enrollment = validEnrollment();
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 35 with Enrollment

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

the class PreCheckUpdatableFieldsValidationHookTest method verifyEnrollmentValidationFailsWhenUpdateTrackedEntity.

@Test
void verifyEnrollmentValidationFailsWhenUpdateTrackedEntity() {
    // given
    Enrollment enrollment = validEnrollment();
    enrollment.setTrackedEntity("NewTrackedEntityId");
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1127, ENROLLMENT, enrollment.getUid());
    assertThat(reporter.getReportList().get(0).getErrorMessage(), containsString("trackedEntity"));
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

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