Sidebar

Split OBX5 into multiple OBX segments at line break(\.br\)

0 votes
339 views
asked Jun 14, 2022 by surya-p-7473 (200 points)
I have a ORU message with a single OBX segment and I need to split it into multiple OBX segments based on OBX5 observations which are separated by \.br\ as opposed to a ~. Is there any string utilities that I can use to do that?

 

So the OBX looks like this:

OBX|1|ST|Coding Summary^Coding Summary||\.br\\.br\\.br\\.br\\.br\     Line1    \.br\     Line2\.br\\.br\     Line3:\.br\    Line4\.br\\.br\     

and it should be parsed to:

OBX|1|ST|Coding Summary^Coding Summary||     Line1|||||

OBX |1|ST|Coding Summary^Coding Summary|Line2||||||  

OBX |1|ST|Coding Summary^Coding Summary|Line3:||||

OBX |1|ST|Coding Summary^Coding Summary|Line4|||||

 

Please suggest the right script to use to accomplish this translation.

2 Answers

0 votes

Here's some example code that will accomplish what you would like.  The idea is that we create an array of elements based off the OBX-5 field split by \.br\.  We remove the existing OBX segment from the message, then re-add OBX segments back in with the individual items from the original OBX segment, this time each in their own segment.

var obxString = message.getNode('OBX-5');
var obxArray = StringUtils.splitByWholeSeparator(obxString, '\\.br\\');

message.removeAllNodes('OBX');

for (var i = 0; i < obxArray.length; i++) {
   if (StringUtils.length(obxArray[i]) > 0) {
      message.addChild('/', 'OBX', 'OBX|1|ST|Coding Summary^Coding Summary||' + obxArray[i].trim());
   }
}
 

answered Jun 14, 2022 by jon-t-7005 (7,590 points)
0 votes
Thank you for the script. Can we tweat the code a lil bit to make sure we are not hard coding OBX3 with Coding Summary^Coding Summary. So the OBX looks like this

 

OBX|1|ST|Something^Something||\.br\\.br\\.br\\.br\\.br\     Line1    \.br\     Line2\.br\\.br\     Line3:\.br\    Line4\.br\\.br\

That OBX 3 can be anything.
answered Jul 12, 2022 by surya-p-7473 (200 points)
...