Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Move and convert date from OBX line to OBR (http://www.mirthcorp.com/community/forums/showthread.php?t=220477)

Jaypell22 08-28-2019 09:59 AM

Move and convert date from OBX line to OBR
 
Good afternoon. I am trying to grab the date located in OBX.5 which will always follow "DATE OF SERVICE:" and convert it to YYYYMMDDHHMM date format finally inserting it into OBR.6.2. Can someone guide me in the right direction? Thanks! - Jay

OBX|1||||Referring Physician: TEST REFERRING||||||F|||20190820071530
OBX|2||||||||||F|||20190820071530
OBX|3||||Patient Name: TEST PATIENT||||||F|||20190820071530
OBX|4||||||||||F|||20190820071530
OBX|5||||RADIOLOGY REPORT:||||||F|||20190820071530
OBX|6||||||||||F|||20190820071530
OBX|7||||DATE OF SERVICE: 2019-08-20 02:56:53||||||F|||20190820071530
OBX|8||||||||||F|||20190820071530
OBX|9||||IMAGES: 2||||||F|||20190820071530
OBX|10||||||||||F|||20190820071530
OBX|11||||EXAM: XR CHEST 2V||||||F|||20190820071530
OBX|12||||||||||F|||20190820071530

ISLITM 08-28-2019 10:40 AM

This should work for you, Mirth has a built in date converter which is handy
Code:

//Loop through all OBX segments
for each (seg in msg..OBX)
{
        //Find the "DATE OF SERVICE:" line
        if (seg['OBX.5']['OBX.5.1'].toString().indexOf("DATE OF SERVICE:") != -1)
        {
                //Just get the last portion of the line
                var rawDate = seg['OBX.5']['OBX.5.1'].toString().slice(-19);

                //Convert the date
                var modifiedDate = DateUtil.convertDate("yyyy-MM-dd HH:mm:ss", "yyyyMMddHHmm", rawDate);

                //Insert the date into OBR-6.2
                msg['OBR']['OBR.6']['OBR.6.2'] = modifiedDate;

                //Exit the loop
                break;
        }
}


Jaypell22 08-28-2019 10:57 AM

Brilliant! Thank you for this. It works flawlessly. Regards


All times are GMT -8. The time now is 03:30 PM.

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