web stats
Yesterday's Date Filename - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2012, 12:48 PM
rmcginness rmcginness is offline
What's HL7?
 
Join Date: Nov 2011
Posts: 5
rmcginness is on a distinguished road
Cool Yesterday's Date Filename

Greetings,

I have spent more hours than I care to admit trying to figure out how to create my own custom Destination Mapping variable for a "Date -1"

scenario. I have only found javascript code examples but there is no step by step instructions on where to place the code and how to execute.

Details: FTP source to an FTP destination no tranformation scrictly passing data.

I am using Mirth Connect Version 2.1.1.5490

I would greatly appreciate any help. Thanks in advance!
Reply With Quote
  #2  
Old 03-14-2012, 06:10 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

If you're dealing with a java.util.Date, I believe you can do something like Date.setTime(Date.getTime()-(1000*60*60*24)). Even better though is to use a java.util.Calendar object. Then you can just call .add(Calendar.DATE,-1).

From there, you can either invoke a SimpleDatePattern yourself, or use DateUtil to convert the date to a string specified by an output pattern.
Reply With Quote
  #3  
Old 03-15-2012, 01:50 AM
StefanScholte StefanScholte is offline
 
Join Date: May 2009
Location: Netherlands, Harderwijk
Posts: 321
StefanScholte is on a distinguished road
Default

Here's what I needed a while ago.

Code:
var kalender = java.util.Calendar.getInstance();
kalender.add(java.util.Calendar.DATE, -1);

//format: yyyyMMdd
var date = kalender.get(kalender.YEAR).toString()+ZeroPadLeft((kalender.get(kalender.MONTH)+1).toString(), 2)+ZeroPadLeft(kalender.get(kalender.DATE).toString(), 2) + "";
ZeroPadLeft is used to fill the leading zero's (selfmade function)
the reason I use + "" at the end is to ensure it is a javascript string rather than a java string object.
Reply With Quote
  #4  
Old 06-13-2012, 03:36 PM
albac albac is offline
What's HL7?
 
Join Date: Oct 2010
Posts: 1
albac is on a distinguished road
Default

Thanks! I just needed this for a filename, in the source transformer.
You can use getTime() and DateUtil.formatDate instead of your ZeroPadLeft function as in the following code:

Code:
var kalender = java.util.Calendar.getInstance();
kalender.add(java.util.Calendar.DATE, -1);

//format: yyyyMMdd
var yesterday = DateUtil.formatDate("yyyyMMdd",kalender.getTime());
Reply With Quote
  #5  
Old 08-16-2012, 12:30 PM
rmcginness rmcginness is offline
What's HL7?
 
Join Date: Nov 2011
Posts: 5
rmcginness is on a distinguished road
Default Yesterday's Date Filename

What I am trying to do is use the "Destination Mappings" variables under the destinations tab to create a filename with yesterday's date for the output.

I have tried adding "-1" to this example below but doesn't work.

Example: myfile_${date.get('yyyy-M-d H.m.s')}
Reply With Quote
  #6  
Old 08-16-2012, 12:35 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

You could probably do this in the template by calling date.getDate(), etc. But an easier way is to add a transformer step that puts your pre-formatted date string into the connector map. Then, you'll be able to drag it over from the Destination Mappings frame.
__________________
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
  #7  
Old 09-06-2012, 10:28 AM
rmcginness rmcginness is offline
What's HL7?
 
Join Date: Nov 2011
Posts: 5
rmcginness is on a distinguished road
Default

I'm not sure what to put in the Transformer step (mapping field) to return yesterdays date formatted. Do you have an example. Thanks in advance.

I can't upload the channel as it exceeds the max file size. Version is 2.1.1.5490

Last edited by rmcginness; 09-06-2012 at 01:15 PM.
Reply With Quote
  #8  
Old 09-06-2012, 05:10 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Just create a JavaScript transformer step, and place your date string in a map variable. Here's an example using Joda:

Code:
$co('yesterday',org.joda.time.format.DateTimeFormat.forPattern('yyyyMMdd').print((new org.joda.time.DateTime()).minusDays(1)));
Then you can include it in your filename with the following Velocity reference:

Code:
${yesterday}
__________________
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 10-29-2014, 07:01 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

I would LOVE to be able to get yesterday's date BEFORE looking for a file.

Scenario: I have a dir with several files each containing the date. "Created_File_20141028" is an example. right now I have channels set to run at 12:10 am and check file age at 600000 ms.

Is it possible to look for a file with the previous date in the filename? Like "Created_File_$(yesterday)" or something.

Or would it be best to do all this in a Javascript channel?
Reply With Quote
  #10  
Old 10-29-2014, 07:07 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Quote:
Originally Posted by appsbyaaron View Post
I would LOVE to be able to get yesterday's date BEFORE looking for a file.

Scenario: I have a dir with several files each containing the date. "Created_File_20141028" is an example. right now I have channels set to run at 12:10 am and check file age at 600000 ms.

Is it possible to look for a file with the previous date in the filename? Like "Created_File_$(yesterday)" or something.

Or would it be best to do all this in a Javascript channel?
Right now, the File Reader fields are only replaced once when the channel is deployed. So it would work the first time, but perhaps not subsequent times. We have an issue for that: MIRTH-3131.

In the meantime, unfortunately yeah it would have to be done with a JavaScript Reader instead. Assuming you're just reading from the local filesystem, FileUtils makes it really easy though.

Of course the File Age method works as well.
__________________
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
Reply

Tags
date, destination, filename, mappings, yesterday

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


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