web stats
converting HL7v2 to JSON - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2019, 08:09 AM
mrando mrando is offline
Mirth Newb
 
Join Date: Dec 2019
Posts: 6
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, 20 views)
File Type: png Channel setup.PNG (4.6 KB, 16 views)
Reply With Quote
  #2  
Old 12-06-2019, 06:30 PM
peterl peterl is offline
Mirth Employee
 
Join Date: Mar 2013
Posts: 14
peterl is on a distinguished road
Default

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:
Code:
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:
Code:
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 12:06 PM. Reason: Incomplete/incorrect information
Reply With Quote
  #3  
Old 12-09-2019, 07:42 AM
mrando mrando is offline
Mirth Newb
 
Join Date: Dec 2019
Posts: 6
mrando is on a distinguished road
Default

Peterl,

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, 10 views)
File Type: png Channel setup.PNG (2.8 KB, 6 views)
File Type: png transformation.PNG (10.6 KB, 9 views)
Reply With Quote
Reply

Tags
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 05:49 PM.


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