Sidebar

Delete multiple blanks in a OBX section.

0 votes
198 views
asked Dec 28, 2020 by david-m-6327 (240 points)
edited Dec 28, 2020 by david-m-6327
So there's a way to use a for loop to iterate through an HL7 section, such as OBX.

Now imagine the HL7 message looks something like this:

OBX|1||Name|1|This is a line of text

OBX|1||Name|2|This is the second line

OBX|1||Name|3|

OBX|1||Name|4|

OBX|1||Name|5|

OBX|1||Name|6|

OBX|1||Name|7|This is now the second paragraph.

OBX|1||Name|8|

OBX|1||Name|9|This starts the third paragraph.

 

If in formatting the message, we'd like to keep a single blank line when it exists, but remove multiple blank lines with a single one (ie 3-6 with a single blank line) is there a way to do this?

You can iterate and then do something like StringUtils.isBlank, but how do you track how many lines are blank, and then delete them, given this number could change in how many blank lines there are between segments?

Could this be something like identifying when the first instance happens, then the last, and iterate between them? Would that be a for loop inside the for loop? Something like having a variable that iterates, and when isblank it is increased, and when it isn't, it's compared to see if it's greater than 1, and if so, you delete i-1 obx segments?

1 Answer

+1 vote
 
Best answer

You can use a for loop to find the extra empty lines and remove them.

var isLastLineBlank = false;
var linesRemoved = 0;
//get OBX count
var obxCount = message.getCount('OBX');
for (var i = 1; i <= obxCount; i++) {
   var obx5Blank = message.checkNodeIsBlank('OBX-5', (i - linesRemoved));
   if (isLastLineBlank && obx5Blank) {
      qie.debug('linesRemoved: ' + linesRemoved);
      message.removeFirstNode('OBX[' + (i - linesRemoved) + ']');
      linesRemoved++;
   } else if (obx5Blank) {
      isLastLineBlank = true;
   } else {
      isLastLineBlank = false;
   }
}

answered Dec 29, 2020 by brandon-w-8204 (33,170 points)
selected Dec 29, 2020 by david-m-6327
...