public EncounterListItem(Encounter encounter) {

    if (encounter != null) {
      encounterId = encounter.getEncounterId();
      encounterDateTime = encounter.getEncounterDatetime();
      encounterDateString = Format.format(encounter.getEncounterDatetime());
      PersonName pn = encounter.getPatient().getPersonName();
      if (pn != null) {
        personName = "";
        if (pn.getGivenName() != null) {
          personName += pn.getGivenName();
        }
        if (pn.getMiddleName() != null) {
          personName += " " + pn.getMiddleName();
        }
        if (pn.getFamilyName() != null) {
          personName += " " + pn.getFamilyName();
        }
      }
      if (encounter.getProvider() != null) {
        providerName = encounter.getProvider().getPersonName().getFullName();
      }
      if (encounter.getLocation() != null) {
        location = encounter.getLocation().getName();
      }
      if (encounter.getEncounterType() != null) {
        encounterType = encounter.getEncounterType().getName();
      }
      if (encounter.getForm() != null) {
        formName = encounter.getForm().getName();
        formId = encounter.getForm().getFormId();
      }
      voided = encounter.isVoided();
      if (encounter.getCreator() != null) {
        PersonName entererPersonName = encounter.getCreator().getPersonName();
        if (entererPersonName != null) {
          entererName = "";
          if (entererPersonName.getGivenName() != null) {
            entererName += entererPersonName.getGivenName();
          }
          if (entererPersonName.getMiddleName() != null) {
            entererName += " " + entererPersonName.getMiddleName();
          }
          if (entererPersonName.getFamilyName() != null) {
            entererName += " " + entererPersonName.getFamilyName();
          }
        }
      }
    }
  }
예제 #2
0
파일: Obs.java 프로젝트: sapna-m/openmrs
  /**
   * Convenience method for obtaining the observation's value as a string If the Obs is complex,
   * returns the title of the complexData denoted by the section of getValueComplex() before the
   * first bar '|' character; or returns the entire getValueComplex() if the bar '|' character is
   * missing.
   *
   * @param locale locale for locale-specific depictions of value
   * @should return first part of valueComplex for complex obs
   * @should return first part of valueComplex for non null valueComplexes
   */
  public String getValueAsString(Locale locale) {
    // branch on hl7 abbreviations
    if (getConcept() != null) {
      String abbrev = getConcept().getDatatype().getHl7Abbreviation();
      if (abbrev.equals("BIT"))
        return getValueAsBoolean() == null ? "" : getValueAsBoolean().toString();
      else if (abbrev.equals("CWE")) {
        if (getValueCoded() == null) return "";
        if (getValueDrug() != null) return getValueDrug().getFullName(locale);
        else {
          ConceptName valueCodedName = getValueCodedName();
          if (valueCodedName != null) {
            return valueCodedName.getName();
          } else {
            ConceptName fallbackName = getValueCoded().getName();
            if (fallbackName != null) {
              return fallbackName.getName();
            } else {
              return "";
            }
          }
        }
      } else if (abbrev.equals("NM") || abbrev.equals("SN"))
        return getValueNumeric() == null ? "" : getValueNumeric().toString();
      else if (abbrev.equals("DT"))
        return (getValueDatetime() == null
            ? ""
            : Format.format(getValueDatetime(), locale, FORMAT_TYPE.DATE));
      else if (abbrev.equals("TM"))
        return (getValueDatetime() == null
            ? ""
            : Format.format(getValueDatetime(), locale, FORMAT_TYPE.TIME));
      else if (abbrev.equals("TS"))
        return (getValueDatetime() == null
            ? ""
            : Format.format(getValueDatetime(), locale, FORMAT_TYPE.TIMESTAMP));
      else if (abbrev.equals("ST")) return getValueText();
      else if (abbrev.equals("ED") && getValueComplex() != null) {
        String[] valueComplex = getValueComplex().split("\\|");
        for (int i = 0; i < valueComplex.length; i++) {
          if (!"".equals(valueComplex[i])) {
            return valueComplex[i].trim();
          }
        }
      }
    }

    // if the datatype is 'unknown', default to just returning what is not null
    if (getValueNumeric() != null) return getValueNumeric().toString();
    else if (getValueCoded() != null) {
      if (getValueDrug() != null) return getValueDrug().getFullName(locale);
      else {
        ConceptName valudeCodedName = getValueCodedName();
        if (valudeCodedName != null) {
          return valudeCodedName.getName();
        } else {
          return "";
        }
      }
    } else if (getValueDatetime() != null)
      return Format.format(getValueDatetime(), locale, FORMAT_TYPE.DATE);
    else if (getValueText() != null) return getValueText();
    else if (hasGroupMembers()) {
      // all of the values are null and we're an obs group...so loop
      // over the members and just do a getValueAsString on those
      // this could potentially cause an infinite loop if an obs group
      // is a member of its own group at some point in the hierarchy
      StringBuilder sb = new StringBuilder();
      for (Obs groupMember : getGroupMembers()) {
        if (sb.length() > 0) sb.append(", ");
        sb.append(groupMember.getValueAsString(locale));
      }
      return sb.toString();
    }

    // returns the title portion of the valueComplex
    // which is everything before the first bar '|' character.
    if (getValueComplex() != null) {
      String[] valueComplex = getValueComplex().split("\\|");
      for (int i = 0; i < valueComplex.length; i++) {
        if (!"".equals(valueComplex[i])) {
          return valueComplex[i].trim();
        }
      }
    }

    return "";
  }