Search in sources :

Example 1 with FormSubmissionActions

use of org.openmrs.module.htmlformentry.FormSubmissionActions in project openmrs-module-coreapps by openmrs.

the class EncounterDiagnosesElement method handleSubmission.

@Override
public void handleSubmission(FormEntrySession formEntrySession, HttpServletRequest request) {
    DiagnosisMetadata diagnosisMetadata = emrApiProperties.getDiagnosisMetadata();
    String submitted = request.getParameter("encounterDiagnoses");
    // if we are in edit mode, we need to map the submitted diagnoses to their existing obs
    Map<Integer, Obs> existingDiagnosisObs = getExistingDiagnosisObs(formEntrySession.getContext(), diagnosisMetadata);
    FormSubmissionActions submissionActions = formEntrySession.getSubmissionActions();
    try {
        // we need to void any existing that isn't resubmitted
        Set<Integer> resubmittedObs = new HashSet<Integer>();
        List<Diagnosis> diagnoses = parseDiagnoses(submitted, existingDiagnosisObs);
        for (Diagnosis diagnosis : diagnoses) {
            if (diagnosis.getExistingObs() != null) {
                resubmittedObs.add(diagnosis.getExistingObs().getId());
            }
            Obs obsGroup = diagnosisMetadata.buildDiagnosisObsGroup(diagnosis);
            createObsGroup(submissionActions, obsGroup);
        }
        if (formEntrySession.getContext().getMode().equals(FormEntryContext.Mode.EDIT)) {
            // void any diagnosis that wasn't resubmitted
            Collection<Integer> obsToVoid = CollectionUtils.subtract(existingDiagnosisObs.keySet(), resubmittedObs);
            for (Integer obsId : obsToVoid) {
                submissionActions.modifyObs(existingDiagnosisObs.get(obsId), null, null, null, null, null);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } catch (InvalidActionException e) {
        throw new IllegalStateException(e);
    }
}
Also used : Obs(org.openmrs.Obs) InvalidActionException(org.openmrs.module.htmlformentry.InvalidActionException) DiagnosisMetadata(org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata) IOException(java.io.IOException) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) FormSubmissionActions(org.openmrs.module.htmlformentry.FormSubmissionActions) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Obs (org.openmrs.Obs)1 Diagnosis (org.openmrs.module.emrapi.diagnosis.Diagnosis)1 DiagnosisMetadata (org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata)1 FormSubmissionActions (org.openmrs.module.htmlformentry.FormSubmissionActions)1 InvalidActionException (org.openmrs.module.htmlformentry.InvalidActionException)1