Search in sources :

Example 76 with TrackerImportParams

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

the class OwnershipTest method initTest.

@Override
protected void initTest() throws IOException {
    setUpMetadata("tracker/ownership_metadata.json");
    superUser = userService.getUser("M5zQapPyTZI");
    nonSuperUser = userService.getUser("Tu9fv8ezgHl");
    TrackerImportParams teiParams = fromJson("tracker/ownership_tei.json", superUser.getUid());
    assertNoImportErrors(trackerImportService.importTracker(teiParams));
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", superUser.getUid());
    assertNoImportErrors(trackerImportService.importTracker(enrollmentParams));
    manager.flush();
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams)

Example 77 with TrackerImportParams

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

the class OwnershipTest method testDeleteEnrollmentWithoutOwnership.

@Test
void testDeleteEnrollmentWithoutOwnership() throws IOException {
    // Change ownership
    TrackedEntityInstance tei = manager.get(TrackedEntityInstance.class, "IOR1AXXl24H");
    OrganisationUnit ou = manager.get(OrganisationUnit.class, "B1nCbRV3qtP");
    Program pgm = manager.get(Program.class, "BFcipDERJnf");
    TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
    trackerOwnershipManager.transferOwnership(tei, pgm, ou, true, false);
    enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
    assertEquals(1, updatedReport.getStats().getIgnored());
    assertEquals(TrackerErrorCode.E1102, updatedReport.getValidationReport().getErrors().get(0).getErrorCode());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Program(org.hisp.dhis.program.Program) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 78 with TrackerImportParams

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

the class ReportSummaryDeleteIntegrationTest method testTrackedEntityInstanceDeletion.

@Test
void testTrackedEntityInstanceDeletion() throws IOException {
    TrackerImportParams params = fromJson("tracker/tracked_entity_basic_data_for_deletion.json");
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    assertEquals(9, params.getTrackedEntities().size());
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    assertDeletedObjects(trackerImportReport.getBundleReport(), 9, TrackerType.TRACKED_ENTITY);
    // remaining
    assertEquals(4, manager.getAll(TrackedEntityInstance.class).size());
    assertEquals(2, manager.getAll(ProgramInstance.class).size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test) TrackerTest(org.hisp.dhis.tracker.TrackerTest)

Example 79 with TrackerImportParams

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

the class ProgramOrgUnitsSupplier method preheatAdd.

@Override
public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) {
    // fetch all existing Org Units from payload
    final List<Long> orgUnitIds = preheat.getMap().getOrDefault(OrganisationUnit.class, Collections.emptyMap()).values().stream().map(IdentifiableObject::getId).distinct().collect(Collectors.toList());
    if (orgUnitIds.isEmpty()) {
        return;
    }
    final String sql = "SELECT p.uid AS programuid, ou.uid AS organisationunituid " + "FROM program_organisationunits po " + "JOIN program p ON po.programid=p.programid " + "JOIN organisationunit ou ON po.organisationunitid=ou.organisationunitid " + "WHERE po.organisationunitid IN ( :ids )";
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", orgUnitIds);
    preheat.setProgramWithOrgUnitsMap(jdbcTemplate.query(sql, parameters, rs -> {
        Map<String, List<String>> map = new HashMap<>();
        while (rs.next()) {
            final String pid = rs.getString("programuid");
            final String ouid = rs.getString("organisationunituid");
            if (map.containsKey(pid)) {
                map.get(pid).add(ouid);
            } else {
                List<String> ouids = new ArrayList<>();
                ouids.add(ouid);
                map.put(pid, ouids);
            }
        }
        return map;
    }));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) java.util(java.util) Component(org.springframework.stereotype.Component) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Collectors(java.util.stream.Collectors) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 80 with TrackerImportParams

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

the class ProgramStageInstanceProgramStageMapSupplier method preheatAdd.

@Override
public void preheatAdd(TrackerImportParams params, TrackerPreheat preheat) {
    if (params.getEvents().size() == 0) {
        return;
    }
    List<String> notRepeatableProgramStageUids = params.getEvents().stream().map(Event::getProgramStage).filter(Objects::nonNull).map(ps -> (ProgramStage) preheat.get(ProgramStage.class, ps)).filter(Objects::nonNull).filter(ps -> !ps.getRepeatable()).map(ProgramStage::getUid).distinct().collect(Collectors.toList());
    List<String> programInstanceUids = params.getEvents().stream().map(Event::getEnrollment).filter(Objects::nonNull).distinct().collect(Collectors.toList());
    if (!notRepeatableProgramStageUids.isEmpty() && !programInstanceUids.isEmpty()) {
        List<Pair<String, String>> programStageWithEvents = new ArrayList<>();
        MapSqlParameterSource parameters = new MapSqlParameterSource();
        parameters.addValue("programStageUids", notRepeatableProgramStageUids);
        parameters.addValue("programInstanceUids", programInstanceUids);
        jdbcTemplate.query(SQL, parameters, rs -> {
            programStageWithEvents.add(Pair.of(rs.getString(PS_UID), rs.getString(PI_UID)));
        });
        preheat.setProgramStageWithEvents(programStageWithEvents);
    }
}
Also used : Objects(java.util.Objects) TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) Event(org.hisp.dhis.tracker.domain.Event) List(java.util.List) Component(org.springframework.stereotype.Component) Pair(org.apache.commons.lang3.tuple.Pair) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Collectors(java.util.stream.Collectors) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Objects(java.util.Objects) ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage) Pair(org.apache.commons.lang3.tuple.Pair)

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