View raw Markdown
type: docsource: source/validation.html

[%settitle Validating Resources%] [%file newheader%] [%file newnavbar%]

Validating Resources

Responsible Owner: [[%wgt fhir%]]([%wg fhir%]) Work GroupStandards 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:

MethodXMLJSONRDFStructureCardinalityValuesBindingsInvariantsProfilesQuestionnairesBusiness Rules
XML Schema
XML Schema + Schematron1
JSON Schema2
ShEx3
Validator
Validation Operation4

Notes:

  1. Schematron generated for a profile can test cardinality and invariants, but not bindings, and slicing is not really supported well
  2. JSON schema generated for a profile can test cardinality, and slicing is partially supported
  3. ShEx can enforce some bindings for well understood terminologies, but this is an ongoing area of development
  4. It is at the discretion of the server how much validation to perform, but most servers offer the same services as or even use the common validators. Some servers also offer a web interface

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.

Correct Use of Validation

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.

Using the XML schema

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.

Using the JSON schema

The JSON schema can be used with JSON schema validation software. Links:

Using FHIR validators

See the HL7 Confluence for an overview of commonly used tools to help with implementing FHIR, including FHIR validators.

Asking a FHIR Server

The operation validate can be used to check whether a resource conforms to a profile. The simplest way to execute this operation is to post the resource to a server:

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:

Via a web interface

Some servers expose the $validate functionality through a web page. For known public implementations, see the FHIR Confluence page

[%file newfooter%]