org.hl7.fhir.dstu3.model.Extension Java Examples

The following examples show how to use org.hl7.fhir.dstu3.model.Extension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static String readStringExtension(Element c, String uri) {
  Extension ex = ExtensionHelper.getExtension(c, uri);
  if (ex == null)
    return null;
  if (ex.getValue() instanceof UriType)
    return ((UriType) ex.getValue()).getValue();
  if (ex.getValue() instanceof CodeType)
    return ((CodeType) ex.getValue()).getValue();
  if (ex.getValue() instanceof IntegerType)
    return ((IntegerType) ex.getValue()).asStringValue();
  if ((ex.getValue() instanceof MarkdownType))
    return ((MarkdownType) ex.getValue()).getValue();
  if (!(ex.getValue() instanceof StringType))
    return null;
  return ((StringType) ex.getValue()).getValue();
}
 
Example #2
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static String readStringExtension(DomainResource c, String uri) {
  Extension ex = getExtension(c, uri);
  if (ex == null)
    return null;
  if ((ex.getValue() instanceof StringType))
    return ((StringType) ex.getValue()).getValue();
  if ((ex.getValue() instanceof UriType))
    return ((UriType) ex.getValue()).getValue();
  if (ex.getValue() instanceof CodeType)
    return ((CodeType) ex.getValue()).getValue();
  if (ex.getValue() instanceof IntegerType)
    return ((IntegerType) ex.getValue()).asStringValue();
  if ((ex.getValue() instanceof MarkdownType))
    return ((MarkdownType) ex.getValue()).getValue();
  return null;
}
 
Example #3
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void addLanguageRow(ValueSetExpansionContainsComponent c, XhtmlNode t, List<String> langs) {
  XhtmlNode tr = t.tr();
  tr.td().addText(c.getCode());
  for (String lang : langs) {
    String d = null;
    for (Extension ext : c.getExtension()) {
      if (ToolingExtensions.EXT_TRANSLATION.equals(ext.getUrl())) {
        String l = ToolingExtensions.readStringExtension(ext, "lang");
        if (lang.equals(l))
          d = ToolingExtensions.readStringExtension(ext, "content");;
      }
    }
    tr.td().addText(d == null ? "" : d);
  }
  for (ValueSetExpansionContainsComponent cc : c.getContains()) {
    addLanguageRow(cc, t, langs);
  }
}
 
Example #4
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public Type getExampleValue(ElementDefinition ed) {
  if (ed.hasFixed())
    return ed.getFixed();
  for (Extension ex : ed.getExtension()) {
   String ndx = ToolingExtensions.readStringExtension(ex, "index");
   Type value = ToolingExtensions.getExtension(ex, "exValue").getValue();
   if (index.equals(ndx) && value != null)
     return value;
  }
  return null;
}
 
Example #5
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean hasAnyExampleValues(StructureDefinition sd, String index) {
  for (ElementDefinition ed : sd.getSnapshot().getElement())
    for (Extension ex : ed.getExtension()) {
      String ndx = ToolingExtensions.readStringExtension(ex, "index");
      Extension exv = ToolingExtensions.getExtension(ex, "exValue");
      if (exv != null) {
        Type value = exv.getValue();
      if (index.equals(ndx) && value != null)
        return true;
      }
     }
  return false;
}
 
Example #6
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static Extension makeIssueSource(Source source) {
  Extension ex = new Extension();
  // todo: write this up and get it published with the pack (and handle the redirect?)
  ex.setUrl(ToolingExtensions.EXT_ISSUE_SOURCE);
  CodeType c = new CodeType();
  c.setValue(source.toString());
  ex.setValue(c);
  return ex;
}
 
Example #7
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void addMarkdownExtension(DomainResource dr, String url, String content) {
  if (!StringUtils.isBlank(content)) {
    Extension ex = getExtension(dr, url);
    if (ex != null)
      ex.setValue(new StringType(content));
    else
      dr.getExtension().add(Factory.newExtension(url, new MarkdownType(content), true));   
  }
}
 
Example #8
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void addStringExtension(Element e, String url, String content) {
  if (!StringUtils.isBlank(content)) {
    Extension ex = getExtension(e, url);
    if (ex != null)
      ex.setValue(new StringType(content));
    else
      e.getExtension().add(Factory.newExtension(url, new StringType(content), true));   
  }
}
 
Example #9
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void addStringExtension(DomainResource e, String url, String content) {
  if (!StringUtils.isBlank(content)) {
    Extension ex = getExtension(e, url);
    if (ex != null)
      ex.setValue(new StringType(content));
    else
      e.getExtension().add(Factory.newExtension(url, new StringType(content), true));   
  }
}
 
Example #10
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void addIntegerExtension(DomainResource dr, String url, int value) {
  Extension ex = getExtension(dr, url);
  if (ex != null)
    ex.setValue(new IntegerType(value));
  else
    dr.getExtension().add(Factory.newExtension(url, new IntegerType(value), true));   
}
 
Example #11
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static PrimitiveType<Type> readPrimitiveExtension(DomainResource c, String uri) {
  Extension ex = getExtension(c, uri);
  if (ex == null)
    return null;
  return (PrimitiveType<Type>) ex.getValue();
}
 
Example #12
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static boolean findStringExtension(Element c, String uri) {
  Extension ex = ExtensionHelper.getExtension(c, uri);
  if (ex == null)
    return false;
  if (!(ex.getValue() instanceof StringType))
    return false;
  return !StringUtils.isBlank(((StringType) ex.getValue()).getValue());
}
 
Example #13
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static Boolean readBooleanExtension(Element c, String uri) {
  Extension ex = ExtensionHelper.getExtension(c, uri);
  if (ex == null)
    return null;
  if (!(ex.getValue() instanceof BooleanType))
    return null;
  return ((BooleanType) ex.getValue()).getValue();
}
 
Example #14
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static boolean findBooleanExtension(Element c, String uri) {
  Extension ex = ExtensionHelper.getExtension(c, uri);
  if (ex == null)
    return false;
  if (!(ex.getValue() instanceof BooleanType))
    return false;
  return true;
}
 
Example #15
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static List<CodeType> getSubsumes(ConceptDefinitionComponent c) {
  List<CodeType> res = new ArrayList<CodeType>();

  for (Extension e : c.getExtension()) {
    if (EXT_SUBSUMES.equals(e.getUrl()))
      res.add((CodeType) e.getValue());
  }
  return res;
}
 
Example #16
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * @param name the identity of the extension of interest
 * @return The extension, if on this element, else null
 */
public static Extension getExtension(DomainResource resource, String name) {
  if (name == null)
    return null;
  if (!resource.hasExtension())
    return null;
  for (Extension e : resource.getExtension()) {
    if (name.equals(e.getUrl()))
      return e;
  }
  return null;
}
 
Example #17
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static Extension getExtension(Element el, String name) {
  if (name == null)
    return null;
  if (!el.hasExtension())
    return null;
  for (Extension e : el.getExtension()) {
    if (name.equals(e.getUrl()))
      return e;
  }
  return null;
}
 
Example #18
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setStringExtension(DomainResource resource, String uri, String value) {
  Extension ext = getExtension(resource, uri);
  if (ext != null)
    ext.setValue(new StringType(value));
  else
    resource.getExtension().add(new Extension(new UriType(uri)).setValue(new StringType(value)));
}
 
Example #19
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setStringExtension(Element element, String uri, String value) {
  Extension ext = getExtension(element, uri);
  if (ext != null)
    ext.setValue(new StringType(value));
  else
    element.getExtension().add(new Extension(new UriType(uri)).setValue(new StringType(value)));
}
 
Example #20
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setCodeExtension(DomainResource resource, String uri, String value) {
  Extension ext = getExtension(resource, uri);
  if (ext != null)
    ext.setValue(new CodeType(value));
  else
    resource.getExtension().add(new Extension(new UriType(uri)).setValue(new CodeType(value)));
}
 
Example #21
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setIntegerExtension(DomainResource resource, String uri, int value) {
  Extension ext = getExtension(resource, uri);
  if (ext != null)
    ext.setValue(new IntegerType(value));
  else
    resource.getExtension().add(new Extension(new UriType(uri)).setValue(new IntegerType(value)));
}
 
Example #22
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static boolean hasLanguageTranslation(Element element, String lang) {
  for (Extension e : element.getExtension()) {
    if (e.getUrl().equals(EXT_TRANSLATION)) {
      Extension e1 = ExtensionHelper.getExtension(e, "lang");

      if (e1 != null && e1.getValue() instanceof CodeType && ((CodeType) e.getValue()).getValue().equals(lang))
        return true;
    }
  }
  return false;
}
 
Example #23
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static String getLanguageTranslation(Element element, String lang) {
  for (Extension e : element.getExtension()) {
    if (e.getUrl().equals(EXT_TRANSLATION)) {
      Extension e1 = ExtensionHelper.getExtension(e, "lang");

      if (e1 != null && e1.getValue() instanceof CodeType && ((CodeType) e.getValue()).getValue().equals(lang)) {
        e1 = ExtensionHelper.getExtension(e, "content");
        return ((StringType) e.getValue()).getValue();
      }
    }
  }
  return null;
}
 
Example #24
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setAllowableUnits(ElementDefinition eld, CodeableConcept cc) {
  for (Extension e : eld.getExtension()) 
    if (e.getUrl().equals(EXT_ALLOWABLE_UNITS)) {
      e.setValue(cc);
      return;
    }
  eld.getExtension().add(new Extension().setUrl(EXT_ALLOWABLE_UNITS).setValue(cc));
}
 
Example #25
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static List<Extension> getExtensions(Element element, String url) {
  List<Extension> results = new ArrayList<Extension>();
  for (Extension ex : element.getExtension())
    if (ex.getUrl().equals(url))
      results.add(ex);
  return results;
}
 
Example #26
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static List<Extension> getExtensions(DomainResource resource, String url) {
  List<Extension> results = new ArrayList<Extension>();
  for (Extension ex : resource.getExtension())
    if (ex.getUrl().equals(url))
      results.add(ex);
  return results;
}
 
Example #27
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void addDEReference(DataElement de, String value) {
  for (Extension e : de.getExtension()) 
    if (e.getUrl().equals(EXT_CIMI_REFERENCE)) {
      e.setValue(new UriType(value));
      return;
    }
  de.getExtension().add(new Extension().setUrl(EXT_CIMI_REFERENCE).setValue(new UriType(value)));
}
 
Example #28
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setExtension(Element focus, String url, Coding c) {
  for (Extension e : focus.getExtension()) 
    if (e.getUrl().equals(url)) {
      e.setValue(c);
      return;
    }
  focus.getExtension().add(new Extension().setUrl(url).setValue(c));    
}
 
Example #29
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void removeExtension(DomainResource focus, String url) {
  Iterator<Extension> i = focus.getExtension().iterator();
  while (i.hasNext()) {
    Extension e = i.next(); // must be called before you can call i.remove()
    if (e.getUrl().equals(url)) {
      i.remove();
    }
  }
}
 
Example #30
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void removeExtension(Element focus, String url) {
  Iterator<Extension> i = focus.getExtension().iterator();
  while (i.hasNext()) {
    Extension e = i.next(); // must be called before you can call i.remove()
    if (e.getUrl().equals(url)) {
      i.remove();
    }
  }
}