use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class AbstractEnrollmentService method updateEnrollments.
// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@Override
public ImportSummaries updateEnrollments(List<Enrollment> enrollments, ImportOptions importOptions) {
if (importOptions == null) {
importOptions = new ImportOptions();
}
ImportSummaries importSummaries = new ImportSummaries();
int counter = 0;
for (Enrollment enrollment : enrollments) {
importSummaries.addImportSummary(updateEnrollment(enrollment, importOptions));
if (counter % FLUSH_FREQUENCY == 0) {
clearSession();
}
counter++;
}
return importSummaries;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class AbstractEnrollmentService method getEnrollment.
@Override
public Enrollment getEnrollment(ProgramInstance programInstance, TrackedEntityInstanceParams params) {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(programInstance.getUid());
if (programInstance.getEntityInstance() != null) {
enrollment.setTrackedEntity(programInstance.getEntityInstance().getTrackedEntity().getUid());
enrollment.setTrackedEntityInstance(programInstance.getEntityInstance().getUid());
}
if (programInstance.getOrganisationUnit() != null) {
enrollment.setOrgUnit(programInstance.getOrganisationUnit().getUid());
enrollment.setOrgUnitName(programInstance.getOrganisationUnit().getName());
}
if (programInstance.getProgram().getCaptureCoordinates()) {
Coordinate coordinate = null;
if (programInstance.getLongitude() != null && programInstance.getLatitude() != null) {
coordinate = new Coordinate(programInstance.getLongitude(), programInstance.getLatitude());
try {
List<Double> list = OBJECT_MAPPER.readValue(coordinate.getCoordinateString(), new TypeReference<List<Double>>() {
});
coordinate.setLongitude(list.get(0));
coordinate.setLatitude(list.get(1));
} catch (IOException ignored) {
}
}
if (coordinate != null && coordinate.isValid()) {
enrollment.setCoordinate(coordinate);
}
}
enrollment.setCreated(DateUtils.getIso8601NoTz(programInstance.getCreated()));
enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(programInstance.getCreatedAtClient()));
enrollment.setLastUpdated(DateUtils.getIso8601NoTz(programInstance.getLastUpdated()));
enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(programInstance.getLastUpdatedAtClient()));
enrollment.setProgram(programInstance.getProgram().getUid());
enrollment.setStatus(EnrollmentStatus.fromProgramStatus(programInstance.getStatus()));
enrollment.setEnrollmentDate(programInstance.getEnrollmentDate());
enrollment.setIncidentDate(programInstance.getIncidentDate());
enrollment.setFollowup(programInstance.getFollowup());
enrollment.setCompletedDate(programInstance.getEndDate());
enrollment.setCompletedBy(programInstance.getCompletedBy());
List<TrackedEntityComment> comments = programInstance.getComments();
for (TrackedEntityComment comment : comments) {
Note note = new Note();
note.setValue(comment.getCommentText());
note.setStoredBy(comment.getCreator());
if (comment.getCreatedDate() != null) {
note.setStoredDate(comment.getCreatedDate().toString());
}
enrollment.getNotes().add(note);
}
if (params.isIncludeEvents()) {
for (ProgramStageInstance programStageInstance : programInstance.getProgramStageInstances()) {
enrollment.getEvents().add(eventService.getEvent(programStageInstance));
}
}
return enrollment;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class AbstractEnrollmentService method saveTrackedEntityComment.
private void saveTrackedEntityComment(ProgramInstance programInstance, Enrollment enrollment) {
String storedBy = currentUserService.getCurrentUsername();
for (Note note : enrollment.getNotes()) {
TrackedEntityComment comment = new TrackedEntityComment();
comment.setCreator(storedBy);
comment.setCreatedDate(new Date());
comment.setCommentText(note.getValue());
commentService.addTrackedEntityComment(comment);
programInstance.getComments().add(comment);
programInstanceService.updateProgramInstance(programInstance);
}
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class AbstractEnrollmentService method addEnrollments.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@Override
public ImportSummaries addEnrollments(List<Enrollment> enrollments, ImportOptions importOptions) {
if (importOptions == null) {
importOptions = new ImportOptions();
}
ImportSummaries importSummaries = new ImportSummaries();
int counter = 0;
for (Enrollment enrollment : enrollments) {
importSummaries.addImportSummary(addEnrollment(enrollment, importOptions));
if (counter % FLUSH_FREQUENCY == 0) {
clearSession();
}
counter++;
}
return importSummaries;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EnrollmentController method deleteEnrollment.
// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteEnrollment(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
if (!programInstanceService.programInstanceExists(id)) {
throw new WebMessageException(WebMessageUtils.notFound("Enrollment not found for ID " + id));
}
response.setStatus(HttpServletResponse.SC_OK);
ImportSummary importSummary = enrollmentService.deleteEnrollment(id);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
Aggregations