1.2k questions

1.4k answers

361 comments

339 users

Categories

Sidebar
0 votes
542 views
by justin-g-4098 (200 points)
I have several OBR segments all with different OBR-4 values.

I need to replace what is in the OBR-4.1 for every OBR with OBR.4.2 (but only the text that is contained within a set of brackets if the brackets exst).

IE:

OBR|1||1909160461|CBC^CBC, WITH DIFFERENTIAL [M10047]
OBR|1||1909160461|URIC^URIC ACID [M10162]

RESULT:

OBR|1||1909160461|M10047^CBC, WITH DIFFERENTIAL [M10047]
OBR|1||1909160461|M10162^URIC ACID [M10162]

1 Answer

0 votes
 
Best answer

Here is the code to do set OBR-4.1 to what is in the brackets of OBR-4.2

var obrCount = message.getCount('OBR');
for (var i = 1; i <= obrCount; i++) {
   if (StringUtils.isNotBlank(StringUtils.substringBetween(message.getNode('OBR-4.2', i), '[', ']'))) {
      message.setNode('OBR-4.1', StringUtils.substringBetween(message.getNode('OBR-4.2', i), '[', ']'), i);
   }
}

by brandon-w-8204 (34.1k points)
selected by justin-g-4098
...