Operators as Variables
We have the need to write a function that can loop through say a field in an OBX segment within HL7 and compare it to a string passed. Is it possible to have the user enter the Operator ( >,<,=,<>) as a variable inside Cache object script? Does anyone have any examples they can share?
Thanks
Scott Roth
The Ohio State University Wexner Medical Center
Are you not using the Transformations?
This is not in a translation. We want to write a function to loop through a repeating segment and compare it to a string value within a Routing Rule. I've done this before as a lookup against a table but not compare strings before.
could you use the function called xecute ?
I am not familiar with that function.
This is how I am looking up a repeatable segment against a lookup table.
ClassMethod GroupIDExists(pHL7Msg As EnsLib.HL7.Message, pSegment As %String, pField As %String, pLookupTable As %String) As %Boolean
{
#dim tSeg as EnsLib.HL7.Segment
set tSegCount = pHL7Msg.SegCountGet()
set i = 1
Set tFound = 0
//get new values
set tval=""
while ((i <= tSegCount) && (tval="")) {
set tSeg = pHL7Msg.GetSegmentAt(i)
if (tSeg.Name = pSegment) {
set tID = tSeg.GetValueAt(pField)
set tval= ..Lookup(pLookupTable, tID)
}
set i = i + 1
}
if (tval '= "")
{
Q 1
}
quit 0
}
Not sure how you would do that with XECUTE
Here's an example of what Carlos is suggesting with XECUTE:
ClassMethod CompareValues(val1, val2, operator) as %Boolean {
set testStatement="set testResult=(val1 "_operator_" val2)"
XECUTE testStatement
quit testResult
}
[edited code to fix a typo]
Same idea within a shell session. I often like to evaluate expressions to check they work as expected before writing any significant code.
set val2 = 11
set operator = "<"
set testStatement="set testResult=(val1_operator_val2)"
xecute testStatement
zwrite testResult
I'd try to avoid giving user an ability to enter arbitrary code.
1. Offer user a list of predefined operations ( >,<,=,<> or Equals,More, Not Equals,...)
2. Get input from user.
3. Check that input is actually one option on a list and not something else.
4. Perform the check using IF, for example.
eXecute command is sensible to variable scoping
in addition control of allowed operates is required.
this small method gives you an easy to maintain code.
goto $case(op
,"<":lt
,">":gt
,"=":eq
,"<>":ne
,:fail
)
fail quit 0
lt quit var1 < var2
gt quit var1 > var2
eq quit var1 = var2
ne quit (var1 '= var2)
}
.
and you are free to use any naming of your operator you allow ( & , $ , @, GOOFY, DAISY, DUFFY, DONALD, .. )
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue