web stats
Convert date regardless of incoming pattern - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2018, 11:27 AM
OmarAQ OmarAQ is offline
What's HL7?
 
Join Date: Sep 2018
Posts: 3
OmarAQ is on a distinguished road
Default Convert date regardless of incoming pattern

Hi all;

I am new to Mirth with very little java script knowledge.

I am creating a channel to send an ORM to a PACS server in order to create a MWL, I managed to do so, but there is one problem, I cannot change the date format to: yyyyMMdd.

I searched the forums and found posts talking about this, using the DateUtil.convertDate, but the date I am getting after using it is incorrect (it changes the outcome to yyyyMMdd but not to the correct date).

I think that its because I receive date in multiple formats, mostly as dd-MMM-yy, sometimes as MM/dd/yyyy.

I found below method posted by naruply that changes the format regardless of the inbound message date/time to a specific pattern, no matter what pattern it comes in.

http://www.mirthcorp.com/community/f...1&postcount=27

I am stuck here, as I really don`t know what to do with this code, I tried using it in the script section, but I always get: ReferenceError: "convertDate" is not defined.

Would you please help me in this issue.
Reply With Quote
  #2  
Old 09-14-2018, 12:37 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 435
agermano is on a distinguished road
Default

In the Channels screen, on the left you will see "Edit Code Templates." Go there, and create a new Code Template Library and associate it with any channels that need the function. Then create a new Code Template in your Library and paste "The Code" from the forum post you linked.

After that, you should be able to call convertDate from your transformer.

Download the user guide from the mirth downloads page for more information. It has pictures.
Reply With Quote
  #3  
Old 09-15-2018, 01:25 AM
OmarAQ OmarAQ is offline
What's HL7?
 
Join Date: Sep 2018
Posts: 3
OmarAQ is on a distinguished road
Default

Thanks agermano, I did exactly as you said, added more date patterns to the list, assigned it to the source connector, and managed to drag and drop it from the user defined functions in my transformer, I am not receiving any errors now, but its removing the date from the outbound message instead of converting it.

My test channel is attached for your kind input.
Attached Files
File Type: xml Test1.xml (28.2 KB, 1 views)
Reply With Quote
  #4  
Old 09-17-2018, 10:58 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 435
agermano is on a distinguished road
Default

Try this as your Message Segment.

Code:
tmp['PID']['PID.7']['PID.7.1']
Your Mapping should probably also be only
Code:
convertDate(msg['row']['Date_of_Birth'].toString(),'yyyyMMdd')
but it may work the way you have it.

Edit - I removed the row index after msg['row']. Since you have batch processing enabled on your source connector, you will only ever have one row at a time. If you change your inbound template to only have one row, the drag-and-drop won't include the row index either.

Last edited by agermano; 09-17-2018 at 01:53 PM. Reason: removed row index
Reply With Quote
Reply

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 12:15 AM.


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