/** * This method returns a FormEntrySession object using data in the instance object * @return FormEntrySession object * @throws Exception */ private void createSession() throws Exception { //TODO: Check for null patientUuid and try to parse the xml to obtain the patient ID instead. Patient patient = Context.getPatientService().getPatientByUuid(getPatientUuid()); session = new FormEntrySession(patient,getXmlDefinition(),null); HtmlForm htmlForm = HtmlFormEntryUtil.getService().getHtmlForm(htmlFormId); htmlForm.setXmlData(xmlDefinition); session.setHtmlForm(htmlForm); //getHtmlToDisplay() is called to generate necessary tag handlers and cache the form session.getHtmlToDisplay(); //PrepareForSubmit is called to set patient and encounter if specified in tags session.prepareForSubmit(); }
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; }