p.campbell
p.campbell

Reputation: 100657

Mirth: overwriting msg object with contents in an XML object

The task is to send an XML object from Channel-A to Channel-B

<MyMessage>
<ID>42</ID>
<hl7v2>
    MSH|^~\&|LAB|....
    PID|1|....
</hl7v2>
</MyMessage>

The steps of the channel communication:

The good news is that I can extract the HL7v2 'payload' into a variable. The problem or difficulty is resetting the msg object, or any other object to be able to reference the HL7 properties as expected.

When I create a new variable with the SerializerFactory.getHL7Serializer, it wraps with the tags <HL7Message>.

channelMap.put('MessageID', msg['ID']); //successful
channelMap.put('v2payload',msg['HL7v2']); //also looks good

var v2Msg = SerializerFactory.getHL7Serializer(false,false,true).toXML(msg['HL7v2']);

channelMap.put('v2Msg', v2Msg );

alt text link to full size image

Question: Do you have any suggestions on how to overwrite the msg object?

How can I start referencing the msg as such:

msg['PID']['PID.5']

Current Conditions

Upvotes: 1

Views: 4956

Answers (2)

bradd
bradd

Reputation: 13

All you have to do is put your incoming xml message into the inbound template area in mirth and then use the message tree to drag and drop the info from the XML that you need to the javascript section of the connector.

Upvotes: 0

csj
csj

Reputation: 22426

I'm sorry my original answer was bogged down with the peculiarities of my own scenario. I have reworked and tested to ensure that this works in your scenario.

Sending Channel - wraps the raw hl7 into your xml structure, and forwards to a channel called ReceiveXML. I have coded this in the Source Transformer, but you should code it where it works for you.

var wrappedHL7 = <MyMessage><ID>123</ID>
                      <hl7v2>{messageObject.getRawData()}</hl7v2>
                 </MyMessage>;

router.routeMessage("ReceiveXML", wrappedHL7);

Receiving Channel - extracts the hl7 from the xml, converts it to xml, and assigns back to the msg object. I have coded this in the source Filter - hence "return true;"

msg = new XML(SerializerFactory.getHL7Serializer(false,false,true).toXML(msg['hl7v2'].toString()));
return true;

Upvotes: 2

Related Questions