web stats
Converting JSON to HL7 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2020, 09:58 AM
mrando mrando is offline
Mirth Newb
 
Join Date: Dec 2019
Posts: 6
mrando is on a distinguished road
Default Converting JSON to HL7

I have 2 channels setup in Mirth 1 being HL7 to Json for a rest endpoint and then I need to send the results back from the endpoint HL7. Not all segments of the HL7 message are used so I included a section in the JSON file called "SOURCE HL7" so that I could rebuild the outbound message back. I have attached the file for an example.

I am looking to convert the inbound JSON message from a REST endpoint to HL7 to be sent out via TCP/IP. I was trying to use "Convert JSON to XML" and then Convert XML to HL7 v2.x but was unable to get it to work.

I also tried using the map builder setting...

tmp = msg["Source HL7"] and I get the original raw HL7 message in the transformed section but I get an error. Please see attached.

I figure if I get the RAW HL7 back I could use the map builder to update the file with the new JSON sections in the source.

Any help would be appreciated.
Attached Images
File Type: png JSON to HL7 Error.PNG (77.7 KB, 12 views)
File Type: png Transformed section.PNG (58.8 KB, 12 views)
Attached Files
File Type: txt JSON file w hl7.txt (1.8 KB, 7 views)

Last edited by mrando; 01-02-2020 at 10:30 AM.
Reply With Quote
  #2  
Old 01-02-2020, 11:43 AM
mrando mrando is offline
Mirth Newb
 
Join Date: Dec 2019
Posts: 6
mrando is on a distinguished road
Default Update

I now have this converting the "Source HL7" to XML. My next step is to map the new values... I am trying to now take the XML in the source transformation and map it with map builder but get the attached error. Without the Mapping the interface sends an outbound HL7 message which consists of the "Source HL7" values.
Attached Images
File Type: png JSON to HL7 mapping.PNG (60.1 KB, 6 views)
File Type: png JSON mapping error.PNG (12.8 KB, 8 views)
Reply With Quote
  #3  
Old 01-02-2020, 11:46 AM
peterl peterl is offline
Mirth Employee
 
Join Date: Mar 2013
Posts: 14
peterl is on a distinguished road
Default

One option is, in the channel that converts JSON to HL7, try the following in your transformer code:
Code:
hl7Message = msg['HL7'][0]['Source HL7'];

// Convert HL7 to XML, and set it as the message
msg = SerializerFactory.getSerializer('HL7V2').toXML(hl7Message);
This assumes that the datatypes for the Source Connector are Inbound:JSON and Outbound:HL7 v2.x.

Connect will automatically try to do an XML->HL7 conversion when processing the message, post-transformation, so that is why this code is necessary. Also, I realize I responded to an earlier post of yours and gave some misinformation about usage of the "tmp" variable. It is only used when an outbound message template is defined. Otherwise, "msg" should be used.

Edit: I had not seen your update post, so this is addressing your original question. Hopefully this can solve your issue without needing the map builder.

Last edited by peterl; 01-02-2020 at 11:55 AM. Reason: Didn't see follow up post
Reply With Quote
  #4  
Old 01-02-2020, 01:20 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,106
agermano is on a distinguished road
Default

Slight modification to peterl's response since you are using an outbound template now. The serializer will return a string, which you still need to convert to an XML object before you can modify it.

Code:
hl7Message = msg['HL7'][0]['Source HL7'];

// Convert HL7 to XML, and set it as the template
tmp = new XML(SerializerFactory.getSerializer('HL7V2').toXML(hl7Message));

Last edited by agermano; 01-02-2020 at 01:23 PM.
Reply With Quote
  #5  
Old 01-06-2020, 11:43 AM
mrando mrando is offline
Mirth Newb
 
Join Date: Dec 2019
Posts: 6
mrando is on a distinguished road
Default

Thanks guys! All is working now except the mapping portion. I could write the mapping in Javascript which I did for PID.5.1, 5.2 and 5.3. I just think it would have a cleaner look if I had it in the message builder. I have uploaded my channel to show what I mean in the transformer for PID.2
Attached Files
File Type: xml Inbound from REST.xml (25.7 KB, 4 views)
Reply With Quote
  #6  
Old 01-08-2020, 11:24 AM
mrando mrando is offline
Mirth Newb
 
Join Date: Dec 2019
Posts: 6
mrando is on a distinguished road
Default

Does anyone know if there is a way to do this or should I just stick with the javascript?
Reply With Quote
  #7  
Old 01-08-2020, 03:37 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,106
agermano is on a distinguished road
Default

You should be able to drag-and-drop elements from your inbound template to your outbound template to create the message builder steps automatically. Keep in mind this will use the tmp variable. So, you would either need to assign tmp from the serializer output as in my previous comment, or you'd need to edit all of the message builder steps to change tmp to hl7XML.

If you end up doing a lot of hand editing of the message builders, I'd just stick with the javascript. What makes the auto-generated message builder steps nice is that you can see from the name of the step what it's going to do. Ultimately, the javascript in the "Generated Script" tab of the message builder is what gets compiled into your channel at deploy time anyway.
Reply With Quote
Reply

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:47 AM.


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