Package org.openmrs.module.htmlformentry

Examples of org.openmrs.module.htmlformentry.FormEntrySession


        } else {
          p = HtmlFormEntryUtil.getFakePerson();
        }
        HtmlForm fakeForm = new HtmlForm();
        fakeForm.setXmlData(xml);
        FormEntrySession fes = new FormEntrySession(p, null, Mode.ENTER, fakeForm, request.getSession());
        String html = fes.getHtmlToDisplay();
        if (fes.getFieldAccessorJavascript() != null) {
                  html += "<script>" + fes.getFieldAccessorJavascript() + "</script>";
                }
        model.addAttribute("previewHtml", html);
        //clear the error message
        message = "";
      } else {
View Full Code Here


      }
     
    if (mode != Mode.ENTER && patient == null)
      throw new IllegalArgumentException("No patient with id of personId=" + personId + " or patientId=" + patientId);
               
        FormEntrySession session = null;
    if (mode == Mode.ENTER && patient == null) {
      patient = new Patient();     
    }
    if (encounter != null) {
      session = new FormEntrySession(patient, encounter, mode, htmlForm, request.getSession());
    }
    else {
      session = new FormEntrySession(patient, htmlForm, request.getSession());
    }

        if (StringUtils.hasText(returnUrl)) {
            session.setReturnUrl(returnUrl);
        }

        // Since we're not using a sessionForm, we need to check for the case where the underlying form was modified while a user was filling a form out
        if (formModifiedTimestamp != null) {
            if (!OpenmrsUtil.nullSafeEquals(formModifiedTimestamp, session.getFormModifiedTimestamp())) {
                throw new RuntimeException(Context.getMessageSourceService().getMessage("htmlformentry.error.formModifiedBeforeSubmission"));
            }
        }

        // Since we're not using a sessionForm, we need to make sure this encounter hasn't been modified since the user opened it
        if (encounter != null) {
          if (encounterModifiedTimestamp != null && !OpenmrsUtil.nullSafeEquals(encounterModifiedTimestamp, session.getEncounterModifiedTimestamp())) {
            throw new RuntimeException(Context.getMessageSourceService().getMessage("htmlformentry.error.encounterModifiedBeforeSubmission"));
          }
        }
       
        if (hasChangedInd != null) session.setHasChangedInd(hasChangedInd);

        // ensure we've generated the form's HTML (and thus set up the submission actions, etc) before we do anything
        session.getHtmlToDisplay();

        Context.setVolatileUserData(FORM_IN_PROGRESS_KEY, session);
      
        log.info("Took " + (System.currentTimeMillis() - ts) + " ms");
       
View Full Code Here

        }
       
    Patient p = HtmlFormEntryUtil.getFakePerson();
    HtmlForm fakeForm = new HtmlForm();
    fakeForm.setXmlData(xml);
        FormEntrySession fes = new FormEntrySession(p, null, Mode.ENTER, fakeForm, httpSession);
        fes.getHtmlToDisplay();
        HtmlFormSchema schema = fes.getContext().getSchema();
        model.addAttribute("schema", schema);
        model.addAttribute("message", message);
    }
View Full Code Here

    if (hf.getId() == null) {
      model.addAttribute("previewHtml", "");
    } else {
      try {
                Patient demo = HtmlFormEntryUtil.getFakePerson();
                FormEntrySession fes = new FormEntrySession(demo, hf.getXmlData(), httpSession);
                String html = fes.getHtmlToDisplay();
                if (fes.getFieldAccessorJavascript() != null) {
                  html += "<script>" + fes.getFieldAccessorJavascript() + "</script>";
                }
                model.addAttribute("previewHtml", html);
            } catch (Exception ex) {
                log.warn("Error rendering html form", ex);
                model.addAttribute("previewHtml", "Error! " + ex);
View Full Code Here

    @Test
  public void autocompleteWidget_shouldAcceptLocationOptionsWithSingleOrDoubleQuotesInMiddle() throws Exception {

        AutocompleteWidget autocompleteWidget = null;
        String htmlform = "<htmlform><encounterLocation type=\"autocomplete\" /></htmlform>";
    FormEntrySession session = new FormEntrySession(null, htmlform, null);
        FormEntryContext enterContext = session.getContext();
        Map<Widget, String> widgets = enterContext.getFieldNames();
        Set<Map.Entry<Widget,String>> entries = widgets.entrySet();

        for(Map.Entry<Widget,String> entry : entries){
            if(entry.getKey().getClass().equals(AutocompleteWidget.class)){
View Full Code Here

    @Test
  public void autocompleteWidget_shouldAcceptLocationOptionsWithSpecialCharacters() throws Exception {

        AutocompleteWidget autocompleteWidget = null;
        String htmlform = "<htmlform><encounterLocation type=\"autocomplete\" /></htmlform>";
    FormEntrySession session = new FormEntrySession(null, htmlform, null);
        FormEntryContext enterContext = session.getContext();
        Map<Widget, String> widgets = enterContext.getFieldNames();
        Set<Map.Entry<Widget,String>> entries = widgets.entrySet();

        for(Map.Entry<Widget,String> entry : entries){
            if(entry.getKey().getClass().equals(AutocompleteWidget.class)){
View Full Code Here

     * @param HtmlForm htmlForm
     * @return
     */
    public static Map<Integer, String> getSectionIndex(HtmlForm htmlForm) throws Exception{
        Document doc = HtmlFormEntryUtil.stringToDocument(htmlForm.getXmlData());
        FormEntrySession session = new FormEntrySession(HtmlFormEntryUtil.getFakePerson(), htmlForm, null); // session gets a null HttpSession
        NodeList nl = doc.getElementsByTagName("section");
        Map<Integer, String> ret = new LinkedHashMap<Integer, String>();
        for (int i = 0; i < nl.getLength(); i++){
            Node sectionNode = nl.item(i);
            NamedNodeMap map = sectionNode.getAttributes();
            String headerLabel = "no name specified";
            for (int j = 0; j < map.getLength(); ++j) {
                Node attribute = map.item(j);
                if (attribute.getNodeName().equals("headerLabel")) {
                    headerLabel = attribute.getNodeValue();
                }
                if (attribute.getNodeName().equals("headerCode")) {
                    Translator trans = session.getContext().getTranslator();
                    headerLabel = trans.translate(Context.getLocale().toString(), attribute.getNodeValue());
                }
            }
            ret.put(i, headerLabel);
        }
View Full Code Here

     * @throws Exception
     */
    public static Encounter trimEncounterToMatchForm(Encounter e, HtmlForm htmlform) throws Exception {
       
       //this should move existing obs from session to tag handlers.
        FormEntrySession session = new FormEntrySession(e.getPatient(), e, FormEntryContext.Mode.VIEW, htmlform, null); // session gets a null HttpSession
        session.getHtmlToDisplay();
       
        if (log.isDebugEnabled()){
            Map<Concept, List<Obs>>  map = session.getContext().getExistingObs();
            if (map != null){
                for (Map.Entry<Concept, List<Obs>> existingObs : map.entrySet()){
                    List<Obs> oList = existingObs.getValue();
                    for (Obs oInner : oList)
                        log.debug("Obs in existingObs " + existingObs.getKey() + " " + oInner.getConcept());
                }
            }
            Map<Obs, Set<Obs>> map2 = session.getContext().getExistingObsInGroups();
            if (map2 != null){
                for (Map.Entry<Obs, Set<Obs>> existingObsInGroups : map2.entrySet()){
                    Set<Obs> oList = existingObsInGroups.getValue();
                    for (Obs oInner : oList)
                        log.debug("Obs in existingObsInGroups " + existingObsInGroups.getKey().getConcept() + " " + oInner.getConcept());
                }
            }
        }
        Encounter ret = new Encounter();
        ret.setCreator(e.getCreator());
        ret.setEncounterDatetime(e.getEncounterDatetime());
        ret.setProvider(e.getProvider());
        ret.setLocation(e.getLocation());
        ret.setDateCreated(e.getDateCreated());
        ret.setPatient(e.getPatient());
        //renders new encounter unsave-able:
        ret.setEncounterId(e.getEncounterId());
       
        for (Obs oTest : e.getAllObs()){
            boolean found = false;
            if (session.getContext().getExistingObs() != null && !oTest.isObsGrouping()){
                List<Obs> obsList = session.getContext().getExistingObs().get(oTest.getConcept());
                if (obsList != null && obsList.size() > 0){
                    for (Obs o : obsList){
                        if (o.getObsId().equals(oTest.getObsId())){
                            found = true;
                            continue;
                        }
                    }  
                }
            }
            if (!found && session.getContext().getExistingObsInGroups() != null){
                for (Map.Entry<Obs, Set<Obs>> mapEntry : session.getContext().getExistingObsInGroups().entrySet()){
                    if (mapEntry.getKey().equals(oTest)){
                        found = true;
                        continue;
                    } else {
                        Set<Obs> oSet = mapEntry.getValue();
View Full Code Here

     * @param extraCols
     * @return
     * @throws Exception
     */
    public static String generateColumnHeadersFromHtmlForm(HtmlForm form, List<String> extraCols, StringBuffer sb, List<PatientIdentifierType> pitList) throws Exception {
        FormEntrySession session = new FormEntrySession(HtmlFormEntryUtil.getFakePerson(), form, null); // session gets a null HttpSession
        session.getHtmlToDisplay();
        HtmlFormSchema hfs = session.getContext().getSchema();
       
        sb.
        append(DEFAULT_QUOTE).append("ENCOUNTER_ID").append(DEFAULT_QUOTE).append(DEFAULT_COLUMN_SEPARATOR).
        append(DEFAULT_QUOTE).append("ENCOUNTER_DATE").append(DEFAULT_QUOTE).append(DEFAULT_COLUMN_SEPARATOR).
        append(DEFAULT_QUOTE).append("ENCOUNTER_LOCATION").append(DEFAULT_QUOTE).append(DEFAULT_COLUMN_SEPARATOR).
View Full Code Here

                if (index < pitList.size())
                    sb.append(DEFAULT_COLUMN_SEPARATOR);
                index ++;
            }
           
            FormEntrySession session = new FormEntrySession(e.getPatient(), e, Mode.VIEW, form, null); // session doesn't get HttpSession
            session.getHtmlToDisplay();
            FormSubmissionController  fsa = session.getSubmissionController();
            List<FormSubmissionControllerAction> actions = fsa.getActions();
            for (FormSubmissionControllerAction fsca : actions){
                if (fsca instanceof ObsSubmissionElement){
                    ObsSubmissionElement ose = (ObsSubmissionElement) fsca;
                    sb = appendObsToRow(ose, sb, extraCols, locale);  
View Full Code Here

TOP

Related Classes of org.openmrs.module.htmlformentry.FormEntrySession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.