web stats
Combining OBX lines into one AND inserting 80 character limit ~ tilde - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-05-2013, 10:49 AM
Jaypell22 Jaypell22 is offline
Mirth Newb
 
Join Date: Jul 2011
Location: Upstate NY
Posts: 24
Jaypell22 is on a distinguished road
Default Combining OBX lines into one AND inserting 80 character limit ~ tilde

Version 2.2.1.5861.
I am currently using the below code to create one OBX line from Multiple OBX lines. This has been working great however I now have to ensure there is a ~ no more than 80 characters apart within this one line as this is a limitation by the vendor's engine I am sending ORU messages to and is getting rejected.

I did try to first limit each OBX line to 80 characters but it then truncated an lost the rest of the line instead of inserting it into a new one. I think this can be done 2 ways. Before and after this code (who knows maybe in the middle of it!)

So in short.... I need to insert a ~ 80 characters or less apart but not falling in the middle of a word splitting it up in addition to the code I already have in place that combines all OBX.5 data.

Thanks for any help - Jay

Code I am using:

var newOBX = <OBX/>;
newOBX['OBX.1']['OBX.1.1'] = '1';
newOBX['OBX.2']['OBX.2.1'] = 'FT';
newOBX['OBX.5'] = '';
for each (seg in msg.children())
if (seg.name().toString() == 'OBX')
for each (obx5 in seg['OBX.5'])
newOBX['OBX.5'] = newOBX['OBX.5'].toString() ? newOBX['OBX.5']+obx5 : obx5;
newOBX['OBX.14']['OBX.14.1'] = msg['OBR']['OBR.8']['OBR.8.1'].toString();
newOBX['OBX.16']['OBX.16.1'] = msg['OBR']['OBR.32']['OBR.32.1'];
newOBX['OBX.16']['OBX.16.2'] = msg['OBR']['OBR.32']['OBR.32.2'];
newOBX['OBX.16']['OBX.16.3'] = msg['OBR']['OBR.32']['OBR.32.3'];
msg.OBX = newOBX;

Last edited by Jaypell22; 10-05-2013 at 10:52 AM.
Reply With Quote
  #2  
Old 10-07-2013, 12:50 PM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 963
cory_cole is on a distinguished road
Default

give this a try.

var newOBX = <OBX/>;
newOBX['OBX.1']['OBX.1.1'] = '1';
newOBX['OBX.2']['OBX.2.1'] = 'FT';
newOBX['OBX.5'] = '';
for each (obx in msg.OBX)
{
var obxArray = new Array();
for each (obx5 in obx['OBX.5'])
{
while(obx5.toString().length() > 80)
{
var tmpOBX = obx.toString().substring(0,80);
var obxIndex = tmpObx.lastIndexOf(' ');
obxArray.push(tmpOBX.substring(0,obxIndex));
obx5 = obx5.toString().subString(80,obx5.toString().lengt h());
}
obxArray.push(obx5);
}
}

for(i = 0; i < obxArray.length(); i++)
{
newOBX['OBX.5']['OBX.5.' + i] = obxArray[i];
}

newOBX['OBX.14']['OBX.14.1'] = msg['OBR']['OBR.8']['OBR.8.1'].toString();
newOBX['OBX.16']['OBX.16.1'] = msg['OBR']['OBR.32']['OBR.32.1'];
newOBX['OBX.16']['OBX.16.2'] = msg['OBR']['OBR.32']['OBR.32.2'];
newOBX['OBX.16']['OBX.16.3'] = msg['OBR']['OBR.32']['OBR.32.3'];
msg.OBX = newOBX;
Reply With Quote
  #3  
Old 10-09-2013, 08:54 AM
Jaypell22 Jaypell22 is offline
Mirth Newb
 
Join Date: Jul 2011
Location: Upstate NY
Posts: 24
Jaypell22 is on a distinguished road
Default

Thanks for your Help! I am hitting a snag right now however. Maybe you can understand the error. That is the first OBX Line that it gets stuck on. Let me know if you have any ideas - also if you are going to test or use the code there is just an extra space in this line in the word length which I highlighted below

obx5 = obx5.toString().subString(80,obx5.toString().lengt h()); this was fixed so not causing problems, just an FYI.

ERROR-300: Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: TEST CHANNEL
CONNECTOR: Test to Channel
SCRIPT SOURCE:
SOURCE CODE:
193: for each (obx in msg.OBX)
194: {
195: var obxArray = new Array();
196: for each (obx5 in obx['OBX.5'])
197: {
198: while(obx5.toString().length() > 80)
199: {
200: var tmpOBX = obx.toString().substring(0,80);
201: var obxIndex = tmpObx.lastIndexOf(' ');
202: obxArray.push(tmpOBX.substring(0,obxIndex));
LINE NUMBER: 198
DETAILS: TypeError: Cannot call property length in object <OBX.5><OBX.5.1>Referring Physician: FIRSTNAME, LASTNAME, PA</OBX.5.1></OBX.5>. It is not a function, it is "number".
at com.mirth.connect.server.mule.transformers.JavaScr iptTransformer.evaluateScript(JavaScriptTransforme r.java:398)

Last edited by Jaypell22; 10-09-2013 at 10:12 AM.
Reply With Quote
  #4  
Old 10-09-2013, 10:16 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 963
cory_cole is on a distinguished road
Default

while(obx5.toString().length() > 80)

change to

while(obx5.toString().length > 80)
Reply With Quote
  #5  
Old 10-09-2013, 10:34 AM
sandersmr sandersmr is offline
OBX.2 Kenobi
 
Join Date: Feb 2013
Posts: 59
sandersmr is on a distinguished road
Default

Shouldn't this also be looking at OBX.5.1 rather than the whole of OBX.5?

e.g.
Code:
for each (obx5 in obx['OBX.5']['OBX.5.1'])
{
[...]
}
Reply With Quote
  #6  
Old 10-09-2013, 10:36 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 963
cory_cole is on a distinguished road
Default

Not if he want each of the entries. That loop is to look at each one individually.
Reply With Quote
  #7  
Old 10-09-2013, 11:30 AM
Jaypell22 Jaypell22 is offline
Mirth Newb
 
Join Date: Jul 2011
Location: Upstate NY
Posts: 24
Jaypell22 is on a distinguished road
Default

So I have been playing around with this, made a few tweaks/fixes for capitalizations, and removed 2 "()" which were hanging things up. Everything processes now but look at the OBX. It deletes everything and puts "~" in OBX.4! That is slightly mind-blowing! I don't think I have any other code that would cause it to show up in OBX.4

OBX|1|FT||~||||||||||201310091417||123456^LAST^FIR ST


Below is the current code I'm using.



Code:
var newOBX = <OBX/>;
newOBX['OBX.1']['OBX.1.1'] = '1';
newOBX['OBX.2']['OBX.2.1'] = 'FT';
newOBX['OBX.5'] = '';
for each (obx in msg.OBX)
{ 
var obxArray = new Array();
for each (obx5 in obx['OBX.5'])
{
while(obx5.toString().length > 80)
{
var tmpOBX = obx.toString().substring(0,80);
var obxIndex = tmpOBX.lastIndexOf(' ');
obxArray.push(tmpOBX.substring(0,obxIndex));
obx5 = obx5.toString().substring(80,obx5.toString().length);
}
obxArray.push(obx5);
}
}

for(i = 0; i < obxArray.length; i++)
{
newOBX['OBX.5']['OBX.5.' + i] = obxArray[i];
}

newOBX['OBX.14']['OBX.14.1'] = msg['OBR']['OBR.8']['OBR.8.1'].toString();
newOBX['OBX.16']['OBX.16.1'] = msg['OBR']['OBR.32']['OBR.32.1'];
newOBX['OBX.16']['OBX.16.2'] = msg['OBR']['OBR.32']['OBR.32.2'];
newOBX['OBX.16']['OBX.16.3'] = msg['OBR']['OBR.32']['OBR.32.3'];
msg.OBX = newOBX;
Reply With Quote
  #8  
Old 10-09-2013, 12:00 PM
sandersmr sandersmr is offline
OBX.2 Kenobi
 
Join Date: Feb 2013
Posts: 59
sandersmr is on a distinguished road
Default

Try this:

Code:
var newOBX = <OBX/>;
newOBX['OBX.1']['OBX.1.1'] = '1';
newOBX['OBX.2']['OBX.2.1'] = 'FT';
newOBX['OBX.5'] = '';
var obxArray = new Array();
for each (obx in msg.OBX)
{
	for each (obx5 in obx['OBX.5'])
	{
		while(obx5.toString().length > 80)
		{
			var tmpOBX = obx.toString().substring(0,80);
			var obxIndex = tmpOBX.lastIndexOf(' ');
			obxArray.push(tmpOBX.substring(0,obxIndex));
			obx5 = obx5.toString().substring(80,obx5.toString().length);
		}
		obxArray.push(obx5);
	}
}

for(i = 0; i < obxArray.length; i++)
{
	newOBX['OBX.5'][i] = obxArray[i];
}

newOBX['OBX.14']['OBX.14.1'] = msg['OBR']['OBR.8']['OBR.8.1'].toString();
newOBX['OBX.16']['OBX.16.1'] = msg['OBR']['OBR.32']['OBR.32.1'];
newOBX['OBX.16']['OBX.16.2'] = msg['OBR']['OBR.32']['OBR.32.2'];
newOBX['OBX.16']['OBX.16.3'] = msg['OBR']['OBR.32']['OBR.32.3'];
msg.OBX = newOBX;
The obxArray was going out of scope (was declared in the first for each), and each new piece of OBX.5 needed to be assigned on OBX.5, not OBX.5.*, since each string already contained the whole OBX.5 structure, eg

Code:
<OBX.5><OBX.5.1>Referring Physician: FIRSTNAME, LASTNAME, PA</OBX.5.1></OBX.5>
Reply With Quote
  #9  
Old 10-09-2013, 12:13 PM
Jaypell22 Jaypell22 is offline
Mirth Newb
 
Join Date: Jul 2011
Location: Upstate NY
Posts: 24
Jaypell22 is on a distinguished road
Default

Getting there, Now I get this as a result using the most recent code.

OBX|1|FT|||Referring Physician: MR DOCTOR, MD~~Patient Name: FIRST LAST~~~5>~~Exam: X-ray 2 view PA lateral chest.~~~~~~~~.</OBX.5.1></OBX.5>~~~tudy of 10/4/13.</OBX.5.1></OBX.5>~~~THIS DOCUMENT HAS BEEN ELECTRONICALLY SIGNED~~DR Me M.D.~~10/09/2013 15:03~|||||||||201310091504||123456^last^First
Reply With Quote
  #10  
Old 10-09-2013, 12:17 PM
sandersmr sandersmr is offline
OBX.2 Kenobi
 
Join Date: Feb 2013
Posts: 59
sandersmr is on a distinguished road
Default

What does the original message look like (with PHI cleaned of course)? It's probably due to splitting the entirety of OBX.5 (including the XML structure) rather than picking an individual field (like OBX.5.1).
Reply With Quote
Reply

Tags
character limit, combine, insert character, insert tilde ~, obx

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 -7. The time now is 07:21 PM.


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