web stats
Delete Leading WhiteSpace - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-02-2011, 07:05 AM
lukekrouse lukekrouse is offline
OBX.1 Kenobi
 
Join Date: Jul 2011
Posts: 40
lukekrouse is on a distinguished road
Unhappy Delete Leading WhiteSpace

I am sometimes getting a leading whitespace in the PV1.3.2 segment that is causing some issues. Is it possible to delete that whitespace if it exists and to not do anything if it doesn't?
Thanks
Reply With Quote
  #2  
Old 08-02-2011, 07:35 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

A single leading white space can be stripped with

Code:
strString = strString.replace(' ','');

//all white spaces

strString = strString.replace(' '\g,'');

//or

strString = strString.replace(\ \g,'');

//may contain typos  (and just a caveat...for some reason string replace always gives //me problems
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
  #3  
Old 08-02-2011, 07:35 AM
upstart33 upstart33 is offline
Mirth Guru
 
Join Date: Dec 2010
Location: Chicago, IL.
Posts: 459
upstart33 is on a distinguished road
Default

You would probably have to take care of the Whitespace within the Pre-Processing script section.

You might be able to do something along these lines:

Code:
message = message.toString().replace(/\s+/g, ' ');
or
Code:
message = new java.lang.String(message).trim();
Reply With Quote
  #4  
Old 08-02-2011, 07:43 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

Thanks upstart, I was wondering if .trim would work in Mirth (I hadn't had a chance to try it).

Wouldn't recommend this in the pre-processor though as the replacement has to be in the specific field. The pre-processor will strip all white spaces in the message. If you're passing any NTE segments or OBX.5's with narratives, that would really irritate your users.
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
  #5  
Old 08-02-2011, 07:43 AM
lukekrouse lukekrouse is offline
OBX.1 Kenobi
 
Join Date: Jul 2011
Posts: 40
lukekrouse is on a distinguished road
Default

Do I have to specify the segment PV1.3.2 or will this message = message.toString().replace(/\s+/g, ' '); just work for any whitespace?
Reply With Quote
  #6  
Old 08-02-2011, 09:24 AM
lukekrouse lukekrouse is offline
OBX.1 Kenobi
 
Join Date: Jul 2011
Posts: 40
lukekrouse is on a distinguished road
Default

I must be doing something wrong because I am still getting the whitespaces. Should I apply those suggestions to a javascript transformer?
Reply With Quote
  #7  
Old 08-02-2011, 09:27 AM
upstart33 upstart33 is offline
Mirth Guru
 
Join Date: Dec 2010
Location: Chicago, IL.
Posts: 459
upstart33 is on a distinguished road
Default

Is the issue that the whitespace is breaking the message as you are receiving it, before you have a chance to do anything to it, or when you are trying to put the data into the database?
Reply With Quote
  #8  
Old 08-02-2011, 10:25 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

Quote:
Originally Posted by lukekrouse View Post
I must be doing something wrong because I am still getting the whitespaces. Should I apply those suggestions to a javascript transformer?
Hi;
Yes, add a transformer, double click on the right hand column (where is says Message Builder), then select javascript.

If that doesn't work, post your code please
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation

Last edited by Bostad; 08-02-2011 at 10:28 AM. Reason: oops, missed that last bit of the question...
Reply With Quote
  #9  
Old 08-02-2011, 10:28 AM
lukekrouse lukekrouse is offline
OBX.1 Kenobi
 
Join Date: Jul 2011
Posts: 40
lukekrouse is on a distinguished road
Default

When I am trying to put the data in the database I am having some issues. I can process the data just fine, it is just that I do not want to store the data i.e room number with a space. Right now, I am getting PV1|1|I|2SN^ 302^01. What I need is PV1|1|I|2SN^302^01 <-- no space between ^ 302.
Reply With Quote
  #10  
Old 08-02-2011, 10:34 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

Quote:
Originally Posted by lukekrouse View Post
I must be doing something wrong because I am still getting the whitespaces. Should I apply those suggestions to a javascript transformer?
Quote:
Originally Posted by lukekrouse View Post
When I am trying to put the data in the database I am having some issues. I can process the data just fine, it is just that I do not want to store the data i.e room number with a space. Right now, I am getting PV1|1|I|2SN^ 302^01. What I need is PV1|1|I|2SN^302^01 <-- no space between ^ 302.

I just fired this into a channel I'm working on and tested with your values, it works.

Just create a javascript transformer and paste this in and viola...

Code:
msg['PV1']['PV1.3']['PV1.3.2'] = msg['PV1']['PV1.3']['PV1.3.2'].toString().replace(' ','');
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
Reply

Tags
segment, whitespace

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 08:53 PM.


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