Sidebar

How can I evaluate each OBX-5 field in a message and populate if empty

0 votes
1.1K views
asked Mar 5, 2014 by brandon-w-8204 (33,270 points)

2 Answers

0 votes
 
Best answer

The following code will add 'Value1' to each OBX-5 segment if it is empty

 

var obxArray = message.getAllNodes('OBX-5');
for (var i=0 ; i < obxArray.length ; i++) {
   var obx5 = '' + obxArray[i];
   if (obx5.length === 0) {
      message.setNode('OBX-5', 'Value1', (i+1));
   }
}
answered Mar 5, 2014 by brandon-w-8204 (33,270 points)
0 votes
//Gets all OBX segments as an Array
var obxSegments = message.getAllNodes('OBX');
 
//Loops through each OBX segment individually
for (var i = 0; i < obxSegments.length; i++) {
   //Gets the individual OBX segment and stores in a variable and;
   //converts it to an HL7 object.
   var obxSeg = qie.parseHL7String(obxSegments[i]);
 
   //Because the obxSeg has been converted to an HL7 object all;
   // of the functions in the code wizard now work on the new object.
   // in this case obxSeg.getNode works the same as message.getNode. 
   var obx5 = obxSeg.getNode('OBX-5');
   
   //Checks to see if OBX-5 is blank using stringUtils which
   // is "Type" aware (ie. string, number) and Null safe.
   if (StringUtils.isBlank(obx5)) {
      //If OBX is Null of empty then this line of code will execute.
      message.setNode('OBX-5', 'someValue', (i+1));
   }
}
 
 
Before:
Before

 

After:

After

answered Oct 5, 2015 by gary-t-8719 (14,860 points)
...