Set Mirth destination to send transform data back as a custom ACK

12.9k views Asked by At

I have a Mirth channel that set up as a web service listener, it receives an ID, build an HL7 query message and send this query and eventually get back an HL7 response.

  • Channel Name: QueryChanel
  • Source Connector Type: Web Service Listener
  • Destination Connector Name: QueryToVista
  • Destination connector Type:LLP Sender.

This is the typical HL7 response I receive back from my query is as follow:

MSH|~|\&|VAFC RECV|FACILITY|VAFC TRIGGER||20121011141136-0800||ADR~A19|58269|D|2.4|||NE|NE|USA
MSA|AA|1234|
QRD|20121011051137|R|I|500000001|||1^ICN|***500000001***|ICN|NI|
EVN|A1|20121004064809-0800||A1|0^^^^^^^^USVHA\\0363^L^^^NI^TEST FACILITY ID\050\L|20121004064809-0800|050
PID|1|500000001V075322|500000001V075322^^^USVHA\\0363^NI^VA FACILITY ID\050\L~123123123^^^USSSA\\0363^SS^TEST FACILITY ID\050\L~9^^^USVHA\\0363^PI^VA FACILITY ID\050\L||JOHN^DOE^^^^^L|""|19800502|M||""|""^""^""^""^""^^P^""^""~^^""^""^^^N|""|""|""||S|""||123123123|||""|""||||||""||
PD1|||SOFTWARE SERVICE^D^050
ZPD|1||||||||||||||||""

I can get all the above to return if I set my Source's Response From parameter to QueryToVista

However, I want to return only the value 500000001 from the above message. I've tried to play around with the transformer in the QueryChanel destination without success.

Update:

I tried to add a javascriptwriter connector after the QueryToVista connector in the same channel as follow:

   var destination = responseMap.get('QueryToVista');
   var responseMessage = destination.getMessage();

   //Fails with following error: TypeError: Cannot read property "QRD.4" from undefined
   var customack = ResponseFactory.getSuccessResponse(responseMessage['QRD']['QRD.4']  ['QRD.4.1'].toString())**


   //work but send the whole HL7 message
   var customack = ResponseFactory.getSuccessResponse(responseMessage.toString())**


   responseMap.put('Barcode', customack);

I can't seem to use the normal transformation to retrieve the element at all. Thank you.

2

There are 2 answers

0
csj On BEST ANSWER

You're on the right track, but your update illustrates a couple of issues. However, your basic approach of using two destinations is valid, so long as "Synchronize channel" is checked on the Summary tab.

Issue 1

In your example, the HL7 response you are wanting to parse is in pipe delimited HL7 form. In order to access the elements using E4X notation (eg. responseMessage['QRD']['QRD.4']['QRD.4.1']) you must first convert it into an E4X XML object. This can be done in two steps.

  • Convert the pipe delimited HL7 string into an XML string.
  • Convert the XML string into an E4X XML object

In a Javascript transformer of the JavaScript Writer (not the Javascript Writer script itself)

var response = responseMap.get("QueryToVista");
var responseStatus = response.getStatus();

// Get's the pipe delimited HL7 string
var responseMessageString = response.getMessage();

if (responseStatus == "SUCCESS")
{
    // converts the pipe delimited HL7 string into an XML string
    // note: the SerializeFactory object is available for use in transformer
    //       scripts, but not in the Javascript destination script itself
    var responseMessageXMLString = SerializerFactory.getHL7Serializer(false,false,true).toXML(responseMessageString);

    // convert the XML string into an E4X XML object
    var responseMessageXMLE4X = new XML(responseMessageXMLString);

    // grab the value you want
    var ack_msg = responseMessageXMLE4X['QRD']['QRD.4']['QRD.4.1'].toString();

    channelMap.put('ack_msg', ack_msg)
}
else
{
    // responseStatus probably == "FAILURE" but I'm not sure of the full range of possibilities
    // take whatever failure action you feel is appropriate
}

Edit**

I don't believe there is an Issue 2. After reviewing your own approach, I played a bit further, and believe I have confirmed that your approach was indeed correct for generating the SOAP reponse. I'm editing this section to reflect simpler code that still works.

In the Javascript Writer script

var barcode = channelMap.get('ack_msg');
var mirthResponse = ResponseFactory.getSuccessResponse(barcode);
responseMap.put('Barcode', mirthResponse);
1
Fylix On

Thank you very much csj,

I played around and got mine to work and looking at your solution, you pointed out my bottle neck to the issue as well which is the XML part, I did not realize you have to cast it into XML as per the new XML when you already call toXML function :)

Here is my script, though basic I thought I post it up for anyone find it useful down the road.

var destination = responseMap.get('QueryToVista');
var responseMessage = destination.getMessage();
var Xmsg = new XML(SerializerFactory.getHL7Serializer().toXML(responseMessage));

var xml_msg = '<?xml version="1.0" encoding="utf-8" ?>'+
              '<XML><Patient Name="'+Xmsg['PID']['PID.5']['PID.5.1']+
              '" Barcode="'+Xmsg['QRD']['QRD.8']['QRD.8.1']+'" /></XML>';

var sResp = ResponseFactory.getSuccessResponse(xml_msg)

responseMap.put('Response', sResp);