No announcement yet.

response transformer in 3.1

  • Filter
  • Time
  • Show
Clear All
new posts

  • response transformer in 3.1


    In 3.0 I had some logic that stored a copy of the message in a channelMap and then later in a response transformer accessed the message to built an email which provided alerts for errors. When moving this logic to 3.1 however I am getting errors.

    << In Destination Transformer >>

    << in Response Transformer >>
    		// send email alert
    		var srcMsg = channelMap.get('srcMsg');
    		var msgType = srcMsg['MSH']['MSH.9']['MSH.9.1'].toString() + ' ' + srcMsg['MSH']['MSH.9']['MSH.9.2'].toString();
    		var body = 'This is an automated email, please do not reply. \n\n';
    .. etc ..
    error Msg:

    100: var srcMsg = channelMap.get('srcMsg');
    101: var msgType = srcMsg['MSH']['MSH.9']['MSH.9.1'].toString() + ' ' + srcMsg['MSH']['MSH.9']['MSH.9.2'].toString();

    .. etc ..

    LINE NUMBER: 101
    DETAILS: TypeError: Cannot read property "MSH.9" from undefined
    at 0d9e48e6-b940-4ba0-bd6b-8c49b9e929b5:101 (doTransform)
    at 0d9e48e6-b940-4ba0-bd6b-8c49b9e929b5:121 (doScript)

    Do I have to run some sort of conversion in 3.1.. If I dump the srcMsg out to log I can see its intact in xml form.

  • #2
    It probably doesn't have to do with your upgrade, but instead has to do with destination queuing. Realize that message data (including channel map values) get converted to strings when persisted to the database. If the connector message never goes out of memory then any Object values in the channel map should remain intact. However if a message gets queued and then you redeploy the channel, the original Object is lost, and instead the channel pulls from whatever is in the database. If the value is serializable then everything should be okay. However if it's not (like with an E4X XML object), then it will just be a String the second time around.

    In your response transformer, you can convert the XML string to an E4X XML object with the new XML() constructor.
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

    - How do I foo?
    - You just bar.


    • #3
      I am having a similar issue with a response transformer in Mirth Connect 3.1. The original transformer gets the response message and writes it to a log file. Now my customer wants me to look into the content of the message and log details.

      The channel sends orders (OML^O33) and receives acknowledgement messages (ORL^O34).

      Here is the code of my transformer:

      if (response.getMessage() != '')
      LogReceivedData("Response to Patient Order", response.getMessage());

      var xmlMsg = SerializerFactory.getSerializer('HL7V2').toXML(res ponse.getMessage());"Response Raw: " + response.getMessage());"Response Xml: " + xmlMsg);
      // This line causes the crash
      var responseCode = xmlMsg['MSA']['MSA.1']['MSA.1.1'].toString();

      if (responseCode == "AA")
      var orderControlId = xmlMsg['ORC']['ORC.1']['ORC.1.1'].toString();
      var orderId = xmlMsg['ORC']['ORC.2']['ORC.2.1'].toString()
      var orderStatus = xmlMsg['ORC']['ORC.5']['ORC.5.1'].toString();"Order: " + orderId + " Control code: " + orderControlId + " orderStatus: " + orderStatus);

      I see the raw HL7 in the first logger message and the XML in the second logger statement. When I try to access the contents of the XML message, I get the error "TypeError: Cannot read property "MSA.1" from undefined" buried in a huge java stack dump.

      Having trouble seeing what I'm doing wrong.

      Thanks in advance for any help.


      I have a fix. Don't fully understand why it works, but it does.

      After I transformed the raw message into XML, I created a new XML object and I was able to get what I wanted from the message.

      Here is the updated transformer.

      if (response.getMessage() != '')
      // Send to received message log.
      LogReceivedData("Response to Patient Order", response.getMessage());

      // Get the message as XML.
      var xmlMsg = SerializerFactory.getSerializer('HL7V2').toXML(res ponse.getMessage());

      // This line fixed the issue.
      var reply = new XML(xmlMsg);

      var responseCode = reply['MSA']['MSA.1']['MSA.1.1'].toString();
      if (responseCode == "AA")
      var orderControlId = reply['ORC']['ORC.1']['ORC.1.1'].toString();
      var orderId = reply['ORC']['ORC.2']['ORC.2.1'].toString()
      var orderStatus = reply['ORC']['ORC.5']['ORC.5.1'].toString();"Order: " + orderId + " Control code: " + orderControlId + " Order Status: " + orderStatus);
      Last edited by gkberkheiser; 05-29-2015, 05:31 AM. Reason: Fixed the issue


      • #4
        Here you can find the explanation why your additional line solves the error (thanks Narupley).

        "The toXML method returns a String representation of the XML. In order to access the child nodes within the XML, you'll have to convert that string to an E4X XML object: