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

The following examples show how to use org.hl7.fhir.r4.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 CanonicalType)
    return ((CanonicalType) 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: 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) {
  if (Utilities.noString(value))
    return;
      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 #4
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 #5
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 resource, String uri, String value) {
  if (Utilities.noString(value))
    return;
      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 #6
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) {
  if (Utilities.noString(value))
    return;
  
  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 #7
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void setCodeExtension(Element element, String uri, String value) {
  if (Utilities.noString(value))
    return;
  
  Extension ext = getExtension(element, uri);
  if (ext != null)
    ext.setValue(new CodeType(value));
  else
    element.getExtension().add(new Extension(new UriType(uri)).setValue(new CodeType(value)));
}
 
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 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 #9
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 #10
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 #11
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void addLanguageTranslation(Element element, String lang, String value) {
  if (Utilities.noString(lang) || Utilities.noString(value))
    return;
  
  Extension extension = new Extension().setUrl(EXT_TRANSLATION);
  extension.addExtension().setUrl("lang").setValue(new CodeType(lang));
  extension.addExtension().setUrl("content").setValue(new StringType(value));
  element.getExtension().add(extension);
}
 
Example #12
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 #13
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 #14
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 #15
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 #16
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 #17
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();
    }
  }
}
 
Example #18
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static int readIntegerExtension(DomainResource dr, String uri, int defaultValue) {
  Extension ex = ExtensionHelper.getExtension(dr, uri);
  if (ex == null)
    return defaultValue;
  if (ex.getValue() instanceof IntegerType)
    return ((IntegerType) ex.getValue()).getValue();
  throw new Error("Unable to read extension "+uri+" as an integer");
}
 
Example #19
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static int readIntegerExtension(Element e, String uri, int defaultValue) {
  Extension ex = ExtensionHelper.getExtension(e, uri);
  if (ex == null)
    return defaultValue;
  if (ex.getValue() instanceof IntegerType)
    return ((IntegerType) ex.getValue()).getValue();
  throw new Error("Unable to read extension "+uri+" as an integer");
}
 
Example #20
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static Map<String, String> getLanguageTranslations(Element e) {
  Map<String, String> res = new HashMap<String, String>();
  for (Extension ext : e.getExtension()) {
    if (ext.getUrl().equals(EXT_TRANSLATION)) {
      String lang = readStringExtension(ext, "lang");
      String value = readStringExtension(ext, "content");
      res.put(lang,  value);
    }
  }
  return res;
}
 
Example #21
Source File: PlanDefinitionApplyProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public CarePlan resolveCdsHooksPlanDefinition(Context context, PlanDefinition planDefinition, String patientId) {

        CarePlanBuilder carePlanBuilder = new CarePlanBuilder();
        RequestGroupBuilder requestGroupBuilder = new RequestGroupBuilder().buildStatus().buildIntent();

        // links
        if (planDefinition.hasRelatedArtifact()) {
            List<Extension> extensions = new ArrayList<>();
            for (RelatedArtifact relatedArtifact : planDefinition.getRelatedArtifact()) {
                AttachmentBuilder attachmentBuilder = new AttachmentBuilder();
                ExtensionBuilder extensionBuilder = new ExtensionBuilder();
                if (relatedArtifact.hasDisplay()) { // label
                    attachmentBuilder.buildTitle(relatedArtifact.getDisplay());
                }
                if (relatedArtifact.hasUrl()) { // url
                    attachmentBuilder.buildUrl(relatedArtifact.getUrl());
                }
                if (relatedArtifact.hasExtension()) { // type
                    attachmentBuilder.buildExtension(relatedArtifact.getExtension());
                }
                extensionBuilder.buildUrl("http://example.org");
                extensionBuilder.buildValue(attachmentBuilder.build());
                extensions.add(extensionBuilder.build());
            }
            requestGroupBuilder.buildExtension(extensions);
        }

        resolveActions(planDefinition.getAction(), context, patientId, requestGroupBuilder, new ArrayList<>());

        CarePlanActivityBuilder carePlanActivityBuilder = new CarePlanActivityBuilder();
        carePlanActivityBuilder.buildReferenceTarget(requestGroupBuilder.build());
        carePlanBuilder.buildActivity(carePlanActivityBuilder.build());

        return carePlanBuilder.build();
    }
 
Example #22
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 #23
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 #24
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 #25
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void addCodeExtension(Element e, String url, String content) {
  if (!StringUtils.isBlank(content)) {
    Extension ex = getExtension(e, url);
    if (ex != null)
      ex.setValue(new CodeType(content));
    else
      e.getExtension().add(Factory.newExtension(url, new CodeType(content), true));   
  }
}
 
Example #26
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 #27
Source File: ToolingExtensions.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void addUriExtension(Element e, String url, String uri) {
  Extension ex = getExtension(e, url);
  if (ex != null)
    ex.setValue(new UriType(uri));
  else
    e.getExtension().add(Factory.newExtension(url, new UriType(uri), true));   
}
 
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 addBooleanExtension(Element e, String url, boolean content) {
  Extension ex = getExtension(e, url);
  if (ex != null)
    ex.setValue(new BooleanType(content));
  else
    e.getExtension().add(Factory.newExtension(url, new BooleanType(content), true));   
}
 
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 addBooleanExtension(DomainResource e, String url, boolean content) {
  Extension ex = getExtension(e, url);
  if (ex != null)
    ex.setValue(new BooleanType(content));
  else
    e.getExtension().add(Factory.newExtension(url, new BooleanType(content), true));   
}
 
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 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));   
}