JSON FHIR schema validation

Hey,

I’m writing a package which is expected to speak the JSON dialect of FHIR - it’s a set of adapters that talk to an ORM on one end, and to a FHIR-compliant data store on the other. I wanted to ensure that structures emitted by this adapter are compliant with FHIR.

In the SVN repo, I’ve found files that appear to be used to validate a JSON document against the FHIR JSON schema - from what I can tell they use draft 4 from json-schema.org. Having loaded them up into a validator (to validate against the draft4 metaschema), I got a few messages indicating that their syntax is incorrect. Specifically, when I load the file fhir.schema.json in http://json-schema-validator.herokuapp.com/syntax.jsp, I get the following:

[ {
“level” : “error”,
“message” : ““true | false” is not a valid primitive type (valid values are: [array, boolean, integer, null, number, object, string])”,
“domain” : “syntax”,
“schema” : {
“loadingURI” : “#”,
“pointer” : “/definitions/ActivityDefinition/allOf/1/properties/experimental”
},
“keyword” : “type”,
“found” : “true | false”,
“valid” : [ “array”, “boolean”, “integer”, “null”, “number”, “object”, “string” ]
}, {
“level” : “error”,
“message” : ““true | false” is not a valid primitive type (valid values are: [array, boolean, integer, null, number, object, string])”,
“domain” : “syntax”,
“schema” : {
“loadingURI” : “#”,
“pointer” : “/definitions/AuditEvent.Agent/allOf/1/properties/requestor”
},
…]

This would indicate that that schema is probably not usable right out of the box. Is this a known problem? Are these files typed up by hand or generated from some even-higher-level schema document? I could probably fix these - how would I submit a patch to rectify this?

The json schemas are work in progress. I meant to get back to finishing them off prior to ballot, but didn’t make it.
They are generated by code. If you want to contribute, you can send me a patch to the generation code in the java code at org.hl7.fhir.definitions.generators.specification.json in the FHIR svn (see http://wiki.hl7.org/index.php?title=FHIR, middle column). Else, I’ll take bug reports about what’s wrong with them, and I need to have them right in a few weeks time.

OK, I’ll have a look and see if I can get them to work.

Is the build process documented anywhere, eg. what are the sources of truth, what provides what, and what gets produced in the end?

Also - which version should I check out to be able to generate the JSON schema for the latest revision of DSTU2?

The build process is documented here on the HL7 wiki. There’s no JSON schema for DSTU2 and I don’t think there’s an intention to provide one now that we’re well along to publishing STU 3. We limit changes to STU 2 to addressing searious security issues or similar problems that seriously impact implementation of the spec. All JSON schema work is for the STU 3 release. (Though if you wanted to back convert the schema for your own use or make it available for others, we could provide a link here or on the wiki or something.)

Graham - I think the schemas are missing definitions for a number of entities - I could identify the following as missing:

  • DomainResource
  • Resource
  • Type
  • SimpleQuantity
  • Structure
  • ResourceContainer
  • xhtml

The problem with some JSON schema validators is that they are lazy in the sense that they will build a schema, but not resolve references until they are needed for validation, so if your set of example data isn’t exhaustive, you won’t necessarily be able to identify what is missing.

I think for the time being, I’ll see if I can find a converter that can convert the JSON representation to XML, and validate that as it seems the XSD validation piece is complete - I hope that will be sufficient, provided the converter I will find will be correct.

The reference implementations all have built-in conversion capability. You won’t be able to use any of the off-the-shelf JSON->XML converters that we’re aware of.

For those interested. I will enter a bug report and make a fix the issues identified in this thread targeting the Final STU 3 version.