hapifhir / org.hl7.fhir.core

Apache License 2.0
155 stars 157 forks source link

Validator: Profile version is ignored #1106

Closed karzideh closed 1 year ago

karzideh commented 1 year ago

When appending a version to meta.profile element as specified here, the validator ignores the appended version and validates against the profile that is available. It would be helpful if the validator also checks the appended version and validates against the specified version and if no version is found, throws an error.

Example-resource:

{
    "id": "12345",
    "meta": {
        "profile": [
            "https://www.medizininformatik-initiative.de/fhir/core/modul-fall/StructureDefinition/KontaktGesundheitseinrichtung|1.0.4"
        ]
    },
    "type": [
        {
            "coding": [
                {
                    "code": "abteilungskontakt",
                    "system": "https://www.medizininformatik-initiative.de/fhir/core/modul-fall/CodeSystem/Kontaktebene",
                    "display": "Abteilungskontakt"
                }
            ]
        },
        {
            "coding": [
                {
                    "code": "abteilungskontakt",
                    "system": "http://fhir.de/CodeSystem/Kontaktebene",
                    "display": "Abteilungskontakt"
                }
            ]
        }
    ],
    "class": {
        "code": "AMB",
        "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
        "display": "ambulatory"
    },
    "partOf": {
        "reference": "Encounter/1234"
    },
    "period": {
        "end": "2016-05-02T23:59:00.000+02:00",
        "start": "2017-09-11T07:04:00.000+02:00"
    },
    "status": "finished",
    "subject": {
        "reference": "Patient/1234"
    },
    "location": [
        {
            "location": {
                "reference": "Location/1234"
            },
            "physicalType": {
                "coding": [
                    {
                        "code": "wa",
                        "system": "http://terminology.hl7.org/CodeSystem/location-physical-type",
                        "display": "Ward"
                    }
                ]
            }
        }
    ],
    "identifier": [
        {
            "type": {
                "coding": [
                    {
                        "code": "VN",
                        "system": "http://terminology.hl7.org/CodeSystem/v2-0203",
                        "display": "Visit number"
                    }
                ]
            },
            "value": "12345",
            "system": "https://testurl.org"
        }
    ],
    "participant": [
        {
            "type": [
                {
                    "coding": [
                        {
                            "code": "ADM",
                            "system": "http://terminology.hl7.org/CodeSystem/v3-ParticipationType",
                            "display": "admitter"
                        }
                    ]
                }
            ],
            "individual": {
                "reference": "Practitioner/12345"
            }
        }
    ],
    "resourceType": "Encounter",
    "serviceProvider": {
        "reference": "Organization/12345"
    }
} 
karzideh commented 1 year ago

I used validator version 5.6.97 and validated with the command java -jar validator_cli.jar -version 4.0.1 -ig validation-profile_folder example.json

karzideh commented 1 year ago

I also tried validating the resource programmatically with the lines:

validationOptions = new ValidationOptions().addProfile("https://www.medizininformatik-initiative.de/fhir/core/modul-fall/StructureDefinition/KontaktGesundheitseinrichtung|1.0.4")
validator.validateWithResult(resource, validationOptions)

This is the result:


INFO  c.u.f.c.s.DefaultProfileValidationSupport - Loading structure definitions from classpath: /org/hl7/fhir/r4/model/profile/profiles-types.xml
INFO  c.u.f.c.s.DefaultProfileValidationSupport - Loading structure definitions from classpath: /org/hl7/fhir/r4/model/profile/profiles-others.xml
INFO  c.u.f.c.s.DefaultProfileValidationSupport - Loading structure definitions from classpath: /org/hl7/fhir/r4/model/extension/extension-definitions.xml
INFO  c.u.f.c.s.DefaultProfileValidationSupport - Loading CodeSystem/ValueSet from classpath: /org/hl7/fhir/r4/model/valueset/valuesets.xml
INFO  c.u.f.c.s.DefaultProfileValidationSupport - Loading CodeSystem/ValueSet from classpath: /org/hl7/fhir/r4/model/valueset/v2-tables.xml
INFO  c.u.f.c.s.DefaultProfileValidationSupport - Loading CodeSystem/ValueSet from classpath: /org/hl7/fhir/r4/model/valueset/v3-codesystems.xml
WARN  d.s.a.e.s.f.v.HapiResourceValidation$ - Validation warning: SingleValidationMessage[col=722,row=1,locationString=Encounter.identifier[0].type,message=None of the specified codes are in the valueset 'IdentifierType' (http://hl7.org/fhir/ValueSet/identifier-type), and a code should come from this valueset unless it does not contain an appropriate code) (Codes = http://terminology.hl7.org/CodeSystem/v2-0203#VN),severity=warning] (resource Encounter/12345)
INFO  d.s.a.e.s.f.v.HapiResourceValidation$ - Validation information: SingleValidationMessage[col=2208,row=1,locationString=Encounter.hospitalization.dischargeDisposition.extension[0],message=Unknown extension http://fhir.de/StructureDefinition/Entlassungsgrund,severity=information] (resource Encounter/12345)
WARN  d.s.a.e.s.f.v.HapiResourceValidation$ - Validation warning: SingleValidationMessage[col=2,row=1,locationString=Encounter.meta.profile[0],message=Profile Reference "https://www.medizininformatik-initiative.de/fhir/core/modul-fall/StructureDefinition/KontaktGesundheitseinrichtung|1.0.1" could not be resolved, so was not checked,severity=warning] (resource Encounter/12345)```
karzideh commented 1 year ago

Problem does not have to do with the hapi validator but with the profiles used for validation. The profile versions in the resources were not the same as in the StructureDefinitions that are used for validation. Thus the resources could not be validated against the profile. When the versions correspond, the validator seems to correctly validate against the profile. Issue was therefore closed.