Announcement

Collapse
No announcement yet.

Create Mirth Filter for Messages older then 48 hours

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 08:18 AM.

  • #2
    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;

    Comment


    • #3
      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.

      Comment


      • #4
        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)

        Comment


        • #5
          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.

          Comment

          Working...
          X