web stats
getFullYear method for Date - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-25-2013, 12:36 PM
anand14 anand14 is offline
OBX.2 Kenobi
 
Join Date: Dec 2006
Posts: 54
anand14
Default getFullYear method for Date

I searched the forums before I posted this.

We are using Mirth 2.1.1.5490 on a V1000 VM and all I am trying to do is compare two dates (the dates are formatted correctly and my script works perfectly on jsfiddle and jsbin). The variables date1 and date2 are correctly formatted.



function dateDiff (date1, date2) {
//Using UTC time gets rids of DayLight savings issues
//We want to check if the DOB in PID.7 is less than 72 hours
//
date1 = Date.UTC(date1.getFullYear(), date1.getMonth(), date1.getDate());
date2 = Date.UTC(date2.getFullYear(), date2.getMonth(), date2.getDate());
var ms = Math.abs(date1-date2);
var diffinDays = Math.floor(ms/1000/60/60/24);


return diffinDays;
}

When I move the script to my TEST Mirth channel, I get a Transformer error.

This is the error message:

TypeError: Cannot call method "getFullYear" of undefined (com.mirth.connect.server.MirthJavascriptTransform erException) (org.mule.umo.transformer.TransformerException)
com.mirth.connect.server.mule.transformers.JavaScr iptTransformer:410 (http://mule.codehaus.org/docs/apidoc...Exception.html)
************************************************** ******************************
Root Exception stack trace: <blah >
DETAILS:
TypeError: Cannot call method "getFullYear" of undefined




It seems like getFullYear() is not supported or do I need another library.

Thanks
-AR
Reply With Quote
  #2  
Old 03-25-2013, 12:40 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

The issue is not that getFullYear() isn't supported (it is), it's that you're trying to call it on an undefined variable (either date1 or date2).
__________________
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
  #3  
Old 03-25-2013, 12:53 PM
anand14 anand14 is offline
OBX.2 Kenobi
 
Join Date: Dec 2006
Posts: 54
anand14
Default

Thanks!
But that is why I wrote in my post that the code is working on JSFIDDLE and JSBIN. Of course, I had to modify the document.write on JSFIDDLE vs logger.info on Mirth to print my values to screen.

On Mirth, the logger.info statement does not work on our instance (maybe because of the apparent error) but I figure if the logger statements are upstream of the error, it should at least output the values before it errors.

Thank you
Reply With Quote
  #4  
Old 03-25-2013, 12:58 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Quote:
Originally Posted by anand14 View Post
Thanks!
But that is why I wrote in my post that the code is working on JSFIDDLE and JSBIN. Of course, I had to modify the document.write on JSFIDDLE vs logger.info on Mirth to print my values to screen.

On Mirth, the logger.info statement does not work on our instance (maybe because of the apparent error) but I figure if the logger statements are upstream of the error, it should at least output the values before it errors.

Thank you
Can you post the channel you're using? Also regarding the INFO logs, make sure your channel log level is set to at least INFO (in the Server Manager or in log4j.properties), otherwise those won't show up in the server log.
__________________
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 03-26-2013, 04:18 AM
anand14 anand14 is offline
OBX.2 Kenobi
 
Join Date: Dec 2006
Posts: 54
anand14
Default

Hi Nick,
I found the issue. It was my extract from the HL7 message on Mirth.


I was able to change the Mirth Connect settings to "INFO" and check the value of the
variable being used

var PID7 = msg['PID']['PID.7']['PID.7.1'].toString();


logger.info("The value of PID7 is" +PID7);
//clean up XML tags for PID7
PID7 = PID7.replace(/PID7\.(\.\d+)?/g, '');
PID7 = PID7.replace(/>/g, '');
PID7 = PID7.replace(/</g, '');

The method getFullYear() is not the issue but the value of the variable was.

Thanks for your time!
Reply With Quote
Reply

Tags
date, getfullyear

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


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