Announcement

Collapse
No announcement yet.

Moving DG1 segments after last OBX

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

  • #2
    Code:
    var dg1List = msg.DG1;
    delete msg.DG1;
    msg.OBX[msg.OBX.length()-1] += dg1List;

    Comment


    • #3
      That helped me tremendously. Greatly appreciated!

      Thank you,
      Matt

      Comment

      Working...
      X