Package org.hl7.fhir.validation
Class NativeHostServices
- java.lang.Object
-
- org.hl7.fhir.validation.NativeHostServices
-
public class NativeHostServices extends Object
This class allows you to host the java validator in another service, and use the services it has in a wider context. The way it works is - put the jar in your class path - Find the class org.hl7.fhir.validation.NativeHostServices - call init(path) where path refers to one of the definitions files from the main build (e.g. definitions.xml.zip) - required, do only once, do before anything else - call load(path) where path refers to the igpack.zip produced by the ig publisher (do this once for each IG you care about) - call connectToTxSvc(url) where the url is your terminology service of choice (can be http://tx.fhir.org/r4 or /r3) now the jar is ready for action. There's 3 functions you can call (all are thread safe): - validate - given a resource, validate it against all known rules - convert - given a resource in a different version convert it to this version (if possible) - unconvert - given a resource, convert it to a different version (if possible) also, call "status" to get a json object that describes the internals of the jar (e.g. for server status) The interface is optimised for JNI.- Author:
- Grahame Grieve
-
-
Constructor Summary
Constructors Constructor Description NativeHostServices()
Create an instance of the service
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connectToTxSvc(String txServer, String log)
Set up the validator with a terminology servicevoid
connectToTxSvc(String txServer, String log, String txCache)
Set up the validator with a terminology servicebyte[]
convertResource(byte[] r, String fmt, String version)
Convert a resource to R4 from the specified versionvoid
dropResource(String type, String id)
forget a resource that was previously seen (using @seeResource)void
init(String pack)
Initialize the service and prepare it for usevoid
load(String pack)
Load an IG so that the validator knows all about it.void
seeResource(byte[] source, org.hl7.fhir.r5.elementmodel.Manager.FhirFormat fmt)
Call when the host process encounters one of the following: - (for validation): - profile - extension definition - value set - code system - (for conversion): - structure map - concept mapString
status()
get back a JSON object with information about the process.byte[]
unConvertResource(byte[] r, String fmt, String version)
Convert a resource from R4 to the specified versionbyte[]
validateResource(String location, byte[] source, String cntType, String options)
Validate a resource.
-
-
-
Constructor Detail
-
NativeHostServices
public NativeHostServices()
Create an instance of the service
-
-
Method Detail
-
init
public void init(String pack) throws Exception
Initialize the service and prepare it for use- Parameters:
pack
- - the filename of a pack from the main build - either definitions.xml.zip, definitions.json.zip, or igpack.zip- Throws:
Exception
-
load
public void load(String pack) throws Exception
Load an IG so that the validator knows all about it.- Parameters:
pack
- - the filename (or URL) of a validator.pack produced by the IGPublisher- Throws:
Exception
-
connectToTxSvc
public void connectToTxSvc(String txServer, String log) throws Exception
Set up the validator with a terminology service- Parameters:
txServer
- - the URL of the terminology service (http://tx.fhir.org/r4 default)- Throws:
Exception
-
connectToTxSvc
public void connectToTxSvc(String txServer, String log, String txCache) throws Exception
Set up the validator with a terminology service- Parameters:
txServer
- - the URL of the terminology service (http://tx.fhir.org/r4 default)- Throws:
Exception
-
seeResource
public void seeResource(byte[] source, org.hl7.fhir.r5.elementmodel.Manager.FhirFormat fmt) throws Exception
Call when the host process encounters one of the following: - (for validation): - profile - extension definition - value set - code system - (for conversion): - structure map - concept map- Parameters:
source
-- Throws:
Exception
-
dropResource
public void dropResource(String type, String id) throws Exception
forget a resource that was previously seen (using @seeResource)- Parameters:
type
- - the resource typeid
- - the resource id- Throws:
Exception
-
validateResource
public byte[] validateResource(String location, byte[] source, String cntType, String options) throws Exception
Validate a resource. Possible options: - id-optional : no resource id is required (default) - id-required : a resource id is required - id-prohibited : no resource id is allowed - any-extensions : allow extensions other than those defined by the encountered structure definitions - bp-ignore : ignore best practice recommendations (default) - bp-hint : treat best practice recommendations as a hint - bp-warning : treat best practice recommendations as a warning - bp-error : treat best practice recommendations as an error - display-ignore : ignore Coding.display and do not validate it (default) - display-check : check Coding.display - must be correct - display-case-space : check Coding.display but allow case and whitespace variation - display-case : check Coding.display but allow case variation - display-space : check Coding.display but allow whitespace variation- Parameters:
location
- - a text description of the context of validation (for human consumers to help locate the problem - echoed into error messages)source
- - the bytes to validatecntType
- - the format of the content. one of XML, JSON, TURTLEoptions
- - a list of space separated options- Returns:
- Throws:
Exception
-
convertResource
public byte[] convertResource(byte[] r, String fmt, String version) throws org.hl7.fhir.exceptions.FHIRException, IOException
Convert a resource to R4 from the specified version- Parameters:
r
- - the source of the resource to convert fromfmt
- - the format of the content. one of XML, JSON, TURTLEversion
- - the version of the content. one of r2, r3- Returns:
- - the converted resource (or an exception if can't be converted)
- Throws:
org.hl7.fhir.exceptions.FHIRException
IOException
-
unConvertResource
public byte[] unConvertResource(byte[] r, String fmt, String version) throws org.hl7.fhir.exceptions.FHIRException, IOException
Convert a resource from R4 to the specified version- Parameters:
r
- - the source of the resource to convert fromfmt
- - the format of the content. one of XML, JSON, TURTLEversion
- - the version to convert to. one of r2, r3- Returns:
- - the converted resource (or an exception if can't be converted)
- Throws:
org.hl7.fhir.exceptions.FHIRException
IOException
-
-