web stats
Mirth Community - View Single Post - Search for alpha characters and delete OBX
View Single Post
  #1  
Old 05-13-2019, 09:19 AM
Mits87 Mits87 is offline
OBX.2 Kenobi
 
Join Date: Nov 2016
Posts: 58
Mits87 is on a distinguished road
Default Search for alpha characters and delete OBX

I need to check if OBX 5.1 contains any alpha characters and if it does then delete the entire OBX segment. I have below code in place but somehow it's not deleting the OBX line. There is no error either.

Code:
for ( var a=0; a < msg['OBX'].length(); a++ )
{
	if (msg['OBX'][a]['OBX.5']['OBX.5.1'].toString().indexOf(/^[a-zA-Z]*/) > -1 )
	{
		 logger.info(msg['OBX'][a]['OBX.5']['OBX.5.1'].toString());
		 delete msg['OBX'][a];
		 var OBXCounter = 1;
			for each (seg in msg..OBX)
			{
  			seg['OBX.1']['OBX.1.1'] = OBXCounter;
  			OBXCounter++;
			}
	} 
}
Here is the sample message I use

MSH|^~\&|||||20180718104950||ORU^R01|9705201905130 11103|P|2.4|||AL|AL
PID|1||10000000
ORC|NW|||||||||||||||||
OBR|1|||Test1|||20180622115219||||O||||VEN||
OBX|1|ST|Glu||>180|mmol/L||H|||F|||||2||
OBX|2|ST|WBC||57|mg/dL|||||F|||||2||
OBX|3|ST|UREA||<23|mg/dL|||||F|||||2||
OBX|4|ST|BE||NaN|mg/dL|||||F|||||2||
OBX|5|ST|Glu||HIGH|||||||||||2||
OBX|6|ST|Site||ED|||||||||||2||
OBX|7|ST|Verified||No|||||||||||2||
Reply With Quote