web stats
Parsing in Preprocessor - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-29-2015, 11:04 AM
GregD GregD is offline
Mirth Guru
 
Join Date: May 2010
Posts: 234
GregD is on a distinguished road
Default 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 Images
File Type: png Loop.png (3.2 KB, 11 views)
Attached Files
File Type: txt PP3.txt (7.3 KB, 13 views)

Last edited by GregD; 06-29-2015 at 12:21 PM.
Reply With Quote
  #2  
Old 06-30-2015, 05:08 AM
StefanScholte StefanScholte is offline
 
Join Date: May 2009
Location: Netherlands, Harderwijk
Posts: 321
StefanScholte is on a distinguished road
Default

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.
Reply With Quote
  #3  
Old 06-30-2015, 06:54 AM
GregD GregD is offline
Mirth Guru
 
Join Date: May 2010
Posts: 234
GregD is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 06-30-2015, 08:05 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 06-30-2015, 08:11 AM
GregD GregD is offline
Mirth Guru
 
Join Date: May 2010
Posts: 234
GregD is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 06-30-2015, 08:25 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

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).
__________________
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.

Last edited by narupley; 06-30-2015 at 08:28 AM.
Reply With Quote
  #7  
Old 06-30-2015, 08:46 AM
GregD GregD is offline
Mirth Guru
 
Join Date: May 2010
Posts: 234
GregD is on a distinguished road
Default

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
Reply With Quote
  #8  
Old 06-30-2015, 08:49 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

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.
Reply With Quote
  #9  
Old 06-30-2015, 09:13 AM
GregD GregD is offline
Mirth Guru
 
Join Date: May 2010
Posts: 234
GregD is on a distinguished road
Default

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
Reply With Quote
  #10  
Old 06-30-2015, 09:55 AM
GregD GregD is offline
Mirth Guru
 
Join Date: May 2010
Posts: 234
GregD is on a distinguished road
Default

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
Reply With Quote
Reply

Tags
preprocessor

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:53 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation