Package org.openmrs.module.htmlformentry

Examples of org.openmrs.module.htmlformentry.FormEntryContext


        TimeWidget widget = new TimeWidget();
        widget.setHidden(true);
        widget.setInitialValue(date);

        FormEntryContext formEntryContext = mock(FormEntryContext.class);
        when(formEntryContext.getFieldName(widget)).thenReturn("w1");

        String html = widget.generateHtml(formEntryContext);

        assertTrue(html.contains("<input type=\"hidden\" class=\"hfe-hours\" name=\"w1hours\" value=\"18\"/>"));
        assertTrue(html.contains("<input type=\"hidden\" class=\"hfe-minutes\" name=\"w1minutes\" value=\"09\"/>"));
View Full Code Here


        DateWidget widget = new DateWidget();
        widget.setHidden(true);
        widget.setInitialValue(date);

        FormEntryContext formEntryContext = mock(FormEntryContext.class);
        when(formEntryContext.getFieldName(widget)).thenReturn("w1");

        String html = widget.generateHtml(formEntryContext);
        assertThat(html, is("<input type=\"hidden\" name=\"w1\" id=\"w1\" value=\"2014-10-01\" />"));
    }
View Full Code Here

    if (patient == null) {
      throw new RuntimeException("Programming exception: person shouldn't be null");
    }

    FormEntryContext context = session.getContext();

    if (nameWidget != null) {
      PersonName name = (PersonName) nameWidget.getValue(context, request);

      if (patient != null) {
        if (!name.isPreferred()) {
          PersonName currentPreferredName = context.getExistingPatient().getPersonName();
          if (currentPreferredName != null){
            currentPreferredName.setPreferred(false);
            currentPreferredName.setVoided(true);
          }
        }
      }
     
      // HACK: we need to set the date created and uuid here as a hack around a hibernate flushing issue (see saving the Patient in FormEntrySession applyActions())
      if (name.getDateCreated() == null) {
        name.setDateCreated(new Date());
      }
      if (name.getUuid() == null) {
        name.setUuid(UUID.randomUUID().toString());
      }
     
     
      name.setPreferred(true);
      patient.addName(name);
    }

    if (genderWidget != null) {
      String value = (String) genderWidget.getValue(context, request);
      patient.setGender(value);
    }

    if (ageWidget != null) {
      Double value = (Double) ageWidget.getValue(context, request);
      if (value != null)
        calculateBirthDate(patient, null, value);
    }

    if (birthDateWidget != null) {
      Date value = (Date) birthDateWidget.getValue(context, request);
      if (value != null) {
        calculateBirthDate(patient, value, null);
      }
    }
    if (identifierTypeValueWidget != null && identifierTypeWidget != null) {
      String identifier = (String) identifierTypeValueWidget.getValue(context, request);
      PatientIdentifierType identifierType = getIdentifierType((String) identifierTypeWidget.getValue(context, request));

      // Look for an existing identifier of this type
      PatientIdentifier patientIdentifier = patient.getPatientIdentifier(identifierType);

      if (StringUtils.hasText(identifier)) {
        // No existing identifier of this type, so create new
        if (patientIdentifier == null) {
          patientIdentifier = new PatientIdentifier();
          patientIdentifier.setIdentifierType(identifierType);

          // HACK: we need to set the date created  and uuid here as a hack around a hibernate flushing issue (see saving the Patient in FormEntrySession applyActions())
          patientIdentifier.setDateChanged(new Date());
          patientIdentifier.setUuid(UUID.randomUUID().toString());

          // For 1.9+ onwards patients require a preferred identifier
          if (patient.getPatientId() == null) {
            patientIdentifier.setPreferred(true);
          }

          patient.addIdentifier(patientIdentifier);
        }

        if (!identifier.equals(patientIdentifier.getIdentifier()) || !identifierType.equals(patientIdentifier.getIdentifierType())) {
          validateIdentifier(identifierType.getId(), identifier);
        }

        patientIdentifier.setIdentifier(identifier);
      }
      else if (patientIdentifier != null) {
        // If this field is not required, then we interpret a blank value as a request to avoid any existing identifier
        session.getSubmissionActions().getIdentifiersToVoid().add(patientIdentifier);
      }
    }

    //
    // TODO current behavior always updates location of the preferred identifier rather than
    // a specific identifier type being edited by the identifier widget. But identifier location
    // widget isn't aware of the identifier type widget
    //
    if (identifierLocationWidget != null) {
      PatientIdentifier patientIdentifier = patient.getPatientIdentifier();
      if (patientIdentifier == null) {
        patientIdentifier = new PatientIdentifier();
        patient.addIdentifier(patientIdentifier);
      }

      Object locationString = identifierLocationWidget.getValue(context, request);
      Location location = (Location) HtmlFormEntryUtil.convertToType(locationString.toString().trim(), Location.class);
      patientIdentifier.setLocation(location);
      patientIdentifier.setPreferred(true);

    }

    if (addressWidget != null) {
      PersonAddress personAddress = (PersonAddress) addressWidget.getValue(context, request);
      if (context.getMode() == Mode.EDIT) {
        if (!personAddress.isPreferred()) {
          PersonAddress currentPreferredAddress = context.getExistingPatient().getPersonAddress();
          currentPreferredAddress.setPreferred(false);
          currentPreferredAddress.setVoided(true);
        }
      }
      personAddress.setPreferred(true);
View Full Code Here

  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)){
              autocompleteWidget = (AutocompleteWidget)entry.getKey();
View Full Code Here

  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)){
              autocompleteWidget = (AutocompleteWidget)entry.getKey();
View Full Code Here

    @Test
    public void testGenerateHtml() throws Exception {
        RemoteJsonAutocompleteWidget widget = new RemoteJsonAutocompleteWidget("drug.form");

        FormEntryContext fec = mock(FormEntryContext.class);
        when(fec.getFieldName(widget)).thenReturn("w17");

        String html = widget.generateHtml(fec);
        assertThat(html, containsString("<input id=\"w17-display\"/>"));
        assertThat(html, containsString("<input id=\"w17-value\" type=\"hidden\" name=\"w17\"/>"));
        assertThat(html, containsString("var displayTemplatew17 ="));
View Full Code Here

  }


    @Override
    public boolean doStartTag(FormEntrySession session, PrintWriter out, Node parent, Node node) throws BadFormDesignException {
        FormEntryContext context = session.getContext();
        ObsSubmissionElement element = new ObsSubmissionElement(context, getAttributes(node));
        session.getSubmissionController().addAction(element);
        out.print(element.generateHtml(context));

        context.pushToStack(element);
        return true;
    }
View Full Code Here

TOP

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

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.