private Concept createConceptWithName(String name) {
   Concept concept = new Concept(new Random().nextInt());
   ConceptName conceptName = new ConceptName();
   conceptName.setName(name);
   conceptName.setLocale(Context.getLocale());
   conceptName.setLocalePreferred(true);
   concept.addName(conceptName);
   return concept;
 }
 public String getTRValueSetCode(Concept concept) {
   for (ConceptMap mapping : concept.getConceptMappings()) {
     if (mapping.getConceptMapType().getUuid().equals(ConceptMapType.SAME_AS_MAP_TYPE_UUID)) {
       return mapping.getConceptReferenceTerm().getCode();
     }
   }
   for (ConceptName conceptName : concept.getShortNames()) {
     return conceptName.getName();
   }
   return concept.getName().getName();
 }
Ejemplo n.º 3
0
  /**
   * 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 "";
  }