use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class OwnershipTest method testProgramOwnerWhenEnrolled.
@Test
void testProgramOwnerWhenEnrolled() throws IOException {
TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
List<TrackedEntityInstance> teis = manager.getAll(TrackedEntityInstance.class);
assertEquals(1, teis.size());
TrackedEntityInstance tei = teis.get(0);
assertNotNull(tei.getProgramOwners());
Set<TrackedEntityProgramOwner> tepos = tei.getProgramOwners();
assertEquals(1, tepos.size());
TrackedEntityProgramOwner tepo = tepos.iterator().next();
assertNotNull(tepo.getEntityInstance());
assertNotNull(tepo.getProgram());
assertNotNull(tepo.getOrganisationUnit());
assertEquals(enrollmentParams.getEnrollments().get(0).getProgram(), tepo.getProgram().getUid());
assertEquals(enrollmentParams.getEnrollments().get(0).getOrgUnit(), tepo.getOrganisationUnit().getUid());
assertEquals(enrollmentParams.getEnrollments().get(0).getTrackedEntity(), tepo.getEntityInstance().getUid());
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class OwnershipTest method testUpdateEnrollment.
@Test
void testUpdateEnrollment() throws IOException {
TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
List<ProgramInstance> pis = manager.getAll(ProgramInstance.class);
assertEquals(2, pis.size());
ProgramInstance pi = pis.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get();
compareEnrollmentBasicProperties(pi, enrollmentParams.getEnrollments().get(0));
Enrollment updatedEnrollment = enrollmentParams.getEnrollments().get(0);
updatedEnrollment.setStatus(EnrollmentStatus.COMPLETED);
updatedEnrollment.setCompletedBy("admin");
updatedEnrollment.setCompletedAt(Instant.now());
updatedEnrollment.setCreatedAtClient(Instant.now());
updatedEnrollment.setUpdatedAtClient(Instant.now());
updatedEnrollment.setEnrolledAt(Instant.now());
updatedEnrollment.setOccurredAt(Instant.now());
enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
assertNoImportErrors(updatedReport);
assertEquals(1, updatedReport.getStats().getUpdated());
pis = manager.getAll(ProgramInstance.class);
assertEquals(2, pis.size());
pi = pis.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get();
compareEnrollmentBasicProperties(pi, updatedEnrollment);
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class OwnershipTest method testCreateEnrollmentWithoutOwnership.
@Test
void testCreateEnrollmentWithoutOwnership() throws IOException {
TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
List<ProgramInstance> pis = manager.getAll(ProgramInstance.class);
assertEquals(2, pis.size());
enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE);
TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
assertNoImportErrors(updatedReport);
assertEquals(1, updatedReport.getStats().getDeleted());
TrackedEntityInstance tei = manager.get(TrackedEntityInstance.class, "IOR1AXXl24H");
OrganisationUnit ou = manager.get(OrganisationUnit.class, "B1nCbRV3qtP");
Program pgm = manager.get(Program.class, "BFcipDERJnf");
trackerOwnershipManager.transferOwnership(tei, pgm, ou, true, false);
enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE);
enrollmentParams.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid());
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 testEnrollmentDeletion.
@Test
void testEnrollmentDeletion() throws IOException {
assertEquals(4, manager.getAll(ProgramInstance.class).size());
assertEquals(2, manager.getAll(ProgramStageInstance.class).size());
TrackerImportParams params = fromJson("tracker/enrollment_basic_data_for_deletion.json");
params.setImportStrategy(TrackerImportStrategy.DELETE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.ENROLLMENT);
// remaining
assertEquals(3, manager.getAll(ProgramInstance.class).size());
// delete associated events as well
assertEquals(1, manager.getAll(ProgramStageInstance.class).size());
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class ReportSummaryDeleteIntegrationTest method testDeleteMultipleEntities.
@Test
void testDeleteMultipleEntities() throws IOException {
TrackerImportParams params = fromJson("tracker/tracker_data_for_deletion.json");
params.setImportStrategy(TrackerImportStrategy.DELETE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.ENROLLMENT);
assertDeletedObjects(trackerImportReport.getBundleReport(), 1, TrackerType.TRACKED_ENTITY);
}
Aggregations