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

The following examples show how to use org.hl7.fhir.r4.model.UriType. 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: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValueSet importValueSet(String value, List<ValueSetExpansionParameterComponent> params, Parameters expParams) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException, FHIRFormatError {
  if (value == null)
    throw new TerminologyServiceException("unable to find value set with no identity");
  ValueSet vs = context.fetchResource(ValueSet.class, value);
  if (vs == null)
    throw new TerminologyServiceException("Unable to find imported value set " + value);
  ValueSetExpansionOutcome vso = new ValueSetExpanderSimple(context).expand(vs, expParams);
  if (vso.getError() != null)
    throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
  if (vs.hasVersion())
    if (!existsInParams(params, "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
      params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
  for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
    if (!existsInParams(params, p.getName(), p.getValue()))
      params.add(p);
  }
  canBeHeirarchy = false; // if we're importing a value set, we have to be combining, so we won't try for a heirarchy
  return vso.getValueset();
}
 
Example #2
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, Parameters expParams, boolean heirarchical) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
  inc.checkNoModifiers("Compose.include", "expanding");
  List<ValueSet> imports = new ArrayList<ValueSet>();
  for (UriType imp : inc.getValueSet()) {
    imports.add(importValueSet(imp.getValue(), params, expParams));
  }

  if (!inc.hasSystem()) {
    if (imports.isEmpty()) // though this is not supposed to be the case
      return;
    ValueSet base = imports.get(0);
    imports.remove(0);
    base.checkNoModifiers("Imported ValueSet", "expanding");
    copyImportContains(base.getExpansion().getContains(), null, expParams, imports);
  } else {
    CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
    if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE)) {
      doServerIncludeCodes(inc, heirarchical, params, imports, expParams);
    } else {
      doInternalIncludeCodes(inc, params, expParams, imports, cs);
    }
  }
}
 
Example #3
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void doServerIncludeCodes(ConceptSetComponent inc, boolean heirarchical, List<ValueSetExpansionParameterComponent> params, List<ValueSet> imports, Parameters expParams) throws FHIRException {
  ValueSetExpansionOutcome vso = context.expandVS(inc, heirarchical);
  if (vso.getError() != null)
    throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
  ValueSet vs = vso.getValueset();
  if (vs.hasVersion())
    if (!existsInParams(params, "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
      params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
  for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
    if (!existsInParams(params, p.getName(), p.getValue()))
      params.add(p);
  }
  for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
    addCodeAndDescendents(cc, null, expParams, imports);
  }
}
 
Example #4
Source File: VersionConvertorPrimitiveType40_50Test.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static Stream<Arguments> r5PrimitiveTypes() {
  return Stream.of(
    Arguments.arguments(org.hl7.fhir.r5.model.BooleanType.class.getSimpleName(), new org.hl7.fhir.r5.model.BooleanType()),
    Arguments.arguments(org.hl7.fhir.r5.model.CodeType.class.getSimpleName(), new org.hl7.fhir.r5.model.CodeType()),
    Arguments.arguments(org.hl7.fhir.r5.model.DateType.class.getSimpleName(), new org.hl7.fhir.r5.model.DateType()),
    Arguments.arguments(org.hl7.fhir.r5.model.DateTimeType.class.getSimpleName(), new org.hl7.fhir.r5.model.DateTimeType()),
    Arguments.arguments(org.hl7.fhir.r5.model.DecimalType.class.getSimpleName(), new org.hl7.fhir.r5.model.DecimalType()),
    Arguments.arguments(org.hl7.fhir.r5.model.InstantType.class.getSimpleName(), new org.hl7.fhir.r5.model.InstantType()),
    Arguments.arguments(org.hl7.fhir.r5.model.PositiveIntType.class.getSimpleName(), new org.hl7.fhir.r5.model.PositiveIntType()),
    Arguments.arguments(org.hl7.fhir.r5.model.UnsignedIntType.class.getSimpleName(), new org.hl7.fhir.r5.model.UnsignedIntType()),
    Arguments.arguments(org.hl7.fhir.r5.model.IntegerType.class.getSimpleName(), new org.hl7.fhir.r5.model.IntegerType()),
    Arguments.arguments(org.hl7.fhir.r5.model.MarkdownType.class.getSimpleName(), new org.hl7.fhir.r5.model.MarkdownType()),
    Arguments.arguments(org.hl7.fhir.r5.model.OidType.class.getSimpleName(), new org.hl7.fhir.r5.model.OidType()),
    Arguments.arguments(org.hl7.fhir.r5.model.StringType.class.getSimpleName(), new org.hl7.fhir.r5.model.StringType()),
    Arguments.arguments(org.hl7.fhir.r5.model.TimeType.class.getSimpleName(), new org.hl7.fhir.r5.model.TimeType()),
    Arguments.arguments(org.hl7.fhir.r5.model.UuidType.class.getSimpleName(), new org.hl7.fhir.r5.model.UuidType()),
    Arguments.arguments(org.hl7.fhir.r5.model.Base64BinaryType.class.getSimpleName(), new org.hl7.fhir.r5.model.Base64BinaryType()),
    Arguments.arguments(org.hl7.fhir.r5.model.UriType.class.getSimpleName(), new org.hl7.fhir.r5.model.UriType()));
}
 
Example #5
Source File: VersionConvertorPrimitiveType40_50Test.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static Stream<Arguments> r4PrimitiveTypes() {
  return Stream.of(
    Arguments.arguments(BooleanType.class.getSimpleName(), new BooleanType()),
    Arguments.arguments(CodeType.class.getSimpleName(), new CodeType()),
    Arguments.arguments(DateType.class.getSimpleName(), new DateType()),
    Arguments.arguments(DateTimeType.class.getSimpleName(), new DateTimeType()),
    Arguments.arguments(DecimalType.class.getSimpleName(), new DecimalType()),
    Arguments.arguments(InstantType.class.getSimpleName(), new InstantType()),
    Arguments.arguments(PositiveIntType.class.getSimpleName(), new PositiveIntType()),
    Arguments.arguments(UnsignedIntType.class.getSimpleName(), new UnsignedIntType()),
    Arguments.arguments(IntegerType.class.getSimpleName(), new IntegerType()),
    Arguments.arguments(MarkdownType.class.getSimpleName(), new MarkdownType()),
    Arguments.arguments(OidType.class.getSimpleName(), new OidType()),
    Arguments.arguments(StringType.class.getSimpleName(), new StringType()),
    Arguments.arguments(TimeType.class.getSimpleName(), new TimeType()),
    Arguments.arguments(UuidType.class.getSimpleName(), new UuidType()),
    Arguments.arguments(Base64BinaryType.class.getSimpleName(), new Base64BinaryType()),
    Arguments.arguments(UriType.class.getSimpleName(), new UriType()));
}
 
Example #6
Source File: QuestionnaireBuilder.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void addReferenceQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<CanonicalType> profileURL, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
  //  var
  //    rn : String;
  //    i : integer;
  //    q : TFhirQuestionnaireGroupQuestion;
  ToolingExtensions.addFhirType(group, "Reference");

  QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.REFERENCE, path, "value", group.getText(), answerGroups);
  group.setText(null);
  CommaSeparatedStringBuilder rn = new CommaSeparatedStringBuilder();
  for (UriType u : profileURL)
  if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/"))
    rn.append(u.getValue().substring(40));
  if (rn.length() == 0)
    ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
  else {
    ToolingExtensions.addAllowedResource(q, rn.toString());
    ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
  }
  for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups)
    ag.setText(null);
}
 
Example #7
Source File: TerminologyCache.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private String getIncSummary(ConceptSetComponent cc) {
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  for (UriType vs : cc.getValueSet())
    b.append(vs.asStringValue());
  String vsd = b.length() > 0 ? " where the codes are in the value sets ("+b.toString()+")" : "";
  String system = cc.getSystem();
  if (cc.hasConcept())
    return Integer.toString(cc.getConcept().size())+" codes from "+system+vsd;
  if (cc.hasFilter()) {
    String s = "";
    for (ConceptSetFilterComponent f : cc.getFilter()) {
      if (!Utilities.noString(s))
        s = s + " & ";
      s = s + f.getProperty()+" "+f.getOp().toCode()+" "+f.getValue();
    }
    return "from "+system+" where "+s+vsd;
  }
  return "All codes from "+system+vsd;
}
 
Example #8
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 #9
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 #10
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 #11
Source File: RandomCodeGenerator.java    From synthea with Apache License 2.0 5 votes vote down vote up
private static void initializeCache() {
  responseCache = CacheBuilder.newBuilder()
      .maximumSize(RESPONSE_CACHE_SIZE)
      .build(
          new CacheLoader<ExpandInput, ValueSet>() {
            @Override
            public ValueSet load(@Nonnull ExpandInput key) {
              return terminologyClient
                  .expand(new UriType(key.getValueSetUri()), new IntegerType(EXPAND_PAGE_SIZE),
                      new IntegerType(key.getOffset()));
            }
          }
      );
}
 
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 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 #13
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 #14
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 #15
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 #16
Source File: CodeSystemUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static CodeSystem makeShareable(CodeSystem cs) {
  if (!cs.hasMeta())
    cs.setMeta(new Meta());
  for (UriType t : cs.getMeta().getProfile()) 
    if (t.getValue().equals("http://hl7.org/fhir/StructureDefinition/shareablecodesystem"))
      return cs;
  cs.getMeta().getProfile().add(new CanonicalType("http://hl7.org/fhir/StructureDefinition/shareablecodesystem"));
  return cs;
}
 
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 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 #18
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static void renderImports(StringBuilder b, StructureMap map) {
	for (UriType s : map.getImport()) {
		b.append("imports \"");
		b.append(s.getValue());
		b.append("\"\r\n");
	}
	if (map.hasImport())
		b.append("\r\n");
}
 
Example #19
Source File: ValueSetUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void checkShareable(ValueSet vs) {
  if (!vs.hasMeta())
    throw new Error("ValueSet "+vs.getUrl()+" is not shareable");
  for (UriType t : vs.getMeta().getProfile()) {
    if (t.getValue().equals("http://hl7.org/fhir/StructureDefinition/shareablevalueset"))
      return;
  }
  throw new Error("ValueSet "+vs.getUrl()+" is not shareable");    
}
 
Example #20
Source File: ValueSetUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static ValueSet makeShareable(ValueSet vs) {
  if (!vs.hasMeta())
    vs.setMeta(new Meta());
  for (UriType t : vs.getMeta().getProfile()) 
    if (t.getValue().equals("http://hl7.org/fhir/StructureDefinition/shareablevalueset"))
      return vs;
  vs.getMeta().getProfile().add(new CanonicalType("http://hl7.org/fhir/StructureDefinition/shareablevalueset"));
  return vs;
}
 
Example #21
Source File: ConceptMaps.java    From bunsen with Apache License 2.0 4 votes vote down vote up
private static Iterator<Mapping> expandMappingsIterator(ConceptMap map) {

    List<Mapping> mappings = new ArrayList<>();

    for (ConceptMapGroupComponent group: map.getGroup()) {

      for (SourceElementComponent element: group.getElement()) {

        for (TargetElementComponent target: element.getTarget()) {

          Mapping mapping = new Mapping();

          mapping.setConceptMapUri(map.getUrl());
          mapping.setConceptMapVersion(map.getVersion());

          try {
            String sourceValue = map.getSource() instanceof UriType
                ? map.getSourceUriType().getValue()
                : map.getSourceUriType().getValue();

            mapping.setSourceValueSet(sourceValue);

            String targetValue = map.getTarget() instanceof UriType
                ? map.getTargetUriType().getValue()
                : map.getTargetUriType().getValue();

            mapping.setTargetValueSet(targetValue);

          } catch (FHIRException fhirException) {

            // This should not happen because we check the types,
            // but rethrow to avoid any possibility of swallowing
            // an exception.
            throw new RuntimeException(fhirException);
          }

          mapping.setSourceSystem(group.getSource());
          mapping.setSourceValue(element.getCode());

          mapping.setTargetSystem(group.getTarget());
          mapping.setTargetValue(target.getCode());

          if (target.getEquivalence() != null) {
            mapping.setEquivalence(target.getEquivalence().toCode());
          }

          mappings.add(mapping);
        }
      }
    }

    return mappings.iterator();
  }
 
Example #22
Source File: BroadcastableMappingsTest.java    From bunsen with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up Spark and concept maps for testing.
 */
@BeforeClass
public static void setUp() {
  spark = SparkSession.builder()
      .master("local[2]")
      .appName("BroadcastableMappingsTest")
      .getOrCreate();

  ConceptMap conceptMap = new ConceptMap();

  conceptMap.setUrl("uri:test:concept:map")
      .setVersion("0")
      .setSource(new UriType("uri:test:source:valueset"))
      .setTarget(new UriType("uri:test:target:valueset"));

  ConceptMapGroupComponent group = conceptMap.addGroup()
      .setSource("uri:test:source:system")
      .setTarget("uri:test:target:system");

  group.addElement().setCode("abc").addTarget().setCode("123");
  group.addElement().setCode("def").addTarget().setCode("456");

  ConceptMap delegatingMap = new ConceptMap();

  delegatingMap.setUrl("uri:test:concept:delegating")
      .setVersion("0")
      .setSource(new UriType("uri:test:source:valueset"))
      .setTarget(new UriType("uri:test:target:valueset"));

  delegatingMap.addGroup()
      .setSource("uri:test:source:system")
      .setTarget("uri:test:target:system")
      .setUnmapped(new ConceptMapGroupUnmappedComponent()
          .setMode(ConceptMapGroupUnmappedMode.OTHERMAP)
          .setUrl("uri:test:concept:map"));

  broadcast = ConceptMaps.getEmpty(spark)
      .withConceptMaps(conceptMap, delegatingMap)
      .broadcast(ImmutableMap.of(
          "uri:test:concept:map", "0",
          "uri:test:concept:delegating", "0"));

  ConceptMap conceptMapLatest = new ConceptMap();

  conceptMapLatest.setUrl("uri:test:concept:map")
      .setVersion("1")
      .setSource(new UriType("uri:test:source:valueset"))
      .setTarget(new UriType("uri:test:target:valueset"));

  ConceptMapGroupComponent groupLatest = conceptMapLatest.addGroup()
      .setSource("uri:test:source:system")
      .setTarget("uri:test:target:system");

  groupLatest.addElement().setCode("abc").addTarget().setCode("123");
  groupLatest.addElement().setCode("def").addTarget().setCode("xyz");

  ConceptMaps maps = ConceptMaps.getEmpty(spark)
      .withConceptMaps(conceptMap, conceptMapLatest);

  broadcastLatest = maps.broadcast(maps.getLatestVersions(true));
}
 
Example #23
Source File: TerminologyClient.java    From synthea with Apache License 2.0 4 votes vote down vote up
@Operation(type = ValueSet.class, name = "$expand")
ValueSet expand(@OperationParam(name = "url") UriType url, 
    @OperationParam(name = "count") IntegerType count, 
    @OperationParam(name = "offset") IntegerType offset);