FHIR Chat · Failing validation of DocRef.status in HAPI 4.2 · hapi

Stream: hapi

Topic: Failing validation of DocRef.status in HAPI 4.2


view this post on Zulip Morten Ernebjerg (Nov 13 2020 at 15:02):

Hi :wave: I'm moving some validation code from HAPI 4.2 to 5.1. Now when I try to validate an STU3 DocumentReference, I always get the error

The value provided ('current') is not in the value set http://hl7.org/fhir/ValueSet/document-reference-status (http://hl7.org/fhir/ValueSet/document-reference-status), and a code is required from this value set) (error message = Validation failed)

even thought I set the status in the resource using the matching enum ( Enumerations.DocumentReferenceStatus). I have added both DefaultProfileValidationSupport and CommonCodeSystemsTerminologyService to my validation chain (see code below). Debugging in, I see that in org.hl7.fhir.common.hapi.validation.support#validateCodeInValueSet, none of the validation supports return true for isValueSetSupported, hence null is returned. This null, in turn, is converted to an error in org.hl7.fhir.common.hapi.validation.validator#convertValidationResult.

Any idea why this is happening? Here is the (effective) code reproducing what I am doing (in Kotlin, hence no new operators for creation etc. - hope it is still Java-readable :smile: ):

 val fhirContext = FhirContext.forDstu3()
 val defaultValidationSupport = DefaultProfileValidationSupport(fhirContext)
 val commonCodeSystemValidationSupport = CommonCodeSystemsTerminologyService(fhirContext)
 val validationSupportChain = ValidationSupportChain(defaultValidationSupport, commonCodeSystemValidationSupport)
 // Create a HAPI FhirInstanceValidator and register it to a validator
 val instanceValidatorMod = FhirInstanceValidator(validationSupportChain)
 validator = HapiContext.stu3Context.newValidator()
 val valResult = validator.validateWithResult(resource) // resporce has status set to Enumerations.DocumentReferenceStatus.CURRENT

view this post on Zulip Morten Ernebjerg (Nov 16 2020 at 14:29):

For reference, this is how I construct the STU3 DocumentReference that triggers the above error (again in Kotlin, so no new and direct property assignment instead of getters and setters):

val resource = DocumentReference()
resource.status = Enumerations.DocumentReferenceStatus.CURRENT
val coding = Coding()
coding.system = "http://loinc.org"
coding.code = "789-8"
resource.type = CodeableConcept(coding)
resource.indexed = Date()

view this post on Zulip Morten Ernebjerg (Nov 26 2020 at 08:46):

(additions to my last msg: I forgot to add this but I also set the content element so the resource is overall valid)

I'm seeing the same for R4. Debugging, I see the same problem: none of the validation supports know http://hl7.org/fhir/ValueSet/document-reference-status (isValueSetSupported() returns false for all supports I added). That, in turn, is interpreted by the validation engine as an invalid code error because it is a required code binding.

This looks like a bug to me - I would have expected the DefaultProfileValidationSupport to be able to validate this as it says that it supports "FHIR built-in vocabulary (ValueSet and CodeSystem resources)."

view this post on Zulip Patrick Werner (Nov 26 2020 at 10:02):

Hi @Morten Ernebjerg , i think you missed to add the InMemoryTerminologyServerValidationSupport to the ValidationChain?

view this post on Zulip Morten Ernebjerg (Nov 26 2020 at 10:17):

@Patrick Werner Yes, that was it! - thank you, saved my day :tada: I think I was throw off by the statement in the documentation about DefaultProfileValidationSupport supporting "FHIR built-in vocabulary (ValueSet and CodeSystem resources)."

view this post on Zulip Patrick Werner (Nov 26 2020 at 10:33):

Yeah, this module contains them, applying them is done by the InMemoryTermSupport


Last updated: Apr 12 2022 at 19:14 UTC