FHIR Chat · FHIR Json Schema Validation · implementers

Stream: implementers

Topic: FHIR Json Schema Validation


view this post on Zulip Richard Braman (Jul 02 2020 at 18:28):

I have validated some example FHIR resources with https://ajv.js.org and the HL7 FHIR JSON Schemas . It seems the validation could produce some better results. So far, in my testing, AJV never returned valid when I sent it an invalid FHIR resource, so that was good. It just seemed like the errors were cascading instead of the usual error, warning, info motif with a line number and a description unique for each error. It very well maybe a tool issue but I don't know I am just getting started with JSON Schema Validation with FHIR. The first tool I tried failed to function with our FHIR json schemas. Avj was better but not great, so wondering if anyone on the channel has some experiences with JSON schema they would like to share. I realize that JSON schema is in draft not IETF RFC yet so this is experimental.

view this post on Zulip nicola (RIO/SS) (Jul 02 2020 at 18:38):

You need discriminator extension for schema - https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

view this post on Zulip Richard Braman (Jul 02 2020 at 20:28):

How does OpenAPI apply to HL7's FHIR JSON schemas? Can you reference the schema from OpenAPI? Not sure why I need that. What I would lI would like to do is instance validation of FHIR resources using the Hl7 FHIR JSON schema on the command line. Does anyone know of. better tool than AJV?

view this post on Zulip Lloyd McKenzie (Jul 02 2020 at 20:41):

Note that JSON schema only gets you so far with validation - it won't test invariants or most vocabulary bindings and has a few other limitations - so you may want to look at the Java or .NET validators if validation is your primary objective.

view this post on Zulip Grahame Grieve (Jul 02 2020 at 21:20):

because openAPI deviates from the JSON schema spec, I think we're going to need 2 sets of JSON schema, one for JSON schema compliant tools and one for openAPI

view this post on Zulip Grahame Grieve (Jul 02 2020 at 21:21):

but JSON schema won't ever generate simple error messages because of how the Json Schema validation works, and I can't magically fix that. It's because of the way we use the resourceType property - a resource is always invalid against all the schemas all at once

view this post on Zulip Richard Braman (Jul 05 2020 at 02:27):

I had much better luck with the GO Json schema validator https://github.com/xeipuuv/gojsonschema. Its error messages were concise when validating a few real world resources from our server. I am looking for straight FHIR resource schema validation some other way than HAPI, preferably something standard and fast :). I tried to convert the Hl7 java validatdaion classes into a webservice last year but could never get it running. I think that would be a valuable tool for the community. Are there things we can ask the JSON Schema working group that would help us make our validator better?

@Lloyd McKenzie what do you mean by testing "invariants"? Also what other limitations?

@Grahame Grieve Does HL7 have open api 3 file for FHIR? IS that something you are working on?

view this post on Zulip Kevin Mayfield (Jul 05 2020 at 04:02):

Code im using for a service https://github.com/NHSDigital/fhir-validation-service
I'm looking at using this instead of schemas which we currently are using

view this post on Zulip Lloyd McKenzie (Jul 05 2020 at 13:44):

Invariants are all of the constraints asserted in the 'constraints' section for any resource. JSON schema also can't handle certain types of slicing or handle checking of declared profiles. I don't think it supports some of the extensions that constrain things like regular expressions or minimum length, though it could probably be extended to. @Grahame Grieve would know best. You can certainly choose to just use JSON schema validation if you wish, but be aware that just because you pass schema validation, that doesn't mean your instances will be valid. You can tune the FHIR Java validator to be faster - for example bypassing calls to an external terminology service. That might give you more complete validation with performance that is still acceptable.

view this post on Zulip Grahame Grieve (Jul 05 2020 at 20:31):

We don't generate an openAPI file for all of FHIR. We do generate one for any capability statement in an implementation guide - e.g. https://www.hl7.org/fhir/us/core/CapabilityStatement-us-core-server.html has https://www.hl7.org/fhir/us/core/us-core-server.openapi.json

view this post on Zulip Grahame Grieve (Jul 05 2020 at 20:32):

with regard to slicing, json schema can generally only handle slicing based on fixed values - that's only a portion of slicing.

view this post on Zulip Grahame Grieve (Jul 05 2020 at 20:32):

Lloyd covered the other high points though no doubt there's more.

view this post on Zulip Richard Braman (Jul 09 2020 at 12:45):

@Kevin Mayfield Is your service basically a stripped down version of HAPI that just supports $validate for every resource?

view this post on Zulip Richard Braman (Jul 09 2020 at 12:47):

@Grahame Grieve @Lloyd McKenzie @James Agnew has anyone benchmarked the HL7 FHIR Validation classes vs what HAPI provides in terms of speed?

view this post on Zulip Kevin Mayfield (Jul 09 2020 at 14:31):

Yes stripped down, no JPA and just supports one $validate operation

view this post on Zulip James Agnew (Jul 09 2020 at 15:14):

HAPI uses the exact same validator code that the Validator CLI does, so the performance should be comparable. HAPI uses its own built-in terminology services unlike the CLI so there are differences, but TBH I'm not sure how much difference that makes in terms of speed.

view this post on Zulip Grahame Grieve (Jul 09 2020 at 20:18):

could make quite a lot - the latency of the network is usually the biggest factor.

view this post on Zulip Grahame Grieve (Jul 09 2020 at 20:26):

of course the other factor is start up time; the validator has to load, and you can do this in advance if you're using HAPI

view this post on Zulip Lloyd McKenzie (Jul 09 2020 at 20:34):

Time is going to vary significantly by how many profiles need to get validated, how deeply those profiles set requirements. Validating documents and other Bundles can get relatively time intensive.

view this post on Zulip Grahame Grieve (Jul 09 2020 at 20:39):

to help, the next release of the validator will support a parameter -show-times that reports how long various things take

view this post on Zulip Grahame Grieve (Aug 11 2020 at 01:29):

We have several challenges with JSON schema, and growing interest in this. Should we create a stream specifically for json schema?


Last updated: Apr 12 2022 at 19:14 UTC