web stats
Substring or Regular Expression? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2012, 08:13 AM
psanders psanders is offline
OBX.2 Kenobi
 
Join Date: Nov 2011
Posts: 55
psanders is on a distinguished road
Default Substring or Regular Expression?

Hi all,
In my Inbound message I have a field that contains an immunization amount expressed this way, "1 mL". I need to break it out into two fields for the output message. I need the "1" put to the HL7 RXA6 and the "mL" put to the HL7 RXA7 field. The input may be any combination of values like "3 cc" or something similar, and so I thought I could use a substring or regular expression to key on the white space to seperate it and store it in a variable within the transform step, but not sure what the mapping code would be, or if I should use the String Replacement area below with a regular expression. Any thoughts?

what I have now:
RXA|0|1|20120501||^TRIAMCINOLONE ACETATE^CVX|1 mL||||||||
what I need:
RXA|0|1|20120501||^TRIAMCINOLONE ACETATE^CVX|1|mL|||||||
Reply With Quote
  #2  
Old 06-12-2012, 11:24 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,235
cory_cole is on a distinguished road
Default

var immunization = msg['RXA']['RXA.6]['RXA.6.1'].toString().split(' ');
var amount = immunization[0];
var unit = immunization[1];

msg['RXA']['RXA.6]['RXA.6.1'].toString() = amount;
msg['RXA']['RXA.7]['RXA.7.1'].toString() = unit;
Reply With Quote
  #3  
Old 06-12-2012, 11:35 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

If you want to separate them by just whitespace, you could do this:

Code:
for each (rxa in msg.RXA) {
	rxa['RXA.7']['RXA.7.1'] = rxa['RXA.6']['RXA.6.1'].toString().trim().replace(/^.*\s+|^[^\s]+$/g,'');
	rxa['RXA.6']['RXA.6.1'] = rxa['RXA.6']['RXA.6.1'].toString().trim().replace(/\s+.*$/g,'');
}
__________________
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
  #4  
Old 07-16-2012, 07:01 AM
psanders psanders is offline
OBX.2 Kenobi
 
Join Date: Nov 2011
Posts: 55
psanders is on a distinguished road
Default

In testing this I found that sometimes the space isn't there, they will sometimes look like this: "1ml" but I can key on the fact it will always be a numeric value followed by an alpha value. What would the regular expression be then?

Thanks
Reply With Quote
  #5  
Old 07-16-2012, 07:12 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

Quote:
Originally Posted by psanders View Post
In testing this I found that sometimes the space isn't there, they will sometimes look like this: "1ml" but I can key on the fact it will always be a numeric value followed by an alpha value. What would the regular expression be then?

Thanks
This site will help!

http://www.javascriptkit.com/javatutors/redev2.shtml

Numeric values are usually denoted by [0-9] and alphabetic values by [a-zA-Z] (or either [a-z] or [A-Z] if you use the case insensitivity flag).
__________________
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
  #6  
Old 11-12-2012, 06:45 AM
psanders psanders is offline
OBX.2 Kenobi
 
Join Date: Nov 2011
Posts: 55
psanders is on a distinguished road
Default

I'm using a javascript transformer step with the code below in my destination. This regular expression works when the text it's parsing looks like the following:

0.5 ml

I get the 0.5 split correctly from the ml

but if the text has the value without the unit like this:

0.5

The output is split incorrectly 0. and the 5. Anyone have a good regular expression testing site they use? I need to change the code to split only on the space.


Code:
var immunization = msg['dose_size'].toString().trim();
var immunization = immunization.split(/(\d+(?:\.\d*)?|\.\d+)\s*(\S+)/g);
var amount = immunization[1];
var unit = immunization[2];

tmp['RXA']['RXA.6']['RXA.6.1'] = amount;
tmp['RXA']['RXA.7']['RXA.7.1'] = unit;
Reply With Quote
  #7  
Old 11-12-2012, 07:05 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

What about the following?

Code:
for each (rxa in msg.RXA) {
	rxa['RXA.7']['RXA.7.1'] = rxa['RXA.6']['RXA.6.1'].toString().trim().replace(/^(\s|\.|\d)+/g,'');
	rxa['RXA.6']['RXA.6.1'] = rxa['RXA.6']['RXA.6.1'].toString().trim().replace(/(\s|[^\.\d])+$/g,'');
}
__________________
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
  #8  
Old 11-12-2012, 12:34 PM
psanders psanders is offline
OBX.2 Kenobi
 
Join Date: Nov 2011
Posts: 55
psanders is on a distinguished road
Default

Hi Narupley, I tried using the suggestion, but must not have it set up correctly as I'm getting empty results.

Code:
var unit = msg['RXA.6']['RXA.6.1'].toString().trim().replace(/^.*\s+|^[^\s]+$/g,'');
var amount = msg['RXA.6']['RXA.6.1'].toString().trim().replace(/\s+.*$/g,'');

tmp['RXA']['RXA.6']['RXA.6.1'] = amount;
tmp['RXA']['RXA.7']['RXA.7.1'] = unit;
Reply With Quote
  #9  
Old 11-12-2012, 01:36 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

First, you have the amount and units switched around. Second, you're not including the RXA node of msg, so those references will always yield empty strings. Third, you're using my previous suggestion, which assumes that there is always whitespace between the amount and units. That's fine, as long as you're sure there will always be a space in the middle (at least when the amount and units are both present).

Anyway, you probably need to do this instead:

Code:
tmp.RXA['RXA.6']['RXA.6.1'] = msg.RXA['RXA.6']['RXA.6.1'].toString().trim().replace(/(\s|[^\.\d])+$/g,'');
tmp.RXA['RXA.7']['RXA.7.1'] = msg.RXA['RXA.6']['RXA.6.1'].toString().trim().replace(/^(\s|\.|\d)+/g,'');
__________________
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
  #10  
Old 11-12-2012, 04:14 PM
psanders psanders is offline
OBX.2 Kenobi
 
Join Date: Nov 2011
Posts: 55
psanders is on a distinguished road
Default

This code worked:
Code:
tmp.RXA['RXA.6']['RXA.6.1'] = msg['dose_size'].toString().trim().replace(/(\s|[^\.\d])+$/g,'');
tmp.RXA['RXA.7']['RXA.7.1'] = msg['dose_size'].toString().trim().replace(/^(\s|\.|\d)+/g,'');
Attached Files
File Type: txt exmaple2.txt (2.4 KB, 4 views)
File Type: txt example1.txt (2.4 KB, 3 views)
File Type: xml Immunizations_DWtoUSIIS.xml (69.6 KB, 7 views)

Last edited by psanders; 11-14-2012 at 10:09 AM.
Reply With Quote
Reply

Tags
javascript, regular expression

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 03:39 PM.


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