web stats
Issue with parsing OBX value - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-15-2018, 02:29 PM
Mits87 Mits87 is offline
OBX.2 Kenobi
 
Join Date: Nov 2016
Posts: 59
Mits87 is on a distinguished road
Default Issue with parsing OBX value

We need to reject the result if any of the OBX 5 contains either '***' or '<>'. The no of OBX are random. There are no error message and the result is making it to destination. i have below code for it in my transformer i also tried to use in Filter but same result.

Code:
for(var a=0; a<msg['OBX'].length();a++ ){
	if (msg['OBX'][a]['OBX.5']['OBX.5.1'].toString() != '***' && msg['OBX'][a]['OBX.5']['OBX.5.1'].toString() != '<>')
	return true;
	{
	return false;
}
}
This is the sample message i use

MSH|^~\&|TEST|TEST|||20110529130917-04:00||ORU^R30^ORU-R30|1|P|2.6
PID|1|12349|123||E^A^B^III||19610615|M|||2222 HOMESTREET^^GREENSBORO^NC^27401-1020|GL|(555) 555-2004|(555)555-2004||S||PATID12345001^2^M10^ADT1^AN^A
ORC|NW|1234
PV1|1|I|2000^2012^01||||004777^ATTEND^AARON^A^titl e|||||||1||||||||||||||||||||||||||||||20070110230 0|200701102300
OBX|1||^HCT^LN||<10|%PCV|||||F|||||APOC3214|||2011 0529130917-04:00|MIX
OBX|2||41651-1^GLU^LN||28|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|3||^BUN^LN||139|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|4||^CREA^LN||15.5|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|5||^NA^LN||100|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|6||^K^LN||2.1|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|7||^CL^LN||76|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|8||^TCO2^LN||11|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|9||^ANGAP^LN||16|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|10||^ICA^LN||<>|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
OBX|11||^HB^LN||123|g/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
NTE|1|||Sample Type=MIX||20110529130917-04:00
NTE|2|||CPB=Yes||20110529130917-04:00
NTE|3|||DSN=314237||20110529130917-04:00
NTE|4|||HCT=LOW||20110529130917-04:00


I also tried below code but same result no error and result is processed instead of reject

Code:
for(var Y=0; Y<msg['OBX'].length();Y++ ){
	var OBXVal= msg['OBX'][Y]['OBX.5'].toString();
	if (OBXVal == '***'  && OBXVal == '<>')
	return false;
	{
	return true;
}
}
Reply With Quote
  #2  
Old 03-15-2018, 11:34 PM
aTom aTom is offline
OBX.3 Kenobi
 
Join Date: Feb 2016
Location: Lake Geneva Area
Posts: 115
aTom is on a distinguished road
Default

Hi,

'&&' is a logical AND. Use '||' for an OR.

I'm wondering if Mirth won't escape '<' to '&lt;' and '>' to '&gt;' as HL7 messages get parsed into XML.
__________________
Tom
Reply With Quote
  #3  
Old 03-16-2018, 07:06 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

You're missing the 'else' keyword before the block after your 'if' statement in both samples, however, you also can't return true in your loop or it will short circuit the loop after the first OBX and not check the rest. After you know that none of the OBX segments cause the message to reject, then it is safe to return true.

Filtering must be done in a filter. Returning false from a transformer won't have the desired effect.

It's not incorrect to loop with an index variable like you are doing, but there is a cleaner way to do it.

Code:
for each (obx5_1 in msg['OBX']['OBX.5']['OBX.5.1']) {
  if (obx5_1.toString().match(/^<>|\*\*\*$/))
    return false;
}
return true;
This uses a regular expression to check that it matches exactly to '<>' or '***'. As aTom pointed out, you need to use a logical OR when checking for the false condition. It can never be both at the same time, so your AND will always be false.

If you change the regular expression from /^<>|\*\*\*$/ to /<>|\*\*\*/, it will check for those character sequences anywhere in the string, even if it starts with spaces or has other characters following them.

Mirth uses Mozilla Rhino as it's Javascript engine. Rhino uses a now depricated (but very useful) standard called e4x for processing XML. Your HL7 is represented by e4x xml objects in your filters/transformers. Here are a couple of resources for working with e4x:

https://developer.mozilla.org/en-US/...g_XML_with_E4X

https://wso2.com/project/mashup/0.2/...uickstart.html
Reply With Quote
  #4  
Old 03-16-2018, 07:10 AM
austina austina is offline
Mirth Newb
 
Join Date: Jul 2017
Posts: 7
austina is on a distinguished road
Default

I like agermano's solution since it's short and sweet and uses reg expressions.

Try something like this in your JavaScript type in Edit Filter and not in your Edit Transformer only if the value is *** or <> in OBX.5.1

Code:
// Initialize variable
var suppress 

// Loop through all the OBXs.
for ( var a=0; a < msg['OBX'].length(); a++ )
{
	// Check for values in OBX and set suppress to yes if condition is met.
	if (msg['OBX'][a]['OBX.5']['OBX.5.1'].toString() == '***' || msg['OBX'][a]['OBX.5']['OBX.5.1'].toString() == '<>')
	{
		//set the value for the variable
		 suppress = 'yes';
	} 
}

// if supress is yes then it will cause the message to be filtered.
// else the message will get sent.
if (suppress == 'yes') {
	return false
} else {
	return true
}

Last edited by austina; 03-16-2018 at 07:13 AM.
Reply With Quote
  #5  
Old 03-16-2018, 07:12 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

Quote:
Originally Posted by aTom View Post
I'm wondering if Mirth won't escape '<' to '&lt;' and '>' to '&gt;' as HL7 messages get parsed into XML.
You're safe when calling toString().

Code:
js> x = <xml/>

js> x.lt = '<'
<
js> x.lt.toString()
<
js> x.lt.toXMLString()
<lt>&lt;</lt>
Reply With Quote
  #6  
Old 03-19-2018, 06:51 AM
Mits87 Mits87 is offline
OBX.2 Kenobi
 
Join Date: Nov 2016
Posts: 59
Mits87 is on a distinguished road
Default

Thank you all for your help. I am fairly new to mirth and programming so still trying to catch up. you guys are so helpful cant say how much thankful i am. @agermano thanks a lot for detailed explanation with link for further details. As a newcomer it really helps a lot to learn.
Reply With Quote
  #7  
Old 08-03-2018, 11:08 AM
Mits87 Mits87 is offline
OBX.2 Kenobi
 
Join Date: Nov 2016
Posts: 59
Mits87 is on a distinguished road
Default

My filter is working with manual coding but i upgraded my mirth to 3.6.1 and they have iterator function which i tried to use but some reason its not filtering the data if its *** can someone explain me why may be i am missing something very basic. I am really new to scripting/programming so sorry if its a dumb question but i really want to understand whats wrong with my iterator



my manual code looks like below:

Code:
for ( var b=0; b < msg['OBX'].length(); b++ )
{
	// Check for values in OBX and set suppress to yes if condition is met.
	var OBXValue = msg['OBX'][b]['OBX.5']['OBX.5.1'].toString();
	if (OBXValue == '***')
	{
		//set the value for the variable
		reject = true;
		break;
	}
}

if (reject == false) 
{ return true;} else 
{ return false; }
the code generated by iterator looks like below:

Code:
var _iterator_flag_0 = false;
for (var b = 0; b < getArrayOrXmlLength(msg['OBX']); b++) {
    if (
        (function() {
            if (msg['OBX'][b]['OBX.5']['OBX.5.1'].toString() != '***') {
                return true;
            }
            return false;
        }() == true)
    ) {
        _iterator_flag_0 = true;
        break;
    }

}
return _iterator_flag_0;
Reply With Quote
  #8  
Old 08-06-2018, 06:09 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

I think you just need to change your iterator to accept if All are true instead of At least one.
Reply With Quote
  #9  
Old 08-06-2018, 12:06 PM
Mits87 Mits87 is offline
OBX.2 Kenobi
 
Join Date: Nov 2016
Posts: 59
Mits87 is on a distinguished road
Default

Actually its already set to At lease one only.
Reply With Quote
Reply

Tags
multiple obx

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 03:41 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation