Sidebar

Creating Multiple DFT messages from single message with multiple FT1 segments

+1 vote
391 views
asked Oct 12, 2020 by douglas-l-4571 (190 points)
I found the code below which does work except for segments after the FT1 segments.  At the bottom of my message is a GT1, IN1 and IN2 Segment.  There are 9 FT1 segments and the GT1, IN1 and IN2 only show up on the last message.

 

// Get headers to use on all new messages

var headers = message.getNode('MSH[group=!FT1]');

//Retrieve the FT1 Segments

var ft1Groups = message.getAllNodes('FT1[group=!FT1]');

//Loop Through Each one

for (var i=0 ; i < ft1Groups.length ; i++) {

   //Set newMessage to the headers and the individual FT1 Segment

   var newMessage = qie.parseHL7String(headers + ft1Groups[i]);

   //Reset FT1-1 to "1"

   newMessage.setNode('FT1-1', '1');

   //  Ensure we have a unique id in MSH-10 (message ID)

   //  so the messages don't error out in the receiving system

   newMessage.setNode('MSH-10', newMessage.getNode('MSH-10') + '-' + i);

   // Send the new message through to the remaining nodes

   qie.spawnNewMessage(newMessage);

}

//Discard original message as it is no longer needed.

message.discard();

1 Answer

0 votes

You can save off the footer by finding the last FT1 group and then removing the FT1 segment.

 

// Get headers to use on all new messages
var headers = message.getNode('MSH[group=!FT1]');

//Retrieve the FT1 Segments
var ft1Groups = message.getAllNodes('FT1');

var footers = message.getAllNodes('FT1[group=!FT1]');
var foosterLength = footers.length - 1;
footers = qie.parseHL7String(footers[foosterLength]);
var extraFt1 = footers.getNode('FT1');
footers = StringUtils.replace(footers, extraFt1, '');

//Loop Through Each one
for (var i=0 ; i < ft1Groups.length ; i++) {
   //Set newMessage to the headers and the individual FT1 Segment
   var newMessage = qie.parseHL7String(headers + ft1Groups[i] + footers);

   //Reset FT1-1 to "1"
   newMessage.setNode('FT1-1', '1');

   //  Ensure we have a unique id in MSH-10 (message ID)
   //  so the messages don't error out in the receiving system
   newMessage.setNode('MSH-10', newMessage.getNode('MSH-10') + '-' + i);

   // Send the new message through to the remaining nodes
   qie.spawnNewMessage(newMessage);
}

//Discard original message as it is no longer needed.
message.discard();
 

answered Oct 12, 2020 by michael-h-5027 (14,350 points)
commented Oct 12, 2020 by douglas-l-4571 (190 points)
Thank you.  This works except for each FT1 there is a ZFT segment, which I forgot to mention.  After running the code above I get the last ZFT segment in each message rather than the matching ZFT segment with the FT1 segment.  Hope this makes sense and sorry for any confussion.
commented Oct 12, 2020 by douglas-l-4571 (190 points)
I just figured it out.  Thanks for your help
...