Sidebar

Removing segments that start with a phrase

0 votes
393 views
asked Dec 28, 2020 by david-m-6327 (240 points)
So I was working off this link: https://www.qvera.com/kb/index.php/768/how-do-i-properly-remove-segments-using-a-for-loop

The problem I'm running into is if I have a situation like this in my HL7 message:

OBX|1||TEST|1|NAME: DOE, JOHN    DATE OF EXAM: 10-31-2020

OBX|1||TEST|2|DATE OF BIRTH: 08-12-1951    CHART #: 123456-AA

OBX|1||TEST|3|PHYSICIAN: Dr. Feelgood, M.D.

OBX|1||TEST|4|This is the part of the report I want to keep now.

Code:

var obx5 = message.getAllNodes('OBX-5');

for (var j= 0; j < obx5.length; j++)  {

if (StringUtils.starsWithIgnoreCase(obx5[j],'NAME: ')) {

    message.removeAllNodes('OBX[@5=' + obx5[j] + ']');

}

}

Also IF statements for 'DATE OF EXAM:' , 'PHYSICIAN' etc.

What I"m finding is that this will match if it's the ONLY thing in OBX-5, but if there is information afterwards it's not matching. Is there a better way to match what the line starts with, or wildcard for a phrase in the line?

1 Answer

0 votes

You could use contains instead of startsWith.

 

if (StringUtils.contains(obx5[j],'DATE OF EXAM: ')) {

answered Dec 28, 2020 by michael-h-5027 (14,390 points)
commented Dec 28, 2020 by david-m-6327 (240 points)
I tried that, and also tried StringUtils.containsIgnoreCase and it seems to ignore the line. Thats why I tried the startsWithIgnoreCase thinking since I know what it starts with I could go that route. Not finding any ways to troubleshoot why it's not matching. Thanks for the reply.
commented Dec 28, 2020 by michael-h-5027 (14,390 points)
You can use a qie.debug to view what is in your obx array values. If you wanted to check for multiple values you can use || as or statement.

var obx5 = message.getAllNodes('OBX-5');

for (var j= 0; j < obx5.length; j++)  {
   qie.debug(obx5[j]);
   //if (StringUtils.startsWithIgnoreCase(obx5[j],'NAME: ')) {
   if (StringUtils.contains(obx5[j],'DATE OF EXAM: ') || StringUtils.contains(obx5[j],'DATE OF BIRTH: ') || StringUtils.contains(obx5[j],'PHYSICIAN: ')) {
      message.removeAllNodes('OBX[@5=' + obx5[j] + ']');
   }
}
commented Dec 28, 2020 by david-m-6327 (240 points)
So I put that in. It debugs each individual line.

Code now looks like this:
var obx5 = message.getAllNodes('OBX-5');

for (var j = 0; j < obx5.length; j++) {

   qie.debug(obx5[j]);

   //Check for lines to remove

   if ((StringUtils.contains(obx5[j], 'RADIOLOGY REPORT')) || (StringUtils.contains(obx5[j], '____________________')) || (StringUtils.contains(obx5[j], 'PHYSICIAN: ')) || (StringUtils.contains(obx5[j], 'CHART #: ')) || (StringUtils.contains(obx5[j], 'DATE OF BIRTH: ')) || (StringUtils.contains(obx5[j], 'DATE OF EXAM:')) || (StringUtils.contains(obx5[j], 'NAME: ')) ){

      message.removeAllNodes('OBX[@5=' + obx5[j] + ']');
   
   }

}

One of the lines in the debug is listed as:

[path=1-2] - NAME:  LAST, FIRST     DATE OF EXAM: 12-21-2020

Yet it still doesn't remove that line. Any of the matches that ONLY have that on the line are matched and removed, but any (like the above) that only contain part of the line appear to be ignored.
...