Stream: implementers
Topic: FHIR JSON Schema Validation?
John Silva (Jul 25 2017 at 13:51):
I'm looking for others with experience using the FHIR JSON Schema for validating FHIR JSON instances. Here's what I've found out so far:
I found the FHIR JSON Shema ZIP file and was trying to use that with Newtonsoft’s JSchema validation library. When I tried this, once I realized I needed to use their JSchemaUrlResolver API, I was able to validate a Patient resource against the HL7.org Patient.schema.json schema. However, I tried to modify a “good Patient” JSON resource (file) to try to make the validation fail, but couldn’t! I’m not convinced that the JSchema tool is really importing (or referencing) all the leaf-level JSON schemas referenced by the Patient.schema.json file.
Have any of you had any experience with this? Any guidance you can give?
BTW, there is an online JSchema tool that uses the Newtonsoft library, you can use that to test for pass/fail FHIR resources. I tried this online with the FHIR Patient resource (had to remove the first $ref line though -- "$ref": "#/definitions/Patient") and I could not get it to fail on a ‘bad’ Patient JSON file. Here’s the link to this: http://www.jsonschemavalidator.net/ I tried renaming the identifier tag and other tags but couldn’t get it to fail the JSchema validator.
Grahame Grieve (Jul 25 2017 at 21:08):
I'm going to respond to this on the mailling list. btw, see http://wiki.hl7.org/index.php?title=FHIR_Rules_for_asking_questions
John Silva (Jul 26 2017 at 13:54):
Thanks Grahame! (Didn't realize FHIR had so many places for discussions; I'm used to the older HL7 listserv-only model, sorry to dup my question in multiple places; I didn't know where FHIR-folks 'hang out').
Lloyd McKenzie (Jul 26 2017 at 14:14):
More people hang out here I think, although there are slightly different communities in each place. General rule is pick a place and wait a few days. If there's no response, try somewhere else.
John Silva (Jul 27 2017 at 15:32):
Today I tried using the full fhir.schema.json file with JScema so that the JSON schema is all self-contained; using this method I was able to load the full FHIR JSON schema without any errors. I was then able to validated a Patient JSON instance and it passed as expected. However, I modified some of the tags on the Patient JSON instance, e.g. changed "identifier" to "identifierZ" which I would have expected to cause the validation to fail but it still passed validation! At this point I'm not sure if it is because the FHIR.schema.json is "so wide open" (for extensions) that virtually anything (that is legal JSON) would validate against it. If you want to try this out use Newtonsoft's online JSON schema validator and cut-and-paste the full fhir.schema.json file into the schema window on the left, and something NOT FHIR on the right --- and it will still pass! I used this nonsense JSON and it did validate:
{
"gobbly-goop": {
"street_address": "1st Street SE",
"city": "Washington",
"state": "DC",
"type": "business"
}
}
Grahame Grieve (Jul 27 2017 at 20:37):
it shouldn't be because of extensions - any extension has the name extension, a url, and some kind of value. From a schema perspective, there's no extensibility there.
John Silva (Jul 28 2017 at 14:18):
Grahame, were you able to try the fhir.schema.json and the sample (nonsense) JSON above on the http://www.jsonschemavalidator.net/ page? I don't understand how the "nonsense JSON" above could validate against the fhir.schema.json schema though?
Grahame Grieve (Jul 28 2017 at 21:40):
no I haven't had a chance
Todd Cooper (Jul 28 2017 at 21:41):
no I haven't had a chance
It is Saturday morning, after all ...
Nikolaos Alexandros Kaloumenos (Jul 29 2017 at 13:28):
I found this npm package which looks it does the work:
https://www.npmjs.com/package/fhir-validator
Does this considered to be an effective way by the community, other than the official .jar validator that is provided or HAPI FHIR parser?
Grahame Grieve (Jul 29 2017 at 21:23):
I'm not familiar with this validator, or it's author.
John Silva (Jul 30 2017 at 00:04):
Yes, I posted it realizing soon after that it was already too late for Grahame to see.
I'm getting the sense that not many (if any) folks are using the FHIR JSON schema; is that true? Are folks validating FHIR JSON (at run-time) using other mechanisms? Is this like in the XML world where systems only make sure that the syntax is correct (i.e. is valid XML) not that it matches the XML schema?
Lloyd McKenzie (Jul 30 2017 at 03:35):
Neither XML schema validation nor JSON schema validation give you full validation.
Grahame Grieve (Jul 30 2017 at 04:19):
some people are using one of the FHIR validators - they give a much more thorough check anyway
John Silva (Aug 02 2017 at 21:01):
Lloyd, yes, I realize that XML or JSON schema can't do much, but when what is coming in is FHIR JSON, that's pretty much the only option. (this is starting to feel like HL7 V2.x conformance discussions ;-) ) I did find some page on the FHIR website where you (FHIR team) list the different levels of validation that can be done with each of the approaches so I understand that JSON schema can only do so much; but it's better than "nothing". (of course this raises the question about the run-time performance impact of performing JSON schema [or any] validation in FHIR interchange handling.)
Grahame Grieve (Aug 02 2017 at 21:07):
it's no the only option - you can run a FHIR validator in line - there are options for java, C#, and win32/64 which covers most requirements
Grahame Grieve (Aug 02 2017 at 21:08):
any updates on the JSON schema?
John Silva (Aug 02 2017 at 21:35):
Grahame, just sent you 'regular email' on JSON schema; thanks.
Cagdas Alcicek (Aug 08 2017 at 12:54):
Hey guys,
I found the current (DSTU3) JSON schemas on here https://www.hl7.org/fhir/downloads.html. However, I cant seem to find the DSTU2 equivalents. I want to do my own JSON schema validations at runtime, can someone point me in the right direction?
Igor Sirkovich (Aug 08 2017 at 14:34):
As far as I remember, JSON schemas were introduce in STU3, so probably, these just don't exist in DSTU2.
Lloyd McKenzie (Aug 09 2017 at 02:08):
Igor is correct. No JSON schemas were defined in DSTU2. (In part because the JSON schema spec was extremely immature at that point. It's since turned out that the schema spec is still pretty immature in that the various tools that claim to support the JSON schema spec have varying behaviors and expectations.
Lloyd McKenzie (Aug 09 2017 at 02:08):
(HL7 encountered exactly the same issues when we were an early adopter of XML schema way back when we defined the HL7 v3 standard.)
Last updated: Apr 12 2022 at 19:14 UTC