[FHIR - Profile] - Validate Content of an Element with Profile

Dear all,

I need to perform a validation through a PROFILE in FHIR and I would like some help on how to create this validation in the profile.

The validation we need is to know the content of an element informing in the payload is what is expected for our business.

Example:

Resource: Patient
Method: POST
Payload:

{
“identifier”: [
{
“system”: “validate-company”,
“value”: “00000000000000001”
}
],
“name”: [
{
“text”: “Example Patient - 00000000000000001”
}
]“meta”: {
“source”: “test-constraint”
},
“resourceType”: “Patient”
}

Expected Validation: I need to validate if the value sent in “Identifier.system” really is “validate-company”.

Can anyone help with an example?

Thanks.

You can do it in two ways:

  1. Use slicing for identifier (more complicated approach)
  2. Use FHIRPath expression in Structure Definition
 identifier.system = 'validate-company'

Thanks for the feedback.

I will run the tests.

Thanks.

Hi @Andrew_Krylov,

Using your second suggestion, should I create a constraint for the “identifier.system” element?

It would be like the example below:

{
“id”: “Patient.identifier.system”,
“path”: “Patient.identifier.system”,
“min”: 1,
“max”: “1”,
“base”: {
“path”: “Identifier.system”,
“min”: 0,
“max”: “1”
},
“type”: [
{
“code”: “uri”
}
],
“constraint”: [
{
“key”: “ele-11”,
“severity”: “error”,
“expression”: “Patient.identifier.system = ‘validate-company’”,
“source”: “http://hl7.org/fhir/StructureDefinition/Element
}
],
“mustSupport”: true,
“isModifier”: false,
“isSummary”: true
}

That would force all identifiers to have that system, which I don’t think is what you want. Also, the invariant is defined within system itself, which is the wrong scope
I suspect what you want is a constraint defined on the root Patient element that says
identifier.where(system = ‘validate-company’).exists()

Also, your key shouldn’t use a prefix already used in the inheritance tree for the resource as it may eventually collide with a core invariant. Make your key something like “rule-1” or based on your profile name.

1 Like

Thanks @lloyd,

Can you guide me what could be wrong? Not validating…

Below is the Profile and the test performed:

Profile:

{
“resourceType”: “StructureDefinition”,
“id”: “patientidentifiersystem”,
“identifier”: [
{
“system”: “patientIdentifierSystem”,
“value”: “patientIdentifierSystem”
}
],
“url”: “http://empresa.br/fhir/us/core/StructureDefinition/patientIdentifierSystem”,
“version”: “0.0.1”,
“name”: “USCorePatientIdentifierSystemProfile”,
“title”: “US Core Patient Identifier System Profile”,
“status”: “draft”,
“experimental”: true,
“date”: “2022-07-26T15:00:00-03:00”,
“publisher”: “HL7 International - Cross-Group Projects”,
“description”: “Profile para realizar a validação do conteúdo que esta sendo enviado no payload de entrada.”,
“jurisdiction”: [
{
“coding”: [
{
“system”: “urn:iso:std:iso:3166”,
“code”: “US”
}
]
}
],
“fhirVersion”: “4.0.1”,
“kind”: “resource”,
“abstract”: false,
“type”: “Patient”,
“baseDefinition”: “http://hl7.org/fhir/StructureDefinition/Patient”,
“derivation”: “constraint”,
“snapshot”: {
“element”: [
{
“id”: “Patient.identifier.system”,
“path”: “Patient.identifier.system”,
“min”: 1,
“max”: “1”,
“base”: {
“path”: “Identifier.system”,
“min”: 0,
“max”: “1”
},
“type”: [
{
“code”: “uri”
}
],
“constraint”: [
{
“key”: “regra-idenfier-system”,
“severity”: “error”,
“human”: “Validate that the ‘identifier.system’ element has ‘validate-company’ content”,
“expression”: “identifier.where(system = ‘validate-company’).exists()”,
“source”: “http://hl7.org/fhir/StructureDefinition/Element
}
],
“definition”: “Establishes the namespace for the value - that is, a URL that describes a set values that are unique.”,
“mustSupport”: true,
“isModifier”: false,
“isSummary”: true
}
]
}
}

Validation Request:

curl --location --request POST ‘https://hostname.br/v1/projects/{{PROJECT_ID}}/locations/us-central1/datasets/{{DATA_SET}}/fhirStores/{{FHIR_STORE}}/fhir/Patient/$validate?profile=http://empresa.br/fhir/us/core/StructureDefinition/patientIdentifierSystem’
–header ‘Authorization: Bearer key’
–header ‘Content-Type: application/json’
–header ‘charset: utf-8’
–data-raw ‘{
“identifier”: [
{
“system”: “notFound”,
“value”: “00000000000000001”
}
],
“name”: [
{
“use”: “temp”,
“text”: “Patient com 00000000000000001”
}
],
“gender”: “male”,
“meta”: {
“source”: “teste-restricao”
},
“resourceType”: “Patient”
}’

Result:

{

"issue": [

    {

        "code": "informational",

        "details": {

            "text": "success"

        },

        "diagnostics": "success",

        "severity": "information"

    }

],

"resourceType": "OperationOutcome"

}

Thanks.

You’ve put the constraint on “id”: “Patient.identifier.system”
You need to put it on “id”: “Patient”

The FHIRPath is evaluated relative to the path of the element it’s declared on.

Here example of structure definition with this validation . It can help :). Pay attention to constraint ‘rule-1’
I couldn’t past it in the text - it’s too long. I uploaded the example on fileshare-exchange.

1 Like

Sorry!

@Andrew_Krylov and @lloyd,

I made the adjustments as you guided me, but still no success…

I’m providing the JSON of my StructureDefinition, can you see if I’m doing something wrong?

The rule is “rule-1”, I put the constraint in the 3 levels of “ID”, being: “Patient”, “Patient.identifier” and “Patient.identifier.system”.

Thanks in advance for help.

You posted a copy of the core Patient resource StructureDefinition. It doesn’t have your constraint in it…

You can’t use the same ‘key’ for multiple rules. The only one you need is the one with the scope of Patient. Remove the others and try.

@lloyd and @Andrew_Krylov,

I removed, I left the rule only in the ID “Patient”, but without success the validation.

Is the expression correct “identifier.where(system=‘validate-company’).exists()” ?

Here is the StructureDefinition JSON:

Thanks.

Can you share your instance? (One thing is that ‘validate-company’ as a string isn’t actually a valid system - systems have to be a valid URI.)

@lloyd ,

Really the type is URI, so I can’t validate?

Here’s the link on “Hapi.fhir”:

http://hapi.fhir.org/baseR4/StructureDefinition/6857024

Test Validation:

curl --location --request POST ‘http://hapi.fhir.org/baseR4/Patient/$validate?profile=http://empresa.br/fhir/us/core/StructureDefinition/patientIdentifierSystem
–header ‘Authorization: Bearer KEY’
–header ‘Content-Type: application/json’
–header ‘charset: utf-8’
–data-raw ‘{
“identifier”: [
{
“value”: “00000000000000001”
}
],
“name”: [
{
“use”: “temp”,
“text”: “Patient com 00000000000000001”
}
],
“gender”: “male”,
“meta”: {
“source”: “teste-restricao”
},
“resourceType”: “Patient”
}’

Hi! ## Rodrigo What is your time-zone? You share just a part of Structure Definition. Could you share the resource and full SD. Thank’s.