
Package org.hl7.fhir.r5.context
Interface IWorkerContext
- All Known Implementing Classes:
BaseWorkerContext
,HapiWorkerContext
,SimpleWorkerContext
public interface IWorkerContext
This is the standard interface used for access to underlying FHIR
services through the tools and utilities provided by the reference
implementation.
The functionality it provides is
- get access to parsers, validators, narrative builders etc
(you can't create these directly because they need access
to the right context for their information)
- find resources that the tools need to carry out their tasks
- provide access to terminology services they need.
(typically, these terminology service requests are just
passed through to the local implementation's terminology
service)
- Author:
- Grahame
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
static interface
static interface
static interface
static class
static class
static class
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cachePackage
(IWorkerContext.PackageDetails packageDetails, List<IWorkerContext.PackageVersion> dependencies) Inform the cache about package dependencies.void
cacheResource
(Resource res) cache a resource for later retrieval using fetchResource.void
cacheResourceFromPackage
(Resource res, IWorkerContext.PackageVersion packageDetails) cache a resource for later retrieval using fetchResource.org.hl7.fhir.utilities.TimeTracker
clock()
expandVS
(ElementDefinition.ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heiarchical) ValueSet Expansion - see $expand, but resolves the binding firstexpandVS
(ValueSet.ConceptSetComponent inc, boolean hierarchical, boolean noInactive) Value set expanion inside the internal expansion engine - used for references to supported system (see "supportsSystem") for which there is no value set.ValueSet Expansion - see $expandValueSet Expansion - see $expandfetchCodeSystem
(String system) Find the code system definition for the nominated system uri.fetchCodeSystem
(String system, String version) fetchRawProfile
(String url) <T extends Resource>
TfetchResource
(Class<T> class_, String uri) Find an identified resource.<T extends Resource>
TfetchResource
(Class<T> class_, String uri, String version) <T extends Resource>
TfetchResource
(Class<T> class_, String uri, CanonicalResource canonicalForSource) has the same functionality as fetchResource, but passes in information about the source of the reference (this may affect resolution of version)fetchResourceById
(String type, String uri) Variation of fetchResource when you have a string type, and don't need the right class The URI can have one of 3 formats: - a full URL e.g.<T extends Resource>
TfetchResourceWithException
(Class<T> class_, String uri) fetchTypeDefinition
(String typeName) findMapsForSource
(String url) find concept maps for a sourceformatMessage
(String theMessage, Object... theMessageArguments) void
Given a structure definition, generate a snapshot (or regenerate it)void
generateSnapshot
(StructureDefinition mr, boolean ifLogical) getAbbreviation
(String name) returns the recommended tla for the type (from the structure definitions)int
Set the expansion parameters passed through the terminology server when txServer calls are made Note that the Validation Options override these when they are specified on validateCodegetLinkForUrl
(String corePath, String s) getPackageForUrl
(String url) Get a parser to read/write instances.getParser
(ParserType type) Get a parser to read/write instances.return the link to the base of the specification for the loaded version e.g.getTransform
(String url) org.fhir.ucum.UcumService
Get the versions of the definitions loaded in contextboolean
hasCache()
boolean
hasPackage
(String id, String ver) boolean
<T extends Resource>
booleanhasResource
(Class<T> class_, String uri) find whether a resource is available.boolean
int
loadFromPackage
(org.hl7.fhir.utilities.npm.NpmPackage pi, IWorkerContext.IContextResourceLoader loader) Load relevant resources of the appropriate types (as specified by the loader) from the nominated package note that the package system uses lazy loading; the loader will be called later when the classes that use the context need the relevant resourceint
loadFromPackage
(org.hl7.fhir.utilities.npm.NpmPackage pi, IWorkerContext.IContextResourceLoader loader, String[] types) Deprecated.int
loadFromPackageAndDependencies
(org.hl7.fhir.utilities.npm.NpmPackage pi, IWorkerContext.IContextResourceLoader loader, org.hl7.fhir.utilities.npm.BasePackageCacheManager pcm) Load relevant resources of the appropriate types (as specified by the loader) from the nominated package note that the package system uses lazy loading; the loader will be called later when the classes that use the context need the relevant resource This method also loads all the packages that the package depends on (recursively)Get a JSON parserGet a validator that can check whether a resource is validGet an XML parsertranslate an OID to a URI (look through known NamingSystems)setClientRetryCount
(int value) void
setExpansionProfile
(Parameters expParameters) Get the expansion parameters passed through the terminology server when txServer calls are made Note that the Validation Options override these when they are specified on validateCodevoid
void
void
setOverrideVersionNs
(String value) void
setUcumService
(org.fhir.ucum.UcumService ucumService) void
setValidationMessageLanguage
(Locale locale) boolean
supportsSystem
(String system) True if the underlying terminology service provider will do expansion and code validation for the terminology.org.hl7.fhir.utilities.TranslationServices
validateCode
(org.hl7.fhir.utilities.validation.ValidationOptions options, String system, String version, String code, String display) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known.validateCode
(org.hl7.fhir.utilities.validation.ValidationOptions options, String system, String version, String code, String display, ValueSet vs) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known.validateCode
(org.hl7.fhir.utilities.validation.ValidationOptions options, String code, ValueSet vs) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known.validateCode
(org.hl7.fhir.utilities.validation.ValidationOptions options, CodeableConcept code, ValueSet vs) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known.validateCode
(org.hl7.fhir.utilities.validation.ValidationOptions options, Coding code, ValueSet vs) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known.validateCode
(org.hl7.fhir.utilities.validation.ValidationOptions options, Coding code, ValueSet vs, ValidationContextCarrier ctxt) void
validateCodeBatch
(org.hl7.fhir.utilities.validation.ValidationOptions options, List<? extends IWorkerContext.CodingValidationRequest> codes, ValueSet vs)
-
Method Details
-
getVersion
Get the versions of the definitions loaded in context- Returns:
-
getSpecUrl
return the link to the base of the specification for the loaded version e.g. http://hl7.org/fhir/R4 -
getUcumService
org.fhir.ucum.UcumService getUcumService() -
getParser
Get a parser to read/write instances. Use the defined type (will be extended as further types are added, though the only currently anticipate type is RDF) XML/JSON - the standard renderers XHTML - render the narrative only (generate it if necessary)- Parameters:
type
-- Returns:
-
getParser
Get a parser to read/write instances. Determine the type from the stated type. Supported value for type: - the recommended MIME types - variants of application/xml and application/json - _format values xml, json- Parameters:
type
-- Returns:
-
newJsonParser
Get a JSON parser- Returns:
-
newXmlParser
Get an XML parser- Returns:
-
newValidator
Get a validator that can check whether a resource is valid- Returns:
- a prepared generator
- Throws:
org.hl7.fhir.exceptions.FHIRException
-
fetchResource
Find an identified resource. The most common use of this is to access the the standard conformance resources that are part of the standard - structure definitions, value sets, concept maps, etc. Also, the narrative generator uses this, and may access any kind of resource The URI is called speculatively for things that might exist, so not finding a matching resouce, return null, not an error The URI can have one of 3 formats: - a full URL e.g. http://acme.org/fhir/ValueSet/[id] - a relative URL e.g. ValueSet/[id] - a logical id e.g. [id] It's an error if the second form doesn't agree with class_. It's an error if class_ is null for the last form- Parameters:
resource
-Reference
-- Returns:
- Throws:
org.hl7.fhir.exceptions.FHIRException
Exception
-
fetchResourceWithException
<T extends Resource> T fetchResourceWithException(Class<T> class_, String uri) throws org.hl7.fhir.exceptions.FHIRException - Throws:
org.hl7.fhir.exceptions.FHIRException
-
fetchResource
-
fetchResource
<T extends Resource> T fetchResource(Class<T> class_, String uri, CanonicalResource canonicalForSource) has the same functionality as fetchResource, but passes in information about the source of the reference (this may affect resolution of version)- Type Parameters:
T
-- Parameters:
class_
-uri
-canonicalForSource
-- Returns:
-
fetchResourceById
Variation of fetchResource when you have a string type, and don't need the right class The URI can have one of 3 formats: - a full URL e.g. http://acme.org/fhir/ValueSet/[id] - a relative URL e.g. ValueSet/[id] - a logical id e.g. [id] if type == null, the URI can't be a simple logical id- Parameters:
type
-uri
-- Returns:
-
hasResource
find whether a resource is available. Implementations of the interface can assume that if hasResource ruturns true, the resource will usually be fetched subsequently- Parameters:
class_
-uri
-- Returns:
-
cacheResource
cache a resource for later retrieval using fetchResource. Note that various context implementations will have their own ways of loading rseources, and not all need implement cacheResource. If the resource is loaded out of a package, call cacheResourceFromPackage instead- Parameters:
res
-- Throws:
org.hl7.fhir.exceptions.FHIRException
-
cacheResourceFromPackage
void cacheResourceFromPackage(Resource res, IWorkerContext.PackageVersion packageDetails) throws org.hl7.fhir.exceptions.FHIRException cache a resource for later retrieval using fetchResource. The package information is used to help manage the cache internally, and to help with reference resolution. Packages should be define using cachePackage (but don't have to be) Note that various context implementations will have their own ways of loading rseources, and not all need implement cacheResource- Parameters:
res
-- Throws:
org.hl7.fhir.exceptions.FHIRException
-
cachePackage
void cachePackage(IWorkerContext.PackageDetails packageDetails, List<IWorkerContext.PackageVersion> dependencies) Inform the cache about package dependencies. This can be used to help resolve references Note that the cache doesn't load dependencies- Parameters:
packageInfo
-
-
getResourceNames
- Returns:
- a list of the resource names defined for this version
-
getResourceNamesAsSet
- Returns:
- a set of the resource names defined for this version
-
getTypeNames
- Returns:
- a list of the resource and type names defined for this version
-
allStructures
- Returns:
- a list of all structure definitions, with snapshots generated (if possible)
-
getStructures
- Returns:
- a list of all structure definitions, without trying to generate snapshots
-
allConformanceResources
- Returns:
- a list of all conformance resources
-
generateSnapshot
void generateSnapshot(StructureDefinition p) throws org.hl7.fhir.exceptions.DefinitionException, org.hl7.fhir.exceptions.FHIRException Given a structure definition, generate a snapshot (or regenerate it)- Parameters:
p
-- Throws:
org.hl7.fhir.exceptions.DefinitionException
org.hl7.fhir.exceptions.FHIRException
-
generateSnapshot
-
getExpansionParameters
Set the expansion parameters passed through the terminology server when txServer calls are made Note that the Validation Options override these when they are specified on validateCode -
setExpansionProfile
Get the expansion parameters passed through the terminology server when txServer calls are made Note that the Validation Options override these when they are specified on validateCode -
fetchCodeSystem
Find the code system definition for the nominated system uri. return null if there isn't one (then the tool might try supportsSystem)- Parameters:
system
-- Returns:
-
fetchCodeSystem
-
supportsSystem
True if the underlying terminology service provider will do expansion and code validation for the terminology. Corresponds to the extension http://hl7.org/fhir/StructureDefinition/capabilitystatement-supported-system in the Conformance resource- Parameters:
system
-- Returns:
- Throws:
Exception
org.hl7.fhir.exceptions.TerminologyServiceException
-
findMapsForSource
find concept maps for a source- Parameters:
url
-- Returns:
- Throws:
org.hl7.fhir.exceptions.FHIRException
-
expandVS
ValueSetExpander.ValueSetExpansionOutcome expandVS(ValueSet source, boolean cacheOk, boolean heiarchical) ValueSet Expansion - see $expand- Parameters:
source
-- Returns:
-
expandVS
ValueSetExpander.ValueSetExpansionOutcome expandVS(ValueSet source, boolean cacheOk, boolean heiarchical, boolean incompleteOk) ValueSet Expansion - see $expand- Parameters:
source
-- Returns:
-
expandVS
ValueSetExpander.ValueSetExpansionOutcome expandVS(ElementDefinition.ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heiarchical) throws org.hl7.fhir.exceptions.FHIRException ValueSet Expansion - see $expand, but resolves the binding first- Parameters:
source
-- Returns:
- Throws:
org.hl7.fhir.exceptions.FHIRException
-
expandVS
ValueSetExpander.ValueSetExpansionOutcome expandVS(ValueSet.ConceptSetComponent inc, boolean hierarchical, boolean noInactive) throws org.hl7.fhir.exceptions.TerminologyServiceException Value set expanion inside the internal expansion engine - used for references to supported system (see "supportsSystem") for which there is no value set.- Parameters:
inc
-- Returns:
- Throws:
org.hl7.fhir.exceptions.FHIRException
org.hl7.fhir.exceptions.TerminologyServiceException
-
getLocale
-
setLocale
-
formatMessage
-
setValidationMessageLanguage
-
validateCode
IWorkerContext.ValidationResult validateCode(org.hl7.fhir.utilities.validation.ValidationOptions options, String code, ValueSet vs) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known. If known, return a description of it note: always return a result, with either an error or a code description corresponds to 2 terminology service calls: $validate-code and $lookup in this case, the system will be inferred from the value set. It's an error to call this one without the value set- Parameters:
options
- - validation options (required)code
- he code to validate (required)vs
- the applicable valueset (required)- Returns:
-
validateCode
IWorkerContext.ValidationResult validateCode(org.hl7.fhir.utilities.validation.ValidationOptions options, String system, String version, String code, String display) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known. If known, return a description of it note: always return a result, with either an error or a code description corresponds to 2 terminology service calls: $validate-code and $lookup- Parameters:
options
- - validation options (required)system
- - equals Coding.system (required)code
- - equals Coding.code (required)display
- - equals Coding.display (optional)- Returns:
-
validateCode
IWorkerContext.ValidationResult validateCode(org.hl7.fhir.utilities.validation.ValidationOptions options, String system, String version, String code, String display, ValueSet vs) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known. If known, return a description of it note: always return a result, with either an error or a code description corresponds to 2 terminology service calls: $validate-code and $lookup- Parameters:
options
- - validation options (required)system
- - equals Coding.system (required)code
- - equals Coding.code (required)display
- - equals Coding.display (optional)vs
- the applicable valueset (optional)- Returns:
-
validateCode
IWorkerContext.ValidationResult validateCode(org.hl7.fhir.utilities.validation.ValidationOptions options, CodeableConcept code, ValueSet vs) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known. If known, return a description of it note: always return a result, with either an error or a code description corresponds to 2 terminology service calls: $validate-code and $lookup Note that this doesn't validate binding strength (e.g. is just text allowed?)- Parameters:
options
- - validation options (required)code
- - CodeableConcept to validatevs
- the applicable valueset (optional)- Returns:
-
validateCode
IWorkerContext.ValidationResult validateCode(org.hl7.fhir.utilities.validation.ValidationOptions options, Coding code, ValueSet vs) Validation of a code - consult the terminology infrstructure and/or service to see whether it is known. If known, return a description of it note: always return a result, with either an error or a code description corresponds to 2 terminology service calls: $validate-code and $lookup in this case, the system will be inferred from the value set. It's an error to call this one without the value set- Parameters:
options
- - validation options (required)code
- - Coding to validatevs
- the applicable valueset (optional)- Returns:
-
validateCode
IWorkerContext.ValidationResult validateCode(org.hl7.fhir.utilities.validation.ValidationOptions options, Coding code, ValueSet vs, ValidationContextCarrier ctxt) -
validateCodeBatch
void validateCodeBatch(org.hl7.fhir.utilities.validation.ValidationOptions options, List<? extends IWorkerContext.CodingValidationRequest> codes, ValueSet vs) -
getAbbreviation
returns the recommended tla for the type (from the structure definitions)- Parameters:
name
-- Returns:
-
oid2Uri
translate an OID to a URI (look through known NamingSystems)- Parameters:
code
-- Returns:
-
hasCache
boolean hasCache()- Returns:
- true if the contxt has a terminology caching service internally
-
setLogger
-
getLogger
-
isNoTerminologyServer
boolean isNoTerminologyServer() -
getCodeSystemsUsed
-
translator
org.hl7.fhir.utilities.TranslationServices translator() -
listTransforms
-
getTransform
-
getOverrideVersionNs
-
setOverrideVersionNs
-
fetchTypeDefinition
-
fetchRawProfile
-
setUcumService
-
getLinkForUrl
-
getBinaries
Map<String,byte[]> getBinaries() -
loadFromPackage
int loadFromPackage(org.hl7.fhir.utilities.npm.NpmPackage pi, IWorkerContext.IContextResourceLoader loader) throws FileNotFoundException, IOException, org.hl7.fhir.exceptions.FHIRException Load relevant resources of the appropriate types (as specified by the loader) from the nominated package note that the package system uses lazy loading; the loader will be called later when the classes that use the context need the relevant resource- Parameters:
pi
- - the package to loadloader
- - an implemenation of IContextResourceLoader that knows how to read the resources in the package (e.g. for the appropriate version).- Returns:
- the number of resources loaded
- Throws:
FileNotFoundException
IOException
org.hl7.fhir.exceptions.FHIRException
-
loadFromPackage
@Deprecated int loadFromPackage(org.hl7.fhir.utilities.npm.NpmPackage pi, IWorkerContext.IContextResourceLoader loader, String[] types) throws FileNotFoundException, IOException, org.hl7.fhir.exceptions.FHIRException Deprecated.Load relevant resources of the appropriate types (as specified by the loader) from the nominated package note that the package system uses lazy loading; the loader will be called later when the classes that use the context need the relevant resource Deprecated - use the simpler method where the types come from the loader.- Parameters:
pi
- - the package to loadloader
- - an implemenation of IContextResourceLoader that knows how to read the resources in the package (e.g. for the appropriate version).types
- - which types of resources to load- Returns:
- the number of resources loaded
- Throws:
FileNotFoundException
IOException
org.hl7.fhir.exceptions.FHIRException
-
loadFromPackageAndDependencies
int loadFromPackageAndDependencies(org.hl7.fhir.utilities.npm.NpmPackage pi, IWorkerContext.IContextResourceLoader loader, org.hl7.fhir.utilities.npm.BasePackageCacheManager pcm) throws FileNotFoundException, IOException, org.hl7.fhir.exceptions.FHIRException Load relevant resources of the appropriate types (as specified by the loader) from the nominated package note that the package system uses lazy loading; the loader will be called later when the classes that use the context need the relevant resource This method also loads all the packages that the package depends on (recursively)- Parameters:
pi
- - the package to loadloader
- - an implemenation of IContextResourceLoader that knows how to read the resources in the package (e.g. for the appropriate version).pcm
- - used to find and load additional dependencies- Returns:
- the number of resources loaded
- Throws:
FileNotFoundException
IOException
org.hl7.fhir.exceptions.FHIRException
-
hasPackage
-
hasPackage
-
getPackage
-
getClientRetryCount
int getClientRetryCount() -
setClientRetryCount
-
clock
org.hl7.fhir.utilities.TimeTracker clock() -
getPackageForUrl
-