web stats
Splitting on the carriage return "\r" - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2013, 01:46 PM
eslingerc eslingerc is offline
Mirth Newb
 
Join Date: Oct 2012
Posts: 19
eslingerc is on a distinguished road
Default Splitting on the carriage return "\r"

Mirth doesn't seem to like the fact that I am splitting based on a carriage return.

Here is an example OBX (where the splitting should occur):

OBX|1|FT|Radiology Report^Radiology Rpt||***FINAL REPORT***

Portable crosstable lateral x-rays of the lumbar spine

HISTORY: Intraoperative views

COMPARISON: None

FINDINGS: The images show placement of bilateral pedicle screws
with interlocking bars in the lowest lumbar vertebrae and upper
sacrum. There is mild anterolisthesis of the lowest lumbar

Converting this into a document type with the following code:

var obxText = msg['OBX']['OBX.5']['OBX.5.1'].toString().split("\r");
for (i=0; i < obxtext.length; i++) {
var obxseg = <OBX/>;
obxseg['OBX.1']['OBX.1.1'] = (cOBX+1);
obxseg['OBX.2']['OBX.2.1'] = "TX";
obxseg['OBX.3']['OBX.3.1'] = testCode;
obxseg['OBX.3']['OBX.3.2'] = test;
obxseg['OBX.5']['OBX.5.1'] = obxText[i];
obsseg['OBX.11']['OBX.11.1'] = res;
obsseg['OBX.14']['OBX.14.1'] = msgTime;
tmp.appendChild(obxseg); cOBX++;
}

As mentioned Mirth doesn't seem to split on the carriage return. Is there an easy way around this or will I have to dive into an OBX wrapper object code template?
Reply With Quote
  #2  
Old 05-01-2013, 01:49 PM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,299
cory_cole is on a distinguished road
Default

I believe it is a newline carriage return

var obxText = msg['OBX']['OBX.5']['OBX.5.1'].toString().split("\n\r");
Reply With Quote
  #3  
Old 05-01-2013, 02:02 PM
eslingerc eslingerc is offline
Mirth Newb
 
Join Date: Oct 2012
Posts: 19
eslingerc is on a distinguished road
Default

Thanks Cory! I was thinking the same, but haven't had any luck with that option as well. In other words, is there anyway I can have Mirth recognize the invisible carriage return or maybe .trim at these points instead?
Reply With Quote
  #4  
Old 05-02-2013, 06:02 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,299
cory_cole is on a distinguished road
Default

I ran some tests and looked at the transformed message. The issue that you are having is that Mirth converts the message into an xml to parse. It is reading the carriage returns as new segments. There for there technically is no carriage return at the transformer step. You will have to make your adjustments at the preprocessor script before it is converted. At this point is will be just a normal string and the msg['OBX'] notation will not work.
Reply With Quote
  #5  
Old 05-02-2013, 10:12 AM
eslingerc eslingerc is offline
Mirth Newb
 
Join Date: Oct 2012
Posts: 19
eslingerc is on a distinguished road
Default

Thanks again Cory! Here is what I did to work around this issue after noticing that the incoming message actually comes in with the \r carriage return after every segment except the obx segment which comes in with the \n carriage return.

Turned off the convert lf to cr data setting for both the inbound and outbound connectors on the summary tab.

Set the preprocessor to: return message.split("\n");

At this point the OBX group was joined with a , as a separator. Then I had to split based on this new character:
var obxText = msg['OBX']['OBX.5']['OBX.5.1'].toString().split(",");
for (i=0; i < obxText.length; i++) {
var obxseg = <OBX/>;
obxseg['OBX.1']['OBX.1.1'] = (cOBX+1);
obxseg['OBX.2']['OBX.2.1'] = "TX";
obxseg['OBX.3']['OBX.3.1'] = testCode;
obxseg['OBX.3']['OBX.3.2'] = test;
obxseg['OBX.5']['OBX.5.1'] = obxText[i];
obxseg['OBX.11']['OBX.11.1'] = res;
obxseg['OBX.14']['OBX.14.1'] = msgTime;
tmp.appendChild(obxseg); cOBX++;
}

Luckily, I haven't seen this client sending any punctuation in the obx.5.1 field besides sometimes when they use the date ex. April 10, 2012. This should be okay, but if I have a chance I will update this thread with the better solution.
Reply With Quote
  #6  
Old 05-23-2013, 04:01 PM
eslingerc eslingerc is offline
Mirth Newb
 
Join Date: Oct 2012
Posts: 19
eslingerc is on a distinguished road
Default

FYI - Here is how I fixed this issue. It still seems a little silly to me, but it works!

Inserted the preprocessor:
return message.replace(/\n/g,"MAKETHISWORK");

Then utilized this for the segment for which originally had the new line feed character \n
obxseg['OBX.5']['OBX.5.1'] = msg['OBX']['OBX.5']['OBX.5.1'].toString().replace(/MAKETHISWORK/g,"~");
Reply With Quote
  #7  
Old 05-06-2015, 01:30 PM
lino.e.gomez lino.e.gomez is offline
What's HL7?
 
Join Date: May 2015
Posts: 1
lino.e.gomez is on a distinguished road
Default

Quote:
Originally Posted by eslingerc View Post
FYI - Here is how I fixed this issue. It still seems a little silly to me, but it works!

Inserted the preprocessor:
return message.replace(/\n/g,"MAKETHISWORK");

Then utilized this for the segment for which originally had the new line feed character \n
obxseg['OBX.5']['OBX.5.1'] = msg['OBX']['OBX.5']['OBX.5.1'].toString().replace(/MAKETHISWORK/g,"~");
Hi eslingerc, I know it's been 2 years from your last post in this threads, but I'm having a similar issue. I am trying to insert a radiology report from mssql to OBX segments. But I end up with hl7 messages with a single OBX segment with the whole report. I need multiple OBX segments. Can you please explain how did you resolve this problem?

Thanks!
Reply With Quote
Reply

Tags
array, carriage returm, split, wrapper object

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:09 AM.


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