Trouble with constraint obs-7 in HAPI FHIR validation

Hello,

I’m not sure why I’m getting this error:

SingleValidationMessage[
    col=-1,
    row=-1,
    locationString=Observation,
    message=[error] in /*:Observation[namespace-uri()='http://hl7.org/fhir'][1] @ Observation obs-7: If code is the same as a component code then the value element associated with the code SHALL NOT be present Test=not(exists(f:*[starts-with(local-name(.), 'value')])) or not(count(for $coding in f:code/f:coding return parent::*/f:component/f:code/f:coding[f:code/@value=$coding/f:code/@value and 
f:system/@value=$coding/f:system/@value])=0),
    severity=error
]

for a JSON such as this:

{
  "identifier": {
    "system": "urn:oid:1.2.3.4",
    "value": "1234"
  },
  "entry": [
    {
      "resource": {
        "valueCodeableConcept": {
          "coding": [
            {
              "system": "urn:oid:2.16.840.1",
              "code": "258219007",
              "display": "Stage 2 (qualifier value)"
            }
          ]
        },
        "identifier": [
          {
            "system": "urn:oid:1.2.3.4",
            "type": {
              "coding": [
                {
                  "system": "http://example.com",
                  "code": "Document"
                }
              ]
            },
            "value": "1234"
          }
        ],
        "code": {
          "coding": [
            {
              "code": "397137005",
              "system": "urn:oid:2.16.840.1",
              "display": "Mammography assessment finding (finding)"
            }
          ]
        },
        "effectiveDateTime": "2020-07-07T14:53:05-04:00",
        "subject": {
          "reference": "Patient/pt1"
        },
        "context": {
          "reference": "Encounter/en1"
        },
        "id": "ob1",
        "category": [
          {
            "coding": [
              {
                "code": "imaging",
                "system": "http://hl7.org/fhir/observation-category",
                "display": "Imaging"
              }
            ]
          }
        ],
        "resourceType": "Observation",
        "status": "final"
      },
      "fullUrl": "ob1"
    }
  ],
  "meta": {
    "versionId": "v78979"
  },
  "id": "bu1",
  "type": "collection",
  "resourceType": "Bundle"
}

I’m using HAPI version 4.2.0 and FHIR STU3.

These are the FHIR specifications given for this error:

obs-7 : If code is the same as a component code then the value element associated with the code SHALL NOT be present (expression: value.empty() or component.code.where( (coding.code = %resource.code.coding.code) and (coding.system = %resource.code.coding.system)).empty())

If I understand that correctly, this should only ever be relevant if there is a component element in an Observation resource. Since my bundle only contains one Observation resource, I assume that the error refers to that resource, even though the error message from the ValidationResult object seems to locate the error at column -1 and row -1. However, my Observation resource does not have a component element, so I don’t see why the presence of the valueCodeableConcept should be a problem according the constraint.

Am I missing something? Is there possibly a bug in the validation code?

Thank you!

1 Like

Looks like there’s a bug in the schematron in the spec. I think the correct schematron should be:
not(exists(f:*[starts-with(local-name(.), 'value')])) or count(for $coding in f:code/f:coding return parent::f:code/parent::f:Observation/f:component/f:code/f:coding[f:code/@value=$coding/f:code/@value and f:system/@value=$coding/f:system/@value])=0

Can you please submit a change request?

Of course!

How/where do I submit a change request to HAPI FHIR?

The change request would actually be to the FHIR specification itself. There’s a “propose a change” link at the bottom of each page in the FHIR spec. Click on that. You’ll need to do a 1-time registration, after which you can freely request changes if/when you find issues.

The fhirpath shown in the FHIR spec is accurate though:

value.empty()
or
component.code.where(
    (coding.code = %resource.code.coding.code)
    and
    (coding.system = %resource.code.coding.system)
).empty()

It is the coded schematron in HAPI that is the issue…

Should I still propose the change via the link on the FHIR website?

Yes. The schematron is defined in the core spec- it’s just not as visible.