web stats
I need help building a filter that checks a repeating segment - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-14-2018, 07:28 AM
J R J R is offline
OBX.1 Kenobi
 
Join Date: Nov 2017
Posts: 26
J R is on a distinguished road
Default I need help building a filter that checks a repeating segment

It seems like this should be pretty easy, but I have tried this about 5 different ways with single javascript rules, using rule builder, and adding multiple java rules with and without setting variables first.

Here is what I need to do:

Check inbound result messages (ORU^R01)

- If the MRN in PID.3.1 contains the value 'XYZ' (the length of the field varies, but it will always have 'XYZ' at the end if it is for the facility I want)

and

- If the Result Status in OBR.25.1 is anything other than 'P' (Preliminary)

send that result to my destination.


This standalone filter works fine:

if ((msg['PID']['PID.3']['PID.3.1'].toString().indexOf('XYZ') != -1)) {
return true;
}
return false;

But it's the OBR.25 part that is giving me fits. Because some of these results come with more than 1 ORC-OBR set, I can't seem to get it to filter if it repeats.

I have tried inserting a loop. Something like this, but even though the syntax validates, I don't think it is right (I hve tried moving the 'if' part out of the for loop as well:

for each(OBRrep in msg.OBR)
{
var OrdStatus = ['OBR']['OBR.25']['OBR.25.1'].toString().toUpperCase();
if (OrdStatus != 'P') {
return true;}
}
return false;

This will cause an error when processing. If I take out the 'for each' and just look for 'P' in OBR.25.1, it will send the message if there are more than 1 OBR segments present even if all of them have 'P' in OBR.25.

I can assume if ANY OBR repetition is 'P', the message should be skipped, although I am fairly certain each OBR will have the same status regardless.
Reply With Quote
  #2  
Old 02-16-2018, 05:58 AM
amble amble is offline
OBX.2 Kenobi
 
Join Date: Nov 2015
Posts: 95
amble is on a distinguished road
Default

Should do what you're attempting.
Attached Files
File Type: xml mirthTest.xml (21.5 KB, 17 views)
Reply With Quote
  #3  
Old 02-16-2018, 07:23 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 841
siddharth is on a distinguished road
Default

You could make use of a flag that sets to false when any of OBR[i].25 is a Preliminary.
Then you could combine this flag with the already existing filter with an AND condition.
__________________
HL7v2.7 Certified Control Specialist!
Reply With Quote
  #4  
Old 02-19-2018, 12:35 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,181
agermano is on a distinguished road
Thumbs up

While it's generally better to remove a destination from the destinationSet, as in amble's attachment, than to filter the destination, your code was really close to working.

Quote:
Originally Posted by J R View Post
for each(OBRrep in msg.OBR)
{
var OrdStatus = ['OBR']['OBR.25']['OBR.25.1'].toString().toUpperCase();
if (OrdStatus != 'P') {
return true;}
}
return false;
To use the for each loop, this should just be:
Code:
for each (var OBRrep in msg.OBR)
	{
	var OrdStatus = OBRrep['OBR.25']['OBR.25.1'].toString().toUpperCase();
	if (OrdStatus != 'P') {
		return true;
	}
}
return false;
If you only care about checking the first one you don't need a loop. You can check:
Code:
msg['OBR'][0]['OBR.25']['OBR.25.1'].toString().toUpperCase() != 'P'
You can use this even when there is only one OBR segment.
Reply With Quote
  #5  
Old 02-20-2018, 12:55 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 841
siddharth is on a distinguished road
Default :D

Welcome Tony!
__________________
HL7v2.7 Certified Control Specialist!
Reply With Quote
Reply

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 01:12 PM.


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