Here is a script to add OBX segments if they do not exist in the OBR group:
//Get all OBR groups
var obrGroups = message.getAllNodes('OBR[group=!OBR]');
//Loop through each group
for (var i = 0; i < obrGroups.length; i++) {
//Parse the string as hl7 to allow lookup.
var obrGroup = qie.parseHL7String(obrGroups[i]);
//Check if an OBX segment exists.
if (!obrGroup.checkNodeExists('OBX')) {
//Get the NTE-3 node to use in the OBX-3
var obx5 = obrGroup.getNode('NTE-3');
//Add the OBX segment after the NTE segement.
message.addChildAfter('NTE[@3=' + obx5 + ']', 'OBX', 'OBX|1||||' + obx5);
}
}