Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Best practises - How do I ... ? - DateTime conversion (http://www.mirthcorp.com/community/forums/showthread.php?t=454)

nshaik 09-14-2006 07:10 AM

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!

chrisl 09-14-2006 11:02 AM

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

kashif 10-22-2009 06:29 AM

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);


All times are GMT -8. The time now is 05:40 AM.

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