@Override protected String getSubstitution(FormEntrySession session, FormSubmissionController controllerActions, Map<String, String> parameters) { Map<String, Object> temp = new HashMap<String, Object>(); temp.putAll(parameters); temp.put("provider", true); EncounterDetailSubmissionElement element = new EncounterDetailSubmissionElement(session.getContext(), temp); session.getSubmissionController().addAction(element); return element.generateHtml(session.getContext()); }
protected String getQueryPrameters(HttpServletRequest request, FormEntrySession formEntrySession) { return "?patientId=" + formEntrySession.getPatient().getPersonId(); } }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfWorkflowIdMissing() throws Exception { String htmlform = "<htmlform><workflowState/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Override public void applyAction(FormEntrySession session) { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(scriptType); scriptEngine.put("patient", session.getPatient()); scriptEngine.put("encounter", session.getSubmissionActions().getCurrentEncounter()); scriptEngine.put("formEntrySession", session); try { Object result = scriptEngine.eval(script); session.setAfterSaveUrlTemplate(result.toString()); } catch (ScriptException ex) { throw new IllegalStateException("Exception while evaluating " + scriptType + " for <redirectOnSave>", ex); } } }
/** * @see org.openmrs.module.htmlformentry.action.FormSubmissionControllerAction#handleSubmission(org.openmrs.module.htmlformentry.FormEntrySession, javax.servlet.http.HttpServletRequest) */ @Override public void handleSubmission(FormEntrySession session, HttpServletRequest submission) { if (session.getContext().getMode() == Mode.ENTER) { session.getSubmissionActions().completeProgram(program); } }
Model model) throws Exception { try { List<FormSubmissionError> validationErrors = session.getSubmissionController().validateSubmission(session.getContext(), request); if (validationErrors != null && validationErrors.size() > 0) { errors.reject("Fix errors"); session.prepareForSubmit(); if (session.getContext().getMode() == Mode.ENTER && session.hasPatientTag() && session.getPatient() == null && (session.getSubmissionActions().getPersonsToCreate() == null || session.getSubmissionActions().getPersonsToCreate().size() == 0)) 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"); session.getSubmissionController().handleFormSubmission(session, request); HtmlFormEntryUtil.getService().applyActions(session); String successView = session.getAfterSaveUrlTemplate(); if (successView != null) { successView = successView.replaceAll("\\{\\{patient.id\\}\\}", session.getPatient().getId().toString()); successView = successView.replaceAll("\\{\\{encounter.id\\}\\}", session.getEncounter().getId().toString()); successView = request.getContextPath() + "/" + successView; } else { successView = session.getReturnUrlWithParameters();
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; }
protected void enterStandardRegimen(FormEntrySession session, HttpServletRequest submission, String regCode, Date startDate, Date discontinuedDate, String discontinuedReasonStr) { RegimenSuggestion rs = RegimenUtil.getStandardRegimenByCode(possibleRegimens, regCode); //create new drugOrders Set<Order> ords = RegimenUtil.standardRegimenToDrugOrders(rs, startDate, session.getPatient()); for (Order o: ords){ if (o.getDateCreated() == null) o.setDateCreated(new Date()); if (o.getCreator() == null) o.setCreator(Context.getAuthenticatedUser()); if (o.getUuid() == null) o.setUuid(UUID.randomUUID().toString()); if (!StringUtils.isEmpty(discontinuedReasonStr)) o.setDiscontinuedReason(HtmlFormEntryUtil.getConcept(discontinuedReasonStr)); if (discontinuedDate != null){ o.setDiscontinuedDate(discontinuedDate); o.setDiscontinued(true); o.setDiscontinuedBy(Context.getAuthenticatedUser()); } session.getSubmissionActions().getCurrentEncounter().addOrder(o); } }
String stateUuid = (String) widget.getValue(session.getContext(), submission); if (!StringUtils.isBlank(stateUuid)) { if (Mode.EDIT.equals(session.getContext().getMode())) { PatientState oldPatientState = getActivePatientState(session.getContext().getExistingPatient(), session .getContext().getPreviousEncounterDate(), workflow); PatientProgram patientProgram = HtmlFormEntryUtil.getPatientProgramByProgramOnDate(session.getPatient(), newState.getProgramWorkflow().getProgram(), session.getEncounter().getEncounterDatetime()); session.getSubmissionActions().getPatientProgramsToUpdate().add(patientProgram); session.getSubmissionActions().transitionToState(newState); Date previousEncounterDate = session.getContext().getPreviousEncounterDate(); Date newEncounterDate = session.getEncounter().getEncounterDatetime(); PatientState existingPatientStateOnNewEncounterDate = getActivePatientState(session.getContext().getExistingPatient(), newEncounterDate, workflow); if (existingPatientStateOnNewEncounterDate != null && !existingPatientStateOnNewEncounterDate.equals(oldPatientState)) { existingPatientStateOnNewEncounterDate.setEndDate(newEncounterDate); session.getSubmissionActions().getPatientProgramsToUpdate().add(oldPatientState.getPatientProgram()); PatientProgram patientProgram = HtmlFormEntryUtil.getPatientProgramByProgramOnDate(session.getPatient(), state.getProgramWorkflow().getProgram(), session.getEncounter().getEncounterDatetime()); session.getSubmissionActions().getPatientProgramsToUpdate().add(patientProgram); session.getSubmissionActions().transitionToState(state);
private HtmlFormSchema generateSchema(String xml, HttpSession httpSession, Encounter encounter) throws Exception { HtmlForm fakeForm = new HtmlForm(); fakeForm.setXmlData(xml); FormEntrySession fes = new FormEntrySession(encounter.getPatient(), encounter, FormEntryContext.Mode.VIEW, fakeForm, httpSession); fes.getHtmlToDisplay(); return fes.getContext().getSchema(); }
@Before public void setUp() { patient = new Patient(); encounter = new Encounter(); encounter.setPatient(patient); unknownConcept = new Concept(); patientService = mock(PatientService.class); submissionController = mock(FormSubmissionController.class); formEntrySession = mock(FormEntrySession.class); when(formEntrySession.getSubmissionController()).thenReturn(submissionController); when(formEntrySession.getPatient()).thenReturn(patient); when(formEntrySession.getEncounter()).thenReturn(encounter); tagHandler = new MarkPatientDeadTagHandler() { @Override Concept getUnknownConcept() { return unknownConcept; } }; tagHandler.setPatientService(patientService); }
@Test public void shouldDisplayEncounterTypeValuePropertyAccessorUsingCustomName() throws Exception { String htmlform = "<htmlform><encounterType id=\"myEncounter\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); session.getHtmlToDisplay(); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['myEncounter.value'\\]", session.getFieldAccessorJavascript()); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['myEncounter.error'\\]", session.getFieldAccessorJavascript()); }
/** * 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(); }
@Override public void handleSubmission(FormEntrySession session, HttpServletRequest submission) { session.getSubmissionActions().addCustomFormSubmissionAction(this); }
@Override public boolean doStartTag(FormEntrySession session, PrintWriter out, Node parent, Node node) throws BadFormDesignException { if (session.getContext().getHighestOnStack(ObsSubmissionElement.class) == null) { throw new IllegalStateException("controlsSections tag must be inside an obs tag"); } return true; }
Patient patient = session.getPatient(); Encounter encounter = session.getEncounter(); SerializableFormObject formObject = null; if (patient != null && encounter != null) { formObject = new SerializableFormObject(session.getXmlDefinition(), submission.getParameterMap(), patient.getPatientIdentifier().getIdentifier(), patient.getUuid(), encounter.getUuid(),session.getHtmlFormId()); } else if(patient==null || encounter==null) { if(log.isDebugEnabled()) log.debug("Either patient or encounter or both are null"); formObject = new SerializableFormObject(session.getXmlDefinition(), submission.getParameterMap(), session.getHtmlFormId());
@Override public void doEndTag(FormEntrySession session, PrintWriter out, Node parent, Node node) { session.getSubmissionController().endRepeat(); }
@Override public void applyAction(FormEntrySession session) { Patient patient = session.getPatient(); Encounter encounter = session.getEncounter(); patient.setDead(true); if (deathDateFromEncounter) { if (patient.getDeathDate() == null || !preserveExistingDeathDate) { patient.setDeathDate(encounter.getEncounterDatetime()); } } if (patient.getCauseOfDeath() == null || !preserveExistingCauseOfDeath) { Concept causeOfDeath = null; if (causeOfDeathFromObs != null) { causeOfDeath = findObsCodedValue(session.getEncounter(), causeOfDeathFromObs); } if (causeOfDeath == null) { // don't overwrite with Unknown, even if we haven't specifically said to preserve existing causeOfDeath = patient.getCauseOfDeath(); } if (causeOfDeath == null) { causeOfDeath = getUnknownConcept(); } patient.setCauseOfDeath(causeOfDeath); } patientService.savePatient(patient); }
List<Obs> outcomeObs = findObsForConcept(outcomesConcept, submissionActions.getObsToCreate()); if (outcomeObs.size() == 1) { pp.setOutcome(outcomeObs.get(0).getValueCoded()); obsService.voidObs(o, "htmlformentry"); voidObsGroupIfAllChildObsVoided(o.getObsGroup()); patientIdentifier.setVoided(true); patientIdentifier.setVoidedBy(Context.getAuthenticatedUser()); patientIdentifier.setVoidReason(getForm().getName()); // Use form name as reason patientIdentifier.setDateVoided(new Date()); submissionActions.getExitFromCareProperty(); if (exitFromCareProperty.getCauseOfDeathConcept() != null) { Context.getPatientService().processDeath(this.getPatient(), exitFromCareProperty.getDateOfExit(), exitFromCareProperty.getCauseOfDeathConcept(), exitFromCareProperty.getOtherReason()); } else { PatientServiceCompatibility patientService = Context.getRegisteredComponent("htmlformentry.PatientServiceCompatibility", PatientServiceCompatibility.class); patientService.exitFromCare(this.getPatient(), exitFromCareProperty.getDateOfExit(), exitFromCareProperty.getReasonExitConcept());
/** * calls session.createForm on a form that has both conceptIds with labels, and conceptIds without labels in obs tags. * Verifies that the dropdown options for selecting a concept are correctly labeled. * @throws Exception */ @Test @Verifies(value = "should test labels generation for concept selects on dropdown options", method = "") public void getSectionNodes_shouldReturnDropdownForConceptSelects() throws Exception { Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "obsGroupDataExportTest.xml")); FormEntrySession session = new FormEntrySession(HtmlFormEntryUtil.getFakePerson(), htmlform, null); String xml = session.createForm(htmlform.getXmlData()); // System.out.println(xml); Assert.assertTrue(xml.contains("<option value=\"\" selected=\"true\"></option><option value=\"2474\">Susc</option><option value=\"3017\">Interm</option>")); Assert.assertTrue(xml.contains("<option value=\"\" selected=\"true\"></option><option value=\"2474\">Susceptible</option><option value=\"3017\">Intermediate</option><option value=\"1441\">Resistant</option>")); }