web stats
Translating escape sequences - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-24-2014, 07:26 AM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default Translating escape sequences

Has anyone got some code they can share to translate all the \.sk[N]\ escape sequences into spaces?

Code:
OBX|1|TX||17|\.sk+1\\.sk+1\astraia\.sk+1\\.sk+1\software for women's health\.sk+1\\.sk+1\obstetric and gynaecological database application\.sk+1\astraia software gmbh\.sk+1\\.sk+1\\.sk+49\\.sk+1\\.br\\.sk+1\\.sk+1\\.sk+49\\.sk+1\Occamstr. 20\.sk+1\\.sk+1\\.sk+49\\.sk+1\80802 Munich\.sk+1\\.sk+1\\.sk+49\\.sk+1\Germany\.sk+1\\.sk+1\\.sk+49\\.sk+1\\.br\\.sk+1\\.sk+1\\.sk+49\\.sk+1\Tel   +49 (0)89 1271147-0\.sk+1\\.sk+1\\.sk+49\\.sk+1\Fax  +49 (0)89 1271147-17\.sk+1\\.sk+1\\.sk+49\\.sk+1\Email: info@astraia.com\.sk+1\\.sk+1\\.sk+49\\.sk+1\Web:   www.astraia.com\.br\\.br\Patient Data\.br\--------------------\.br\\.sk+4\\.sk+4\Other \.sk+4\\.sk+4\Date of birth\.sk+1\13/05/\.sk+4\\.sk+4\\.sk+4\\.sk+4\1 Albert \.sk+4\\.sk+4\\.sk+4\\.sk+4\EC1 \.sk+4\Ethnic \.sk+4\white (European, Middle Eastern, North African, Hispanic)\.sk+56\\.br\\.sk+13\\.sk+1\White and Black \.sk+4\Hospital no. \.sk+1\\.sk+4\\.sk+4\Dr. A Patel , Royal Docks Medical Practice, Royal Docks Medical Ctre, 21 East Ham Manor Way, Beckton020 \.sk+4\\.br\Present Pregnancy\.br\--------------------\.br\\.sk+4\last period: 01/06/2014\.br\EDD by dates\.sk+1\08/03/\.sk+4\\.br\Examination\.br\--------------------\.br\Date\.sk+1\21/07/2014\.br\Time\.sk+1\10:\.sk+4\\.br\Ultrasound\.br\--------------------\.br\Operator\.sk+1\Dr. Test\.br\\.br\||||||A|||20140724143345
Reply With Quote
  #2  
Old 07-24-2014, 08:05 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,115
narupley is on a distinguished road
Default

This is based off of my replaceAllInXML function:

Code:
function replaceEscapedSpaces(parent) {
	for each (child in parent.children()) {
		if (child.hasComplexContent()) {
			replaceEscapedSpaces(child);
		} else {
			var value = child.toString();
			for each (match in value.match(/\\\.sk\+\d+\\/g)) {
				value = value.replace(match, org.apache.commons.lang3.StringUtils.repeat(' ', parseInt(match.replace(/[^\d]/g,''),10)));
			}
			parent.children()[child.childIndex()] = value.replace(/\\\.br\\/g,'\n');
		}
	}
}
You can use it on the entire message if there are multiple places it could happen:

Code:
replaceEscapedSpaces(msg);
Or you could do it only on the OBXs:

Code:
replaceEscapedSpaces(msg.OBX);
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 07-24-2014, 08:44 AM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default

Wow Nick, I'm so very grateful as have been struggling with this. I was trying to get the number of spaces using capturing groups, and never thought about parseInt
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 10:52 AM.


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