use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class EventDataValueTest method testEventDataValue.
@Test
void testEventDataValue() throws IOException {
TrackerImportParams trackerImportParams = fromJson("tracker/event_with_data_values.json");
TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
List<ProgramStageInstance> events = manager.getAll(ProgramStageInstance.class);
assertEquals(1, events.size());
ProgramStageInstance psi = events.get(0);
Set<EventDataValue> eventDataValues = psi.getEventDataValues();
assertEquals(4, eventDataValues.size());
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class EventDataValueTest method testTrackedEntityProgramAttributeValueUpdate.
@Test
void testTrackedEntityProgramAttributeValueUpdate() throws IOException {
TrackerImportParams trackerImportParams = fromJson("tracker/event_with_data_values.json");
TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
List<ProgramStageInstance> events = manager.getAll(ProgramStageInstance.class);
assertEquals(1, events.size());
ProgramStageInstance psi = events.get(0);
Set<EventDataValue> eventDataValues = psi.getEventDataValues();
assertEquals(4, eventDataValues.size());
// update
trackerImportParams = fromJson("tracker/event_with_updated_data_values.json");
// make sure that the uid property is populated as well - otherwise
// update will
// not work
trackerImportParams.getEvents().get(0).setEvent(trackerImportParams.getEvents().get(0).getEvent());
trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE_AND_UPDATE);
trackerImportReport = trackerImportService.importTracker(trackerImportParams);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
List<ProgramStageInstance> updatedEvents = manager.getAll(ProgramStageInstance.class);
assertEquals(1, updatedEvents.size());
ProgramStageInstance updatedPsi = programStageInstanceService.getProgramStageInstance(updatedEvents.get(0).getUid());
assertEquals(3, updatedPsi.getEventDataValues().size());
List<String> values = updatedPsi.getEventDataValues().stream().map(EventDataValue::getValue).collect(Collectors.toList());
assertThat(values, hasItem("First"));
assertThat(values, hasItem("Second"));
assertThat(values, hasItem("Fourth updated"));
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class EventDataValueTest method successWhenEventHasNoProgramAndHasProgramStage.
@Test
void successWhenEventHasNoProgramAndHasProgramStage() throws IOException {
TrackerImportParams params = fromJson("tracker/validations/events-with_no_program.json");
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
}
use of org.hisp.dhis.tracker.report.TrackerImportReport in project dhis2-core by dhis2.
the class OwnershipTest method testCreateEnrollmentAfterDeleteEnrollment.
@Test
void testCreateEnrollmentAfterDeleteEnrollment() 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());
pis = manager.getAll(ProgramInstance.class);
assertEquals(1, pis.size());
enrollmentParams.setImportStrategy(TrackerImportStrategy.CREATE);
enrollmentParams.getEnrollments().get(0).setEnrollment(CodeGenerator.generateUid());
updatedReport = trackerImportService.importTracker(enrollmentParams);
assertNoImportErrors(updatedReport);
assertEquals(1, updatedReport.getStats().getCreated());
pis = manager.getAll(ProgramInstance.class);
assertEquals(2, pis.size());
}
use of org.hisp.dhis.tracker.report.TrackerImportReport 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);
}
Aggregations