web stats
Mirth Community - View Single Post - Rearrange OBX sections in ORU based on Addendums
View Single Post
  #4  
Old 02-29-2016, 04:37 AM
rauchj rauchj is offline
OBX.1 Kenobi
 
Join Date: Feb 2014
Location: Freiburg, Germany
Posts: 43
rauchj is on a distinguished road
Default

try this:

my approach is to cut out parts of the report an rearrange them as needed. maybe not the most elegant solution but it works

Code:
arObx = new Array();
found = false;

for each (obx in msg..OBX) {
	if ((obx['OBX.5']['OBX.5.1'].toString() != 'ADDENDUM:') && (!found)) {
		arObx.push(obx)
		delete msg.children()[obx.childIndex()]
	}
	else if (obx['OBX.5']['OBX.5.1'].toString() == 'ADDENDUM:') {
		found = true;
	}
}

arIndexTemp = new Array();
i=0;
for each (obx in msg..OBX) {
	if (obx['OBX.5']['OBX.5.1'].toString() == 'ADDENDUM:') {
		arIndexTemp.push(i)
	}
	i++
}

//reversing order of array
arIndexAddendum = arIndexTemp.reverse()
arObxAddendum = new Array();

// Reading Addendum Blocks from Bottom(!) to Top(!)
for (i=0; i<arIndexAddendum.length; i++) {

	lastIndex = msg['OBX'].length()
	for (j=arIndexAddendum[i];j<lastIndex;j++) {
		arObxAddendum.push(msg['OBX'][j])
	}
	
	// Deleting Addendum Report
	for (j=lastIndex;j>=arIndexAddendum[i];j--) {
		logger.debug("j: " + j);
		delete msg['OBX'][j]
	}
}

//Appending Addendum Reports to msg
for (i=0; i<arObxAddendum.length; i++)
{
	msg.appendChild(arObxAddendum[i])
}

//Appending Original Report to msg
for (i=0; i<arObx.length; i++)
{
	msg.appendChild(arObx[i])
}

// recreate OBX Counter
var ObxCounter=1;
for each (obx in msg..OBX) {
	obx['OBX.1']['OBX.1.1'] = ObxCounter;
	ObxCounter++;
}
Reply With Quote