Hi everyone,
I'm experiencing an issue with the FhirValidator where it appears to be applying constraints from the wrong FHIR version.
I'm creating a validator in the following way (scala):
import ca.uhn.fhir.context.FhirContext
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport
import ca.uhn.fhir.validation.FhirValidator
import org.hl7.fhir.common.hapi.validation.support.*
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator
val fhirContext = FhirContext.forDstu3()
val validator = fhirContext.newValidator()
val instanceValidator =
val prePopulatedValidationSupport: PrePopulatedValidationSupport = new PrePopulatedValidationSupport(context)
val validationSupportChain = new ValidationSupportChain(
new DefaultProfileValidationSupport(fhirContext),
prePopulatedValidationSupport,
new CommonCodeSystemsTerminologyService(fhirContext),
new InMemoryTerminologyServerValidationSupport(fhirContext),
)
new FhirInstanceValidator(validationSupportChain)
validator.registerValidatorModule(instanceValidator)
And these are the hapi dependencies in our project:
val HapiFhirBase = "ca.uhn.hapi.fhir" % "hapi-fhir-base" % "8.4.0"
val HapiFhirClient = "ca.uhn.hapi.fhir" % "hapi-fhir-client" % HapiFhirBase.revision
val HapiFhirStructuresDstu3 = "ca.uhn.hapi.fhir" % "hapi-fhir-structures-dstu3" % HapiFhirBase.revision
val HapiFhirStructuresR4 = "ca.uhn.hapi.fhir" % "hapi-fhir-structures-r4" % HapiFhirBase.revision
val HapiFhirCachingCaffeine = "ca.uhn.hapi.fhir" % "hapi-fhir-caching-caffeine" % HapiFhirBase.revision
val HapiFhirValidation = "ca.uhn.hapi.fhir" % "hapi-fhir-validation" % HapiFhirBase.revision
val HapiFhirValidationDstu3 = "ca.uhn.hapi.fhir" % "hapi-fhir-validation-resources-dstu3" % HapiFhirBase.revision
However, when validating the following Bundle resource:
{
"resourceType": "Bundle",
"type": "document",
"identifier" : {
"system" : "urn:ietf:rfc:3986",
"value" : "urn:uuid:0c3151bd-1cbf-4d64-b04d-cd9187a4c6e0"
},
"entry": [
{
"fullUrl": "urn:uuid:00000000-0000-0000-0000-000000000001",
"resource": {
"resourceType": "Composition",
"status": "final",
"type": {
"coding": [{"display": "Document Type"}]
},
"subject": {
"reference": "urn:uuid:00000000-0000-0000-0000-000000000002"
},
"date": "2020-01-01T00:00:00+00:00",
"author": [
{
"reference": "urn:uuid:00000000-0000-0000-0000-000000000003"
}
],
"title": "Example Document"
}
},
{
"fullUrl": "urn:uuid:00000000-0000-0000-0000-000000000002",
"resource": {
"resourceType": "Patient",
"name": [{"text": "Patient Name"}]
}
},
{
"fullUrl": "urn:uuid:00000000-0000-0000-0000-000000000003",
"resource": {
"resourceType": "Practitioner",
"name": [{"text": "Practitioner Name"}]
}
}
]
}
the validator complains that the Bundle is missing a timestamp field, more specifically it says “ERROR: A document must have a date (Bundle.timestamp)”. This is a requirement for FHIR R5, not DSTU3.
In DSTU3, the timestamp field doesn’t exist for Bundles, but the validator seems to be enforcing R5 constraints despite the context being explicitly set to DSTU3.
Are there additional configuration steps needed to ensure the validator strictly uses DSTU3 validation rules? Or is this maybe a bug in the validatior?
I'm using HAPI FHIR version 8.4.0.
Attached is the console output including some debug/trace level logs.
Any help would be greatly appreciated.