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

**URL:** <https://openhealthhub.org/t/howto-check-you-fhir-code-is-correct-transfer-of-care-lhcre-digital-child-health-care-connect-gp-connect-etc/2033>\
**Category:** FHIR\
**Created:** [28 March 2019 08:50 UTC](https://openhealthhub.org/t/howto-check-you-fhir-code-is-correct-transfer-of-care-lhcre-digital-child-health-care-connect-gp-connect-etc/2033 "2019-03-28T08:50:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mayfield.g.kev](https://openhealthhub.org/user_avatar/openhealthhub.org/mayfield.g.kev/32/648_2.png) [@mayfield.g.kev](https://openhealthhub.org/u/mayfield.g.kev)\
**Post date:** [28 March 2019 08:50 UTC](https://openhealthhub.org/t/howto-check-you-fhir-code-is-correct-transfer-of-care-lhcre-digital-child-health-care-connect-gp-connect-etc/2033/1 "2019-03-28T08:50:29Z")

</div>

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](https://github.com/nhsconnect/careconnect-reference-implementation)).

**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](https://www.hl7.org/fhir/validation.html)) 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](https://data.developer.nhs.uk/ccri/term/validate)

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

 ![Validate1](https://new.openhealthhub.org/uploads/default/original/1X/8280058bf05e22724c993ad5a1a6bb14a6fc6940.png)

1. Click on the validate button

![Validate2](https://new.openhealthhub.org/uploads/default/original/1X/554f813a9195fe159102ac929199b0ad5fb654d4.png)

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

 ![Validate3](https://new.openhealthhub.org/uploads/default/original/1X/0e7c978e52dd3d47ecbfcf866d1a9bca2ab17712.png)

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](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](http://hl7.org/fhir/v3/ActCode)

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

 ![Validate4](https://new.openhealthhub.org/uploads/default/original/1X/136db8f9abc0652bd31e31fa6ba7e1db0843de6b.png)

\*\* 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](https://data.developer.nhs.uk/ccri-fhir/STU3/%7Bresource%7D/%24validate)**

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

POSTMan Example ([https://www.getpostman.com/](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](https://data.developer.nhs.uk/ccri-fhir/STU3/Condition/%24validate)

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

 ![Validate5](https://new.openhealthhub.org/uploads/default/original/1X/bd5ddb0808561d504bad3fc7420b7bd123dbf2a1.png)

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

 ![Validate6](https://new.openhealthhub.org/uploads/default/original/1X/2aea9d91300ca559262ee26002210c7de1b73ab7.png)

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](https://chat.fhir.org/#)), 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?).

---

<div class="post-metadata">

**Author:** ![mayfield.g.kev](https://openhealthhub.org/user_avatar/openhealthhub.org/mayfield.g.kev/32/648_2.png) [@mayfield.g.kev](https://openhealthhub.org/u/mayfield.g.kev)\
**Post date:** [28 March 2019 09:04 UTC](https://openhealthhub.org/t/howto-check-you-fhir-code-is-correct-transfer-of-care-lhcre-digital-child-health-care-connect-gp-connect-etc/2033/2 "2019-03-28T09:04:25Z")

</div>

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

> **[nhsconnect/careconnect-reference-implementation](https://github.com/nhsconnect/careconnect-reference-implementation/issues)**
>
> A reference implementation server for the CareConnect API and Care Connect FHIR Validation - nhsconnect/careconnect-reference-implementation

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

---

<div class="post-metadata">

**Author:** ![mayfield.g.kev](https://openhealthhub.org/user_avatar/openhealthhub.org/mayfield.g.kev/32/648_2.png) [@mayfield.g.kev](https://openhealthhub.org/u/mayfield.g.kev)\
**Post date:** [28 March 2019 09:13 UTC](https://openhealthhub.org/t/howto-check-you-fhir-code-is-correct-transfer-of-care-lhcre-digital-child-health-care-connect-gp-connect-etc/2033/3 "2019-03-28T09:13:05Z")

</div>

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](https://data.developer.nhs.uk/ccri-fhir/STU3/StructureDefinition)  
CRUD (POST, GET, PUT and DELETE) is supported

---

<div class="post-metadata">

**Author:** ![elementechemlyn](https://openhealthhub.org/user_avatar/openhealthhub.org/elementechemlyn/32/604_2.png) [@elementechemlyn](https://openhealthhub.org/u/elementechemlyn)\
**Post date:** [28 March 2019 12:05 UTC](https://openhealthhub.org/t/howto-check-you-fhir-code-is-correct-transfer-of-care-lhcre-digital-child-health-care-connect-gp-connect-etc/2033/4 "2019-03-28T12:05:20Z")

</div>

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 :-))

---

<div class="post-metadata">

**Author:** ![mayfield.g.kev](https://openhealthhub.org/user_avatar/openhealthhub.org/mayfield.g.kev/32/648_2.png) [@mayfield.g.kev](https://openhealthhub.org/u/mayfield.g.kev)\
**Post date:** [28 March 2019 12:28 UTC](https://openhealthhub.org/t/howto-check-you-fhir-code-is-correct-transfer-of-care-lhcre-digital-child-health-care-connect-gp-connect-etc/2033/5 "2019-03-28T12:28:10Z")

</div>

cheers. Fixed

---

<div class="post-metadata">

**Author:** ![elementechemlyn](https://openhealthhub.org/user_avatar/openhealthhub.org/elementechemlyn/32/604_2.png) [@elementechemlyn](https://openhealthhub.org/u/elementechemlyn)\
**Post date:** [28 March 2019 16:02 UTC](https://openhealthhub.org/t/howto-check-you-fhir-code-is-correct-transfer-of-care-lhcre-digital-child-health-care-connect-gp-connect-etc/2033/6 "2019-03-28T16:02:36Z")

</div>

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](https://docs.python.org/3/library/unittest.html) test cases:

> <https://gist.github.com/elementechemlyn/7fc360cdf19e44c87358b21eb76ef7d5>
