Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Combining OBX lines into one AND inserting 80 character limit ~ tilde (http://www.mirthcorp.com/community/forums/showthread.php?t=9403)

Jaypell22 10-05-2013 09:49 AM

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;

cory_cole 10-07-2013 11:50 AM

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;

Jaypell22 10-09-2013 07:54 AM

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)

cory_cole 10-09-2013 09:16 AM

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

change to

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

sandersmr 10-09-2013 09:34 AM

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'])
{
[...]
}


cory_cole 10-09-2013 09:36 AM

Not if he want each of the entries. That loop is to look at each one individually.

Jaypell22 10-09-2013 10:30 AM

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;


sandersmr 10-09-2013 11:00 AM

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>

Jaypell22 10-09-2013 11:13 AM

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

sandersmr 10-09-2013 11:17 AM

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).


All times are GMT -8. The time now is 12:05 PM.

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