use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.
the class RelationshipTrackerConverterServiceTest method setUpTest.
@Override
protected void setUpTest() throws IOException {
preCreateInjectAdminUserWithoutPersistence();
renderService = _renderService;
userService = _userService;
TrackedEntityType trackedEntityType = createTrackedEntityType('A');
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
Program program = createProgram('A');
programService.addProgram(program);
ProgramStage programStage = createProgramStage('A', program);
programStageService.saveProgramStage(programStage);
TrackedEntityAttribute trackedEntityAttribute = createTrackedEntityAttribute('A');
OrganisationUnit organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
TrackedEntityInstance trackedEntityInstance = createTrackedEntityInstance('A', organisationUnit, trackedEntityAttribute);
trackedEntityInstance.setUid(TEI);
ProgramInstance programInstance = new ProgramInstance();
programInstance.setEnrollmentDate(new Date());
programInstance.setProgram(program);
programInstance.setUid(ENROLLMENT);
ProgramStageInstance programStageInstance = new ProgramStageInstance();
programStageInstance.setUid(EVENT);
programStageInstance.setProgramInstance(programInstance);
programStageInstance.setProgramStage(programStage);
trackedEntityInstanceService.addTrackedEntityInstance(trackedEntityInstance);
programInstanceService.addProgramInstance(programInstance);
programStageInstanceService.addProgramStageInstance(programStageInstance);
RelationshipType relationshipTypeA = createTeiToEnrollmentRelationshipType('A', program, trackedEntityType, false);
relationshipTypeA.setUid(TEI_TO_ENROLLMENT_RELATIONSHIP_TYPE);
RelationshipType relationshipTypeB = createTeiToEventRelationshipType('B', program, trackedEntityType, false);
relationshipTypeB.setUid(TEI_TO_EVENT_RELATIONSHIP_TYPE);
relationshipTypeService.addRelationshipType(relationshipTypeA);
relationshipTypeService.addRelationshipType(relationshipTypeB);
TrackerImportParams trackerImportParams = renderService.fromJson(new ClassPathResource("tracker/relationships.json").getInputStream(), TrackerImportParams.class);
User adminUser = createAndInjectAdminUser();
trackerImportParams.setUser(adminUser);
trackerBundle = trackerBundleService.create(trackerImportParams);
}
use of org.hisp.dhis.tracker.TrackerImportParams 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.TrackerImportParams 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.TrackerImportParams 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.TrackerImportParams 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());
}
Aggregations