org.hl7.fhir.r4.model.ValueSet Java Examples
The following examples show how to use
org.hl7.fhir.r4.model.ValueSet.
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: ValueSetsTest.java From bunsen with Apache License 2.0 | 6 votes |
private static void checkValueSet(ValueSet valueSet, String url, String version) { Assert.assertNotNull( MessageFormat.format("Could not find value set for url {0} and version {1}", url, version), valueSet); Assert.assertEquals(url, valueSet.getUrl()); Assert.assertEquals(version, valueSet.getVersion()); ConceptSetComponent inclusion = valueSet.getCompose().getIncludeFirstRep(); Assert.assertEquals("urn:cerner:system", inclusion.getSystem()); Assert.assertEquals("1", inclusion.getVersion()); Assert.assertEquals("a", inclusion.getConceptFirstRep().getCode()); Assert.assertEquals(1, valueSet.getCompose().getInclude().size()); }
Example #2
Source File: ValueSetsTest.java From bunsen with Apache License 2.0 | 6 votes |
@Test public void testExpandValues() { ValueSet valueSet = ValueSets.getEmpty(spark) .withValueSets(valueSet("urn:cerner:valueset:valueset", "1")) .getValueSet("urn:cerner:valueset:valueset", "1"); List<Value> values = ValueSets.expandValues(valueSet); Value expectedValue = new Value("urn:cerner:valueset:valueset", "1", "urn:cerner:system", "1", "a"); Assert.assertEquals(1, values.size()); Assert.assertEquals(expectedValue, values.get(0)); }
Example #3
Source File: ProfileComparer.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private ElementDefinitionBindingComponent unionBindings(ElementDefinition ed, ProfileComparison outcome, String path, ElementDefinitionBindingComponent left, ElementDefinitionBindingComponent right) throws FHIRFormatError { ElementDefinitionBindingComponent union = new ElementDefinitionBindingComponent(); if (left.getStrength().compareTo(right.getStrength()) < 0) union.setStrength(left.getStrength()); else union.setStrength(right.getStrength()); union.setDescription(mergeText(ed, outcome, path, "binding.description", left.getDescription(), right.getDescription())); if (Base.compareDeep(left.getValueSet(), right.getValueSet(), false)) union.setValueSet(left.getValueSet()); else { ValueSet lvs = resolveVS(outcome.left, left.getValueSet()); ValueSet rvs = resolveVS(outcome.left, right.getValueSet()); if (lvs != null && rvs != null) union.setValueSet("#"+addValueSet(unite(ed, outcome, path, lvs, rvs))); else if (lvs != null) union.setValueSet("#"+addValueSet(lvs)); else if (rvs != null) union.setValueSet("#"+addValueSet(rvs)); } return union; }
Example #4
Source File: ICD11Generator.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private void makeFullVs(String dest, CodeSystem cs) throws FileNotFoundException, IOException { String url = "http://id.who.int/icd11/ValueSet/all-MMS"; ValueSet vs = new ValueSet(); vs.setId("all-MMS"); vs.setUrl(url); vs.setName("ICDMMSAll"); vs.setTitle("Value Set for all ICD MMS Codes"); vs.setStatus(PublicationStatus.ACTIVE); vs.setExperimental(false); vs.setDate(cs.getDate()); vs.setPublisher("WHO"); vs.setCopyright("Consult WHO For terms of use"); vs.setVersion(cs.getVersion()); vs.setStatus(cs.getStatus()); ConceptSetComponent inc = vs.getCompose().addInclude(); inc.setSystem(cs.getUrl()); new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "vs-all-MMS.xml")), vs); }
Example #5
Source File: ProfileComparer.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) { // this is pretty straight forward - we intersect the lists, and build a compose out of the intersection ValueSet vs = new ValueSet(); vs.setStatus(PublicationStatus.DRAFT); Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>(); scan(lvs.getExpansion().getContains(), left); Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>(); scan(rvs.getExpansion().getContains(), right); Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>(); for (String s : left.keySet()) { if (right.containsKey(s)) { ValueSetExpansionContainsComponent cc = left.get(s); ConceptSetComponent c = inc.get(cc.getSystem()); if (c == null) { c = vs.getCompose().addInclude().setSystem(cc.getSystem()); inc.put(cc.getSystem(), c); } c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay()); } } return vs; }
Example #6
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
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 #7
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
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 #8
Source File: ShExGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
/** * Generate a type reference and optional value set definition * @param sd Containing StructureDefinition * @param ed Element being defined * @param typ Element type * @return Type definition */ private String simpleElement(StructureDefinition sd, ElementDefinition ed, String typ) { String addldef = ""; ElementDefinition.ElementDefinitionBindingComponent binding = ed.getBinding(); if(binding.hasStrength() && binding.getStrength() == Enumerations.BindingStrength.REQUIRED && "code".equals(typ)) { ValueSet vs = resolveBindingReference(sd, binding.getValueSet()); if (vs != null) { addldef = tmplt(VALUESET_DEFN_TEMPLATE).add("vsn", vsprefix(vs.getUrl())).render(); required_value_sets.add(vs); } } // TODO: check whether value sets and fixed are mutually exclusive if(ed.hasFixed()) { addldef = tmplt(FIXED_VALUE_TEMPLATE).add("val", ed.getFixed().primitiveValue()).render(); } return tmplt(SIMPLE_ELEMENT_DEFN_TEMPLATE).add("typ", typ).add("vsdef", addldef).render(); }
Example #9
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
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 #10
Source File: ValueSetsTest.java From bunsen with Apache License 2.0 | 6 votes |
@Test public void testCreateSimpleValueSets() { ValueSets valueSets = ValueSets.getEmpty(spark) .withValueSets(valueSet("urn:cerner:valueset:valueset1", "1"), valueSet("urn:cerner:valueset:valueset2", "1")); Dataset<Value> values = valueSets.getValues(); Assert.assertEquals(2, values.count()); ValueSet firstValueSet = valueSets.getValueSet("urn:cerner:valueset:valueset1", "1"); checkValueSet(firstValueSet, "urn:cerner:valueset:valueset1", "1"); ValueSet secondValueSet = valueSets.getValueSet("urn:cerner:valueset:valueset2", "1"); checkValueSet(secondValueSet, "urn:cerner:valueset:valueset2", "1"); }
Example #11
Source File: ValueSetsTest.java From bunsen with Apache License 2.0 | 6 votes |
@Test public void testWithDisjointValueSetsFromDirectory() { String database = "test_valuesets_disjoint"; spark.sql("CREATE DATABASE " + database); ValueSets.getEmpty(spark) .withValueSetsFromDirectory("src/test/resources/xml/valuesets") .writeToDatabase(database); ValueSets valueSets = ValueSets.getFromDatabase(spark, database) .withDisjointValueSetsFromDirectory("src/test/resources/xml/valuesets", database); ValueSet marriedValueSet = valueSets.getValueSet( "urn:cerner:bunsen:valueset:married_maritalstatus", "0.0.1"); Assert.assertEquals(1, valueSets.getValueSets().count()); Assert.assertNotNull(marriedValueSet); Assert.assertEquals("urn:cerner:bunsen:valueset:married_maritalstatus", marriedValueSet.getUrl()); Assert.assertEquals("0.0.1", marriedValueSet.getVersion()); }
Example #12
Source File: ValueSets.java From bunsen with Apache License 2.0 | 6 votes |
private ValueSets withValueSets(Dataset<ValueSet> newValueSets, Dataset<Value> newValues) { Dataset<UrlAndVersion> newMembers = getUrlAndVersions(newValueSets); // Instantiating a new composite ConceptMaps requires a new timestamp Timestamp timestamp = new Timestamp(System.currentTimeMillis()); Dataset<ValueSet> newValueSetsWithTimestamp = newValueSets .withColumn("timestamp", lit(timestamp.toString()).cast("timestamp")) .as(VALUE_SET_ENCODER); return new ValueSets(spark, this.members.union(newMembers), this.valueSets.union(newValueSetsWithTimestamp), this.values.union(newValues)); }
Example #13
Source File: RandomCodeGenerator.java From synthea with Apache License 2.0 | 6 votes |
private static ValueSetExpansionComponent expandValueSet(String valueSetUri) { ValueSet response; ValueSetExpansionComponent result = new ValueSetExpansionComponent(); int total; int offset = 0; int count = 0; do { offset += count; logger.info("Sending ValueSet expand request to terminology service (" + terminologyClient .getServerBase() + "): url=" + valueSetUri + ", count=" + EXPAND_PAGE_SIZE + ", offset=" + offset); try { response = responseCache.get(new ExpandInput(valueSetUri, offset)); } catch (ExecutionException e) { throw new RuntimeException("Error expanding ValueSet", e); } validateExpansion(response.getExpansion()); total = response.getExpansion().getTotal(); count = response.getExpansion().getContains().size(); result.getContains().addAll(response.getExpansion().getContains()); } while ((offset + count) < total); result.setTotal(total); return result; }
Example #14
Source File: FHIRToolingClient.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public ValueSet expandValueset(ValueSet source, Parameters expParams) { List<Header> headers = null; Parameters p = expParams == null ? new Parameters() : expParams.copy(); p.addParameter().setName("valueSet").setResource(source); ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand"), utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); result.addErrorStatus(422);//Unprocessable Entity result.addSuccessStatus(200); result.addSuccessStatus(201); if(result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload()); } return (ValueSet) result.getPayload(); }
Example #15
Source File: ValueSetExpansionCache.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
@Override public ValueSetExpansionOutcome expand(ValueSet source, Parameters expParams) throws ETooCostly, IOException { String cacheKey = makeCacheKey(source, expParams); if (expansions.containsKey(cacheKey)) return expansions.get(cacheKey); ValueSetExpander vse = new ValueSetExpanderSimple(context); ValueSetExpansionOutcome vso = vse.expand(source, expParams); if (vso.getError() != null) { // well, we'll see if the designated server can expand it, and if it can, we'll cache it locally vso = context.expandVS(source, false, expParams == null || !expParams.getParameterBool("excludeNested")); if (cacheFolder != null) { FileOutputStream s = new FileOutputStream(Utilities.path(cacheFolder, makeFileName(source.getUrl()))); context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, vso.getValueset()); s.close(); } } if (vso.getValueset() != null) expansions.put(cacheKey, vso); return vso; }
Example #16
Source File: FHIRToolingClient.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public ValueSet expandValueset(ValueSet source, Parameters expParams, Map<String, String> params) { List<Header> headers = null; Parameters p = expParams == null ? new Parameters() : expParams.copy(); p.addParameter().setName("valueSet").setResource(source); for (String n : params.keySet()) p.addParameter().setName(n).setValue(new StringType(params.get(n))); ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params), utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); result.addErrorStatus(422);//Unprocessable Entity result.addSuccessStatus(200); result.addSuccessStatus(201); if(result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload()); } return (ValueSet) result.getPayload(); }
Example #17
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void copyImportContains(List<ValueSetExpansionContainsComponent> list, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filter) throws FHIRException { for (ValueSetExpansionContainsComponent c : list) { c.checkNoModifiers("Imported Expansion in Code System", "expanding"); ValueSetExpansionContainsComponent np = addCode(c.getSystem(), c.getCode(), c.getDisplay(), parent, null, expParams, c.getAbstract(), c.getInactive(), filter); copyImportContains(c.getContains(), np, expParams, filter); } }
Example #18
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void addCodeAndDescendents(ValueSetExpansionContainsComponent focus, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters) throws FHIRException { focus.checkNoModifiers("Expansion.contains", "expanding"); ValueSetExpansionContainsComponent np = addCode(focus.getSystem(), focus.getCode(), focus.getDisplay(), parent, convert(focus.getDesignation()), expParams, focus.getAbstract(), focus.getInactive(), filters); for (ValueSetExpansionContainsComponent c : focus.getContains()) addCodeAndDescendents(focus, np, expParams, filters); }
Example #19
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void excludeCode(String theSystem, String theCode) { ValueSetExpansionContainsComponent n = new ValueSet.ValueSetExpansionContainsComponent(); n.setSystem(theSystem); n.setCode(theCode); String s = key(n); excludeKeys.add(s); }
Example #20
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void addCodes(ValueSetExpansionComponent expand, List<ValueSetExpansionParameterComponent> params, Parameters expParams, List<ValueSet> filters) throws ETooCostly, FHIRException { if (expand != null) { if (expand.getContains().size() > maxExpansionSize) throw new ETooCostly("Too many codes to display (>" + Integer.toString(expand.getContains().size()) + ")"); for (ValueSetExpansionParameterComponent p : expand.getParameter()) { if (!existsInParams(params, p.getName(), p.getValue())) params.add(p); } copyImportContains(expand.getContains(), null, expParams, filters); } }
Example #21
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params, String ctxt) throws FHIRException { exc.checkNoModifiers("Compose.exclude", "expanding"); if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) { excludeSystems.add(exc.getSystem()); } if (exc.hasValueSet()) throw new Error("Processing Value set references in exclude is not yet done in "+ctxt); // importValueSet(imp.getValue(), params, expParams); CodeSystem cs = context.fetchCodeSystem(exc.getSystem()); if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) { ValueSetExpansionOutcome vse = context.expandVS(exc, false); ValueSet valueset = vse.getValueset(); if (valueset == null) throw new TerminologyServiceException("Error Expanding ValueSet: "+vse.getError()); excludeCodes(valueset.getExpansion(), params); return; } for (ConceptReferenceComponent c : exc.getConcept()) { excludeCode(exc.getSystem(), c.getCode()); } if (exc.getFilter().size() > 0) throw new NotImplementedException("not done yet"); }
Example #22
Source File: ValueSetUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public static void setOID(ValueSet vs, String oid) { if (!oid.startsWith("urn:oid:")) oid = "urn:oid:" + oid; for (Identifier id : vs.getIdentifier()) { if ("urn:ietf:rfc:3986".equals(id.getSystem()) && id.hasValue() && id.getValue().startsWith("urn:oid:")) { id.setValue(oid); return; } } vs.addIdentifier().setSystem("urn:ietf:rfc:3986").setValue(oid); }
Example #23
Source File: R2016MayToR4Loader.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); cs.setValueSet(vs.getUrl()); cslist.add(cs); }
Example #24
Source File: TerminologyCache.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public ValueSet getVSEssense(ValueSet vs) { if (vs == null) return null; ValueSet vsc = new ValueSet(); vsc.setCompose(vs.getCompose()); if (vs.hasExpansion()) { vsc.getExpansion().getParameter().addAll(vs.getExpansion().getParameter()); vsc.getExpansion().getContains().addAll(vs.getExpansion().getContains()); } return vsc; }
Example #25
Source File: ShExGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public ShExGenerator(IWorkerContext context) { super(); this.context = context; innerTypes = new HashSet<Pair<StructureDefinition, ElementDefinition>>(); emittedInnerTypes = new HashSet<Pair<StructureDefinition, ElementDefinition>>(); datatypes = new HashSet<String>(); emittedDatatypes = new HashSet<String>(); references = new HashSet<String>(); required_value_sets = new HashSet<ValueSet>(); known_resources = new HashSet<String>(); }
Example #26
Source File: ValidationSupportR4.java From synthea with Apache License 2.0 | 5 votes |
private void handleResource(IBaseResource resource) { if (resource instanceof Bundle) { Bundle bundle = (Bundle) resource; for (BundleEntryComponent entry : bundle.getEntry()) { if (entry.hasResource()) { handleResource(entry.getResource()); } } } else { resources.add(resource); if (resource instanceof CodeSystem) { CodeSystem cs = (CodeSystem) resource; resourcesMap.put(cs.getUrl(), cs); codeSystemMap.put(cs.getUrl(), cs); } else if (resource instanceof ValueSet) { ValueSet vs = (ValueSet) resource; resourcesMap.put(vs.getUrl(), vs); if (vs.hasExpansion() && vs.getExpansion().hasContains()) { processExpansion(vs.getExpansion().getContains()); } } else if (resource instanceof StructureDefinition) { StructureDefinition sd = (StructureDefinition) resource; resourcesMap.put(sd.getUrl(), sd); definitions.add(sd); definitionsMap.put(sd.getUrl(), sd); } } }
Example #27
Source File: ShExGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private String genValueSet(ValueSet vs) { ST vsd = tmplt(VALUE_SET_DEFINITION).add("vsuri", vsprefix(vs.getUrl())).add("comment", vs.getDescription()); ValueSetExpander.ValueSetExpansionOutcome vse = context.expandVS(vs, true, false); List<String> valid_codes = new ArrayList<String>(); if(vse != null && vse.getValueset() != null && vse.getValueset().hasExpansion() && vse.getValueset().getExpansion().hasContains()) { for(ValueSet.ValueSetExpansionContainsComponent vsec : vse.getValueset().getExpansion().getContains()) valid_codes.add("\"" + vsec.getCode() + "\""); } return vsd.add("val_list", valid_codes.size() > 0? " [" + StringUtils.join(valid_codes, " ") + ']' : " EXTERNAL").render(); }
Example #28
Source File: RandomCodeGenerator.java From synthea with Apache License 2.0 | 5 votes |
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 #29
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private Coding buildCoding(String uri, String code) throws FHIRException { // if we can get this as a valueSet, we will String system = null; String display = null; ValueSet vs = Utilities.noString(uri) ? null : worker.fetchResourceWithException(ValueSet.class, uri); if (vs != null) { ValueSetExpansionOutcome vse = worker.expandVS(vs, true, false); if (vse.getError() != null) throw new FHIRException(vse.getError()); CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); for (ValueSetExpansionContainsComponent t : vse.getValueset().getExpansion().getContains()) { if (t.hasCode()) b.append(t.getCode()); if (code.equals(t.getCode()) && t.hasSystem()) { system = t.getSystem(); display = t.getDisplay(); break; } if (code.equalsIgnoreCase(t.getDisplay()) && t.hasSystem()) { system = t.getSystem(); display = t.getDisplay(); break; } } if (system == null) throw new FHIRException("The code '"+code+"' is not in the value set '"+uri+"' (valid codes: "+b.toString()+"; also checked displays)"); } else system = uri; ValidationResult vr = worker.validateCode(terminologyServiceOptions, system, code, null); if (vr != null && vr.getDisplay() != null) display = vr.getDisplay(); return new Coding().setSystem(system).setCode(code).setDisplay(display); }
Example #30
Source File: LiquidEngine.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public ValueSet resolveValueSet(Object appContext, String url) { LiquidEngineContext ctxt = (LiquidEngineContext) appContext; if (externalHostServices != null) return externalHostServices.resolveValueSet(ctxt.externalContext, url); else return engine.getWorker().fetchResource(ValueSet.class, url); }