
Class FhirContext
Important usage notes:
- 
 Thread safety: This class is thread safe and may be shared between multiple processing
 threads, except for the registerCustomType(java.lang.Class<? extends org.hl7.fhir.instance.model.api.IBase>)andregisterCustomTypes(java.util.Collection<java.lang.Class<? extends org.hl7.fhir.instance.model.api.IBase>>)methods.
- Performance: This class is expensive to create, as it scans every resource class it needs to parse or encode to build up an internal model of those classes. For that reason, you should try to create one FhirContext instance which remains for the life of your application and reuse that instance. Note that it will not cause problems to create multiple instances (ie. resources originating from one FhirContext may be passed to parsers originating from another) but you will incur a performance penalty if a new FhirContext is created for every message you parse/encode.
- 
Constructor SummaryConstructorsConstructorDescriptionDeprecated.It is recommended that you use one of the static initializer methods instead of this method, e.g.FhirContext(FhirVersionEnum theVersion) In most cases it is recommended that you use one of the static initializer methods instead of this method, e.g.FhirContext(Class<?>... theResourceTypes) Deprecated.It is recommended that you use one of the static initializer methods instead of this method, e.g.FhirContext(Class<? extends IBaseResource> theResourceType) Deprecated.It is recommended that you use one of the static initializer methods instead of this method, e.g.FhirContext(Collection<Class<? extends IBaseResource>> theResourceTypes) Deprecated.It is recommended that you use one of the static initializer methods instead of this method, e.g.
- 
Method SummaryModifier and TypeMethodDescriptionstatic FhirContextforCached(FhirVersionEnum theFhirVersionEnum) Returns a statically cached FhirContext instance for the given version, creating one if none exists in the cache.static FhirContextforDstu2()Creates and returns a new FhirContext with versionDSTU2static FhirContextCreates and returns a new FhirContext with versionDSTU2(2016 May DSTU3 Snapshot)static FhirContextstatic FhirContextCreates and returns a new FhirContext with versionDSTU2(using the Reference Implementation Structures)static FhirContextstatic FhirContextforDstu3()Creates and returns a new FhirContext with versionDSTU3static FhirContextstatic FhirContextforR4()Creates and returns a new FhirContext with versionR4static FhirContextforR4B()Creates and returns a new FhirContext with versionR4Bstatic FhirContextstatic FhirContextstatic FhirContextforR5()Creates and returns a new FhirContext with versionR5static FhirContextstatic FhirContextforVersion(FhirVersionEnum theFhirVersionEnum) An uncached version of forCached()When encoding resources, this setting configures the parser to include an entry in the resource's metadata section which indicates which profile(s) the resource claims to conform to.Class<? extends IBaseResource> getDefaultTypeForProfile(String theProfile) Returns the default resource type for the given profilegetElementDefinition(Class<? extends IBase> theElementType) Returns the scanned runtime model for the given type.getElementDefinition(String theElementName) Returns the scanned runtime model for the given type.Returns all element definitions (resources, datatypes, etc.)This feature is not yet in its final state and should be considered an internal part of HAPI for now - use with cautionReturns the parser options object which will be used to supply default options to newly created parsersGet the configured performance optionsgetPrimitiveBoolean(Boolean theValue) Deprecated, for removal: This API element is subject to removal in a future version.getResourceDefinition(FhirVersionEnum theVersion, String theResourceName) getResourceDefinition(Class<? extends IBaseResource> theResourceType) Returns the scanned runtime model for the given type.getResourceDefinition(String theResourceName) getResourceDefinition(IBaseResource theResource) Returns the scanned runtime model for the given type.getResourceDefinitionById(String theId) Returns the scanned runtime model for the given type.Returns the scanned runtime models.getResourceType(Class<? extends IBaseResource> theResourceType) Returns the name of a given resource class.getResourceType(String theResourceName) getResourceType(IBaseResource theResource) Returns the name of the scanned runtime model for the given type.Returns an unmodifiable set containing all resource names known to this contextGet the restful client factory.Returns the validation support module configured for this context, creating a default implementation if no module has been passed in via thesetValidationSupport(IValidationSupport)methodbooleanReturnstrueif any default types for specific profiles have been defined within this context.booleanbooleanbooleanbooleanbooleanCreates a new FhirPath engine which can be used to evaluate path expressions over FHIR resources.Deprecated.Deprecated in HAPI FHIR 5.0.0.Create and return a new JSON parser.Create and return a new NDJSON parser.newPrimitiveBoolean(Boolean theValue) newPrimitiveString(String theValue) Create and return a new RDF parser.<T extends IRestfulClient>
 TnewRestfulClient(Class<T> theClientType, String theServerBase) Instantiates a new client instance.newRestfulGenericClient(String theServerBase) Instantiates a new generic client.Create a new validator instance.Create and return a new XML parser.voidregisterCustomType(Class<? extends IBase> theType) This method may be used to register a custom resource or datatype.voidregisterCustomTypes(Collection<Class<? extends IBase>> theTypes) This method may be used to register a custom resource or datatype.voidsetAddProfileTagWhenEncoding(AddProfileTagEnum theAddProfileTagWhenEncoding) When encoding resources, this setting configures the parser to include an entry in the resource's metadata section which indicates which profile(s) the resource claims to conform to.voidsetDefaultTypeForProfile(String theProfile, Class<? extends IBaseResource> theClass) Sets the default type which will be used when parsing a resource that is found to be of the given profile.setFhirValidatorFactory(IFhirValidatorFactory theFhirValidatorFactory) Set the factory method used to create FhirValidator instancesvoidsetLocalizer(HapiLocalizer theMessages) This feature is not yet in its final state and should be considered an internal part of HAPI for now - use with cautionsetNarrativeGenerator(INarrativeGenerator theNarrativeGenerator) setParserErrorHandler(IParserErrorHandler theParserErrorHandler) Sets a parser error handler to use by default on all parsersvoidsetParserOptions(ParserOptions theParserOptions) Sets the parser options object which will be used to supply default options to newly created parsersvoidsetPerformanceOptions(PerformanceOptionsEnum... thePerformanceOptions) Sets the configured performance optionsvoidsetPerformanceOptions(Collection<PerformanceOptionsEnum> theOptions) Sets the configured performance optionsvoidsetRestfulClientFactory(IRestfulClientFactory theRestfulClientFactory) Set the restful client factoryvoidsetStoreRawJson(boolean theStoreResourceJsonFlag) voidsetValidationSupport(IValidationSupport theValidationSupport) Sets the validation support module to use for this context.toString()
- 
Constructor Details- 
FhirContextDeprecated.It is recommended that you use one of the static initializer methods instead of this method, e.g.forDstu2()orforDstu3()orforR4()
- 
FhirContextDeprecated.It is recommended that you use one of the static initializer methods instead of this method, e.g.forDstu2()orforDstu3()orforR4()
- 
FhirContextDeprecated.It is recommended that you use one of the static initializer methods instead of this method, e.g.forDstu2()orforDstu3()orforR4()
- 
FhirContextDeprecated.It is recommended that you use one of the static initializer methods instead of this method, e.g.forDstu2()orforDstu3()orforR4()
- 
FhirContextIn most cases it is recommended that you use one of the static initializer methods instead of this method, e.g.forDstu2()orforDstu3()orforR4(), but this method can also be used if you wish to supply the version programmatically.
 
- 
- 
Method Details- 
forDstu2Cached- Since:
- 5.6.0
 
- 
forDstu2Hl7OrgCached- Since:
- 6.2.0
 
- 
forDstu3Cached- Since:
- 5.5.0
 
- 
forR4Cached- Since:
- 5.5.0
 
- 
forR4BCached- Since:
- 6.1.0
 
- 
forR5Cached- Since:
- 5.5.0
 
- 
getAddProfileTagWhenEncodingWhen encoding resources, this setting configures the parser to include an entry in the resource's metadata section which indicates which profile(s) the resource claims to conform to. The default isAddProfileTagEnum.ONLY_FOR_CUSTOM.- See Also:
 
- 
setAddProfileTagWhenEncodingWhen encoding resources, this setting configures the parser to include an entry in the resource's metadata section which indicates which profile(s) the resource claims to conform to. The default isAddProfileTagEnum.ONLY_FOR_CUSTOM.This feature is intended for situations where custom resource types are being used, avoiding the need to manually add profile declarations for these custom types. See Profiles and Extensions for more information on using custom types. Note that this feature automatically adds the profile, but leaves any profile tags which have been manually added in place as well. - Parameters:
- theAddProfileTagWhenEncoding- The add profile mode (must not be- null)
 
- 
getDefaultTypeForProfileReturns the default resource type for the given profile- See Also:
 
- 
getElementDefinitionReturns the scanned runtime model for the given type. This is an advanced feature which is generally only needed for extending the core library.
- 
getElementDefinitionReturns the scanned runtime model for the given type. This is an advanced feature which is generally only needed for extending the core library.Note that this method is case insensitive! 
- 
getElementDefinitionsReturns all element definitions (resources, datatypes, etc.)
- 
getLocalizerThis feature is not yet in its final state and should be considered an internal part of HAPI for now - use with caution
- 
setLocalizerThis feature is not yet in its final state and should be considered an internal part of HAPI for now - use with caution
- 
getNarrativeGenerator
- 
setNarrativeGenerator
- 
getParserOptionsReturns the parser options object which will be used to supply default options to newly created parsers- Returns:
- The parser options - Will not return null
 
- 
setParserOptionsSets the parser options object which will be used to supply default options to newly created parsers- Parameters:
- theParserOptions- The parser options object - Must not be- null
 
- 
getPerformanceOptionsGet the configured performance options
- 
setPerformanceOptionsSets the configured performance options- See Also:
 
- 
setPerformanceOptionsSets the configured performance options- See Also:
 
- 
getResourceDefinitionpublic RuntimeResourceDefinition getResourceDefinition(Class<? extends IBaseResource> theResourceType) Returns the scanned runtime model for the given type. This is an advanced feature which is generally only needed for extending the core library.
- 
getResourceDefinitionpublic RuntimeResourceDefinition getResourceDefinition(FhirVersionEnum theVersion, String theResourceName) 
- 
getResourceDefinitionReturns the scanned runtime model for the given type. This is an advanced feature which is generally only needed for extending the core library.
- 
getResourceTypeReturns the name of a given resource class.
- 
getResourceTypeReturns the name of the scanned runtime model for the given type. This is an advanced feature which is generally only needed for extending the core library.
- 
getResourceType- Throws:
- DataFormatException
 
- 
getResourceDefinitionpublic RuntimeResourceDefinition getResourceDefinition(String theResourceName) throws DataFormatException - Throws:
- DataFormatException
 
- 
getResourceDefinitionByIdReturns the scanned runtime model for the given type. This is an advanced feature which is generally only needed for extending the core library.
- 
getResourceDefinitionsWithExplicitIdReturns the scanned runtime models. This is an advanced feature which is generally only needed for extending the core library.
- 
getResourceTypesReturns an unmodifiable set containing all resource names known to this context- Since:
- 5.1.0
 
- 
getRestfulClientFactoryGet the restful client factory. If no factory has been set, this will be initialized with a new ApacheRestfulClientFactory.- Returns:
- the factory used to create the restful clients
 
- 
setRestfulClientFactorySet the restful client factory- Parameters:
- theRestfulClientFactory- The new client factory (must not be null)
 
- 
getRuntimeChildUndeclaredExtensionDefinition
- 
getValidationSupportReturns the validation support module configured for this context, creating a default implementation if no module has been passed in via thesetValidationSupport(IValidationSupport)method- See Also:
 
- 
setValidationSupportSets the validation support module to use for this context. The validation support module is used to supply underlying infrastructure such as conformance resources (StructureDefinition, ValueSet, etc) as well as to provide terminology services to modules such as the validator and FluentPath executor
- 
setStoreRawJson
- 
isStoreResourceJson
- 
getVersion
- 
hasDefaultTypeForProfileReturnstrueif any default types for specific profiles have been defined within this context.- See Also:
 
- 
isFormatXmlSupported- Returns:
- Returns trueif the XML serialization format is supported, based on the available libraries on the classpath.
- Since:
- 5.4.0
 
- 
isFormatJsonSupported- Returns:
- Returns trueif the JSON serialization format is supported, based on the available libraries on the classpath.
- Since:
- 5.4.0
 
- 
isFormatNDJsonSupported- Returns:
- Returns trueif the NDJSON serialization format is supported, based on the available libraries on the classpath.
- Since:
- 5.6.0
 
- 
isFormatRdfSupported- Returns:
- Returns trueif the RDF serialization format is supported, based on the available libraries on the classpath.
- Since:
- 5.4.0
 
- 
newBundleFactory
- 
newFluentPathDeprecated.Deprecated in HAPI FHIR 5.0.0. UsenewFhirPath()instead.- Since:
- 2.2
 
- 
newFhirPathCreates a new FhirPath engine which can be used to evaluate path expressions over FHIR resources. Note that this engine will use thecontext validation supportmodule which is configured on the context at the time this method is called.In other words, you may wish to call setValidationSupport(IValidationSupport)before callingnewFluentPath()Note that this feature was added for FHIR DSTU3 and is not available for contexts configured to use an older version of FHIR. Calling this method on a context for a previous version of fhir will result in an UnsupportedOperationException- Since:
- 5.0.0
 
- 
newJsonParserCreate and return a new JSON parser.Thread safety: Parsers are not guaranteed to be thread safe. Create a new parser instance for every thread or every message being parsed/encoded. Performance Note: This method is cheap to call, and may be called once for every message being processed without incurring any performance penalty 
- 
newNDJsonParserCreate and return a new NDJSON parser.Thread safety: Parsers are not guaranteed to be thread safe. Create a new parser instance for every thread or every message being parsed/encoded. Performance Note: This method is cheap to call, and may be called once for every message being processed without incurring any performance penalty The NDJsonParser provided here is expected to translate between legal NDJson and FHIR Bundles. In particular, it is able to encode the resources in a FHIR Bundle to NDJson, as well as decode NDJson into a FHIR "collection"-type Bundle populated with the resources described in the NDJson. It will throw an exception in the event where it is asked to encode to anything other than a FHIR Bundle or where it is asked to decode into anything other than a FHIR Bundle. 
- 
newRDFParserCreate and return a new RDF parser.Thread safety: Parsers are not guaranteed to be thread safe. Create a new parser instance for every thread or every message being parsed/encoded. Performance Note: This method is cheap to call, and may be called once for every message being processed without incurring any performance penalty 
- 
newRestfulClientInstantiates a new client instance. This method requires an interface which is defined specifically for your use cases to contain methods for each of the RESTful operations you wish to implement (e.g. "read ImagingStudy", "search Patient by identifier", etc.). This interface must extendIRestfulClient(or commonly its sub-interfaceIBasicClient). See the RESTful Client documentation for more information on how to define this interface.Performance Note: This method is cheap to call, and may be called once for every operation invocation without incurring any performance penalty - Parameters:
- theClientType- The client type, which is an interface type to be instantiated
- theServerBase- The URL of the base for the restful FHIR server to connect to
- Returns:
- A newly created client
- Throws:
- ConfigurationException- If the interface type is not an interface
 
- 
newRestfulGenericClientInstantiates a new generic client. A generic client is able to perform any of the FHIR RESTful operations against a compliant server, but does not have methods defining the specific functionality required (as is the case withnon-generic clients).Performance Note: This method performs an additional GET request to /metadata before the desired request is performed. - Parameters:
- theServerBase- The URL of the base for the restful FHIR server to connect to
 
- 
newTerser
- 
newValidatorCreate a new validator instance.Note on thread safety: Validators are thread safe, you may use a single validator in multiple threads. (This is in contrast to parsers) 
- 
newViewGenerator
- 
newXmlParserCreate and return a new XML parser.Thread safety: Parsers are not guaranteed to be thread safe. Create a new parser instance for every thread or every message being parsed/encoded. Performance Note: This method is cheap to call, and may be called once for every message being processed without incurring any performance penalty 
- 
registerCustomTypeThis method may be used to register a custom resource or datatype. Note that by using custom types, you are creating a system that will not interoperate with other systems that do not know about your custom type. There are valid reasons however for wanting to create custom types and this method can be used to enable them.THREAD SAFETY WARNING: This method is not thread safe. It should be called before any threads are able to call any methods on this context. - Parameters:
- theType- The custom type to add (must not be- null)
 
- 
registerCustomTypesThis method may be used to register a custom resource or datatype. Note that by using custom types, you are creating a system that will not interoperate with other systems that do not know about your custom type. There are valid reasons however for wanting to create custom types and this method can be used to enable them.THREAD SAFETY WARNING: This method is not thread safe. It should be called before any threads are able to call any methods on this context. - Parameters:
- theTypes- The custom types to add (must not be- nullor contain null elements in the collection)
 
- 
setDefaultTypeForProfileSets the default type which will be used when parsing a resource that is found to be of the given profile.For example, this method is invoked with the profile string of "http://example.com/some_patient_profile"and the type ofMyPatient.class, if the parser is parsing a resource and finds that it declares that it conforms to that profile, theMyPatienttype will be used unless otherwise specified.- Parameters:
- theProfile- The profile string, e.g.- "http://example.com/some_patient_profile". Must not be- nullor empty.
- theClass- The resource type, or- nullto clear any existing type
 
- 
setParserErrorHandlerSets a parser error handler to use by default on all parsers- Parameters:
- theParserErrorHandler- The error handler
 
- 
setFhirValidatorFactorySet the factory method used to create FhirValidator instances- Parameters:
- theFhirValidatorFactory-
- Returns:
- this
- Since:
- 5.6.0
 
- 
toString
- 
getPrimitiveBoolean@Deprecated(since="6.6.0", forRemoval=true) public IPrimitiveType<Boolean> getPrimitiveBoolean(Boolean theValue) Deprecated, for removal: This API element is subject to removal in a future version.
- 
newPrimitiveBoolean
- 
newPrimitiveString
- 
forDstu2Creates and returns a new FhirContext with versionDSTU2
- 
forDstu2Hl7OrgCreates and returns a new FhirContext with versionDSTU2(using the Reference Implementation Structures)
- 
forDstu2_1Creates and returns a new FhirContext with versionDSTU2(2016 May DSTU3 Snapshot)
- 
forDstu3Creates and returns a new FhirContext with versionDSTU3- Since:
- 1.4
 
- 
forR4Creates and returns a new FhirContext with versionR4- Since:
- 3.0.0
 
- 
forR4BCreates and returns a new FhirContext with versionR4B- Since:
- 6.2.0
 
- 
forR5Creates and returns a new FhirContext with versionR5- Since:
- 4.0.0
 
- 
forCachedReturns a statically cached FhirContext instance for the given version, creating one if none exists in the cache. One FhirContext will be kept in the cache for each FHIR version that is requested (by calling this method for that version), and the cache will never be expired.- Since:
- 5.1.0
 
- 
forVersionAn uncached version of forCached()- Returns:
- a new FhirContext for theFhirVersionEnum
 
 
-