web stats
Mirth Community - View Single Post - Combining OBX lines into one AND inserting 80 character limit ~ tilde
View Single Post
  #8  
Old 10-09-2013, 11:00 AM
sandersmr sandersmr is offline
OBX.2 Kenobi
 
Join Date: Feb 2013
Posts: 71
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