Using Lookup or Exists on Repeating Fields in Ensemble Business rule
I have a project to only filter certain pathology results into a downstream system.
Within a HL7 router and business I was planning on using a lookup table and either the exists() or Lookup(), but am having issues when using it with repeating fields or segments.
For example if I perform teh analysis per stated segment usign {} brackets this will work, as each stated repeat is assessed:
(HL7.{PIDgrpgrp(1).PIDgrp.PID:PatientIdentifierList(1).ID} DoesNotStartWith "ICE")&&((Lookup("Sunquest.Lorenzo.OBR4Whitelist",HL7.{PIDgrpgrp1(1).ORCgrp(1).OBR:UniversalServiceIdentifier.identifierST},,)="1")||(Lookup("Sunquest.Lorenzo.OBR4Whitelist",HL7.{PIDgrpgrp(1).ORCgrp(2).OBR:UniversalServiceIdentifier.identifierST},,)="1")||(Lookup("Sunquest.Lorenzo.OBR4Whitelist",HL7.{PIDgrpgrp(1).ORCgrp(3).OBR:UniversalServiceIdentifier.identifierST},,)="1"))
However if I try to use () I do not get very far as the second part of this rule does not evaluate as true:
(HL7.{PIDgrpgrp(1).PIDgrp.PID:PatientIdentifierList(1).ID} DoesNotStartWith "ICE")&&(Lookup("Sunquest.Lorenzo.OBR4Whitelist",HL7.(PIDgrpgrp1().ORCgrp().OBR:UniversalServiceIdentifier.identifierST),,)="1")
I've seen in another post (Link) that the repeating fields cannot be handled out of the box with these functions.
If this is the case I guess the next step is to write my own utility function to handle these.
Any advice would be appreciated.
Regards
Stuart
I have built a custom function that I call ListExists that handles checking if a List returned by the [] square bracket syntax has (any or all) items in the lookup table. Square bracket syntax works in a routing rule and returns a >< delimited list of all the values in a particular repeating field.
Here is the code:
Class CustomFunction.ListExists Extends Ens.Rule.FunctionSet
{
/// Test if the keys specified in the <var>List</var> are defined within the lookup table specified by <var>LookupTable</var>.<br/>
/// Can handle lists like <key1><key2><...> or other delimited lists by changing the <var>Delimeter</var>.<br/>
/// Return true (1) if "All" keys exists (default) or if any key exists by entering "Any" in <var>AnyAll</var>, and false (0) otherwise.<br/>
/// <var>IgnoreNullListItem</var> when 1 will ignore empty list items.
ClassMethod ListExists(LookupTable As %String = "", List As %String, Delimeter As %String = "><", AnyAll As %String = "All", IgnoreNullListItem As %Boolean = 1) As %Boolean
{
if LookupTable = ""
{ Quit 0
}
set tAnyAll = ..ToUpper(AnyAll)
set tListLen = $LENGTH(List,Delimeter)
set tcount = 1
While tcount <= tListLen
{
set tListItem = $PIECE(List,Delimeter,tcount)
if Delimeter = "><"
{ // strip off beginning and end half delemiters
if tcount = 1
{ set tListItem = $ZSTRIP(tListItem,"<","<")
}
// could be both first and last
if tcount = tListLen
{
set tListItem = $ZSTRIP(tListItem,">",">")
}
}
if tListItem = ""
{ //list item is null
if IgnoreNullListItem
{
set tcount = tcount + 1
CONTINUE
}
// note that a null list item will never exist in the table so the "ALL" will fail if not ignored
}
if ..Exists(LookupTable,tListItem)
{ // this one exists in lookup table
if tAnyAll = "ANY"
{
Return 1
}
}
else
{ //doesn't exist and we want all to exist
if tAnyAll = "ALL"
{
Return 0
}
}
set tcount = tcount + 1
}
// if comes out of loop then
if tAnyAll = "ANY"
{ Quit 0 // didn't find any
}
else //assume in "ALL" so must have found them all to get here
{ Quit 1
}
}
}
Thank you Stephen, I used your advice on square brackets and your method as a template to write my own.
Thank you for your guidance.
Stuart