use of org.openmrs.module.htmlformentry.InvalidActionException 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);
}
}
Aggregations