web stats
Cache results in a Mirth channel that performs batch processing - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-2017, 02:35 AM
vibinChander vibinChander is offline
OBX.2 Kenobi
 
Join Date: Jul 2015
Location: Chennai
Posts: 74
vibinChander is on a distinguished road
Send a message via Skype™ to vibinChander
Default Cache results in a Mirth channel that performs batch processing

I'm stuck with a problem in Mirth. I have a Mirth channel that will receive a .csv file I'm performing a batch process in that channel. So, channel will read each row in the .csv file. I'm communicating each row and transforming into SOAP to communicate to other end. This is working fine.

I wanted to consolidate all the rows from the .csv file again and create a new .csv file and send it as a attachment to the sender. I figured out a way to attach .csv file and send in mail. But I cannot consolidate the rows (cache the row results) in the same channel.

Please let me know how to do this?
__________________

Mirth Interface Engineer
AWS DevOps
Reply With Quote
  #2  
Old 05-02-2017, 02:53 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

When a row gets successfully processed, you can append it to a variable scoped to a channel Map. Once everything is done, you can send that variable as a template to your Email sender.
Reply With Quote
  #3  
Old 05-02-2017, 03:34 AM
vibinChander vibinChander is offline
OBX.2 Kenobi
 
Join Date: Jul 2015
Location: Chennai
Posts: 74
vibinChander is on a distinguished road
Send a message via Skype™ to vibinChander
Default

Hi Siddharth,

The problem is that the channel map variable is re-setting everytime with the new row value.

Eg: when the first row value is inserted, it is holding the first row value then for the second row it is holding the second row value alone. But not the first row values
__________________

Mirth Interface Engineer
AWS DevOps
Reply With Quote
  #4  
Old 05-02-2017, 07:14 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

Sure, this is technically possible within one channel, but you'd have to be willing to cache messages in memory so you can send it all consolidated at the end.

In your deploy script, initialize a map:

Code:
if (!globalChannelMap.containsKey('csvMap')) {
    $gc('csvMap', Maps.map());
}
In your preprocessor, add each message to a consolidated CSV (essentially un-batching your batch message):

Code:
var csvMap = $('csvMap');
var batchId = $('batchId');
if ($('batchSequenceId') == 1) {
    csvMap.put(batchId, new java.lang.String(message));
} else {
    csvMap.put(batchId, csvMap.get(batchId).concat(message));
}
return message;
Then on your SMTP Sender destination, add a filter rule so it only triggers when the last message in a batch is processing:



On the same destination, add a transformer step that pulls the consolidated CSV out of the global channel map and sets the transformed data to it:

Code:
msg = SerializerFactory.getSerializer('DELIMITED').toXML($('csvMap').remove($('batchId')));
And there you go. Your channel will continue to process one row at a time, but when it's processing the last row in a batch, it will also trigger this other destination. I'll attach the channel (exported from 3.5.0) for illustration.

Of course, another perhaps saner way to do this would be to split it up into two channels. The upstream channel does not do any batching, but sends to your downstream channel as well as sending that e-mail. The downstream channel would have batching enabled, and that's where you'd move your Web Service Sender.
Attached Files
File Type: xml Example - Consolidate CSV.xml (24.1 KB, 11 views)
__________________
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 07-17-2018, 02:43 AM
Pkt Pkt is offline
What's HL7?
 
Join Date: Jul 2018
Posts: 2
Pkt is on a distinguished road
Default Request

Can you provide me this channel og yours ? please
Reply With Quote
  #6  
Old 07-17-2018, 02:44 AM
Pkt Pkt is offline
What's HL7?
 
Join Date: Jul 2018
Posts: 2
Pkt is on a distinguished road
Default Request

Can you provide me this channel?
Reply With Quote
Reply

Tags
batch process, csv, mirth 3.1

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 12:22 AM.


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