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();
}
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());
}
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());
}
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;
}));
}
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);
}
}
Aggregations