Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In the previous Terminology & Profile Support blog post I introduced the HSPC Logica Terminology Server and gave step-by-step instructions on some common use cases including:

  • Utilizing FHIR Terminology Services on the HSPC Logica Terminology Server for common SMART on FHIR app development tasks
  • Validating instance data for non-profiled FHIR resources using the $validate operation
  • Retrieving StructureDefinition resources describing the FPAR resources currently in development

If you haven't read through part one, you can access it at HSPC Logica Sandbox - Terminology & Profile Support (part 1).

In part two I will continue by showing how to validate profiled instance data using the $validate operation on the HSPC Logica Sandbox.  The profiles we'll focus on are those coming from the us-core validation pack, for FHIR version STU3 (3.0.1).  These profiles have been uploaded to the HSPC Logica Terminology Server, which can be found at:

Code Block
https://api-v5-stu3.hspconsortiumlogicahealth.org/stu3/open

Request Format

Our request to validate looks just like it did in our previous examples, the important distinction is the use of the Meta.profile field to indicate that this instance data conforms to a profile.  The value of the Meta.profile field should be a reference to the StructureDefinition.url of the StructureDefinition resource which defines this instance data. 

For our examples, we'll be using http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient, which is the us-core profile for the Patient resource.  You can read the docs for this profile, or you can query the structure definition file directly from the HSPC Logica Terminology Server:

Code Block
https://api-v5-stu3.hspconsortium.org/stu3/open/sand/StructureDefinition?url=http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient

Response

omitted due to size

Putting this all together, we can formulate the $validate request as follows:

Code Block
POST https://api-v5-stu3.hspconsortiumlogicahealth.org/stu3/open/Patient/$validate
--- REQUEST BODY ---
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "resource",
      "resource": {
        "resourceType": "Patient",
        "meta": {
    	"profile": [
    		"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
    		]
		},
        "identifier": [
          {
            "use": "usual",
            "type": {
              "coding": [
                {
                  "system": "http://hl7.org/fhir/v2/0203",
                  "code": "MR"
                }
              ]
            },
            "system": "urn:oid:1.2.36.146.595.217.0.1",
            "value": "12345",
            "period": {
              "start": "2001-05-06"
            },
            "assigner": {
              "display": "Acme Healthcare"
            }
          }
        ],
        "active": true,
        "gender": "male",
        "name": [
          {
            "use": "official",
            "family": "Chalmers",
            "given": [
              "Peter",
              "James"
            ]
          },
          {
            "use": "usual",
            "family": "Yep",
            "given": [
              "Jim"
            ]
          },
          {
            "use": "maiden",
            "family": "Windsor",
            "given": [
              "Peter",
              "James"
            ],
            "period": {
              "end": "2002"
            }
          }
        ]
      }
    }
  ]
}

...

Code Block
languagejs
collapsetrue
{
    "resourceType": "OperationOutcome",
    "text": {
        "status": "generated",
        "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">INFORMATION</td><td>[]</td><td><pre>No issues detected during validation</pre></td>\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
    },
    "issue": [
        {
            "severity": "information",
            "code": "informational",
            "diagnostics": "No issues detected during validation"
        }
    ]
}

Profiled Instance Data Validation

Now that we know what the request looks like, lets take a closer look at some validation examples.  For starters, we'll validate the patient General Purpose Example from the official Patient Resource FHIR docs.  It looks like this:

Code Block
POST https://api-v5-stu3.hspconsortiumlogicahealth.org/stu3/open/Patient/$validate
--- REQUEST BODY ---
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "resource",
      "resource": {
        "resourceType": "Patient",
        "meta": {
    	"profile": [
    		"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
    		]
		},
        "id": "example",
        "identifier": [
          {
            "use": "usual",
            "type": {
              "coding": [
                {
                  "system": "http://hl7.org/fhir/v2/0203",
                  "code": "MR"
                }
              ]
            },
            "system": "urn:oid:1.2.36.146.595.217.0.1",
            "value": "12345",
            "period": {
              "start": "2001-05-06"
            },
            "assigner": {
              "display": "Acme Healthcare"
            }
          }
        ],
        "active": true,
        "name": [
          {
            "use": "official",
            "family": "Chalmers",
            "given": [
              "Peter",
              "James"
            ]
          },
          {
            "use": "usual",
            "given": [
              "Jim"
            ]
          },
          {
            "use": "maiden",
            "family": "Windsor",
            "given": [
              "Peter",
              "James"
            ],
            "period": {
              "end": "2002"
            }
          }
        ],
        "telecom": [
          {
            "use": "home"
          },
          {
            "system": "phone",
            "value": "(03) 5555 6473",
            "use": "work",
            "rank": 1
          },
          {
            "system": "phone",
            "value": "(03) 3410 5613",
            "use": "mobile",
            "rank": 2
          },
          {
            "system": "phone",
            "value": "(03) 5555 8834",
            "use": "old",
            "period": {
              "end": "2014"
            }
          }
        ],
        "gender": "male",
        "birthDate": "1974-12-25",
        "_birthDate": {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/patient-birthTime",
              "valueDateTime": "1974-12-25T14:35:45-05:00"
            }
          ]
        },
        "deceasedBoolean": false,
        "address": [
          {
            "use": "home",
            "type": "both",
            "text": "534 Erewhon St PeasantVille, Rainbow, Vic  3999",
            "line": [
              "534 Erewhon St"
            ],
            "city": "PleasantVille",
            "district": "Rainbow",
            "state": "Vic",
            "postalCode": "3999",
            "period": {
              "start": "1974-12-25"
            }
          }
        ],
        "contact": [
          {
            "relationship": [
              {
                "coding": [
                  {
                    "system": "http://hl7.org/fhir/v2/0131",
                    "code": "N"
                  }
                ]
              }
            ],
            "name": {
              "family": "du Marché",
              "_family": {
                "extension": [
                  {
                    "url": "http://hl7.org/fhir/StructureDefinition/humanname-own-prefix",
                    "valueString": "VV"
                  }
                ]
              },
              "given": [
                "Bénédicte"
              ]
            },
            "telecom": [
              {
                "system": "phone",
                "value": "+33 (237) 998327"
              }
            ],
            "address": {
              "use": "home",
              "type": "both",
              "line": [
                "534 Erewhon St"
              ],
              "city": "PleasantVille",
              "district": "Rainbow",
              "state": "Vic",
              "postalCode": "3999",
              "period": {
                "start": "1974-12-25"
              }
            },
            "gender": "female",
            "period": {
              "start": "2012"
            }
          }
        ]
      }
    }
  ]
}

...

Code Block
POST https://api-v5-stu3.hspconsortiumlogicahealth.org/stu3/open/Patient/$validate
--- REQUEST BODY ---
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "resource",
      "resource": {
        "resourceType": "Patient",
        "meta": {
    	"profile": [
    		"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
    		]
		},
        "id": "example",
        "name": [
        	{
            "use": "usual",
            "given": [
              "Jim"
            ]
          },
          {
            "use": "maiden",
            "family": "Windsor",
            "period": {
              "end": "2002"
            }
          }
        ],
        "telecom": [
          {
            "use": "home"
          },
          {
            "system": "phone",
            "value": "(03) 5555 6473",
            "use": "work",
            "rank": 1
          },
          {
            "system": "phone",
            "value": "(03) 3410 5613",
            "use": "mobile",
            "rank": 2
          },
          {
            "system": "phone",
            "value": "(03) 5555 8834",
            "use": "old",
            "period": {
              "end": "2014"
            }
          }
        ],
        "birthDate": "1974-12-25",
        "address": [
          {
            "use": "home",
            "type": "both",
            "text": "534 Erewhon St PeasantVille, Rainbow, Vic  3999",
            "line": [
              "534 Erewhon St"
            ],
            "city": "PleasantVille",
            "district": "Rainbow",
            "state": "Vic",
            "postalCode": "3999",
            "period": {
              "start": "1974-12-25"
            }
          }
        ],
        "contact": [
          {
            "relationship": [
              {
                "coding": [
                  {
                    "system": "http://hl7.org/fhir/v2/0131",
                    "code": "N"
                  }
                ]
              }
            ],
            "name": {
              "family": "du Marché",
              "_family": {
                "extension": [
                  {
                    "url": "http://hl7.org/fhir/StructureDefinition/humanname-own-prefix",
                    "valueString": "VV"
                  }
                ]
              },
              "given": [
                "Bénédicte"
              ]
            },
            "telecom": [
              {
                "system": "phone",
                "value": "+33 (237) 998327"
              }
            ],
            "address": {
              "use": "home",
              "type": "both",
              "line": [
                "534 Erewhon St"
              ],
              "city": "PleasantVille",
              "district": "Rainbow",
              "state": "Vic",
              "postalCode": "3999",
              "period": {
                "start": "1974-12-25"
              }
            },
            "gender": "female",
            "period": {
              "start": "2012"
            }
          }
        ]
      }
    }
  ]
}

...

Code Block
POST https://api-v5-stu3.hspconsortiumlogicahealth.org/stu3/open/Observation/$validate
--- REQUEST BODY ---
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "resource",
      "resource": {
        "resourceType": "Observation",
        "id": "some-day-smoker",
        "meta": {
          "profile": [
            "http://hl7.org/fhir/us/core/StructureDefinition/us-core-smokingstatus"
          ]
        },
        "status": "final",
        "category": [
          {
            "coding": [
              {
                "system": "http://hl7.org/fhir/observation-category",
                "code": "social-history",
                "display": "Social History"
              }
            ],
            "text": "Social History"
          }
        ],
        "subject": {
          "reference": "Patient/example",
          "display": "Amy Shaw"
        },
        "issued": "2016-03-18T05:27:04Z",
        "valueCodeableConcept": {
          "coding": [
            {
              "system": "http://snomed.info/sct",
              "code": "428041000124106",
              "display": "Current some day smoker"
            }
          ],
          "text": "Current some day smoker"
        }
      }
    }
  ]
}

...

In the response we can see a list of issues, most of the classified as information or warning.  The last two issues are error level and are a result of deleting the LOINC smoking-status code, these indicate that the resource instance does not actually conform to the indicated profile.

Validating Resource Without "Parameters" Resource

If a user wants to validate a resource without embedding in it as a parameter in a Parameters FHIR resource, that is also an option. Here's an example of a heart rate Observation example:

Code Block
languagejs
{
  "resourceType": "Observation",
  "id": "heart-rate",
  "meta": {
    "profile": [
      "http://hl7.org/fhir/StructureDefinition/heartrate"
    ]
  },
  "status": "final",
  "category": [
    {
      "coding": [
        {
          "system": "http://hl7.org/fhir/observation-category",
          "code": "vital-signs",
          "display": "Vital Signs"
        }
      ],
      "text": "Vital Signs"
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    ],
    "text": "Heart rate"
  },
  "subject": {
    "reference": "Patient/example"
  },
  "performer": {
  	"reference": "Practitioner/example"
  },
  "effectiveDateTime": "1999-07-02",
  "valueQuantity": {
    "value": 44,
    "unit": "beats/minute",
    "system": "http://unitsofmeasure.org",
    "code": "/minute"
  }
}

Limitations of

...

Logica Sandbox Validation

In the FHIR Validation spec, there is a mention of being able to pass a custom profile via the url (https://www.hl7.org/fhir/validation.html#op). The call would look something like this:

...

Although this approach would be convenient, HAPI, the FHIR server off of which the HSPC Logica servers are built, does not support this functionality. 

...

So for now, using the approaches described earlier (passing the profile url through the meta.profile parameter) are the only way to validate against custom profiles. We will update our documentation if/when either approach becomes available.

Conclusion

Validating instance data through a FHIR Terminology Service like the HSPC Logica Terminology Server is a great way of ensuring data quality and interoperability.  The example's we've shown have been for the us-core profiles, but should work equally well for any profiles built using the standard StructureDefinition resources and loaded into the terminology service.

...