FHIR Chat · detection of FHIR struct · implementers

Stream: implementers

Topic: detection of FHIR struct


view this post on Zulip René Spronk (Mar 04 2022 at 07:44):

Various programming languages use a simple function to determine the mime-type of a given file. XML and JSON are easily detected that way - but when extending that functionality to detect application/fhir+xml (as opposed to any other XML) or application/fhir+json (versus any other JSON format) - what would be the easiest/most reliable way to detect FHIR-XML, FHIR-JSON ?

view this post on Zulip Vadim Peretokin (Mar 04 2022 at 09:33):

For json I'd say the presence of a resourceType key, if you want to go deeper then with a corresponding valid value.

XML - the fhir namespace declaration, following that the presence of an element id with a value attribute.

Of course these are heuristics with flaws :)

view this post on Zulip Declan Kieran (Mar 04 2022 at 10:01):

René Spronk said:

what would be the easiest/most reliable way to detect FHIR-XML, FHIR-JSON ?

Using schemas, XSD or JSON schema would be the most reliable way, and maybe catching any general parsing errors when loading the xml or json document beforehand, but depending on the language you're using that's maybe built into the schema validation. Easy if all the schemas are already done...

view this post on Zulip René Spronk (Mar 04 2022 at 14:56):

Thanks - I thinks Vadim's suggestion is 'good enough' in my context, where most [but not all] of the XML/JSON being processed will be FHIR. So it's ok to err on the side of FHIR ;-)

Schema validation would be rather costly, and it's very FHIR release dependent. That may be proper fit with some other contexts however.

view this post on Zulip Gino Canessa (Mar 04 2022 at 15:50):

As a note, keep in mind that the JSON resourceType key follows the same rules as the rest of JSON serialization - since it is unordered it does not need to be the first key in a resource.
(noted because if you are using a streaming parser, you cannot guarantee knowing the type until the end of parsing instead of the beginning)

view this post on Zulip Michael Lawley (Mar 07 2022 at 02:08):

Adding to @Gino Canessa 's warning: https://build.fhir.org/json.html#resources


Last updated: Apr 12 2022 at 19:14 UTC