Search in sources :

Example 61 with TrackerImportParams

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

the class TrackerProgramRuleBundleServiceTest method testRunRuleEngineForEventOnBundleCreate.

@Test
void testRunRuleEngineForEventOnBundleCreate() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/event_events_and_enrollment.json");
    assertEquals(8, trackerImportParams.getEvents().size());
    TrackerBundle trackerBundle = trackerBundleService.create(trackerImportParams);
    trackerBundle = trackerBundleService.runRuleEngine(trackerBundle);
    assertEquals(trackerBundle.getEvents().size(), trackerBundle.getEventRuleEffects().size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 62 with TrackerImportParams

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

the class LastUpdateImportTest method shouldUpdateTeiIfEventIsUpdated.

@Test
void shouldUpdateTeiIfEventIsUpdated() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/event_with_data_values.json");
    Date lastUpdateBefore = trackedEntityInstanceService.getTrackedEntityInstance(trackedEntity.getTrackedEntity()).getLastUpdated();
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    trackerImportParams = fromJson("tracker/event_with_updated_data_values.json");
    trackerImportParams.setImportStrategy(TrackerImportStrategy.UPDATE);
    assertNoImportErrors(trackerImportService.importTracker(trackerImportParams));
    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) Date(java.util.Date) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 63 with TrackerImportParams

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

the class LastUpdateImportTest method shouldUpdateTeiIfTeiIsUpdated.

@Test
void shouldUpdateTeiIfTeiIsUpdated() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/single_tei.json", user.getUid());
    trackerImportParams.setImportStrategy(TrackerImportStrategy.UPDATE);
    Attribute attribute = new Attribute();
    attribute.setAttribute("toUpdate000");
    attribute.setValue("value");
    trackedEntity.setAttributes(Collections.singletonList(attribute));
    Date lastUpdateBefore = trackedEntityInstanceService.getTrackedEntityInstance(trackedEntity.getTrackedEntity()).getLastUpdated();
    assertNoImportErrors(trackerImportService.importTracker(trackerImportParams));
    assertTrue(manager.get(TrackedEntityInstance.class, trackedEntity.getTrackedEntity()).getLastUpdated().getTime() > lastUpdateBefore.getTime());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Attribute(org.hisp.dhis.tracker.domain.Attribute) Date(java.util.Date) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 64 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams 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 65 with TrackerImportParams

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

the class LastUpdateImportTest method initTest.

@Override
@Transactional
protected void initTest() throws IOException {
    setUpMetadata("tracker/simple_metadata.json");
    user = userService.getUser("M5zQapPyTZI");
    TrackerImportParams trackerImportParams = fromJson("tracker/single_tei.json", user.getUid());
    assertNoImportErrors(trackerImportService.importTracker(trackerImportParams));
    trackedEntity = trackerImportParams.getTrackedEntities().get(0);
    TrackerImportParams enrollmentParams = fromJson("tracker/single_enrollment.json", user.getUid());
    assertNoImportErrors(trackerImportService.importTracker(enrollmentParams));
    manager.flush();
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)163 Test (org.junit.jupiter.api.Test)142 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)105 TrackerTest (org.hisp.dhis.tracker.TrackerTest)46 User (org.hisp.dhis.user.User)26 ClassPathResource (org.springframework.core.io.ClassPathResource)23 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 InputStream (java.io.InputStream)16 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)9 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 Event (org.hisp.dhis.tracker.domain.Event)7 Pair (org.apache.commons.lang3.tuple.Pair)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 Program (org.hisp.dhis.program.Program)5