|FHIR Infrastructure Work Group||Maturity Level : N/A||Standards Status : Informative|
This page provides an overview of how the FHIR specification supports validation of resources.
Validating a resource means, checking that the following aspects of the resource are valid:
There are multiple ways to validate resources. This table summarizes the options described in this specification, and which of the aspects above they can validate:
|XML Schema + Schematron||1|
|Validation Operation 4|
Note that all these validation methods are incomplete; they can only validate the computable aspects of conformance. There are always additional rules made in narrative that they are not able to check (e.g. a rule such as "All the clinically important content in the data SHALL be in the narrative", which might be made in an implementation guide, but could never be checked by a conformance tool).
In case of disagreement between these conformance methods, note that:
Also, note that static testing of resource content is not enough to prove conformance to the specification. For further information, see FHIR Conformance Testing .
Servers and clients may be configured to validate content when it is received (e.g. some of the public testing services validate resources on create/update). This can be done both during development and in production use of applications in healthcare processes. While use during the development cycle is highly recommended, use during production might not always be a good idea:
On the other hand, validation during production use may be very important:
Generally, following Postel's law is recommended:
An implementation should be conservative in its sending behavior, and liberal in its receiving behavior.
Applications should consider carefully how much validation beyond the security related issues to perform at run-time, and how errors will be handled.
The XML schema can be used to validate XML representations of the resources. When validating a resource, you can nominate one of the following schema:
In addition, the validation schema includes schematron that can be initiated with transform "iso_svrl_for_xslt2.xsl" included in the XML Tools download. Note that XSLT2 is required to run the schematrons.
When running the schematron, use the file "fhir-invariants.sch". This includes all the schematrons. The individual schematron files for each resource are provided to allow implementers to build their own smaller combined file that covers the relevant resource types for them.
The JSON schema can be used with JSON schema validation software. Links:
The FHIR Validator is a Java jar that is provided as part of the specification, and that is used during the publication process to validate all the published examples. To execute the FHIR validator, follow the following steps:
@ECHO OFF ECHO get the validator and unzip it
wget http://build.fhir.org/validator.zip 7z.exe x validator.zipECHO 1. First example shows how to validate against the base spec: ECHO a. get an example to validate wget http://build.fhir.org/patient-example.xml -O pat-ex.xmlECHO b. validate it against FHIR R3 java -jar org.hl7.fhir.validator.jar pat-ex.xml -version 3.0 ECHO 2. Second example shows how to validate against a profile in the spec: ECHO a. get an example to validate wget http://build.fhir.org/observation-example-heart-rate.xml -O obs-ex.xmlECHO b. validate it java -jar org.hl7.fhir.validator.jar obs-ex.xml -version 4.0.1 -profile http://hl7.org/fhir/StructureDefinition/heartrateECHO 3. Third example shows how to validate against a profile in an implementation guide: ECHO a. get an example to validate wget http://build.fhir.org/observation-example-heart-rate.xml -O obs-ex.xmlECHO b. validate it. note that you have to tell the validator where to get the implementation guide information java -jar org.hl7.fhir.validator.jar obs-ex.xml -version 3.0 -ig http://hl7.org/fhir/us/core -profile http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient ECHO Press Any Key to Close pause
Note that it is not necessary to download the resource first; the http address can be supplied directly:
java -jar org.hl7.fhir.validator.jar http://build.fhir.org///patient-example.html -profile http://hl7.org/fhir/StructureDefinition/Patient
The validator requires an underlying terminology server. By default, this is http://fhir3.healthintersections.com.au. For further details of the parameters supported by the validator, see Using the FHIR Validator
POST [base]/Observation/$validate?profile=http://hl7.org/fhir/StructureDefinition/heartrate [other HTTP headers] <Observation>... resource to check as the body
The server will return an OperationOutcome resource listing issues found in the resource.
There are several things to consider when using this operation:
Some servers expose the $validate functionality through a web page. For known public implementations, see the FHIR Confluence page