/** * List all HTML Forms */ @RequestMapping("/module/htmlformentry/htmlForms") public void manageHtmlForms(Model model) { model.addAttribute("forms", HtmlFormEntryUtil.getService().getAllHtmlForms()); }
HtmlForm form = Context.getService(HtmlFormEntryService.class).getHtmlForm(id); xml = form.getXmlData();
@RequestMapping(value = "/module/htmlformentry/encounter.json", method = RequestMethod.GET) @ResponseBody public JsonNode encounterSchemaAsJson(@RequestParam(value="encounter") Encounter encounter, HttpSession httpSession) throws Exception { // TODO error handling-- no form? ObjectMapper jackson = new ObjectMapper(); HtmlForm form = Context.getService(HtmlFormEntryService.class).getHtmlFormByForm(encounter.getForm()); HtmlFormSchema schema = generateSchema(form.getXmlData(), httpSession, encounter); return buildSchemaAsJsonNode(schema, jackson); }
/** * Clears deprecated names and descriptions (because they exactly matched the underlying form * @param request * @return */ @RequestMapping(method=RequestMethod.POST, params="migration=clearNamesAndDescriptions") public String clearNamesAndDescriptionsThatMatch(@RequestParam(value="clearName", required=false) List<Integer> clearNames, @RequestParam(value="clearDescription", required=false) List<Integer> clearDescriptions) { HtmlFormEntryService service = HtmlFormEntryUtil.getService(); for (HtmlForm form : service.getAllHtmlForms()) { boolean needToSave = false; if (clearNames != null && clearNames.contains(form.getId())) { form.setDeprecatedName(null); needToSave = true; } if (clearDescriptions != null && clearDescriptions.contains(form.getId())) { form.setDeprecatedDescription(null); needToSave = true; } if (needToSave) service.saveHtmlForm(form); } return "redirect:migrateNamesAndDescriptions.form"; }
Map<String, TagHandler> tagHandlers = Context.getService(HtmlFormEntryService.class).getHandlers(); OpenmrsObject object = Context.getService(HtmlFormEntryService.class).getItemByUuid( (Class<? extends OpenmrsObject>) attributeDescriptor.getClazz(), id); if (object != null) { HtmlForm htmlForm = Context.getService(HtmlFormEntryService.class).getHtmlFormByForm(form); if (htmlForm != null){ dependencies.add(htmlForm); OpenmrsObject object = Context.getService(HtmlFormEntryService.class).getItemByName( (Class<? extends OpenmrsMetadata>) attributeDescriptor.getClazz(), id); if (object != null) {
@Override public void reprocessArchivedForm(String argument,boolean isPath) throws Exception { SerializableFormObject formObject; if(isPath) { formObject = SerializableFormObject.deserializeXml(argument); } else { formObject = SerializableFormObject.deserializeXml(argument,false); } formObject.handleSubmission(); //Save data to database HtmlFormEntryUtil.getService().applyActions(formObject.getSession()); }
htmlForm = HtmlFormEntryUtil.getService().getHtmlFormByForm(form); if (htmlForm == null) throw new IllegalArgumentException("No HtmlForm associated with formId " + formId); } else { form = encounter.getForm(); htmlForm = HtmlFormEntryUtil.getService().getHtmlFormByForm(encounter.getForm()); if (htmlForm == null) throw new IllegalArgumentException("The form for the specified encounter (" + encounter.getForm() + ") does not have an HtmlForm associated with it"); htmlForm = HtmlFormEntryUtil.getService().getHtmlForm(htmlFormId); } else if (formId != null) { form = Context.getFormService().getForm(formId); htmlForm = HtmlFormEntryUtil.getService().getHtmlFormByForm(form);
throw new RuntimeException("Cannot find role: " + roleParam); } else { users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole()); Role role = Context.getUserService().getRole(defaultRole); if (role != null) { users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole()); users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(null);
public void validateTags(Node node, Errors errors, Map<String, TagHandler> tagHandlerCache) { if (tagHandlerCache == null) { tagHandlerCache = new HashMap<String, TagHandler>(); } TagHandler handler = null; if (node.getNodeName() != null) { if (tagHandlerCache.containsKey(node.getNodeName())) { handler = tagHandlerCache.get(node.getNodeName()); } else { handler = HtmlFormEntryUtil.getService().getHandlerByTagName(node.getNodeName()); tagHandlerCache.put(node.getNodeName(), handler); } } if (handler != null && handler instanceof TagValidator) { TagAnalysis analysis = ((TagValidator) handler).validate(node); if (analysis.getWarnings().size() > 0 || analysis.getErrors().size() > 0) { htmlFormWarnings.addAll(analysis.getWarnings()); for (String errorMsg : analysis.getErrors()) { errors.reject(errorMsg); } } } NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { validateTags(children.item(i), errors, tagHandlerCache); } }
private void stripLocalAttributesFromXml() { Map<String, TagHandler> tagHandlers = Context.getService(HtmlFormEntryService.class).getHandlers();
@Override @SuppressWarnings("unchecked") public String substitute(String value, Class<?> clazz, Map<OpenmrsObject, OpenmrsObject> substitutionMap) { // if this is not a reference to an OpenMRS object, no substitution to perform if (!OpenmrsObject.class.isAssignableFrom(clazz)) { return value; } OpenmrsObject object = null; // if this appears to be an id, try to find the OpenmrsObject referenced by this id if (value.matches("^\\d+$") && !HtmlFormEntryUtil.isValidUuidFormat(value)) { object = Context.getService(HtmlFormEntryService.class).getItemById((Class<? extends OpenmrsObject>) clazz, Integer.valueOf(value)); } // if we have found an object, return the uuid and use it for substitution, otherwise don't do any substitution if (object != null) { return object.getUuid(); } else { return value; } }
/** * @see {@link HtmlFormEntryService#getHtmlFormByUuid()} */ @Test @Verifies(value = "should return the HtmlForm with the given uuid", method = "getHtmlFormByUuid()") public void getHtmlFormByUuid_shouldReturnTheHtmlFormWithTheGivenUuid() throws Exception { Assert.assertNotNull(service.getHtmlFormByUuid("12e41146-e162-11df-9195-001e378eb67e")); }
HtmlFormEntryService service = HtmlFormEntryUtil.getService(); for (HtmlForm htmlForm : service.getAllHtmlForms()) { boolean modified = false; service.saveHtmlForm(htmlForm);
HtmlFormEntryUtil.getService().applyActions(session); String successView = session.getAfterSaveUrlTemplate(); if (successView != null) {
throw new RuntimeException("Cannot find role: " + parameters.get("role")); } else { users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole()); Role role = Context.getUserService().getRole(defaultRole); if (role != null) { users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(role.getRole()); users = Context.getService(HtmlFormEntryService.class).getUsersAsPersonStubs(null);
handler = HtmlFormEntryUtil.getService().getHandlerByTagName(name); tagHandlerCache.put(name, handler);
Map<String, TagHandler> tagHandlers = Context.getService(HtmlFormEntryService.class).getHandlers();
@Override protected Object formBackingObject(HttpServletRequest request) throws Exception { return HtmlFormEntryUtil.getService().getAllHtmlForms(); }
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; }
@ModelAttribute("htmlForm") HtmlForm formBackingObject(@RequestParam(value="id", required=false) Integer id) { if (id != null) { HtmlForm hf = HtmlFormEntryUtil.getService().getHtmlForm(id); // avoid LazyInitializationException hf.getForm().getFormFields().size(); return hf; } else { HtmlForm hf = new HtmlForm(); hf.setForm(new Form()); return hf; } }