web stats
Catch an event when a file reader source begins to read a file - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2009, 11:35 AM
carles carles is offline
OBX.2 Kenobi
 
Join Date: Mar 2007
Location: Girona
Posts: 62
carles is an unknown quantity at this point
Question Catch an event when a file reader source begins to read a file

I'm doing a channel with a File Reader at source and a Database Writer at destination.
The file is a delimited one (using | as column delimiter and \n as a record delimiter)
The file contains about 400 records (the hospital census)
the channel polls for a new file every 15 minutes and "Process Batch files" are checked to "yes"

I want to put all this records in a Database table.

Till here, it seems an easy task to do with Mirth.
But, I want to perform some actions in the database table (if fact, delete all the previous records) when a new file is starting to be processed before putting records on it.

I wonder if exists an event in Mirth that can be triggered when a file is readed or begins to be readed that I could use to perform these actions.

thanks a lot.

carles massallé
Reply With Quote
  #2  
Old 04-23-2009, 01:17 PM
chrisr chrisr is offline
Mirth Employee
 
Join Date: Aug 2007
Posts: 65
chrisr is an unknown quantity at this point
Default

This is interesting, but a bit tricky. so, each time a new file is picked up, you want to truncate the database table?

I'd create two channels. Channel A picks up and reads in the entire content of the file, and re-routes it to another Channel B that processes the batch. You'll create a step in the Channel A that truncates the database table before the batch data is sent to Channel B.

That's just how I'd do it. Someone else may have a completely different approach.
__________________
Chris Ro
Sr. Software Engineer | Mirth Corporation
Reply With Quote
  #3  
Old 04-27-2009, 12:35 AM
carles carles is offline
OBX.2 Kenobi
 
Join Date: Mar 2007
Location: Girona
Posts: 62
carles is an unknown quantity at this point
Default

In fact, each time a new file is picked up (before start processing rows), I want to delete all the records on the destination table.

I'm now trying to do this with two channels, as you suggested.

I'll post here my advances.

thanks.

carles.
Reply With Quote
  #4  
Old 05-04-2009, 02:26 AM
carles carles is offline
OBX.2 Kenobi
 
Join Date: Mar 2007
Location: Girona
Posts: 62
carles is an unknown quantity at this point
Thumbs up

Finally, I've done it.

As I promised, I've attached with this post these two channels if they could be useful for someone.

Summary:
The target is feed the hospital kitchen software with current hospital census. Census are provided by HIS with a delimited file which is updated periodically.
Before insert file rows in the census kitchen database table I have to delete all previous table records.

Channel Descriptions:
- "CensCuinaFitxer":
This channel retrieves the entire content of the file in a single message (by setting "Process batch files as 'no'"). It has 3 destinations:
-- "GuardarFitxerDeCens": This destination only saves the file in other place for backup purposes.
-- "EsborraLaTaulaDeCens": This destination deletes all the content of census table before I fill it again.
-- "PartirElFitxerEnMissatges": A JavaScript transformer step on this destination splits the incoming file in messages and send them to "CensCuinaLinea" channel.

var i=0;
while (msg['row'][i] != null) {
router.routeMessage('CensCuinaLinea',msg['row'][i].toString());
i=i+1;
}

"CensCuinalLinea":
This channel process every row sent by "CensCuinaFitxer" individualy.

thanks chrisr for your useful suggestions.

carles.
Attached Files
File Type: xml CensCuinaFitxer.xml (12.3 KB, 29 views)
File Type: xml CensCuinaLinea.xml (16.1 KB, 21 views)

Last edited by carles; 05-04-2009 at 02:34 AM. Reason: minor corrections
Reply With Quote
Reply

Tags
batch, delimited, file, reader

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 07:16 AM.


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