FHIR R4 validation - how to call "validatecode" correctly

88 views
Skip to first unread message

Alec Alec

unread,
Nov 17, 2022, 7:49:49 AM11/17/22
to FHIR DOTNET
Hi all,

I need to validate FHIR  R4 resources (Json files). I'm using Hl7.Fhir.R4 package. Here is my validation method, zipSourcePath - path to speficification.zip:
...
        public OperationOutcome Validate(string zipSourcePath, string json)
        {
            var poco = (new FhirJsonParser()).Parse<Resource>(json);

            IResourceResolver profileSource = new CachedResolver(ZipSource.CreateValidationSource(zipSourcePath));
            ITerminologyService terminologySource = new LocalTerminologyService(profileSource as IAsyncResourceResolver);

            Hl7.Fhir.Validation.ValidationSettings settings = ValidationSettings.CreateDefault();
            settings.ResourceResolver = profileSource;
            settings.TerminologyService = terminologySource;

            Hl7.Fhir.Validation.Validator validator = new Validator(settings);
            OperationOutcome outcome = validator.Validate(poco);
            return outcome;
        }

This routine returns success for resources where I expect warnings (errors) as some public validators returns them. E.g. my resource is

{  
    "resourceType": "Bundle",
    "type": "searchset",
    "entry": [
        {
            "fullUrl": "Patient/1",
            "resource": {
                "resourceType": "Patient",
                "id": "1",

                "identifier": [
                    {
                        "use": "usual",
                        "type": {
                            "coding": [
                                {
                                    "system": "http://terminology.hl7.org/CodeSystem/v2-0203",
                                    "code": "MR-Test",
                                    "display": "Medical record number"
                                }
                            ]
                        },
                        "system": "http://intrahealth.com/customer/not_assigned/patient-filenum",
                        "value": "77"
                    }
                ],
                "name": [
                    {
                        "use": "official",
                        "text": "Smith, Jack",
                        "family": "Smith II",
                        "given": [
                            "Jack"
                        ]
                    }

                ],
               "gender": "male",
                "birthDate": "2001-01-01"
            }
        }
    ]
}


Validators https://inferno.healthit.gov/validator or https://validator.fhir.org return warnings (errors) on my Json:
Warning Line: 15
None of the codings provided are in the value set 'IdentifierType' (http://hl7.org/fhir/ValueSet/identifier-type), and a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = http://terminology.hl7.org/CodeSystem/v2-0203#MR-Test)
Error Line: 16
Unknown Code http://terminology.hl7.org/CodeSystem/v2-0203#MR-Test in http://terminology.hl7.org/CodeSystem/v2-0203 for 'http://terminology.hl7.org/CodeSystem/v2-0203#MR-Test'

I got a similar outcomes only in a test solution with the source code from firely-net-sdk-develop-r4. To get them I removed BindingStrength.Required requirement in the source code of firely-net-sdk-develop-r4\Hl7.Fhir.Specification library:
firely-net-sdk-develop-r4\src\Hl7.Fhir.Specification\Schema\Binding.cs
...
internal async Task<OperationOutcome> ValidateCode(ITypedElement source, Element bindable, ValidationContext vc)
...
            //EK 20170605 - disabled inclusion of warnings/errors for all but required bindings since this will
            // 1) create superfluous messages (both saying the code is not valid) coming from the validateResult + the outcome.AddIssue()
            // 2) add the validateResult as warnings for preferred bindings, which are confusing in the case where the slicing entry is
            //    validating the binding against the core and slices will refine it: if it does not generate warnings against the slice,
            //    it should not generate warnings against the slicing entry.
            //return Strength == BindingStrength.Required ? outcome : new OperationOutcome(); <-- commented out by me
            return outcome; //<-- added by me

And got something similar to public validators:
Overall result: FAILURE
[ERROR] Code 'MR-Test' from system 'http://terminology.hl7.org/CodeSystem/v2-0203' does not exist in valueset 'http://hl7.org/fhir/ValueSet/identifier-type' (at Bundle.entry[0].resource[0].identifier[0].type[0])

Note: mentioned "validateResult" in the comment does not exist in the r4 package except 2 modules in commented lines.

I could not understand how to set Strength explicitly. Anyway probably my validation code is wrong. Could someone help with my task.

Thank you,
Alec



Reply all
Reply to author
Forward
0 new messages