web stats
Mirth Community - View Single Post - Break HL7 msg into several messages
View Single Post
  #2  
Old 05-23-2018, 05:41 AM
AlexNeiva AlexNeiva is offline
Mirth Guru
 
Join Date: Oct 2013
Location: Portugal
Posts: 275
AlexNeiva is on a distinguished road
Default

Hello,


giving your HL7 example, i develop a JavaScript code in the Transformer in order to split and build up again the HL7 message. It can be done in another way and this is just a "quick fix"
Create a new channel that receives HL7 with name "HL7Receiver" and on the channel that receives the full HL7 to split, put this code on the Transformer:


Code:
var arrOBR=[];
var arrOBX=[];
var arrNTE=[];

var xml;

for each (var seg in msg.children())
{
    if(seg.name() == "OBR")
        arrOBR.push(seg);

    if(seg.name() == "OBX")
        arrOBX.push(seg);

    if(seg.name() == "NTE")
        arrNTE.push(seg);
}

for each(var i=0; i<arrOBR.length; i++)
{
    xml=new XML();
    
    xml="<HL7Message>" + 
            msg['MSH'].toString() + "\r\n" +
            msg['PID'].toString() + "\r\n" +
            msg['NTE'][0].toString() + "\r\n" +
            msg['ORC'].toString() + "\r\n" +
            arrOBR[i].toString() + "\r\n" +
            arrOBX[i].toString() + "\r\n" +
            arrNTE[i].toString() + 
        "</HL7Message>";

    tmp=xml;
    router.routeMessage('HL7Receiver', SerializerFactory.getSerializer('HL7V2').fromXML(tmp));
}
Note: in this code i assume that the same amount of OBR - OBX - NTE is the same. I'm not handling exceptions.
And the Transformer Outbound message type should be XML Type.
__________________
Best Regards,
Alex Neiva

Last edited by AlexNeiva; 05-23-2018 at 05:44 AM.
Reply With Quote