web stats
Generating multiple segments in outbound messages - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-24-2007, 09:15 AM
eisenbrl eisenbrl is offline
Mirth Newb
 
Join Date: Apr 2007
Posts: 7
eisenbrl
Default Generating multiple segments in outbound messages

I have been trying to create an Outbound HL7 message with multiple segments for Next of kin, Allergies, and Insurance companies from my MS SQL database. I have created a channel that uses source message builder type transformers to map my database fields to my HL7 Template. This works fine, but I can only map one next of kin, one allergy, and one insurance company per patient. I would like to know how to support multiple segments in my outbound message if the number of segments is different for each patient.

One thought I had was to create a javascript source transformer that queries the database for the detail next of kin, allergy, and insurance information and then write a segment directly to the output. Is there a better way to do this? if so, how? I have not found any examples of outbound channels that do this, only inbound. Any suggestions about how this is supposed to work would be appreciated.

If it is possible to to this, do I need to change all my message builder transforms to use javascript or can I use a combination of javascript, mapper, and message builder types? If so, how do I know which transformer runs first, second...? Also, How can I write directly to the output of the channel via javascript? Or should the template be modified on the fly to allow various segment formats?
Reply With Quote
  #2  
Old 08-07-2007, 11:20 AM
mombip mombip is offline
Mirth Newb
 
Join Date: Jul 2007
Posts: 13
mombip
Default Re:Generating multiple segments in outbound messag

It is very good and important question. I've tried some JS codes but without success.
Is it possible to modify template or add additional segments to outbound HL7 message?

-Mark
Reply With Quote
  #3  
Old 08-07-2007, 11:45 AM
chrisl chrisl is offline
Mirth Employee
 
Join Date: Aug 2006
Posts: 967
chrisl is an unknown quantity at this point
Default Re:Generating multiple segments in outbound messag

Please check out the E4X tutorial stickied in the other forums. Also, search Google for E4X examples - any E4X can be used to build the outgoing message or inbound.

To add 10 new segments:
Code:
var obx = msg['OBX']; //this could be tmp instead for the outgoing template
for (var i = 0; i < 10; i++){
   msg['OBX'][i] = obx;
   //copies the obx to a new repeating segment. You can now modify msg['OBX'][i] directly
}
You do not have to copy the original OBX first, you could just use XML directly:
Code:
for (var i = 0; i < 10; i++){
   msg['OBX'][i] = "<OBX><OBX.5><OBX.5.1>Test</OBX.5.1></OBX.5></OBX>"; //psuedo code - might need to be adjusted
}
__________________
Chris Lang
Reply With Quote
  #4  
Old 08-08-2007, 05:27 AM
mombip mombip is offline
Mirth Newb
 
Join Date: Jul 2007
Posts: 13
mombip
Default Re:Generating multiple segments in outbound messag

Thank you for that. It is very useful.
Reply With Quote
  #5  
Old 08-08-2007, 02:08 PM
Paul69 Paul69 is offline
What's HL7?
 
Join Date: Jul 2007
Posts: 3
Paul69
Default Re:Generating multiple segments in outbound messages

Hi all,

I was working on the same problem this week and finally got the following JS code to work. I am converting database queries to HL7 and dumping to a file (to be read later by GE Centricity). I needed to add a second A04 IN1 segment if there was any secondary insurance for the patient. Since the A04 always has a default single IN1 seqment, the following script just copies it, renumbers it (= 2) and inserts the secondary ins. patient ID number into field 49. That's all I need it to do.


//add a second IN1 segment if db query variable 'ins_grp_2' not null
var ins2 = msg['ins_code_no_2'].toString()
if (ins2.length > 0) { //tests for presence of incoming message data

var ins = tmp['IN1'];
for (var i = 0; i < 2; i++){
tmp['IN1'][i] = ins; //copies the IN1 to a new repeating segment.

}
tmp['IN1'][1]['IN1.1']['IN1.1.1']= 2;
tmp['IN1'][1]['IN1.49']['IN1.49.1']= ins2;
}

I'm sure there are cleaner ways to do it. Hope it helps.
Paul69
Reply With Quote
  #6  
Old 08-16-2007, 03:40 AM
mombip mombip is offline
Mirth Newb
 
Join Date: Jul 2007
Posts: 13
mombip
Default Re:Generating multiple segments in outbound messag

What was not obvious for me is that msg and tmp objects are in fact XML objects and all statements like
Code:
tmp['IN1'][1]['IN1.49']['IN1.49.1']
are E4X statements.

Code example from previous replies should not have "
Code:
for (var i = 0; i < 10; i++){
   msg['OBX'][i] = <OBX><OBX.5><OBX.5.1>Test</OBX.5.1></OBX.5></OBX>; //no " signs
}
Reply With Quote
  #7  
Old 08-20-2007, 08:10 AM
eisenbrl eisenbrl is offline
Mirth Newb
 
Join Date: Apr 2007
Posts: 7
eisenbrl
Default Re:Generating multiple segments in outbound messag

Thanks to all who have answered my questions. I have successfully created HL7 outbound messages from my MSSQL database. I created some views that give me the main patient information with keys to other tables with related information such as next of kin, Insurance, and allergies. I then used several java transformer steps to create multiple segments when needed for Insurance, Next of kin and Allergies. A typical step looks like this:
Code:
var driver = "net.sourceforge.jtds.jdbc.Driver";
var address = "jdbc:jtds:«»sqlserver://luke1:1433/CPR_MSAOM_LOCAL";
var username = "user"; 
var password = "password"; 
var nk1 = tmp['NK1'];
var i = 0;

// Open a connection to the SQL server and query CPR+ for Contacts.
var dbConn = DatabaseConnectionFactory.createDatabaseConnection(driver,address,username,password);
var Query = "Select [MRN],[LNAME],[FNAME],[LINKTYPE],[TITLE],[ADDRESS],[CITY],[ST],[ZIP],[PHONE1],[PHONE2] From HL7_NK1 Where MRN = "+msg['cpk_hr'].toString();
var cNK1 = dbConn.executeCachedQuery(Query);

while (cNK1.next() != '0') {

    tmp['NK1'][i] = nk1;	// Copy a blank NK1 record into the template
    // Load the current record's contents into the template.

    tmp['NK1'][i]['NK1.1'] = i + 1;			// load Set ID for segment
    tmp['NK1'][i]['NK1.2']['PN.1'] = cNK1.getString(2);	//Last Name
    tmp['NK1'][i]['NK1.2']['PN.2'] = cNK1.getString(3); //First Name
    tmp['NK1'][i]['NK1.3']['CE.1'] = cNK1.getString(4); //LinkType
    tmp['NK1'][i]['NK1.3']['CE.2'] = cNK1.getString(5); //Title
    tmp['NK1'][i]['NK1.4']['AD.1'] = cNK1.getString(6); //Address
    tmp['NK1'][i]['NK1.4']['AD.3'] = cNK1.getString(7); //City
    tmp['NK1'][i]['NK1.4']['AD.4'] = cNK1.getString(8); //State
    tmp['NK1'][i]['NK1.4']['AD.5'] = cNK1.getString(9); //Zip
    tmp['NK1'][i]['NK1.5'] = cNK1.getString(10);	//Phone1
    tmp['NK1'][i]['NK1.6'] = cNK1.getString(11);	//Phone2

    i++;	// Attempt to load another Contact.
}
if (i == 0)
{
    delete tmp['NK1'];
}
cNK1.close();
dbConn.close();
This works pretty well, but I have had some problems. One is the delete tmp['NK1']; statement in the "if" at the end of the while loop. In order to get the step to always work without an "Cannot set property NK1.1 of undefined to 6" error message, I have had to add an NK1 line to the template and then delete it if there are no next of kin records found. I know there is another way to do this, but I always get an error if I do not have a line in the outgoing template. I have the same error for each of the java transformer step segments IN1, NK1 and AL1. I have seen code like:
Code:
var obx = tmp['ORU_R01.RESPONSE']['ORU_R01.ORDER_OBSERVATION']['ORU_R01.OBSERVATION'][0]
but I am not sure where this comes from. I'm sure I could remove the delete code if I knew.

If anyone has any suggestions, I would love to hear them.
Reply With Quote
  #8  
Old 10-16-2007, 09:17 AM
jlehew jlehew is offline
OBX.1 Kenobi
 
Join Date: Sep 2007
Posts: 26
jlehew
Default Re:Generating multiple segments in outbound messag

This is one way to resolve the "Cannot set property OBX of undefined to 6" error message...

I have a situation where I need to add Height and Weight only when Admitted (A01). I added in a place holder (OBX||||||) into the outgoing data template so adding multiple segments works correctly, then added a delete so it would remove that segment for all other messages.

Code:
if (HL7EventCode=="A01"«»)
    {
    var i = 0;
    tmp['OBX'][i] = obx;
	
    tmp['OBX'][i]['OBX.2']['OBX.2.1']="ST";
    tmp['OBX'][i]['OBX.3']="3141-9^WEIGHT^LOINC";
    tmp['OBX'][i]['OBX.5']['OBX.5.1']=Weight;
    tmp['OBX'][i]['OBX.6']['OBX.6.1']="kg";
    tmp['OBX'][i]['OBX.11']['OBX.11.1']="F";

    i++;
    tmp['OBX'][i] = obx;

    tmp['OBX'][i]['OBX.2']['OBX.2.1']="ST";
    tmp['OBX'][i]['OBX.3']="3137-7^HEIGHT^LOINC";
    tmp['OBX'][i]['OBX.5']['OBX.5.1']=Height;
    tmp['OBX'][i]['OBX.6']['OBX.6.1']="cm";
    tmp['OBX'][i]['OBX.11']['OBX.11.1']="F";
    }
else
    {
    // Must put OBX|||||| in the outgoing data template then delete it if it is not needed
    delete tmp['OBX'];
    }
Regards,
John Lehew

Post edited by: jlehew, at: 10/17/2007 14:22
Reply With Quote
  #9  
Old 10-16-2007, 10:45 AM
eisenbrl eisenbrl is offline
Mirth Newb
 
Join Date: Apr 2007
Posts: 7
eisenbrl
Default Re:Generating multiple segments in outbound messag

Thank you. That is a good idea.
Reply With Quote
  #10  
Old 07-28-2008, 07:30 AM
jbartels jbartels is offline
Mirth Guru
 
Join Date: Oct 2006
Posts: 729
jbartels is on a distinguished road
Default Re:Generating multiple segments in outbound messag

I hate to drag up a dead thread, but I just wanted to thank eisenbrl for posting this. The approach outlined here works great.

Thanks eisenbrl!!!
__________________
Jon Bartels

Zen is hiring!!!!
http://consultzen.com/careers/
Talented healthcare IT professionals wanted. Engineers to sales to management.
Good benefits, great working environment, genuinely interesting work.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple XML segments from HL7 dugjohnson Support 1 01-04-2017 05:37 AM
Generating ACK messages - HOW? r_kerry Support 6 03-30-2009 10:06 AM
Multiple IN1 Segments with Optional IN2 Segments bdilworth Support 4 07-29-2008 10:24 AM
Merging multiple inbound channels into a single outbound channel lmann Development 2 11-26-2006 10:23 PM
Multiple IN1 Segments in ADT messages arumpke Support 2 11-01-2006 01:04 PM


All times are GMT -8. The time now is 01:02 PM.


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