Business Rule that can compare two fields in a repeating segment
I am trying to find the best way to evaluate if OBX-3 = ^IS TEST PATIENT? and OBX-5 = Y In the same OBX in a Business Rule
OBX|1|NM|P-CSN|1|7623201922192||||||F OBX|2|NM|P-UCI|2|||||||F OBX|3|TX|^ADT: PATIENT CLASS|1|Outpatient|||||||||20210715 OBX|4|TX|^IS TEST PATIENT?|1|Y
I started to create a function in a class that uses the Rule [] bracket syntax and extends Ens.Rule.FunctionSet:
But after some initial troubleshooting I realized that the [] brackets will not return a value if a field is null, making the two lists different lengths and impossible to compare.
HL7.[OBX:3] = <P-CSN><P-UCI><^ADT: PATIENT CLASS><^IS TEST PATIENT?>
HL7.[OBX:5] = <7623201922192><Outpatient><Y>
HL7.[OBX:5] list has 3 values instead of 4 because the 2nd OBX-5 is null.
Has anyone come up with a way to do this easily in a rule or do I have to try to pass the entire HL7 message into a function to compare a repeating segment like this?
Here is the function I started
PairedValuesInLists(HL7.[OBX:3],HL7.[OBX:5],"IS TEST PATIENT?","Y")
ClassMethod PairedValuesInLists(list1 As %String = "", list2 As %String = "", value1 As %String, value2 As %String) As %Boolean [ Final ]{$$$LOGINFO(list1_"^"_list2_"^"_value1_"^"_value2)set list1 = ##class(Ens.Util.FunctionSet).ReplaceStr(list1, "><", ",")set list2 = ##class(Ens.Util.FunctionSet).ReplaceStr(list2, "><", ",")set list1 = ##class(Ens.Util.FunctionSet).Strip(list1, "*", "<>")set list2 = ##class(Ens.Util.FunctionSet).Strip(list2, "*", "<>")et returnValue = 0for i=1:1:$length(list1,",")
{
set list1Value = $piece(list1,",",i)
set list2Value = $piece(list2,",",i)
w list1Value, !
w list2Value, !
if ((value1 = list1Value) && (value2 = list2Value))
{
set returnValue = 1
}
}
quit returnValue}Comments
Found a way to do this by passing HL7.[OBX] into the function instead of the fields
ClassMethod TwoFieldsInSegments(list1 As %String = "", value1 As %String, value2 As %String, position1 As %String = "4", position2 As %String = "6") As %Boolean [ Final ]
{
//$$$LOGINFO(list1_"^"_value1_"^"_value2)
//<OBX(1)><OBX(2)>
set returnValue = 0
for i=1:1:$length(list1,">")
{
set list1Value = $piece(list1,">",i)
set position1value = $p(list1Value,"|",position1)
set position2value = $p(list1Value,"|",position2)
//w !,position1value,!,position2value if (value1 = position1value) && (value2 = position2value)
{
set returnValue = 1
}
}
quit returnValue
}