web stats
Moving DG1 segments after last OBX - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-21-2020, 04:47 AM
rutledj rutledj is offline
Mirth Guru
 
Join Date: Nov 2010
Location: North Carolina
Posts: 397
rutledj is on a distinguished road
Default Moving DG1 segments after last OBX

I can't seem to get this to work. I'm trying to take all of the DG1 segments and move them to be after the last OBX in the message. So far my code only removes them. Can't get them added back in.

Code:
var reordered = new XMLList();
var dg1 = new XMLList();
var i = 0;
var kids = msg.children();
var obxIndex = 1;
var obxLen = msg['OBX'].length();
var dg1Group = getSegmentsAfter(msg,msg.MSH,'DG1',false);

//logger.info('obx len ' + obxLen.toString());

// add everything up to but not including the GT1 segment
for each (var child in kids) 
{
	//logger.info('in for. Name: ' + child.localName());
	
	if (child.localName() != 'DG1') 
	{
		reordered += child;
		i++;
	}
}


msg.setChildren(reordered);

var found = false;

//Now add back in the DG1 segments after the last OBX
//find last OBX
if(dg1Group.length > 0)
{	
	//loop backwards to find the last OBX
	for(i=msg.children().length()-1;i>0;i--)
	{		
		if(msg.child(i).name() == 'OBX')
		{
			 for (var j = dg1Group.length-1; j >= 0; j--)
	            {
	               msg.insertChildAfter(msg.child(i),dg1Group[j]);
	               break;
	               found = true;
	            }
		}
		if(found == true)
		   break;
	}
}

Would appreciate any help. Probably a much more efficient way to do this.
Reply With Quote
  #2  
Old 01-22-2020, 02:39 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,095
agermano is on a distinguished road
Default

Code:
var dg1List = msg.DG1;
delete msg.DG1;
msg.OBX[msg.OBX.length()-1] += dg1List;
Reply With Quote
Reply

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 10:13 AM.


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