use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class ReportSummaryIntegrationTest method testStatsCountForOneCreatedAndOneUpdatedTEI.
@Test
void testStatsCountForOneCreatedAndOneUpdatedTEI() throws IOException {
InputStream inputStream = new ClassPathResource("tracker/single_tei.json").getInputStream();
TrackerImportParams params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
trackerImportService.importTracker(params);
inputStream = new ClassPathResource("tracker/one_update_tei_and_one_new_tei.json").getInputStream();
params = renderService.fromJson(inputStream, TrackerImportParams.class);
params.setUserId(userA.getUid());
params.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
TrackerImportReport trackerImportTeiReport = trackerImportService.importTracker(params);
assertNotNull(trackerImportTeiReport);
assertEquals(TrackerStatus.OK, trackerImportTeiReport.getStatus());
assertTrue(trackerImportTeiReport.getValidationReport().getErrors().isEmpty());
assertEquals(1, trackerImportTeiReport.getStats().getCreated());
assertEquals(1, trackerImportTeiReport.getStats().getUpdated());
assertEquals(0, trackerImportTeiReport.getStats().getIgnored());
assertEquals(0, trackerImportTeiReport.getStats().getDeleted());
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class EventDataValueTest method initTest.
@Override
protected void initTest() throws IOException {
setUpMetadata("tracker/simple_metadata.json");
final User userA = userService.getUser("M5zQapPyTZI");
injectSecurityContext(userA);
TrackerImportParams teiParams = fromJson("tracker/single_tei.json", userA.getUid());
assertNoImportErrors(trackerImportService.importTracker(teiParams));
TrackerImportParams enrollmentParams = fromJson("tracker/single_enrollment.json", userA.getUid());
assertNoImportErrors(trackerImportService.importTracker(enrollmentParams));
manager.flush();
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class OwnershipTest method testClientDatesForTeiEnrollmentEvent.
@Test
void testClientDatesForTeiEnrollmentEvent() throws IOException {
TrackerImportParams trackerImportParams = fromJson("tracker/ownership_event.json", nonSuperUser.getUid());
TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
manager.flush();
TrackerImportParams teiParams = fromJson("tracker/ownership_tei.json", nonSuperUser.getUid());
TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
List<TrackedEntityInstance> teis = manager.getAll(TrackedEntityInstance.class);
assertEquals(1, teis.size());
TrackedEntityInstance tei = teis.get(0);
assertNotNull(tei.getCreatedAtClient());
assertNotNull(tei.getLastUpdatedAtClient());
assertEquals(DateUtils.fromInstant(teiParams.getTrackedEntities().get(0).getCreatedAtClient()), tei.getCreatedAtClient());
assertEquals(DateUtils.fromInstant(teiParams.getTrackedEntities().get(0).getUpdatedAtClient()), tei.getLastUpdatedAtClient());
Set<ProgramInstance> pis = tei.getProgramInstances();
assertEquals(1, pis.size());
ProgramInstance pi = pis.iterator().next();
assertNotNull(pi.getCreatedAtClient());
assertNotNull(pi.getLastUpdatedAtClient());
assertEquals(DateUtils.fromInstant(enrollmentParams.getEnrollments().get(0).getCreatedAtClient()), pi.getCreatedAtClient());
assertEquals(DateUtils.fromInstant(enrollmentParams.getEnrollments().get(0).getUpdatedAtClient()), pi.getLastUpdatedAtClient());
Set<ProgramStageInstance> psis = pi.getProgramStageInstances();
assertEquals(1, psis.size());
ProgramStageInstance psi = psis.iterator().next();
assertNotNull(psi.getCreatedAtClient());
assertNotNull(psi.getLastUpdatedAtClient());
assertEquals(DateUtils.fromInstant(trackerImportParams.getEvents().get(0).getCreatedAtClient()), psi.getCreatedAtClient());
assertEquals(DateUtils.fromInstant(trackerImportParams.getEvents().get(0).getUpdatedAtClient()), psi.getLastUpdatedAtClient());
}
use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class OwnershipTest method testUpdateEnrollmentWithoutOwnership.
@Test
void testUpdateEnrollmentWithoutOwnership() 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");
trackerOwnershipManager.transferOwnership(tei, pgm, ou, true, false);
TrackerImportParams enrollmentParams = fromJson("tracker/ownership_enrollment.json", nonSuperUser.getUid());
enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
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 OwnershipTest method testDeleteEnrollment.
@Test
void testDeleteEnrollment() 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();
enrollmentParams.setImportStrategy(TrackerImportStrategy.DELETE);
TrackerImportReport updatedReport = trackerImportService.importTracker(enrollmentParams);
assertNoImportErrors(updatedReport);
assertEquals(1, updatedReport.getStats().getDeleted());
pis = manager.getAll(ProgramInstance.class);
assertEquals(1, pis.size());
}
Aggregations