Announcement

Collapse
No announcement yet.

Quick Custom ACK Response

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quick Custom ACK Response

    I'm working with a Cloverleaf system and Mirth Connect 1.8.2.4472 and discovered an issue with the default response ACK from a LLP Listener. It seems when choosing the default Send ACK, the default for Mesage Control ID (MSH.8.1) in the response is being sent the DATE/TIME stamp instead.

    Needless to say, this throws Cloverleaf for a loop and errors it out. Here's my fix (which may help others):

    I created a custom ACK to send back to Cloverleaf.

    1. Under the destination channel, click on Edit transformer
    2. Add a new step and change its type to Javascript
    3. Add the following code:

    Code:
    var MSH_HEAD = "MSH|^~\\&|";
    var sending_app = msg['MSH']['MSH.3']['MSH.3.1'].toString() + "|";
    var sending_facility = msg['MSH']['MSH.4']['MSH.4.1'].toString() + "|";
    var receiving_app = msg['MSH']['MSH.5']['MSH.5.1'].toString() + "|";
    var receiving_fac = msg['MSH']['MSH.6']['MSH.6.1'].toString() + "|";
    var datetime = tmp['MSH']['MSH.7']['MSH.7.1'] + "|";
    var security = tmp['MSH']['MSH.8']['MSH.8.1'] + "|";
    var ACK = "ACK" + "|";
    var MCID =  msg['MSH']['MSH.10']['MSH.10.1'].toString() + "|";
    var MCIDnoterm = msg['MSH']['MSH.10']['MSH.10.1'].toString();
    var MSHEND = "P|2.3" + "\r";
    var MSA_HEAD = "MSA|AA|";
    var MSA_END = "\r";
    var main_ack = MSH_HEAD + sending_app + sending_facility + receiving_app + receiving_fac + datetime + security + ACK + MCID + MSHEND + MSA_HEAD + MCIDnoterm + MSA_END;
    responseMap.put('MSH', ResponseFactory.getSuccessResponse(main_ack));
    4. Go back to the Source Tab
    5. Change the Send ACK to Respond from and choose MSH (the MSH is from the last line of the javascript code variable from the responseMap.put command)

    The code line
    Code:
    var MSHEND = "P|2.3";
    marks the end of the MSH line. You MAY need to force a carriage return to start the new line for MSA. If so, use:
    Code:
    var MSHEND = "P|2.3" + "\r";
    By the way, this only responses with an AA (Success). I haven't had a need to handle errors yet, but you could use this with some if...then...elses to handle that I imagine.

    I hope this helps someone!
    Last edited by 02solutions; 11-01-2011, 02:02 PM. Reason: Oops'd the MSH, from MSA

  • #2
    After a bit of testing, I found out that \n doesn't send the correct HEX code that a normal ACK uses for carriage return. Please use \r instead.

    Plus, the end of an ACK should have 0d 1c 0d as the end of the message. To accomplish this, you must add another carriage return at the end of the message (ACK).

    I've updated the code above to read correctly.

    Comment


    • #3
      I am confused. Mirth should be setting MSA.2.1 to the message control id by default. Are you sure this is not happening? I did a quick test and I am seeing the message control id being returned in MSA.2.1.

      I am using Mirth Connect 2.1.1 so that might be the difference.
      Daniel Svanstedt
      Software Engineer
      Mirth Corporation

      Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
      Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

      Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

      Comment


      • #4
        I'm sure it's not. I'm on Mirth Connect 1.8.2.4472. Here's a sample (default) ACK reply that we get:

        Code:
        MSH|^~\&|PWIM||HNAM|D_PROD|20111027231858||ACK|20111027231858|P|2.3
        MSA|AA|Q52689319T62002647X30481|Success
        Oh, and OOPS! That shouldn't read MSA.2.1, that should be MSH.8.1. Sorry.
        Last edited by 02solutions; 11-01-2011, 02:01 PM. Reason: Oops! Typos

        Comment


        • #5
          I am pretty sure the default ACK is correct. Does the original message have a MSH.10.1 value of Q52689319T62002647X30481? Then the ACK is correct.

          MSA.2.1 should be the same value as the MSH.10.1 of the message you are trying to ACK.

          You should not put the original message control id in MSH.10.1.
          Daniel Svanstedt
          Software Engineer
          Mirth Corporation

          Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
          Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

          Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

          Comment


          • #6
            In fact, ther'is a little error in MIrth's defaults ACK, but it comes with AE or AR messages.

            Mirth NACK sends the error message in MSA.3, and doesn't creates a ERR segment for it. The MSA-3 was deprecated as of v 2.4 to the ERR segment.

            Comment


            • #7
              Okay, help out the ignorant here please.

              So, MSH 10.1 isn't the Message Control ID (ST)?

              What's 7.1 supposed to be?

              Right now, on my default (not custom) ACKs they're (MSH 7.1 & 10.1) both Date/Time stamps. Is that right? Because Cloverleaf is saying it's not right.
              Last edited by 02solutions; 11-02-2011, 02:48 AM. Reason: Added text "default not custom"

              Comment


              • #8
                Here are my last 3 ACKs.
                Notice MSH.10.1. It's a timestamp. Shouldn't it be a Message control ID (Like in MSA.2.1)?


                Code:
                MSH|^~\&|PWIM||HNAM|D_PROD|20111102094728||ACK|20111102094728|P|2.3
                MSA|AA|Q53115453T62121769X53202|Success
                Code:
                MSH|^~\&|PWIM||HNAM|D_PROD|20111102094727||ACK|20111102094727|P|2.3
                MSA|AA|Q53115451T62121766X53201|Success
                Code:
                MSH|^~\&|PWIM||HNAM|D_PROD|20111102094728||ACK|20111102094728|P|2.3
                MSA|AA|Q53115453T62121769X53202|Success

                Comment


                • #9
                  MSH.10.1 is the message control id. A timestamp is a valid value for the message control id. You can use any format for this element but in general you want to use something unique.

                  The ack message should contain a new unique string in MSH.10.1. Mirth generates this based on the current timestamp. This is the intended behavior.

                  In MSA.2.1 we put the message control id of the message we are acknowledging.
                  Daniel Svanstedt
                  Software Engineer
                  Mirth Corporation

                  Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
                  Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

                  Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

                  Comment


                  • #10
                    Mirth FULL_ACK or MSA_ACK Only

                    Thanks to both of you for the code and comments. I have had an issue where are I need to respond back with only MSA|AA after testing and it's been tough getting it to work in mirth. I think last time I got some error about about using ResponseFactory.getSuccessResponse... in the postprocessor trying to code there, now I got code back in the transformer after seeing this sample.
                    Mike Caldwell
                    Alliance HealthCare - GE VAR
                    Rocklin, CA
                    Centricity PM/EMR Support - Developer - Network Engineer

                    Comment


                    • #11
                      Just to add to this, it's actually surprisingly easy to create a custom response in a postprocessor (that even has dynamic ACK codes):

                      Postprocessor
                      Code:
                      var msg = new XML(SerializerFactory.getHL7Serializer().toXML(messageObject.getRawData()));
                      var ack = <HL7Message/>;
                      ack.MSH['MSH.1'] = msg.MSH['MSH.1'].toString();
                      ack.MSH['MSH.2'] = msg.MSH['MSH.2'].toString();
                      ack.MSH['MSH.3']['MSH.3.1'] = msg.MSH['MSH.5']['MSH.5.1'].toString();
                      ack.MSH['MSH.4']['MSH.4.1'] = msg.MSH['MSH.6']['MSH.6.1'].toString();
                      ack.MSH['MSH.5']['MSH.5.1'] = msg.MSH['MSH.3']['MSH.3.1'].toString();
                      ack.MSH['MSH.6']['MSH.6.1'] = msg.MSH['MSH.4']['MSH.4.1'].toString();
                      ack.MSH['MSH.7']['MSH.7.1'] = msg.MSH['MSH.7']['MSH.7.1'].toString();
                      ack.MSH['MSH.8']['MSH.8.1'] = msg.MSH['MSH.8']['MSH.8.1'].toString();
                      ack.MSH['MSH.9']['MSH.9.1'] = 'ACK';
                      ack.MSH['MSH.10']['MSH.10.1'] = msg.MSH['MSH.10']['MSH.10.1'].toString();
                      ack.MSH['MSH.11']['MSH.11.1'] = 'P';
                      ack.MSH['MSH.12']['MSH.12.1'] = '2.3';
                      ack.MSA['MSA.1']['MSA.1.1'] = function(status) {
                      	if (status == 'SUCCESS') return 'AA';
                      	if (status == 'FILTERED') return 'AR';
                      	return 'AE';
                      }($r('Destination 1').getStatus());
                      
                      responseMap.put('ACK',ResponseFactory.getSuccessResponse(SerializerFactory.getHL7Serializer().fromXML(ack)));
                      return;
                      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.

                      Comment


                      • #12
                        Fixed the ACK problem - Custom ACK

                        Anytime I tried to use java code for a Custom ACK in the post processor I kept getting an error. Never figured out why.

                        But I finally fixed the problem I was having with another system. It didn't like MSH's ACKed back. I ended up adding this javacode to the transformation of the Destination channel on the Destination Tab. I just needed something simple to send an MSA back and it worked great:

                        var MSA_HEAD = "MSA|AA|";
                        var MCIDnoterm = msg['MSH']['MSH.10']['MSH.10.1'].toString();
                        var MSA_END = "\r";
                        var mas_ack = MSA_HEAD + MCIDnoterm + MSA_END;
                        responseMap.put('MSA_ACK_ONLY', ResponseFactory.getSuccessResponse(msa_ack));

                        then on the source tab I selected Custom ACK and picked MSA_ACK_ONLY
                        Mike Caldwell
                        Alliance HealthCare - GE VAR
                        Rocklin, CA
                        Centricity PM/EMR Support - Developer - Network Engineer

                        Comment


                        • #13
                          Again thanks 02solutions, you helped me build an answer to my problem and I learned alot more about the whole ACK process but mainly the code sent my right down the right path that I am sure I will need in the future.
                          Mike Caldwell
                          Alliance HealthCare - GE VAR
                          Rocklin, CA
                          Centricity PM/EMR Support - Developer - Network Engineer

                          Comment

                          Working...
                          X