hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.05k stars 1.33k forks source link

STU3 Validation doesn't reject unknown codes even if binding is 'required' #824

Closed ghost closed 6 years ago

ghost commented 6 years ago

We have the following extension in our profile: https://simplifier.net/FinnishPHR/fiphr-medicationcontext

the valueCodeableConcept element is bound with the 'required' modifier.

We have this extension in our resource:

"extension": [
  {
   "url" : "http://phr.kanta.fi/StructureDefinition/fiphr-medicationcontext",
   "valueCodeableConcept" : {
    "coding": [
     {
      "system": "http://phr.kanta.fi/fiphr-cs-medicationcontext",
      "code": "13",
      "display": "Before medication"

     }
    ],
   "text": "mun teksti"
   }
  },
  {
       "url" : "http://phr.kanta.fi/StructureDefinition/fiphr-boolean",
          "valueBoolean" : "true"
  } 
]

The value "13" is not in the valuesystem that the extension is bound to: https://simplifier.net/FinnishPHR/fiphr-vs-medicationcontext

Nevertheless, the resource passes Hapi's validation. I presume part of the reason is the following code which doesn't take into account if the binding is required, extensible or something else. Though I cannot be sure if it is checked in some other part of the implementation. https://github.com/jamesagnew/hapi-fhir/blob/d375977410f98cd6de44ef64a902d9769a4c3d97/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/DefaultProfileValidationSupport.java#L254

Here's the complete profile used: https://simplifier.net/FinnishPHR/fiphr-pef-stu3

Here's the resource we are validating:

{
  "resourceType": "Observation",
    "meta": {
      "profile": [
        "http://phr.kanta.fi/StructureDefinition/fiphr-pef-stu3"
      ],
  "security": [
      {
        "system": "http://hl7.org/fhir/v3/Confidentiality",
        "code": "U",
        "display": "unrestricted"
      }]
  },
   "language": "fi",
"text":{
        "status":"generated",
        "div":"<div><div class=\"hapiHeaderText\"> Mittaustulos<b>Boldattuu </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>Patient/7cf4b0bd-cfb3-493b-a6ee-b290f1a2a72e</td></tr></tbody></table></div>"
    },  
"identifier": [
    {
      "system": "urn:ietf:rfc:3986",
      "value": "urn:uuid:187e0c12-8dd2-67e2-99b2-bf273a9549222"
    }
  ],
    "contained": [
        {
                        "resourceType":"Device",
            "id":"dev1",
   "meta": {
    "profile": [
     "http://phr.kanta.fi/StructureDefinition/fiphr-device"
    ]
   },
    "identifier": [
   {
     "system": "urn:ietf:rfc:3986",
     "value": "urn:uuid:187e0c12-8dd2-67e2-99b2-bf273a9549222"
   }
    ],
            "udi":{
                "deviceIdentifier":"Device123",
                "name":"Scalpel, single-use"
                    }
  },
  {
   "resourceType":"Organization",
   "id":"org1",
   "active":true,
   "name":"Saint Foo Hospital"
  },  
],
  "status": "final",
  "category": [{
    "coding": [
      {
        "system": "http://hl7.org/fhir/observation-category",
        "code": "vital-signs",
        "display": "Vital Signs"
      }
    ]
  }],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "19935-6",
        "display": "Maximum expiratory gas flow Respiratory system airway by Peak flow meter"
      }
    ]
  },
  "subject": {
    "reference": "Patient/7cf4b0bd-cfb3-493b-a6ee-b290f1a2a72e"
  },
  "effectiveDateTime": "2017-11-22",
  "issued": "2017-11-22T16:52:00.943+03:00",
  "performer": [{
    "reference": "Patient/7cf4b0bd-cfb3-493b-a6ee-b290f1a2a72e"
  }],
  "valueQuantity": {
    "value": 134,
    "unit": "L/min",
    "system": "http://unitsofmeasure.org",
    "code": "L/min"
  },
  "interpretation": {
    "coding": [
      {
        "system": "http://hl7.org/fhir/v2/0078",
        "code": "<",
        "display": "Off scale low"
      }
    ]
  },
  "comment": "tässä on kommentteja",
  "method": {
    "coding": [
      {
"system": "http://phr.kanta.fi/fiphr-cs-observationmethod",
     "code": "1",
     "display": "maxima"
      }
    ],
    "text": "tässä tässä mehhod"
  },
  "device": {
    "reference": "#dev1"
  },
  "referenceRange": [{
    "low": [
      {
        "value": 10,
        "unit": "L/min",
        "system": "http://hl7.org/fhir/v2/0078",
        "code": "LU"
      }
    ],
    "high": [
      {
        "value": 16,
        "unit": "L/min",
        "system": "http://hl7.org/fhir/v2/0078",
        "code": "LU"
      }
    ],
    "appliesTo": [{
      "coding": [
        {
          "system": "http://hl7.org/fhir/referencerange-meaning",
          "code": "normal",
          "display": "Normal Range"
        }
      ],
      "text": "T�ss� teksti�"
    }],
    "age": {
      "low": [
        {
          "value": 1,
          "unit": "years",
          "system": "http://unitsofmeasure.org",
          "code": "21612-7"

        }
      ],
      "high": [
        {
          "value": 1,
          "unit": "years",
          "system": "http://unitsofmeasure.org",
          "code": "21612-7"
        }
      ]
    },
    "text": "Sopiva ikä"
  }],
"extension": [
  {
   "url" : "http://phr.kanta.fi/StructureDefinition/fiphr-medicationcontext",
   "valueCodeableConcept" : {
    "coding": [
     {
      "system": "http://phr.kanta.fi/fiphr-cs-medicationcontext",
      "code": "13",
      "display": "Before medication"

     }
    ],
   "text": "mun teksti"
   }
  },
  {
       "url" : "http://phr.kanta.fi/StructureDefinition/fiphr-boolean",
          "valueBoolean" : "true"
  } 
]
}
jamesagnew commented 6 years ago

We have just switched to using the R4 validator (with its many fixes) for validating DSTU3 resources, and I have confirmed that this now works as expected. See test in above commit.

ghost commented 6 years ago

Can we switch to R4 validator without changing our profiles and app to support R4?

jamesagnew commented 6 years ago

You don't need to change anything, HAPI will automatically use the R4 validator to validate your DSTU3 resources as of 3.3.0. It up-converts any StructureDefinitions, ValueSets, and CodeSystems it needs to fetch in order to do the validation.

ghost commented 6 years ago

@jamesagnew Just to be clear:

If we use the R4 validator do the FHIR resources stored to our server need to conform to R4 or can they still be STU3? You mention up-converting profile resources but we are currently STU3 compliant.

I see that I have to refer to the R4 versions of the structures and the validator doesn't like the STU3 FhirContext.