How to convert HL7 v2.x message to FHIR JSON?
Asked Answered
W

4

11

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.

Wigwam answered 20/10, 2016 at 11:6 Comment(0)
O
9

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.

Omaromara answered 4/3, 2020 at 14:0 Comment(1)
Here is another helpful link.Omaromara
D
7

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

Discrepant answered 10/11, 2016 at 22:35 Comment(1)
Interesting concept, but far too resource intensive. Not only does Mirth install by default of 20+G of disk space, the act of converting to xml->json, at least on my system, takes 750ms to 3s longer to process, than manually writing the direct conversion in java, and can use upwards of over a gig of extra ram. Make sure you have an extremely beefy server just to handle it this way, or better, a completely dedicated server to do these conversions.Plasm
K
2

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

var jsonString = XmlUtil.toJson(msg)
var data = JSON.parse(data)
Kesler answered 19/5, 2021 at 17:16 Comment(0)
C
1

You can convert HL7 to FHIR JSON in Java using Apache Camel. Camel supports both formats:

The exact implementation depends on how you're receiving and sending the HL7 and FHIR; but broadly speaking, you would write a Camel route which unmarshals from HL7 using the HL7 dataformat component, then transforms the data into a target FHIR Java object by mapping the source to target fields using a custom class (you would need to write this, but see below for a starting point), and then marshals the data out to JSON using the FHIR dataformat. For example:

from("file:/input/directory")
    .unmarshal().hl7() // convert from HL7 text format to Java object
    .process(new PatientProcessor()) // map source to target fields
    .marshal().fhirJson() // serialise out to FHIR JSON format
    .to("file:/output/directory");

The processor in the middle is where your transformation/mapping class goes.

There is a fully worked example in Camel's unit tests, showing how to convert from HL7 to FHIR. See:

Casque answered 10/3, 2020 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.