HOWTO Check you FHIR code is correct (Transfer Of Care, LHCRE, Digital Child Health, Care Connect, GP Connect, etc)

During the last two INTEROPen hackathons we developed a FHIR Validation service and this is now publicly available.

It is based on the official HL7 FHIR Validator and was built using HAPI. It is also Open Source, contributions welcome (GitHub - nhsconnect/careconnect-reference-implementation: A reference implementation server for the CareConnect API and Care Connect FHIR Validation).

Why would you use it?

I’ll answer on how I use it. When I’m creating a FHIR resource I want to check what I’ve done is correct and conforms to the UK CareConnect Profiles. I also want to check it validates against international FHIR.
I may be working on Transfer of Care (which also validates) but I don’t want to test my work towards the end of development.

Features

The FHIR Server implements the standard FHIR Operation for Validation (Validation - FHIR v4.3.0) with some limitations:

  • Terminology is not currently supported (it needs to be connected to a UK terminology server)

But the others in the link above are supported (inc Questionnaires).

Example

So lets assume I’ve created an Observation following the CareConnect-Condition-1 profile and I’ve created this (JSON but XML is supported):

{
"resourceType": "Condition",
"id": "1",
"meta": {
    "profile": [
        "https://fhir.hl7.org.uk/STU3/StructureDefinition/CareConnect-Condition-1"
    ]
},
"clinicalStatus": "active",
"category": [
    {
        "coding": [
            {
                "system": "https://fhir.hl7.org.uk/STU3/CodeSystem/CareConnect-ConditionCategory-1",
                "code": "encounter-diagnosis",
                "display": "Encounter Diagnosis"
            }
        ],
        "text": "Encounter Diagnosis"
    }
],
"code": {
    "coding": [
        {
            "system": "http://snomed.info/sct",
            "code": "44054006",
            "display": "Type 2 diabetes mellitus"
        }
    ],
    "text": "Type 2 diabetes mellitus"
},
"subject": {
    "reference": "Patient/4",
    "display": "Mrs Fredrica Smith"
},
"onsetDateTime": "2010-10-09T09:00:00+00:00",
"assertedDate": "2010-10-09T09:00:00+00:00",
"asserter": {
    "reference": "Practitioner/200001",
    "display": "Dr. Samuel Darwin"
}
}

We have two ways of validating this resource.

Using Care Connect FHIR Explorer

Open up the CCRI via this link FHIR Explorer

  1. Select the resource type Condition
  2. leave JSON Selected
  3. Copy the example above into the box

  1. Click on the validate button

Validate2

You can also load in samples. In the example below we’ve loaded in a Transfer Of Care FHIR Document.

As you can see this has a number of errors. You can edit your example to help diagnose errors, e.g. in the errors above it mentioned it complained about an unknown code system: http://hl7.org/fhir/v3-ActEncounterCode … a little bit of check revealed this was wrong and the correct system should have been:

http://hl7.org/fhir/v3/ActCode

Amending the example with the correct system and validating again confirms the error has been removed.

** RESTFul (Using Care Connect Reference Implementation **

The FHIR Explorer uses this to perform the validation, the endpoints have this format

https://data.developer.nhs.uk/ccri-fhir/STU3/{resource}/$validate

Where {resource} should be replaced with the correct resource type.

POSTMan Example (https://www.getpostman.com/)

I’m going to use the Condition example from before. In Postman I set the Url, so this would be

https://data.developer.nhs.uk/ccri-fhir/STU3/Condition/$validate

Change the query type from GET to POST and add an header for Content-Type which has a value of ‘application/fhir+json’

Lastly add your example into the body section and click send.

The results are returned in a FHIR OperationOutcome which contains any issues that have been found.

Note

I won’t lie and say the errors returned are easy to understand but if you post on this site or the official FHIR Chat site (Zulip), I’m sure people will try to help you.

As this validation software is based on the latest version of HAPI [3.7] (and FHIR Validator) it will produce different errors to other validators in use in the UK. This tends to result in more issues being found (a good thing?).

p.s. It is open source and if you find errors (with the validator) then you can log them here:

You can also submit fixes on the same git repo. Note: Latest version is 3.8, release is master.

In addition it has some supported for validating against new profiles. You can load them via POSTMAN using this endpoint https://data.developer.nhs.uk/ccri-fhir/STU3/StructureDefinition
CRUD (POST, GET, PUT and DELETE) is supported

Looks good Kev.

Just to note - there is a minor error/typo in the example. The final } of the JSON is outside the code window (which I noticed by sending the contents of the code window to the validator :-))

cheers. Fixed

Just for fun - here is a Python script that will read a set of resources from a folder, validate them against that server and return the results as a set of dynamically generated unittest test cases:

1 Like