
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.
You need to provide an implementation of IWorkerContext in order to use
the following features:
- FHIRPath Engine
- Rendering
- Terminology functions
- Validation
- Version Comparison
The class SimpleWorkerContext provides a fully functional implementation
that is thread safe and tied to the use of a local filesystem based
package management context. The primary reason to not use the SimpleWorkerContext
class is to store resources and packages somewhere other than the local filesystem
If you provide your own implementation, you need to handle packages properly in
order to get correct version resolution
- Author:
- Grahame
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionorg.hl7.fhir.utilities.TimeTrackerclock()Deprecated.expandVS(ExpansionOptions options, String uri) ValueSet Expansion - see $expand Note that caching makes a real performance difference, so turn it off with care.expandVS(ExpansionOptions options, ValueSet source) ValueSet Expansion - see $expand Note that caching makes a real performance difference, so turn it off with care.expandVS(Resource src, ElementDefinition.ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heiarchical) Deprecated.Deprecated.Deprecated.fetchCodeSystem(String system) Find the code system definition for the nominated system uri.fetchCodeSystem(String system, String version, Resource sourceOfReference) Find the code system definition for the nominated system uri.<T extends Resource>
TfetchResource(Class<T> class_, String uri) Fetch (load if necessary) an identified resource.<T extends Resource>
TfetchResource(Class<T> class_, String uri, String version, Resource sourceOfReference) Fetch (load if necessary) an identified resource.fetchResourceById(String type, String uri) Fetch (load if necessary) an identified resource.<T extends Resource>
TfetchResourceRaw(Class<T> class_, String uri) Find an identified resource, but do not do any processing on it.fetchResourcesByType(Class<T> class_) Fetch all the resources of a particular type. if class == (null | Resource | DomainResource | CanonicalResource) return everything Note: this forces every resource to be loaded; this might take a very long time.fetchResourceVersions(Class<T> class_, String url) Fetch all the versions of a resource.<T extends Resource>
TfetchResourceWithException(Class<T> class_, String uri) Fetch (load if necessary) an identified resource.<T extends Resource>
TfetchResourceWithException(Class<T> class_, String uri, String version, Resource sourceOfReference) Fetch (load if necessary) an identified resource.fetchSupplementedCodeSystem(String system) Like fetchCodeSystem, except that the context will find any CodeSysetm supplements and merge them into the definition that's returnedfetchSupplementedCodeSystem(String system, String version, Resource sourceOfReference) Like fetchCodeSystem, except that the context will find any CodeSysetm supplements and merge them into the definition that's returnedfetchTypeDefinition(String typeName) This is a short cut for fetchResource(StructureDefinition.class, ...)fetchTypeDefinitions(String typeName) This finds all the structure definitions that have the given typeName<T extends Resource>
TfindTxResource(Class<T> class_, String canonical) this first does a fetch resource, and if nothing is found, looks in the terminology eco-system for a matching definition for the resource<T extends Resource>
TfindTxResource(Class<T> class_, String canonical, String version, Resource sourceOfReference) this first does a fetch resource, and if nothing is found, looks in the terminology eco-system for a matching definition for the resourceformatMessage(String theMessage, Object... theMessageArguments) Access to the contexts internationalised error messages For rendering internationalization, see RenderingContext Use String.format() functionalityformatMessagePlural(Integer pluralNum, String theMessage, Object... theMessageArguments) Access to the contexts internationalised error messages for messages with a key plural property.byte[]getBinaryForKey(String binaryKey) Returns the binary for the keyReturns a set of keys that can be used to get binaries from this context.intDeprecated.Get a copy of the expansion parameters to be passed through the terminology server when txServer calls are made You can change these - it's not setting the underlying expansion parameters (see IWorkerContextManager) Note that the Validation Options override these when they are specified on validateCodeif this returns null, the context is frozen (usually for threading concerns on the server) If you're considering not providing this service, the context can't load stuff on the fly so you need to take care to load everything in advance.Deprecated.getPackage(String id, String ver) getPackageForUrl(String url) Note: take care with this method - there are multiple packages with the same canonical (different sub-packages, different versions)Deprecated.getProfiledElementBuilder(PEBuilder.PEElementPropertiesPolicy elementProps, boolean fixedProps) Deprecated.getTxSupportInfo(String system, String version) return the System Support Information for the server that serves the specified code systemorg.fhir.ucum.UcumServiceThe version loaded *does not* have to be 5.0 (R5) - the context can load other versions, though the definitions need to be converted to R5 first Note that more than one version might be loaded at once, but one version is always the default / masterbooleanhasBinaryKey(String binaryKey) Returns true if this worker context contains a binary for this key.booleanhasPackage(String id, String ver) booleanhasPackage(PackageInformation pack) <T extends Resource>
booleanhasResource(Class<T> class_, String uri) find whether a resource is available. the principal use of this method is to find whether a resource is known without actually loading it.<T extends Resource>
booleanhasResource(Class<T> class_, String uri, String version, Resource sourceOfReference) find whether a resource is available. the principal use of this method is to find whether a resource is known without actually loading it.booleanisDataType(String type) return whether type is data type.booleanDeprecated.booleanbooleanisPrimitiveType(String type) return whether type is primitive type.Deprecated.setClientRetryCount(int value) Deprecated.voidsetForPublication(boolean value) Deprecated.setPackageTracker(IWorkerContextManager.IPackageLoadingTracker packageTracker) Deprecated.ask the terminology system whether parent subsumes child.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) See comments in ValidationContextCarrier.voidvalidateCodeBatch(org.hl7.fhir.utilities.validation.ValidationOptions options, List<? extends CodingValidationRequest> codes, ValueSet vs, boolean passVS) Batch validate code - reduce latency and do a bunch of codes in a single server call.validateTxResource(org.hl7.fhir.utilities.validation.ValidationOptions options, Resource resource) Validate the actual terminology resource itself on the appropriate terminology server (used for ECL validation)
-
Method Details
-
getVersion
The version loaded *does not* have to be 5.0 (R5) - the context can load other versions, though the definitions need to be converted to R5 first Note that more than one version might be loaded at once, but one version is always the default / master- Returns:
- the version of the base definitions loaded in context
-
getSpecUrl
- Returns:
- The URL that points to the specification for the version loaded
-
getLocale
- Returns:
- the locale used when creating messages and invoking the terminology server
-
getLogger
- Returns:
- the logging service configured for the context
-
getUcumService
org.fhir.ucum.UcumService getUcumService()- Returns:
- Get the UCUM service that provides access to units of measure reasoning services (if available)
-
oidServices
- Returns:
- a handle to provide information about OIDs known to the context (if available)
-
getManager
if this returns null, the context is frozen (usually for threading concerns on the server) If you're considering not providing this service, the context can't load stuff on the fly so you need to take care to load everything in advance. In particular, pay attention to cross-version packages Also, beware of the impact of lazy-loading on thread safety- Returns:
- the manager that can be used to load / unload content from the context
-
formatMessage
Access to the contexts internationalised error messages For rendering internationalization, see RenderingContext Use String.format() functionality- Parameters:
theMessage-theMessageArguments-- Returns:
- the formatted message
-
formatMessagePlural
Access to the contexts internationalised error messages for messages with a key plural property. There's no support for more than one plural property, so messages are designed accordingly For rendering internationalization, see RenderingContext Use String.format() functionality- Parameters:
theMessage-theMessageArguments-- Returns:
- the formatted message
-
getBinaryKeysAsSet
Returns a set of keys that can be used to get binaries from this context. In general, the binaries come from the loaded packages (mostly the pubpack)- Returns:
- a set of binaries or null
-
hasBinaryKey
Returns true if this worker context contains a binary for this key.- Parameters:
binaryKey-- Returns:
- true if binary is available for this key
-
getBinaryForKey
Returns the binary for the key- Parameters:
binaryKey-- Returns:
-
hasPackage
- Returns:
- true if the nominated package has been loaded
-
hasPackage
- Returns:
- true if the nominated package has been loaded (by id and version)
-
getPackage
- Returns:
- package information for nominated package
-
getPackageForUrl
Note: take care with this method - there are multiple packages with the same canonical (different sub-packages, different versions)- Parameters:
url- - canonical URL- Returns:
- - package information for the most recent package with the given canonical
-
getResourceNames
- Returns:
- a list of the resource names defined for this version (sorted alphabetically)
-
getResourceNamesAsSet
- Returns:
- a set of the resource names defined for this version
-
fetchTypeDefinition
This is a short cut for fetchResource(StructureDefinition.class, ...) but it accepts a typename - that is, it resolves based on StructureDefinition.type or StructureDefinition.url. This only resolves to http://hl7.org/fhir/StructureDefinition/{typename}- Parameters:
typeName-- Returns:
- type (or exception if there is multiple candidates
-
fetchTypeDefinitions
This finds all the structure definitions that have the given typeName- Parameters:
typeName-- Returns:
-
isPrimitiveType
return whether type is primitive type. This is called a lot, and needs a high performance implementation- Parameters:
type-- Returns:
-
isDataType
return whether type is data type. This is called a lot, and needs a high performance implementation- Parameters:
type-- Returns:
-
hasResource
find whether a resource is available. the principal use of this method is to find whether a resource is known without actually loading it.- Parameters:
class_- the type of resourceuri- the URL of the resource, optionally with a |version suffix- Returns:
- if the resource is known
-
hasResource
<T extends Resource> boolean hasResource(Class<T> class_, String uri, String version, Resource sourceOfReference) find whether a resource is available. the principal use of this method is to find whether a resource is known without actually loading it.- Parameters:
class_- the type of resourceuri- the URL of the resource, optionally with a |version suffixversion- the version. Don't provide both a version and a |version suffixsourceOfReference- where the reference was found (if the reference is in a resource)- Returns:
- if the resource is known
-
fetchResource
Fetch (load if necessary) an identified resource. The most common use of this is to access the standard conformance resources that are part of the standard - structure definitions, value sets, concept maps, etc. 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 class can be Resource, DomainResource or CanonicalResource, which means resource of all kinds- Parameters:
class_- the type of resourceuri- the URL of the resource, optionally with a |version suffix- Returns:
- the resource if known (or null)
-
fetchResource
<T extends Resource> T fetchResource(Class<T> class_, String uri, String version, Resource sourceOfReference) Fetch (load if necessary) an identified resource. The most common use of this is to access the standard conformance resources that are part of the standard - structure definitions, value sets, concept maps, etc. 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 class can be Resource, DomainResource or CanonicalResource, which means resource of all kinds- Parameters:
class_- the type of resourceuri- the URL of the resource, optionally with a |version suffixversion- the version. Don't provide both a version and a |version suffixsourceOfReference- where the reference was found (if the reference is in a resource)- Returns:
- if the resource is known
-
fetchResourceWithException
<T extends Resource> T fetchResourceWithException(Class<T> class_, String uri) throws org.hl7.fhir.exceptions.FHIRException Fetch (load if necessary) an identified resource. The most common use of this is to access the standard conformance resources that are part of the standard - structure definitions, value sets, concept maps, etc. 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 class can be Resource, DomainResource or CanonicalResource, which means resource of all kinds- Parameters:
class_- the type of resourceuri- the URL of the resource, optionally with a |version suffix- Returns:
- the resource if known (or an exception will be thrown)
- Throws:
org.hl7.fhir.exceptions.FHIRException
-
fetchResourceWithException
<T extends Resource> T fetchResourceWithException(Class<T> class_, String uri, String version, Resource sourceOfReference) throws org.hl7.fhir.exceptions.FHIRException Fetch (load if necessary) an identified resource. The most common use of this is to access the standard conformance resources that are part of the standard - structure definitions, value sets, concept maps, etc. 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 class can be Resource, DomainResource or CanonicalResource, which means resource of all kinds- Parameters:
class_- the type of resourceuri- the URL of the resource, optionally with a |version suffixversion- the version. Don't provide both a version and a |version suffixsourceOfReference- where the reference was found (if the reference is in a resource)- Returns:
- if the resource is known. Will throw an exception if the resource is not known
- Throws:
org.hl7.fhir.exceptions.FHIRException
-
fetchResourceRaw
Find an identified resource, but do not do any processing on it. The usual processing that happens is ensuring that the snapshot is generated before returning it; This routine is used in the snapshot generation routines to avoid circular dependency challenges generating snapshots. 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 class can be Resource, DomainResource or CanonicalResource, which means resource of all kinds- Parameters:
class_- the type of resourceuri- the URL of the resource, optionally with a |version suffix- Returns:
- the resource if known (or an exception will be thrown)
-
fetchResourceById
Fetch (load if necessary) an identified resource. The most common use of this is to access the standard conformance resources that are part of the standard - structure definitions, value sets, concept maps, etc. This is the non-generic version, but the functionality is otherwise the same 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 class can be Resource, DomainResource or CanonicalResource, which means resource of all kinds- Parameters:
type- the type of resourceuri- the URL of the resource, optionally with a |version suffix- Returns:
- the resource if known (or null)
-
fetchResourcesByType
Fetch all the resources of a particular type. if class == (null | Resource | DomainResource | CanonicalResource) return everything Note: this forces every resource to be loaded; this might take a very long time. Some implementations require some flag to be set elsewhere to allow this method to be called for some types to prevent the method from accidentally being called (ValueSets can take minutes to load, since there are so many in scope)- Parameters:
class_- the type of resource to load- Returns:
- all the resources
-
fetchResourceVersions
Fetch all the versions of a resource.- Parameters:
class_- the type of resource to load- Returns:
- all the resources
-
findTxResource
this first does a fetch resource, and if nothing is found, looks in the terminology eco-system for a matching definition for the resource -
findTxResource
<T extends Resource> T findTxResource(Class<T> class_, String canonical, String version, Resource sourceOfReference) this first does a fetch resource, and if nothing is found, looks in the terminology eco-system for a matching definition for the resource -
getExpansionParameters
Get a copy of the expansion parameters to be passed through the terminology server when txServer calls are made You can change these - it's not setting the underlying expansion parameters (see IWorkerContextManager) 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) This is a short cut for fetchResource(CodeSystem.class, system)- Parameters:
system-- Returns:
-
fetchCodeSystem
Find the code system definition for the nominated system uri. return null if there isn't one (then the tool might try supportsSystem) This is a short cut for fetchResource(CodeSystem.class, system, version, sourceOfReference) -
fetchSupplementedCodeSystem
Like fetchCodeSystem, except that the context will find any CodeSysetm supplements and merge them into the definition that's returned -
fetchSupplementedCodeSystem
Like fetchCodeSystem, except that the context will find any CodeSysetm supplements and merge them into the definition that's returned -
expandVS
@Deprecated ValueSetExpansionOutcome expandVS(ValueSet source, boolean cacheOk, boolean heiarchical) Deprecated.ValueSet Expansion - see $expand Note that caching makes a real performance difference, so turn it off with care.- Parameters:
source- - the valueset to expandcacheOk- - whether to look in the cache for an expansionheiarchical- - whether to accept a heirarchical expansion- Returns:
- the expansion, or information about how the expansion failed
-
expandVS
ValueSet Expansion - see $expand Note that caching makes a real performance difference, so turn it off with care.- Parameters:
options- - controls the expansion process (overrides expansion parameters)source- - the valueset to expand- Returns:
- the expansion, or information about how the expansion failed
-
expandVS
@Deprecated ValueSetExpansionOutcome expandVS(ValueSet source, boolean cacheOk, boolean heiarchical, int count) Deprecated.ValueSet Expansion - see $expand Note that caching makes a real performance difference, so turn it off with care.- Parameters:
source- - the valueset to expandcacheOk- - whether to look in the cache for an expansionheiarchical- - whether to accept a heirarchical expansioncount- - maximum concepts to return- Returns:
- the expansion, or information about how the expansion failed
-
expandVS
ValueSet Expansion - see $expand Note that caching makes a real performance difference, so turn it off with care. This isn't quite the same as findTxResource+expand because if the uri can't be resolved, it'll be passed to the terminology service directly, and some terminology servers will expand value sets that they won't return.- Parameters:
options- - controls the expansion process (overrides expansion parameters)uri- - valueset uri.- Returns:
- the expansion, or information about how the expansion failed
-
expandVS
@Deprecated ValueSetExpansionOutcome expandVS(Resource src, ElementDefinition.ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heiarchical) throws org.hl7.fhir.exceptions.FHIRException Deprecated.ValueSet Expansion - see $expand, but resolves the binding first- Parameters:
src-- Returns:
- Throws:
org.hl7.fhir.exceptions.FHIRException
-
validateCode
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 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- The code to validate (required)vs- the applicable valueset (required)- Returns:
-
validateCode
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 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
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- 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
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 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
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- Parameters:
options- - validation options (required)code- - Coding to validatevs- the applicable valueset (optional)- Returns:
-
validateCode
ValidationResult validateCode(org.hl7.fhir.utilities.validation.ValidationOptions options, Coding code, ValueSet vs, ValidationContextCarrier ctxt) See comments in ValidationContextCarrier. This is called when there might be additional value sets etc available in the context, but we don't want to pre-process them.- Parameters:
options-code-vs-ctxt-- Returns:
-
validateCodeBatch
void validateCodeBatch(org.hl7.fhir.utilities.validation.ValidationOptions options, List<? extends CodingValidationRequest> codes, ValueSet vs, boolean passVS) Batch validate code - reduce latency and do a bunch of codes in a single server call. Each is the same as a validateCode- Parameters:
options-codes-vs-
-
validateTxResource
OperationOutcome validateTxResource(org.hl7.fhir.utilities.validation.ValidationOptions options, Resource resource) Validate the actual terminology resource itself on the appropriate terminology server (used for ECL validation)- Parameters:
options-resource-- Returns:
-
subsumes
Boolean subsumes(org.hl7.fhir.utilities.validation.ValidationOptions options, Coding parent, Coding child) ask the terminology system whether parent subsumes child.- Returns:
- true if it does, false if it doesn't, and null if it's not know whether it does
-
getTxSupportInfo
return the System Support Information for the server that serves the specified code system- Parameters:
system-version-- Returns:
-
isNoTerminologyServer
boolean isNoTerminologyServer()- Returns:
- true if there is a terminology server supporting the context
-
getCodeSystemsUsed
- Returns:
- a list of all the code systems used by the functions above
-
newValidator
Deprecated.Get a validator that can check whether a resource is valid this is deprecated because there's lots of properties to set on the validator; the functions using this need to be changed to use the validator directly- Returns:
- a prepared generator
- Throws:
org.hl7.fhir.exceptions.FHIRException
-
getProfiledElementBuilder
@Deprecated PEBuilder getProfiledElementBuilder(PEBuilder.PEElementPropertiesPolicy elementProps, boolean fixedProps) Deprecated. -
clock
Deprecated.- Returns:
- time tracker for when the context is being loaded (0 = start of loading)
-
getNSUrlMap
Deprecated. -
getPackageTracker
Deprecated. -
setPackageTracker
@Deprecated IWorkerContext setPackageTracker(IWorkerContextManager.IPackageLoadingTracker packageTracker) Deprecated. -
getClientRetryCount
Deprecated. -
setClientRetryCount
Deprecated. -
isForPublication
Deprecated. -
setForPublication
Deprecated.
-