web stats
How to translate/escape & character? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-06-2019, 01:40 PM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default How to translate/escape & character?

We have a system sending us an ampersand character and it's causing issues downstream.

I am trying to write a transformer to translate the "&" to something else ("and" or "-", whatever...) but when I write Javascript to catch the value in AIS.3.1 it is not catching anything. It's as if the & is causing the field to be missed, so it seems.


The transformer below already existed and was written by a Mirth employee a while back. You'd think this would work based on that ,but like my JS it seems to be ignored by the channel.

Neither are throwing errors. The message just goes through and the field does not get translated at all.

This is the problematic segment:

AIS|1||Rapid Arc H & N^Rapid Arc H \T\ N|20191206100000|||30|


This is the code from the Mirth rep:

Code:
switch (msg['AIS']['AIS.3']['AIS.3.1'].toString() + "") {
                case "Rapid Arc H & N":
                                msg['AIS']['AIS.3']['AIS.3.1'] = "Rapid Arc H and N";
                                break;                  

               default: break;

}

This is my JS:

Code:
if

(
msg['AIS']['AIS.3']['AIS.3.1'] == "Rapid Arc H & N"
)
{msg['AIS']['AIS.3']['AIS.3.1'] == "Rapid Arc H and N"
)
}
Can anybody explain why neither of these are working? The "&" appears to make the field unreadable, but I'm not sure how to catch it within the field otherwise. I tried adding the 2nd subcomponent (^Rapid Arc H \T\ N) but that didn't make a difference. I didn't think it would since I'm looking specifically to AIS.3.1 in the first place, but had to try.
Reply With Quote
  #2  
Old 12-06-2019, 01:56 PM
jackwhaines jackwhaines is offline
 
Join Date: May 2011
Location: Kansas City, Missouri
Posts: 254
jackwhaines is on a distinguished road
Send a message via Skype™ to jackwhaines
Default

Maybe check the Data Types tab and see if you are parsing subcomponents. If you are, that treats the & like a |. If you disable this, it will treat & like a normal text character and you can manipulate the field at will.
__________________

-= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
-= jack.haines@HealthcareIntegrations.com
-= Mirth Connect (Advanced)-certified
-= Gold member of HL7.org
-= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines
Reply With Quote
  #3  
Old 12-06-2019, 02:11 PM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default

Well that definitely worked! Thanks, I wasn't familiar w/that setting.

Now that is pretty good for now, though I have to consider future needs and whether or not we'll actually want to parse the & separator. I can't imagine the needs would change on his interface, but you never know.

Considering either sets of code I provided above, is there any way I could expand on either to catch that & character while parsing subcomponents? *If* I could have it both ways, I think that would be best.
Reply With Quote
  #4  
Old 12-06-2019, 02:17 PM
jackwhaines jackwhaines is offline
 
Join Date: May 2011
Location: Kansas City, Missouri
Posts: 254
jackwhaines is on a distinguished road
Send a message via Skype™ to jackwhaines
Default

Most channels either need it, or they don't. When it IS parsed, and an & exists, it splits msg['AIS']['AIS.3']['AIS.3.1'] to msg['AIS']['AIS.3']['AIS.3.1']['AIS.3.1.1'] and msg['AIS']['AIS.3']['AIS.3.1']['AIS.3.1.2']. You could always leave it default, then check for the length of msg['AIS']['AIS.3']['AIS.3.1'] and if it's > 1, do what you need to with it, but it rarely worth all that... Your call though!
__________________

-= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
-= jack.haines@HealthcareIntegrations.com
-= Mirth Connect (Advanced)-certified
-= Gold member of HL7.org
-= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines
Reply With Quote
  #5  
Old 12-06-2019, 04:01 PM
Ozz Ozz is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 54
Ozz is on a distinguished road
Default

Quote:
Originally Posted by jackwhaines View Post
Most channels either need it, or they don't. When it IS parsed, and an & exists, it splits msg['AIS']['AIS.3']['AIS.3.1'] to msg['AIS']['AIS.3']['AIS.3.1']['AIS.3.1.1'] and msg['AIS']['AIS.3']['AIS.3.1']['AIS.3.1.2']. You could always leave it default, then check for the length of msg['AIS']['AIS.3']['AIS.3.1'] and if it's > 1, do what you need to with it, but it rarely worth all that... Your call though!
Right, I was thinking right now it would be fine but with the future..."who knows!"

Could always cross that bridge when I come to it, but I can't help but wonder how I could make it work the other way too. For now, it solves the problem though. Thanks again!
Reply With Quote
  #6  
Old 12-06-2019, 06:16 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,110
agermano is on a distinguished road
Default

Turning off that setting is the easiest solution if that works for you. I did write a code template to join them back together if you decide to leave parse subcomponents turned on.

https://github.com/nextgenhealthcare...0Subcomponents
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 02:55 PM.


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