web stats
Mirth Community - View Single Post - Building/Creating new OBXs
View Single Post
  #2  
Old 12-03-2015, 03:40 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

I'm sure there are other ways to accomplish this, but the below code works...

Code:
for each(obr in msg.OBR)
{
	if(obr['OBR.20'].length() > 1)
	{
		for(var i=obr['OBR.20'].length()-1; i >= 0; i--)
		{
			var obrValue = SerializerFactory.getSerializer('HL7V2').fromXML(obr['OBR.20'][i].toString());
			var newOBX = createSegmentAfter('OBX', obr);
			newOBX['OBX.1']['OBX.1.1'] = i+1;
			newOBX['OBX.2']['OBX.2.1'] = '';
			newOBX['OBX.3']['OBX.3.1'] = obrValue;
		}
	}
	for each(obx in msg.OBX){
		var obxGroup = getSegmentsAfter(msg,obr,'OBX');
		for (var o = 0; o <= obxGroup.length-1; o++)
			msg.children()[obxGroup[o].childIndex()]['OBX.1']['OBX.1.1'] = o+1;
	}
}
Reply With Quote