FHIR Validation

FHIR Validation SHOULD be used with this implementation guide.

This IG and FHIR Validation currently tests the following:

Aspect Verified Description Notes
Structure Check that all the content in the resource is described by the specification, and nothing extra is present XML, JSON and RDF
Cardinality Check that the cardinality of all properties is correct (min & max)
Value Domains Check that the values of all properties conform to the rules for the specified types (including checking that enumerated codes are valid)
Coding/CodeableConcept bindings Check that codes/displays provided in the Coding/CodeableConcept types are valid This requires a UK Terminology Server and currently it is not possible to use this directly with FHIR Validation tools.
Is supported in NHS Digital validation-service-fhir-r4
Invariants Check that the invariants (co-occurrence rules, etc.) have been followed correctly
Profiles Check that any rules in profiles have been followed (including those listed in the Resource.meta.profile, or in CapabilityStatement, or in an ImplementationGuide, or otherwise required by context)
Questionnaires Check that a QuestionnaireResponse is valid against its matching Questionnaire
Message Definitions Check that a Bundle (type=message) is valid against its matching MessageDefinition Not supported in HL7 Validation tools but is supported in NHS Digital validation-service-fhir-r4
Operation Definitions Support for FHIR Operations Not currently supported.
Business Rules Business rules are made outside the specification, such as checking for duplicates, checking that references resolve, checking that a user is authorized to do what they want to do, etc. Business rules are beyond the scope of the FHIR Implementation Guide.

HL7 FHIR Validator

When using the FHIR Validator, the general format will be:

java -jar org.hl7.fhir.validator.jar [filename] -version 4.0.1 -ig [nhs-digital-ig-package] -profile [profile]

Where

  • filename is the file name of the resource being validatatd.
  • nhs-digital-ig-package is the url of the NHS Digital IG Package which can be found in the
    Command 'pagelink' could not render: Page not found.
    section
  • profile the URI of the profile to validate against.

e.g.

To validate a patient example against NHS Digital IG profile NHSDigital-Patient

java -jar org.hl7.fhir.validator.jar patient-ex.xml -version 4.0.1 -ig uk.nhsdigital.r4 -profile https://fhir.nhs.uk/StructureDefinition/NHSDigital-Patient

To validate a patient example against UKCore IG profile UKCore-Patient

  • using UKCore IG

java -jar org.hl7.fhir.validator.jar patient-ex.xml -version 4.0.1 -ig fhir.r4.ukcore.stu1 -profile https://fhir.hl7.org.uk/StructureDefinition/UKCore-Patient

Online HL7 FHIR Validation

https://validator.fhir.org/ provides an online method of validating FHIR.

Note: Validation will be performed against base FHIR and international FHIR, UK SNOMED and UK Implementation Guides are configured under Options. The profile is currently specified by adding a meta.profile to the resource. E.g.

{
    "resourceType": "Task",
    "id": "dea023fc-b6ef-4419-b98f-9f209fd25ed4",
    "meta" : {
        "profile" : [
            "https://fhir.nhs.uk/StructureDefinition/NHSDigital-Task"
        ]
    },

Asking a FHIR Server

See Operation $validate for details.

NHS Digital has implemented this operation as a service and is available on GitHub validation-service-fhir-r4. This project has two branches:

  • main2 which is used CI/CD to validate FHIR Implementation Guides.
  • master which is used currently by Electronic Prescription Service (EPS) to validate incoming FHIR resources.

This is built on top of the HL7 Validator code base and extends this to cover:

  • FHIR Message validation using FHIR MessageDefinition
  • UK Terminology validation using OAuth2 authorisation support