/** * If the html form contains both PatientTags and Encounter tags then initialize it with the * Patient and Encounter associated with the Form else if htmlform only contains PatientTags * then initialize it with the Patient associated with the Form. */ public void prepareForSubmit() { submissionActions = new FormSubmissionActions(); if (hasPatientTag() && !hasEncouterTag()) { try { submissionActions.beginPerson(patient); } catch (InvalidActionException e) { log.error("Programming error: should be no errors starting a patient", e); } } else { if (context.getMode() == Mode.EDIT) { if (encounter == null) throw new RuntimeException("Programming exception: encounter shouldn't be null in EDIT mode"); } else { encounter = new Encounter(); } try { submissionActions.beginPerson(patient); submissionActions.beginEncounter(encounter); } catch (InvalidActionException e) { log.error("Programming error: should be no errors starting a patient and encounter", e); } } }
throw new IllegalArgumentException("This form is not going to create an Patient"); if (session.getContext().getMode() == Mode.ENTER && session.hasEncouterTag() && (session.getSubmissionActions().getEncountersToCreate() == null || session.getSubmissionActions().getEncountersToCreate().size() == 0)) throw new IllegalArgumentException("This form is not going to create an encounter");
private SubmissionResults doSubmission(FormEntrySession session, HttpServletRequest request) throws Exception { SubmissionResults results = new SubmissionResults(); session.prepareForSubmit(); List<FormSubmissionError> validationErrors = session.getSubmissionController().validateSubmission( session.getContext(), request); if (validationErrors != null && validationErrors.size() > 0) { results.setValidationErrors(validationErrors); return results; } session.getSubmissionController().handleFormSubmission(session, request); if (session.getContext().getMode() == Mode.ENTER && session.hasEncouterTag() && (session.getSubmissionActions().getEncountersToCreate() == null || session.getSubmissionActions() .getEncountersToCreate().size() == 0)) throw new IllegalArgumentException("This form is not going to create an encounter"); Context.getService(HtmlFormEntryService.class).applyActions(session); results.setPatient(session.getPatient()); results.setEncounterCreated(session.getEncounter()); results.setFormEntrySession(session); return results; }