Search in sources :

Example 96 with TrackerImportParams

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

the class ProgramRuleIntegrationTest method testImportEnrollmentSuccessWithWarningRaised.

@Test
void testImportEnrollmentSuccessWithWarningRaised() throws IOException {
    InputStream inputStream = new ClassPathResource("tracker/single_tei.json").getInputStream();
    TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    TrackerImportReport trackerImportTeiReport = trackerImportService.importTracker(params);
    TrackerImportParams enrollmentParams = renderService.fromJson(new ClassPathResource("tracker/single_enrollment.json").getInputStream(), TrackerImportParams.class);
    enrollmentParams.setUserId(userA.getUid());
    TrackerImportReport trackerImportEnrollmentReport = trackerImportService.importTracker(enrollmentParams);
    assertNotNull(trackerImportTeiReport);
    assertEquals(TrackerStatus.OK, trackerImportTeiReport.getStatus());
    assertNotNull(trackerImportEnrollmentReport);
    assertEquals(TrackerStatus.OK, trackerImportEnrollmentReport.getStatus());
    assertEquals(1, trackerImportEnrollmentReport.getValidationReport().getWarnings().size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 97 with TrackerImportParams

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

the class AtomicModeIntegrationTest method testImportSuccessWithAtomicModeObjectIfThereIsAnErrorInOneTEI.

@Test
void testImportSuccessWithAtomicModeObjectIfThereIsAnErrorInOneTEI() throws IOException {
    InputStream inputStream = new ClassPathResource("tracker/one_valid_tei_and_one_invalid.json").getInputStream();
    TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
    params.setUserId(userA.getUid());
    params.setAtomicMode(AtomicMode.OBJECT);
    TrackerImportReport trackerImportTeiReport = trackerImportService.importTracker(params);
    assertNotNull(trackerImportTeiReport);
    assertEquals(TrackerStatus.OK, trackerImportTeiReport.getStatus());
    assertEquals(1, trackerImportTeiReport.getValidationReport().getErrors().size());
    assertNotNull(trackedEntityInstanceService.getTrackedEntityInstance("VALIDTEIAAA"));
    assertNull(trackedEntityInstanceService.getTrackedEntityInstance("INVALIDTEIA"));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 98 with TrackerImportParams

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

the class TrackerPreheatIdentifiersTest method testDataElementIdentifiers.

@Test
void testDataElementIdentifiers() {
    List<Pair<String, TrackerIdentifier>> data = buildDataSet("DSKTW8qFP0z", "DEAGE", "DE Age");
    for (Pair<String, TrackerIdentifier> pair : data) {
        Event event = new Event();
        event.setProgramStage("NpsdDv6kKSO");
        DataValue dv1 = new DataValue();
        dv1.setDataElement(pair.getLeft());
        dv1.setValue("val1");
        event.setDataValues(Collections.singleton(dv1));
        TrackerImportParams params = buildParams(event, builder().dataElementIdScheme(pair.getRight()).build());
        TrackerPreheat preheat = trackerPreheatService.preheat(params);
        assertPreheatedObjectExists(preheat, DataElement.class, pair.getRight(), pair.getLeft());
    }
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 99 with TrackerImportParams

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

the class TrackerPreheatIdentifiersTest method testProgramStageIdentifiers.

@Test
void testProgramStageIdentifiers() {
    List<Pair<String, TrackerIdentifier>> data = buildDataSet("NpsdDv6kKSO", "PRGA", "ProgramA");
    for (Pair<String, TrackerIdentifier> pair : data) {
        Event event = new Event();
        event.setProgramStage(pair.getLeft());
        TrackerImportParams params = buildParams(event, builder().programStageIdScheme(pair.getRight()).build());
        TrackerPreheat preheat = trackerPreheatService.preheat(params);
        assertPreheatedObjectExists(preheat, ProgramStage.class, pair.getRight(), pair.getLeft());
    }
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) Event(org.hisp.dhis.tracker.domain.Event) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 100 with TrackerImportParams

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

the class TrackerPreheatIdentifiersTest method testCategoryOptionComboIdentifiers.

@Test
void testCategoryOptionComboIdentifiers() {
    List<Pair<String, TrackerIdentifier>> data = buildDataSet("XXXvX50cXC0", "COCA", "COCAname");
    for (Pair<String, TrackerIdentifier> pair : data) {
        Event event = new Event();
        event.setAttributeOptionCombo(pair.getLeft());
        TrackerImportParams params = buildParams(event, builder().categoryOptionComboIdScheme(pair.getRight()).build());
        TrackerPreheat preheat = trackerPreheatService.preheat(params);
        assertPreheatedObjectExists(preheat, CategoryOptionCombo.class, pair.getRight(), pair.getLeft());
    }
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) Event(org.hisp.dhis.tracker.domain.Event) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

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