Announcement

Collapse
No announcement yet.

Best practises - How do I ... ? - DateTime conversion

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

  • Best practises - How do I ... ? - DateTime conversion

    Message: ADT - A04

    =======================
    Transformer for Patient's Date of Birth:

    Variable: patDOB
    Mapping: msg['PID']['PID.7']['TS.1']
    =======================

    Data in msg['PID']['PID.7']['TS.1'] is like "19460130000000"

    and needs to be converted to "01/30/1946" (mm/dd/yyyy format).

    How do I do the conversion ?

    Thanks in advance!

  • #2
    Re: Best practises - How do I ... ? - DateTime conversion

    There are three options:

    1. Using a regular expressions to break apart the string and building the date manually
    2. Using the JAVA data functions
    3. Parsing the string manually

    The *best* practice would be to use the first option:
    **************************
    Code:
    var dob = msg['PID']['PID.7']['TS.1'].text()[0];
    var ar = dob.match(/(\d\d\d\d)(\d\d)(\d\d)/);
    var dobstr = RegExp.$2 + '/' + RegExp.$3 + '/' + RegExp.$1;
    localMap.put('patDOB', dobstr);
    **************************
    Do note that you need to use a Javascript step, not a mapping step to do this.
    -Chris
    Chris Lang

    Comment


    • #3
      RegExp is better

      I tried using Date conversion utility , but failed.

      //Incoming format 2009031823180000
      //Required Output format 2009-18-08 23:18:00

      //Method that failed

      //channelMap.put('STUDY_TIME', DateUtil.convertDate( 'yyyyMMddhhmmss', 'yyyy-dd-MM hh:mm:ss', msg['ORC']['ORC.15']['ORC.15.1'].toString() ));


      //Method that is a success

      var dob = msg['ORC']['ORC.15']['ORC.15.1'].text()[0];
      var ar = dob.match(/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/);

      var dobstr = RegExp.$1 + '-' + RegExp.$3 + '-' + RegExp.$2 + ' ' + RegExp.$4 + ':' + RegExp.$5 + ':' + RegExp.$6 ;
      channelMap.put('STUDY_TIME', dobstr);

      Comment

      Working...
      X