web stats
Create multiple HL7 messages out of raw data through JavaScript - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2015, 10:03 AM
arpitgoel arpitgoel is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 8
arpitgoel is on a distinguished road
Default Create multiple HL7 messages out of raw data through JavaScript

I am trying to create multiple HL7 messages (ORU, RDE and so on....) out of raw data retrieved from a database through JS reader but I don't how to create a new HL7 message in Javascript (not through template). Does anyone know how can I build multiple HL7 messages from scratch in Javascript?

I found this post :http://stackoverflow.com/questions/2...age-with-mirth

It shows how to create new HL7 segments but how do I get the "msg" variable where segements are added using "createSegment"?
Reply With Quote
  #2  
Old 05-04-2015, 10:09 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,101
narupley is on a distinguished road
Default

That's easy. In the JavaScript Reader, you can just declare msg as a new variable:

Code:
var msg = <HL7Message/>;
Then create segments as needed:

Code:
createSegment('MSH', msg);
msg.MSH['MSH.1'] = '|';
msg.MSH['MSH.2'] = '^~\\&';
msg.MSH['MSH.3']['MSH.3.1'] = 'Sending Application';
msg.MSH['MSH.4']['MSH.4.1'] = 'Sending Facility';
// etc...
Then at the end serialize it to ER7:

Code:
var message = SerializerFactory.getSerializer('HL7V2').fromXML(msg);
And dispatch it to the channel:

Code:
return message;
You can dispatch multiple messages if you want:

Code:
var messages = new java.util.ArrayList();
messages.add(message1);
messages.add(message2);
return messages;
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 05-04-2015, 10:16 AM
arpitgoel arpitgoel is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 8
arpitgoel is on a distinguished road
Default

Thank you for such quick reply. I'll try the specified code.
Also, one more thing. I wanted to build the messages in transformer, while returning the raw data from JS reader. How will the transformer receive the raw data. Shall I change the response to "Auto generated (after source transformer)" and "return messages" in transformer script?

Last edited by arpitgoel; 05-04-2015 at 10:17 AM. Reason: typo
Reply With Quote
  #4  
Old 05-04-2015, 10:20 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,101
narupley is on a distinguished road
Default

Quote:
Originally Posted by arpitgoel View Post
Thank you for such quick reply. I'll try the specified code.
Also, one more thing. I wanted to build the messages in transformer, while returning the raw data from JS reader. How will the transformer receive the raw data. Shall I change the response to "Auto generated (after source transformer)"? and "return messages" in transformer script?
That... doesn't make any sense. I think you're using different terms in incorrect ways, so I don't really know what you're trying to do from those sentences.

If you return an ER7 HL7 v2.x message from the JavaScript Reader, and your inbound data type is HL7 v2.x, then in a transformer it will automatically serialize that message into XML for you.

The response you select on the source connector is completely different, and typically only applies when you're actually sending a response to an originating system, like a connecting client to a TCP Listener. It could also apply when dispatching via a Channel Writer from some other channel.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #5  
Old 05-04-2015, 10:30 AM
arpitgoel arpitgoel is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 8
arpitgoel is on a distinguished road
Default

It seems I got things jumbled up.
I meant to say that I want my JS reader to only retrieve data from the database and use the source transformer for creating HL7 messages from the raw data. Is that plausible in this scenario?
Reply With Quote
  #6  
Old 05-04-2015, 10:31 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,101
narupley is on a distinguished road
Default

Quote:
Originally Posted by arpitgoel View Post
It seem I got things jumbled up.
I meant to say that I want my JS reader to only retrieve data from the database and source transformer for creating HL7 messages from the raw data. Is that plausible in my situation?
In that case, you should use a Database Reader source connector instead. Then your source transformer would do the job of converting the result set XML to HL7 v2.x.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #7  
Old 05-04-2015, 10:34 AM
arpitgoel arpitgoel is offline
Mirth Newb
 
Join Date: Apr 2015
Posts: 8
arpitgoel is on a distinguished road
Default

I'll stick to JS reader for transforming data as I find using javascript easier.
Thanks for your help
Reply With Quote
  #8  
Old 02-14-2018, 10:34 AM
ashishshetty1992 ashishshetty1992 is offline
Mirth Newb
 
Join Date: Jan 2018
Location: Boston
Posts: 16
ashishshetty1992 is on a distinguished road
Default Helpful

Wow! Three years down the line, this post is still as helpful. Thanks, guys!
Reply With Quote
Reply

Tags
hl7 messages, javascript, raw, transformer

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 11:07 AM.


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