Sidebar

How can I remove duplicate information from NTE Segments.

0 votes
1.1K views
asked Sep 10, 2015 by brandon-w-8204 (33,270 points)

I have duplicate NTE segments and would like to remove the second instance of it.

Example:

 

NTE|19||

NTE|20||Electronically Signed 8/25/2015 9:54 AM

NTE|21||Doctor A MD, Pathologist

NTE|22||

NTE|23||Electronically Signed 8/25/2015 9:54 AM

NTE|24||Doctor B MD, Pathologist

NTE|25||

2 Answers

+1 vote
 
Best answer

The following code will check that we have 2 Electronically Signed Segments and remove the last group.

//See if we have multiple 'Electronically Signed' in NTE
var split = StringUtils.splitByWholeSeparator(message.getNode('/'), 'Electronically Signed');
if (split.length > 2) {
 
   //Get Count of the NTE segments
   var nteCount = message.getCount('NTE');
 
   //FOR loop reversed to process last NTE first
   for (var i=nteCount ; i > 0 ; i--) {
      //If statement to check for second 'Electronically Signed' NTE segments
      if (StringUtils.containsIgnoreCase(message.getNode('NTE-3', i), 'Electronically Signed')) {
         //Remove 3 NTE segments when second 'Electronically Signed' segment is found.
         for (var j = 0; j < 3; j++) {
            message.removeFirstNode('NTE[' + i + ']');
         }
         //Break so we only remove the last one and do not continue to process the rest of the NTE's
         break;
      }
   }
}

Here is the resulting segments

NTE|19||

NTE|20||Electronically Signed 8/25/2015 9:54 AM

NTE|21||Doctor A MD, Pathologist

NTE|22||

 

answered Sep 10, 2015 by brandon-w-8204 (33,270 points)
0 votes
Another way would be to store the NTE-3 value in a parameter map and then remove the three lines following the duplicate "Electronically Signed" text.
 
 
// remove every NTE segment
message.removeAllNodes('NTE');
 
// store the original NTE segs as an array
var nteSegs = source.getAllNodes("NTE");
var nteMap  = qie.newParameterMap();
 
// cycle each NTE segment and only add not duplicate
for (var i=0 ; i < nteSegs.length ; i++) {
   qie.debug(nteSegs[i]);
   var nteSeg = qie.parseHL7String(nteSegs[i]);
   var nte3   = nteSeg.getNode('NTE-3');
   if (nte3.length() > 0 && nte3 + '' !== '_~') {
      //need to check in the nteSegs array if this current NTE segment exists.
      if (nteMap.get(nte3) === null) {
         message.addChild('/', 'NTE', nteSeg);
         nteMap.put(nte3, true);
      } else if (StringUtils.contains(nte3, 'Electronically Signed')) {
         // So this nte3 was already found once so now remove the next three lines by skipping them.
         i = i + 2;
      }
   } else {
      //go ahead and add blank lines or lines that equal '~'
      message.addChild('/', 'NTE', nteSeg);
   }
}
answered Sep 10, 2015 by michael-h-5027 (14,350 points)
...