web stats
How to send multiple files at different schedule time within one channel - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-21-2020, 10:09 AM
MirthGuy2019 MirthGuy2019 is offline
Mirth Newb
 
Join Date: Feb 2020
Posts: 7
MirthGuy2019 is on a distinguished road
Default How to send multiple files at different schedule time within one channel

Hi folks,

I'm a newbie here. So I have two files need to be scheduled deliver at a different times. Is is doable to accomplish this within one channel?

For example, I have EMPLOYEE.csv to be scheduled on the 1st of each month. And I have another file PHYSICIAN.csv to be scheduled on the 15th of each month.

I can build two separate channels: one for EMPLOYEE and one for PHYSICIAN, and we're all done. But I want to know if it is possible to combine both EMPLOYEE and PHYSICIAN in just "one" channel so that on the 1st, it will send EMPLOYEE.csv to the customer. And on the 15th, it will send PHYSICIAN.csv to customer.

Thank you. I really appreciated
Reply With Quote
  #2  
Old 02-21-2020, 11:42 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,360
cory_cole is on a distinguished road
Default

Yes. Create a file reader that reads both files and in the filter

if(file == customer.csv and date == 1st)
{
true;
}
else if(file ==pharmacy.csv and date == 15th)
{
true;
}
else
{
false;
}
Reply With Quote
  #3  
Old 02-21-2020, 04:56 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,159
agermano is on a distinguished road
Default

That might work, but there are risks with doing it that way.

You'll always be reading in both files, even if you only process one of them. If you do any move or delete operations after reading the file they will apply to the filtered files as well.

You could get around that by calling an object that dynamically generates the filename filter based on the current date.

Try this in your channel deploy script (modify as necessary)
Code:
function createFilenameProvider() {
	function getName(dayOfMonth) {
		if (dayOfMonth >= 15) return 'PHYSICIAN.csv';
		return 'EMPLOYEE.csv';
	}

	function toString() {
		return getName(java.time.LocalDate.now().dayOfMonth);
	}

	return new JavaAdapter(java.lang.Object, {
		getName: getName,
		toString: toString
	});
}

// create instance and put in globalChannelMap
$gc('nameProvider', createFilenameProvider());
Then use ${nameProvider} for your Filename Filter Pattern (this will implicitly call the object's toString method.) Schedule with a cron type that only runs at the time you want on the 1st and 15th. This would run at 3am on the 1st and 15th of every month.
Code:
0 0 3 1,15 * ?
It's set up to return EMPLOYEE.csv if run from the 1st through the 14th of the month, and PHYSICIAN.csv on the 15th or later. If you have an error and need to run it again within a few days of it being missed, you could switch the job to poll on start, run it once, and turn the option back off without needing to modify any code.

If you wanted to run it for a specific day you could change the Filename Filter Pattern to ${nameProvider.getName(1)} to force running as if it were the 1st of the month, even if the real date is after the 15th.

The reason that a JavaAdapter is used here rather than a regular javascript object is because velocity can't invoke javascript functions directly (at least I haven't been able to get them to work.)
Reply With Quote
  #4  
Old 02-24-2020, 10:12 AM
MirthGuy2019 MirthGuy2019 is offline
Mirth Newb
 
Join Date: Feb 2020
Posts: 7
MirthGuy2019 is on a distinguished road
Default

Thank you for your help.
Reply With Quote
Reply

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:34 AM.


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