web stats
converting HL7v2 to JSON - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 12-05-2019, 07:09 AM
mrando mrando is offline
Mirth Newb
Join Date: Dec 2019
Posts: 10
mrando is on a distinguished road
Default converting HL7v2 to JSON

I am new to the Mirth community and have been tasked with working on a channel to convert HL7v2 to JSON. Looking for suggestions on setup ect. So far in my research I have found code on it but keep getting an error trying the conversion. I have attached my Data Types setup as well as the code I am using to transform the MSH. I'm thinking my issue lies in the "source transformation". Any help would be appreciated.
Attached Images
File Type: png Source Transformer.PNG (45.9 KB, 22 views)
File Type: png Channel setup.PNG (4.6 KB, 18 views)
Reply With Quote
Old 12-06-2019, 05:30 PM
peterl peterl is offline
Mirth Employee
Join Date: Mar 2013
Posts: 14
peterl is on a distinguished road

For Data Types, your Source Connector should have an inbound of HL7 v.2 and outbound of JSON, and your Destination Connectors should have an inbound of JSON.

In the Javascript step in your Source Transformer, you should use the tmp variable to build your outbound message. It would be something like:
tmp['msh'] = {}
tmp['msh']['fieldSeparator'] = msg['MSH']['MSH.1'].toString();
tmp['msh']['encodingCharacter'] = msg['MSH']['MSH.2'].toString();
tmp['msh']['sendingApplication'] = msg['MSH']['MSH.3']['MSH.3.1'].toString();
Also, if you are only doing simple one-to-one mappings from HL7 to JSON, you can consider using Message Builder steps instead of Javascript. See the User Guide at https://github.com/nextgenhealthcare/connect to read more about Transformers and Message Builder steps.

Edit: "tmp" is only used when an outbound message template is defined. Otherwise, use "msg". For example:
jsonMessage = {};
jsonMessage['msh'] = {};
jsonMessage['msh']['fieldSeparator'] = msg['MSH']['MSH.1'].toString();
jsonMessage['msh']['encodingCharacter'] = msg['MSH']['MSH.2'].toString();
jsonMessage['msh']['sendingApplication'] = msg['MSH']['MSH.3']['MSH.3.1'].toString();
msg = jsonMessage;

Last edited by peterl; 01-02-2020 at 11:06 AM. Reason: Incomplete/incorrect information
Reply With Quote
Old 12-09-2019, 06:42 AM
mrando mrando is offline
Mirth Newb
Join Date: Dec 2019
Posts: 10
mrando is on a distinguished road


Thanks for the response. I changed my data types to HL7 and JSON (see attached). I also added your snip-it of code to the source transformer to tried to get the transformation to work for those fields. However it gets transformed to XML and I get an error which I have attached as well.
Attached Images
File Type: png Error.PNG (11.8 KB, 12 views)
File Type: png Channel setup.PNG (2.8 KB, 7 views)
File Type: png transformation.PNG (10.6 KB, 10 views)
Reply With Quote

hl7v2, json, transformation

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 01:28 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation