Sidebar

Copy value from OBR-4.2 in between brackets to OBR-4.1 for each OBR

0 votes
353 views
asked Sep 20, 2019 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);
   }
}

answered Sep 20, 2019 by brandon-w-8204 (33,170 points)
selected Sep 23, 2019 by justin-g-4098
...