Node.JS on FHIR

If your using FHIR resources to represent your healthcare models, you may run into some issues when building a Node.JS application to work with your FHIR models.

FHIR does a pretty good job at providing examples (reference implementations) of how to use FHIR in different technology stacks. However, I believe it falls a little short when it comes to the JavaScript stack. They have an example that demonstrates how to build each (and every) resource as a schema within Mongoose. This is great if all you are trying to do is store data in a FHIR model. However, the reference implementation does not seem to address how to serialize those models between XML and JSON (something that you would likely need to do if you wanted to represent your FHIR resources in a complete document).

FHIR has had a great deal of focus on accessing individual resources (such as a single patient, or a single encounter) but little-to-no focus on combining multiple resources into a full document. This has been a big focus of my company. We have been working on ways to create a full document out of these individual resources.

One aspect that we have established, is that in order to represent a full document model, you have to use an ATOM feed. ATOM feeds are best represented in XML, for sure. Additionally, it is much easier to transform XML into other types of documents, as opposed to transform a JSON model to an entirely separate model. So, our need for using FHIR in XML is pretty high.

However, we really like the Node.JS, Angular.JS and Twitter Bootstrap technology stack, and would like to make use of FHIR in JSON as much as possible, and then later conver the JSON to XML when we need to send the data, or transform it to something else (like CDA – Clinical Document Architecture).

The first issue with the JavaScript RI (reference implementation) of FHIR is that does not make use of the “resourceType” property like the FHIR website suggests. This “resourceType” property allows your JS application to have an arbitrary array of resources and still determine what type of resource it is.

The second issue is that it does not expose a method of serializing the JSON models to XML and then back to JSON again. Here, I have discovered is more of a limitation with JS in general. There are plenty of libraries for converting JSON to XML and then other libraries for converting XML to JSON. However, these separate libraries use different methods of representing XML in JSON, so there is a major limitation on round-trip JSON to XML, and back to JSON; you get different (or entirely broken) results.

To solve this issue, I have stumbled on an xml.com article that contains a custom set of functions for converting JSON to XML and XML to JSON that use the same syntax. It doesn’t appear that these libraries have been placed into an official npm or mongoose package, so you have to include them manually in your JS project. But, with a little work, round-trip JSON<->XML is possible. I have created a JSFiddle example to demonstrate this successful round-trip conversion: http://jsfiddle.net/kbcb/4DS4P/4/

Leave a Reply

Your email address will not be published.

Humanity Verification *Captcha loading...