Search in sources :

Example 1 with Enrollment

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;
}
Also used : ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 2 with Enrollment

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;
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Coordinate(org.hisp.dhis.dxf2.events.event.Coordinate) Note(org.hisp.dhis.dxf2.events.event.Note) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 3 with 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);
    }
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Note(org.hisp.dhis.dxf2.events.event.Note) Date(java.util.Date)

Example 4 with Enrollment

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;
}
Also used : ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 5 with Enrollment

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);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)46 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)44 Test (org.junit.jupiter.api.Test)35 Event (org.hisp.dhis.dxf2.events.event.Event)31 Date (java.util.Date)28 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)23 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)20 ArrayList (java.util.ArrayList)18 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)18 ProgramInstance (org.hisp.dhis.program.ProgramInstance)18 List (java.util.List)17 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)17 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)14 Program (org.hisp.dhis.program.Program)14 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 Map (java.util.Map)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Lists (com.google.common.collect.Lists)11