FHIR Chat · Interesting JSON/XML conversion method · tooling

Stream: tooling

Topic: Interesting JSON/XML conversion method


view this post on Zulip Adam Flinton (Mar 29 2021 at 09:08):

Not just... could enrich or redact.... AWS S3 Object lambda...... was thinking wrt fhir XML <> JSON conversions on the fly. ie. using https://aws.amazon.com/blogs/aws/introducing-amazon-s3-object-lambda-use-your-code-to-process-data-as-it-is-being-retrieved-from-s3/

e.g. https://itnext.io/serverless-framework-use-aws-s3-object-lambda-to-resize-images-on-the-fly-868a37017f3c

Are there standard FHIR XML <> JSON conversion routines which could be plugged in?
Load Object model & then output in desired markup?

view this post on Zulip Oliver Egger (Mar 29 2021 at 11:13):

which language are you looking for? here is a node.js library but there are others with java and .net around.

view this post on Zulip Shamil Nizamov (Mar 29 2021 at 16:56):

In case of FHIR simple conversion to/from XML <> JSON does not work well. It may lose structure/semantic in case of narrative, arrays, element's extensions, etc.

view this post on Zulip Oliver Egger (Mar 29 2021 at 19:01):

@Shamil do you have an example? I think it is one of the strengths that you can have different representations (e.g. xml, json) with a FHIR resource and the servers are able to serve these different representations. I'm not aware that you lose structure/semantic.

view this post on Zulip Gino Canessa (Mar 29 2021 at 19:11):

One of the issues is trying to map types without context. E.g., if you have an XML literal: <value value="6"/>, does that map to JSON "valueInteger": 6, "valueDecimal": 6, "valuePositiveInt": 6, or something else?

view this post on Zulip Oliver Egger (Mar 29 2021 at 19:50):

i almost don't dare to ask ... but where can we put <value value="6"/> in a fhir resource?

view this post on Zulip ryan moehrke (Mar 29 2021 at 20:08):

you don't? you use <valueString value="whatever"/> like normal
I think the biggest disconnects happen around extending basic datatypes

view this post on Zulip Gino Canessa (Mar 29 2021 at 20:16):

Sure you do. Inside an Observation that is perfectly valid XML (example).

By context, I know that a <value> tag inside a <valueQuantity> tag is a decimal type, but it's not obvious from the fragment.

view this post on Zulip Lloyd McKenzie (Mar 29 2021 at 20:20):

True, but it's going to be "value": 6.3 in the JSON too, so that's not relevant for conversion. What is relevant is that
<value value="6323"/> becomes "value":"6323"; while <value value="6.3"/> becomes "value":6.3

view this post on Zulip Lloyd McKenzie (Mar 29 2021 at 20:20):

i.e. there's no way to tell numbers from strings (or booleans) without access to the metadata

view this post on Zulip Gino Canessa (Mar 29 2021 at 20:24):

Thanks Lloyd, I was going to add clarify that but got sidetracked by something in the house. This is why I should only write long posts =)

view this post on Zulip Oliver Egger (Mar 29 2021 at 20:28):

Thanks @Lloyd McKenzie and @Gino Canessa

view this post on Zulip Chris Moesel (Mar 29 2021 at 20:40):

This is all true, but I think the point is that serious FHIR XML<-->JSON converters should have access to the metadata and therefore should be able to do non-lossy conversion. Assuming we're not talking about custom resources, then all instances will be based on (at most) constraints of core FHIR types. Since constraints cannot add new elements, then as long as a converter has the core FHIR type definitions, they should be all set. As @ryan moehrke pointed out above, converters know even the type of choice elements since there are serialization rules about that.

view this post on Zulip Gino Canessa (Mar 29 2021 at 21:10):

Yes - I was under the impression that the request was for a generic XML <-> JSON converter that could handle FHIR. Once you include the core definitions, it is fairly straightforward (and many language-based toolkits will even do this for you).

view this post on Zulip Grahame Grieve (Apr 20 2021 at 04:45):

the other challenge is converting XML --> JSON, and knowing when the output is an array or not. You must have access to the metadata to convert from XML to JSON, but not from JSON to XML

view this post on Zulip Dietrich Haag (Apr 27 2021 at 07:01):

Hi everyone, hopefully I am in the right context here.

Is there some FHIR-XML <> FHIR-JSON Converter as single tool (e.g. command line) available? I am aware that a FHIR-Server can $convert an input to an specified output, but this is not applicable for me.
The HL7-Validator is able to consume input as XML or JSON, has it maybe some options for this purpose I'am not aware of (not found anything about it)?

view this post on Zulip Alexander Zautke (Apr 27 2021 at 07:04):

@Ward Weistra

view this post on Zulip Oliver Egger (Apr 27 2021 at 07:33):

@Dietrich Haag you can use the FHIR Java Validator to a conversion, there is a -convert option and you specify the output file and depending on output file format the conversion will be done (json to xml or xml to json).

-convert requires the parameters -source and -output. ig may be used to provide a logical model

e.g. java -jar validator_cli.jar bundle.json -version 4.0.1 -convert -output ./bundle.xml

view this post on Zulip Dietrich Haag (Apr 27 2021 at 12:01):

@Oliver Egger thanks!
My first though about this option was to convert between coding systems or fhir versions, cause I was not aware the output format could be determined by the file extension.

For the -ig parameter, would it be correct if I insert the same ig's I would do for validating an bundle/resource?

In my case I validate with following parameters:

Params: -version 4.0.1  -locale de -recurse -no-extensible-binding-warnings -tx n/a -ig de.basisprofil.r4-0.9.11.tgz -ig hl7.terminology.r4.tgz -ig kbv.basis-1.1.0 -ig kbv.mio.impfpass-1.00.000/package/KBVCSMIOVaccinationTechnicalEntryType.json -ig kbv.mio.impfpass-1.00.000/package/KBVEXMIOVaccinationBasicImmunization.json -ig kbv.mio.impfpass-1.00.000/package/KBVEXMIOVaccinationEntryType.json -ig kbv.mio.impfpass-1.00.000/package/KBVEXMIOVaccinationFollowUp.json -ig kbv.mio.impfpass-1.00.000/package/KBVVSMIOVaccinationEntryType.json -ig Schluesseltabellen -ig KBV_FHIR_AW Mustermann_Martina_10000_AW.xml

So I can convert extending the validation-call with:

-convert -output KBV_FHIR_AW Mustermann_Martina_10000_AW.json

Problem with umlauts
Converting json > xml breaks all umlauts. xml > json works fine - than converting this json> xml and comparing the original xml with the converted xml show the broken umlauts e.g.: "Müller" > "M&#xFC;ller"

Unclear is the "-source" option. What would I use it for?

view this post on Zulip Oliver Egger (Apr 27 2021 at 13:58):

My first though about this option was to convert between coding systems or fhir versions,

for fhir version you can use the -transform parameter see

For the -ig parameter, would it be correct if I insert the same ig's I would do for validating an bundle/resource?

the ig parameter are not necessary for the conversion (except you would provide a logical model which you are parsing or converting to)

Problem with umlauts

I think this is an open issued in the java fhir validator, i prepared a PR but it did not yet get integrated in the code base. maybe you can add a comment below that PR that you experience the same issue?

Unclear is the "-source" option. What would I use it for?

maybe you can add it instead of the file as main parameter? agree that it is not clear ...

view this post on Zulip Vassil Peytchev (Apr 27 2021 at 14:09):

Just a nit-pick:

Converting json > xml breaks all umlauts. xml > json works fine - than converting this json> xml and comparing the original xml with the converted xml show the broken umlauts e.g.: "Müller" > "Müller"

As far as I know, this does not "break" the umlauts - from the point of view of an XML processor, the XML entity is equivalent to the corresponding character.

view this post on Zulip Ward Weistra (Apr 28 2021 at 07:26):

@Dietrich Haag Please also have a look at Firely Terminal. You would just:

  • Push the resources you want to the internal stack, e.g. fhir push *.xml
  • And then save them in the format you want, e.g. fhir save --json --all

You can control the saved filename with FHIRPath or wrap it in a script to keep the original filename-stem.

view this post on Zulip Dietrich Haag (Apr 28 2021 at 08:37):

@Ward Weistra Do I need an running fhir-server to use the Firely Terminal?

view this post on Zulip Ward Weistra (Apr 28 2021 at 08:39):

@Dietrich Haag No, not needed. It just works locally on your filesystem. (It CAN interact as a FHIR client with FHIR servers or Simplifier.net if you need it to though)


Last updated: Apr 12 2022 at 19:14 UTC