I am struggling on how to add this functionality to the code shown below. Multiple values work, as per the foreach commands in the operator sections (is, not, prefixIs), but I am getting the syntax wrong on where to add the foreach in order for the tcl proc to cycle through the OBX (or any other defined segments) iterations.
Any help is appreciated.
Thank you,
Gordon
proc tpsFilterByHL7Field { args } {
global HciConnName gModule
set gModule “(tpsFilterByHL7Field/$HciConnName)”
keylget args MODE mode ;# What mode are we in
switch -exact — $mode {
start {
return “” ;# Perform special init functions
}
run {
keylget args MSGID mh
set msg [msgget $mh]
keylget args ARGS.SEGMENTID segmentId
keylget args ARGS.FIELDID fieldId
keylget args ARGS.VALUELIST valueList
keylget args ARGS.OPERATOR operator
# get the field separator from MSH segment
set fieldSep [string index [getHL7Segment $msg MSH] 3]
# get the field from the hl7 message
set segment [getHL7Segment $msg $segmentId]
set fieldValue [getHL7Field $segment $fieldSep $fieldId]
#echo fieldValue_sam<$fieldValue>
set valueList [split $valueList |]
# run the test
switch $operator {
is {
# if value is found in list, kill
foreach value $valueList {
if {[cequal $value null]} {
set value “”
}
if {[cequal $value numeric]} {
if {[ctype digit $fieldValue]} {
set returnList “{KILL $mh}”
break
} else {
set returnList “{CONTINUE $mh}”
}
} elseif {[cequal $fieldValue $value]} {
set returnList “{KILL $mh}”
break
} else {
set returnList “{CONTINUE $mh}”
}
}
}
not {
# if value not found in list, kill
foreach value $valueList {
if { [cequal $value null] } {
set value “”
}
if {[cequal $value numeric]} {
if {![ctype digit $fieldValue]} {
set returnList “{KILL $mh}”
break
} else {
set returnList “{CONTINUE $mh}”
}
} elseif { ![cequal $fieldValue $value] } {
set returnList “{KILL $mh}”
} else {
set returnList “{CONTINUE $mh}”
break
}
}
}
prefixIs {
# if value begins with one found in list, kill
foreach value $valueList {
if { [string match $value* $fieldValue] } {
set returnList “{KILL $mh}”
break
} else {
set returnList “{CONTINUE $mh}”
}
}
}
}
return $returnList
}
shutdown {
# Doing some clean-up work
}
default {
echo “Unknown mode in tpsFilterByHL7Field: ‘$mode'”
return “” ;# Dont know what to do
}
}
}