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: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private List<PropertyWrapper> splitExtensions(StructureDefinition profile, List<PropertyWrapper> children) throws UnsupportedEncodingException, IOException, FHIRException {
  List<PropertyWrapper> results = new ArrayList<PropertyWrapper>();
  Map<String, PropertyWrapper> map = new HashMap<String, PropertyWrapper>();
  for (PropertyWrapper p : children)
    if (p.getName().equals("extension") || p.getName().equals("modifierExtension")) {
      // we're going to split these up, and create a property for each url
      if (p.hasValues()) {
        for (BaseWrapper v : p.getValues()) {
          Extension ex  = (Extension) v.getBase();
          String url = ex.getUrl();
          StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
          if (p.getName().equals("modifierExtension") && ed == null)
            throw new DefinitionException("Unknown modifier extension "+url);
          PropertyWrapper pe = map.get(p.getName()+"["+url+"]");
          if (pe == null) {
            if (ed == null) {
              if (url.startsWith("http://hl7.org/fhir"))
                throw new DefinitionException("unknown extension "+url);
              // System.out.println("unknown extension "+url);
              pe = new PropertyWrapperDirect(new Property(p.getName()+"["+url+"]", p.getTypeCode(), p.getDefinition(), p.getMinCardinality(), p.getMaxCardinality(), ex));
            } else {
              ElementDefinition def = ed.getSnapshot().getElement().get(0);
              pe = new PropertyWrapperDirect(new Property(p.getName()+"["+url+"]", "Extension", def.getDefinition(), def.getMin(), def.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(def.getMax()), ex));
              ((PropertyWrapperDirect) pe).wrapped.setStructure(ed);
            }
            results.add(pe);
          } else
            pe.getValues().add(v);
        }
      }
    } else
      results.add(p);
  return results;
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private String gen(Extension extension) throws DefinitionException {
if (extension.getValue() instanceof CodeType)
	return ((CodeType) extension.getValue()).getValue();
if (extension.getValue() instanceof Coding)
	return gen((Coding) extension.getValue());

 throw new DefinitionException("Unhandled type "+extension.getValue().getClass().getName());
}
 
Example #16
Source File: FhirStu3.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Create an extension in with a valueMoney in USD.
 * @param url The url of the extension.
 * @param value The value in USD.
 * @return the Extension
 */
private static Extension createMoneyExtension(String url, double value) {
  Money money = new Money();
  money.setValue(value);
  money.setSystem("urn:iso:std:iso:4217");
  money.setCode("USD");

  Extension extension = new Extension();
  extension.setUrl(url);
  extension.setValue(money);

  return extension;
}
 
Example #17
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 #18
Source File: ObservationAccessor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void setExtensions(ObservationComponent iComponent,
	Element observationComponentComponent){
	for (String url : iComponent.getExtensions().keySet()) {
		Extension extension = new Extension(url);
		extension.setValue(new StringType().setValue(iComponent.getExtensions().get(url)));
		observationComponentComponent.addExtension(extension);
	}
}
 
Example #19
Source File: AbstractFindingModelAdapter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public void addStringExtension(String theUrl, String theValue){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent() && resource.get() instanceof DomainResource) {
		DomainResource domainResource = (DomainResource) resource.get();
		Extension extension = new Extension(theUrl);
		extension.setValue(new StringType().setValue(theValue));
		domainResource.addExtension(extension);
		saveResource(domainResource);
	}
}
 
Example #20
Source File: AbstractFindingModelAdapter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public Map<String, String> getStringExtensions(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent() && resource.get() instanceof DomainResource) {
		List<Extension> extensions = ((DomainResource) resource.get()).getExtension();
		return extensions.stream()
			.filter(extension -> extension.getValue() instanceof StringType)
			.collect(Collectors.toMap(extension -> extension.getUrl(),
				extension -> ((StringType) extension.getValue()).getValueAsString()));
	}
	return Collections.emptyMap();
}
 
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: 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 #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 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 #25
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 #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 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 #28
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 #29
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 #30
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();
}