Announcement

Collapse
No announcement yet.

Parsing in Preprocessor

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

  • Parsing in Preprocessor

    At a remote site I'm pulling HL7 out of a database field and sending the messages to my instance of Mirth (2.2.3). Sometimes these are batch messages, but have lost some formatting for Mirth to detect they are batched. In the pre-processor script I am trying to break the message up and send them in one at a time.

    I accidentally wrote an infinite loop in our production Mirth so I wrote it in Android Studio so I could debug it and then tested it in Mirth 3.2.2, which I hope to move to soon. It seems to act like an infinite loop in Mirth 3.2.2. I get received = 1, but nothing after that. I can't stop the channel and after stopping the Mirth service I can't restart it without killing the service and starting over.

    I went back and tried this code in Mirth 2.2.3 and it works. I've attached a sample message file with three messages in it.

    var ProcessMessage = true;

    if (message.substring(0,1) != 'M') {

    message = message.substring(1);

    var SecondMsgInt = message.toString().indexOf("MSH", 4);
    var WholeMsg = message;
    var k = 0;

    if (SecondMsgInt > 0 ) {

    //router.routeMessage('Labs from Planned Parenthood', message.substring(SecondMsgInt));
    while (SecondMsgInt >= 0) {

    router.routeMessage('Labs from Planned Parenthood', WholeMsg.substring(0, SecondMsgInt));

    WholeMsg = WholeMsg.substring(WholeMsg.substring(0, SecondMsgInt).length);
    SecondMsgInt = WholeMsg.toString().indexOf("MSH", 4);

    k += 1;
    if (k === 10) {break;}
    }

    ProcessMessage = false;
    router.routeMessage('Labs from Planned Parenthood', WholeMsg);
    }

    logger.info('k: ' + k)
    }


    globalChannelMap.put('ProcessMessage',ProcessMessa ge)

    return message;
    Attached Files
    Last edited by GregD; 06-29-2015, 12:21 PM.

  • #2
    Hi Greg,

    Could it be that it has something to do with the router.routeMessage ?
    My guess is that it waits for a response e.g.
    Stefan

    Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

    Comment


    • #3
      That was my thought. That maybe the behavior has changed in 3.2.2 and it doesn't like been fed messages to itself. Either that or there is a bug. After about 2 hours of it sitting there with the received counter at one I right-clicked on the channel and saw a limited pop-up menu with 'Halt Channel' as an option. This at least allowed me to shut the channel down more gracefully.

      It is very hard to tell what is going on. logger.info statements in the loop don't print.

      Greg

      Comment


      • #4
        Only one message can go through the main message processing thread at a time. In a channel if you're routing a message to the same channel, then yes you can get into a deadlock situation.

        One way around that is to enable the source queue for your channel. That way you will be able to route the channel to itself.

        Another thing you can do is spawn a new thread and route in there:

        Code:
        new java.lang.Thread({
        	run: function() {
        		router.routeMessage('Labs from Planned Parenthood', WholeMsg);
        	}
        }).start();
        However, the best solution is probably to restructure your channel so that the self-routing isn't necessary to begin with. Have you considered using the batch script? In 3.1 and above batching is available on all source connectors and for nearly all data types, so you can always use a JavaScript batch script to stream the inbound message in and dispatch messages to the channel one at a time.
        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


        • #5
          What is a batch script? I searched the new user guide I just downloaded (MConn_v3_0_1_UserGuide.pdf) and found no mention of 'batch script' when searching?

          Just curious why this works in 2.3 and not 3.2?

          Greg

          Comment


          • #6
            The latest version of the user guide is for 3.2, not 3.0.1, so download that from the client portal for future reference. The user guide doesn't cover absolutely everything though, and batch scripting is one of those things that it merely mentions but doesn't go into great detail on.

            There are settings on the Source tab to enable batch processing (Process Batch: Yes). Then you configure the batch processing on your inbound data type (Summary -> Set Data Types). Choose "Split Batch By: JavaScript", and then click the Edit button to edit the script. There's a description there that tells you how to use it.

            What you describe doesn't quite work in 2.x either. It so happened that channels self-routing was allowed, but only so many were allowed at a time before it locked up in much the same way. It was a side effect of the messaging engine we were using at the time (Mule).
            Last edited by narupley; 06-30-2015, 08:28 AM.
            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


            • #7
              Ok, Batch Processing I know, and it doesn't work in this case because the messages lack the proper formatting. I mentioned that in the original post. I will give threading a try.

              Thanks,

              Greg

              Comment


              • #8
                If they "lack the proper formatting", then how are you possibly doing it in the preprocessor? Anything you're doing in the preprocessor can also be done in the batch script, except that with the batch script, you can correctly dispatch discrete messages one at a time without routing a channel to itself.
                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


                • #9
                  You must not have looked at the code I posted in the original post. It breaks the incoming message up in to distinct messages and sends them in one at a time using the router.routeMessage. As I said in the original post, it works in 2.3, but fails without error in 3.2.2.

                  Greg

                  Comment


                  • #10
                    The threading didn't quite work and it is too hard to debug. Using the test message that had three messages in it, the threading sent the first and third messages fine, but the second message was empty.

                    I removed the threading and just routed them to a cloned channel. All three messages were received.

                    Greg

                    Comment


                    • #11
                      I did read the code, and still assert that the batch script is where that "breaking up" can and should be done. In fact, with the text file you posted, that can be automatically batched using the standard HL7 "batch by MSH segment" option. So you don't even necessarily need to use a script.

                      To prove it, I've attached two channels. The first uses the "MSH Segment" batching, and the second uses a batch script. If you take the exact text file you posted, and run it through either channel, you'll see that it gets correctly split into three discrete messages, as intended. ■

                      As far as the problems you were having with spawning new threads... well yes, you have to know something about multi-threading to correctly use that... that's why it's only an advanced workaround and not recommended compared to using the built-in batch processing capabilities.
                      Attached Files
                      Last edited by narupley; 06-30-2015, 10:37 AM.
                      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
                        I'll need to look at your channels because the term "Batch Script" still escapes me. All I see is "Process Batch: Yes or No". When I set Process Batch to yes, as I have in two other channels I have, it does not process batch messages I pull from the database. Among other problems, when trying to convert PID.7.1 using DateUtil.convertDate() it choked because all three PID.7.1 values were passed in.

                        Thank you though, I will look at the sample channels tomorrow.

                        Greg

                        Comment

                        Working...
                        X