web stats
Create Mirth Filter for Messages older then 48 hours - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2015, 08:16 AM
dhaines dhaines is offline
What's HL7?
 
Join Date: Mar 2015
Posts: 1
dhaines is on a distinguished road
Unhappy Create Mirth Filter for Messages older then 48 hours

I am developing a filter that will disregard any messages that are older then 48 hours.

However I am having some difficulty comparing the actual time of the message with the system time.

I was thinking DateUtil would be acceptable but need some serious help. Here is what i am trying to do


Code:
 var date = DateUtil.getCurrentDate("yyyyMMddHHmm");
var checkTime = msg['MSH']['MSH.9']['MSH.9.2'].toString();

checkTime = DateUtil.convertDATE("yyyyMMddHHmm","yyyyMMddHHmm",checkTime)
I need to compare
Code:
date
with
Code:
checkTime
Anything older then 48 hours will be filtered....

Something like

Code:
if(checkTime.getHours() - date.getHours() >=48)
is this possible with DateUtil?

Thanks in advance for any help!

Last edited by dhaines; 05-06-2015 at 08:18 AM.
Reply With Quote
  #2  
Old 05-06-2015, 08:28 AM
rodrosa rodrosa is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 79
rodrosa is on a distinguished road
Default

this code should work

(Filter)

Code:
var minDate = org.joda.time.format.DateTimeFormat.forPattern('yyyyMMddHHmm').print((new org.joda.time.DateTime()).minusDays(2))

if(msg['MSH']['MSH.9']['MSH.9.2'].toString() < minDate){
return false;
}

return true;
Reply With Quote
  #3  
Old 05-06-2015, 08:35 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

Yep, very easy to do with DateUtil:

Code:
var messageDate = DateUtil.getDate("yyyyMMddHHmm", msg['MSH']['MSH.7']['MSH.7.1'].toString()).getTime();
return ((Date.now() - messageDate) / 86400000) < 2;
Or with Joda Time:

Code:
var messageDateTime = org.joda.time.format.DateTimeFormat.forPattern('yyyyMMddHHmm').parseDateTime(msg['MSH']['MSH.7']['MSH.7.1'].toString());
return new org.joda.time.Period(messageDateTime, new org.joda.time.DateTime()).getDays() < 2;
__________________
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
  #4  
Old 09-13-2016, 02:08 PM
telshayal telshayal is offline
Mirth Newb
 
Join Date: Nov 2013
Posts: 22
telshayal is on a distinguished road
Default

Narupley,

When I use the DateUtil Javascript I get the error below although I an seeing that the date format is conforming with the Date/time sent.
I am trying to suppress any result messages if date/time of OBR22.1 is older than n days say 30 days. I am using Mirth 3.4.1


Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: HIE Passthrough
CONNECTOR: HIE TEST
SCRIPT SOURCE: TRANSFORMER
SOURCE CODE:
44: msg = new XML(connectorMessage.getTransformedData());
45: if (msg.namespace('') != undefined) { default xml namespace = msg.namespace(''); } else { default xml namespace = ''; }
46: function doFilter() { phase[0] = 'filter'; return true; }function doTransform() { phase[0] = 'transformer'; logger = Packages.org.apache.log4j.Logger.getLogger(phase[0]);
47:
48:
49: var messageDate = DateUtil.getDate("yyyyMMddHHmmss", msg['OBR']['OBR.22']['OBR.22.1'].toString()).getTime();
50: return ((Date.now() - messageDate) / 86400000) < 2;
51: if ('xml' === typeof msg) {
52: if (msg.hasSimpleContent()) {
53: msg = msg.toXMLString();
LINE NUMBER: 49
DETAILS: Wrapped java.text.ParseException: Unparseable date: "<OBR.22.1>20120913132400</OBR.22.1><OBR.22.1>20120913132400</OBR.22.1>"
at a165c5c6-aa14-4019-8864-9b174226d27a:49 (doTransform)
at a165c5c6-aa14-4019-8864-9b174226d27a:72 (doScript)
at a165c5c6-aa14-4019-8864-9b174226d27a:74
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:154)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:119)
at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.text.ParseException: Unparseable date: "<OBR.22.1>20120913132400</OBR.22.1><OBR.22.1>20120913132400</OBR.22.1>"
at java.text.DateFormat.parse(Unknown Source)
Reply With Quote
  #5  
Old 09-13-2016, 02:16 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

You're just referencing "msg['OBR']['OBR.22']['OBR.22.1']", but you probably have multiple OBRs in your message. It doesn't know which one you want so it grabs the OBR.22.1 value from both. Either iterate through your OBR segments, or choose one specifically with an [i] index.
__________________
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
datetime, filter, hl7

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 04:43 AM.


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