Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert HL7 v2.x message to FHIR JSON?

I am trying to convert HL7 v2.x message to FHIR JSON using java or python. But I am not able to find any solution. Is there any way to achieve this?

I found that FHIR is capable of converting to JSON but I don't know how to do that.

like image 694
animal Avatar asked Oct 20 '16 11:10

animal


3 Answers

Here is a suggestion:

  1. Download and Install Mirth Connect

  2. Create a new channel

  3. Under the "Scripts" tab, select "preprocessor"

  4. Use the following to convert the HL7 message to XML:

    // Modify the message variable below to pre process data
    message = SerializerFactory.getSerializer('HL7V2').toXML(message);
    
    return message;
    
  5. Now you have the XML file in the variable message, so you can write inline code to convert it to JSON without a library from here: https://davidwalsh.name/convert-xml-json

like image 125
Bryan Avatar answered Nov 17 '22 19:11

Bryan


About HL7 2.x

HL7 2.x versions neither support XML nor JSON as a part of standards.

Version 2 v2.xml XML Schemas for HL7 Version 2.5 and earlier were contributed by Sun Microsystems. These representations are provided for convenience, as the XML schema is a compact and specific way to describe the XML representation. However the schema is not in itself a normative part of this specification.
hl7.org

As you can see above, the "v2.xml XML Schemas" are not part of specifications. They are additional contributions.

The objective of this specification is to present encoding rules for HL7 Version 2.3.1, 2.4, 2.5 and future 2.x messages based on the Extensible Markup Language XML that could be used in environments where senders and receivers both understand XML. The v2.xml specification aims to act as a second normative encoding for v2.3.1, v.2.4 and v2.5 (and future releases of the HL7 v2.x standard).
hl7.org

Following is the quote from Wikipedia:

HL7 v2.x messages use a non-XML encoding syntax based on segments (lines) and one-character delimiters
wikipedia

About HL7 v3.x

HL7 v3.x versions support XML as a part of standards.

Several XML encoding methods could serve as a messaging syntax for HL7 V3 messages. This document represents the method that is recommended by HL7, describing the underlying rules and principles. The corresponding data type descriptions necessary for this specification are described in the Data Types XML ITS.
hl7.org

Following is the quote from "HL7 V3 Guide":

HL7 defines its messages at an abstract level. The "7" in HL7 stands for the Application level of the ISO communication model -- ISO level 7. This level emphasizes the semantic content of the messages, not how they are represented, nor how these representations are encoded for transmission.

HL7 defines its messages at an abstract level. The "7" in HL7 stands for the Application level of the ISO communication model -- ISO level 7. This level emphasizes the semantic content of the messages, not how they are represented, nor how these representations are encoded for transmission.

The HL7 Version 2 abstract message model has the notions of segments and fields. It defines a particular encoding scheme to represent instances of abstract messages -- the so called "vertical bar encoding." Information from the Health domain (the semantic level 7) is represented in Version 2 as segments and fields and represented as ASCII characters with plenty of vertical bars. Consistent with this approach, the new XML encoding of V2 is mostly a direct replacement for the vertical bar encoding

The Version 3 abstract message model is based on the RIM. HL7 Version 3 messages can be thought of as the communication of graphs of RIM objects from sender to receiver. The ITS can best deal with representing these messages by having appropriate representations for objects, attributes and Data Types.
hl7.ihelse.net

Following is the quote from wikipedia:

HL7 v3 messages are based on an XML encoding syntax
wikipedia

You can read more about compatibility here.

None of them support JSON as a part of standards.
Hence, conversion from HL7 to XML or HL7 to JSON is out of standard; one need to handle it on its own.


About FHIR (Fast Healthcare Interoperability Resources)

FHIR is a standard for health care data exchange, published by HL7.
See the relationship between HL7 and FHIR here.

The FHIR supports both XML and JSON formats as a part of standard. Please refer to those links for more details.


Converting v2 to FHIR:

Broadly there are 2 approaches to this conversion:

  • The creation of a FHIR message bundle that mirrors the contents of the v2 message, and is intended to be an equivalent representation, behaving in the same way as v2 messages
  • Using the contents of the v2 message to update a FHIR server – perhaps extracting Encounter resources or creating a Bundle that is intended to act as a ‘transaction’ bundle against a FHIR server. I think this will be a much more common use case.

FHIR Blog

Please read that blog for details about conversion. The community is working on conversion; hope the out-of-the-box solution will available soon.

Conversion between v2 & FHIR is something that the community is working on – there’s a chat stream here: https://chat.fhir.org/#narrow/stream/179188-v2-to.20FHIR where you can get engaged. The mapping between the 2 standards will take some work to define, and there will be variances in implementations but the goal of the project is to define a ‘base’ mapping as a starting point. The relationship between v2 and FHIR is reasonably close, but there are considerable issues to work through…

There’s no single way to actually perform the conversion – it will depend on the technology you have to hand. For example in the post I was using simple javascript in NodeRED – though just as a proof of concept. I imagine that most integration engine vendors will have offerings in this space.
Comment

The mapping details are explained on HL7 site.


Following are some tools:

https://github.com/rimiti/hl7-object-parser#hl7-object-parser (HL7 v2.x to JSON)
https://github.com/nezt/hl72xml#hl72xml (HL7 V2.x to XML)
https://github.com/KevinMayfield/ITKHL7v2-FHIR

Mirth provides a feature to convert HL7 to XML/JSON.
Please refer to other answer from @Bryan.
Few samples can be found here and here.

like image 8
Amit Joshi Avatar answered Nov 17 '22 18:11

Amit Joshi


In Mirth you can use the following code in the source transformer

var jsonString = XmlUtil.toJson(msg)
var data = JSON.parse(data)
like image 2
Dangerous Dave Avatar answered Nov 17 '22 17:11

Dangerous Dave