Unable to set validation severity on patient resource STU3

I want to allow a Patient with no Gender, but write a warning to the log.
For this, I define a StructureDefinition with a snapshot of a “Patient.Gender” element, with a constraint with severity “warning”.

This does not work, as my validator still returns an error message with severity: “error”.

On the other hand if I try to put a “fatal” constraint - ALL my errors disappear, and my resource is suddenly valid, with no errors/log.

Using FHIR Release 3 (STU)

Here is my structure:

      {
    "id": "Patient.gender",
    "path": "Patient.gender",
    "short": "male | female | other | unknown",
    "definition": "Administrative Gender.",
    "comment": "The gender may not match the biological sex as determined by genetics...",
    "requirements": "Needed for identification of the individual, in combination with (at least) name and birth date...",
    "min": 0,
    "max": "1",
    "constraint": [
      {
        "key": "gen-1",
        "severity": "warning",
        "human": "Something something"
      }
    ],
    "type": [
      {
        "code": "code"
      }
    ],
    "isSummary": true,
    "binding": {
      "extension": [
        {
          "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName",
          "valueString": "AdministrativeGender"
        },
        {
          "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding",
          "valueBoolean": true
        }
      ],
      "strength": "required",
      "description": "The gender of a person used for administrative purposes.",
      "valueSetReference": {
        "reference": "http://hl7.org/fhir/ValueSet/administrative-gender"
      }
    },
    "mapping": [
      {
        "identity": "v2",
        "map": "PID-8"
      },
      {
        "identity": "rim",
        "map": "player[classCode=PSN|ANM and determinerCode=INSTANCE]/administrativeGender"
      },
      {
        "identity": "cda",
        "map": ".patient.administrativeGenderCode"
      }
    ]
  },

And my validator:
// Use DefaultProfileValidationSupport since derived profiles generally
// rely on built-in profiles also being available
DefaultProfileValidationSupport defaultSupport = new DefaultProfileValidationSupport();

    // Create a chain that includes both the pre-populated and default. We put
    // the pre-populated (custom) support module first so that it takes precedence
    FhirInstanceValidator instanceValidator = new FhirInstanceValidator();
    ValidationSupportChain support = new ValidationSupportChain(
            new VCValidationSupport(fhirContext), defaultSupport);

    instanceValidator.setValidationSupport(support);
    instanceValidator.setNoTerminologyChecks(true);
    validator.registerValidatorModule(instanceValidator);

What am I missing here?

1 Like

Is this the DotNet validator?

No, not dot net. The Java validator. Although it is probably similar

Does your constraint need a FHIRPath element to run?

Thank you for your response.

I’m not entirely sure…
What I need is to define a constraint for a specific element in a certain resource.
Is it not enough to add the constraint to the structure definition inside my resource?

The constraint needs to use expression to state the test.Try something like

"constraint": [
      {
        "key": "gen-1",
        "severity": "warning",
        "human": "Something something"
        "expression": "$this.exists()"
      }
    ],
1 Like

Thank you… is there a place where I can see more examples of constraints with different expressions?

There are a lot of constraint examples in the core specification itself - just search the XML or JSON structure definitions for “expression”

For example http://hl7.org/fhir/R4/patient.profile.xml.html

1 Like

It doesn’t seem to work.
I even tried with a new element that I called “Patient.level”. There is no such key/field in the json, but the validation is successfull.

    {
        "id": "Patient.level",
        "path": "Patient.level",
        "short": "easy | hard | expert | hardcore",
        "definition": "patient level",
        "comment": "comment",
        "requirements": "Needed for testing",
        "constraint": [
          {
            "key": "lev-1",
            "severity": "error",
            "human": "bla bla bla",
            "expression": "$this.exists()"
          }
        ],
        "condition": [
          "lev-1"
        ],
        "type": [
          {
            "code": "code"
          }
        ],
        "isSummary": true,
        "binding": {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName",
              "valueString": "AdministrativeGender"
            },
            {
              "url": "http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding",
              "valueBoolean": true
            }
          ],
          "strength": "required",
          "description": "The level of a person used for administrative purposes."
        }
      }

This code is in the StructureDefinition in Snapshot section.

What am I missing here?

Try something like the following on the parent of Patient.gender

"id": "Patient",
"path": "Patient",

"constraint": [
  {
    "key": "pat-gen-1",
    "severity": "warning",
    "human": "Gender not recorded.",
    "expression": "gender.exists()"
  }
],

1 Like

Sometimes constraints need to be on the parent of the element.

1 Like

Thank you! this is exactly what we needed!

1 Like