- This topic has 10 replies, 10 voices, and was last updated 9 years, 12 months ago by .
-
Topic
-
Two or three times now I have tried writing scripts using arguments and not succeeded – only to find that if I abandoned the “argument” strategy and simply hard coded the value(s) in the code then the script was successful. This has just happened to me again – so I am posting the script in the hopes that someone might be able to tell me what I’m doing wrong.
For the following I am submitting the aguments like this:
{VALUE_1 HEART}
{VALUE_2 BLAND}
Here’s the script (it runs successfully if not using args and hardcoding the values):
######################################################################
# Name: kill_non_dietary_orders_sub_sep_arg.tcl
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (“start”, “run” or “time”)
# MSGID message handle
# ARGS user-supplied arguments:
# VALUE_1 value_1
# VALUE_2 value_2
# VALUE_3 value_3
# Description: Kills message if the specified substring in the arguments is somewhere present in the OBR-4.2
# Returns: tps disposition list:
# $CONTINUE
# $KILL
proc kill_non_dietary_orders_sub_sep_arg { args } {
keylget args MODE mode ;# Fetch mode
set dispList {} ;# Nothing to return
switch -exact — $mode {
start {
# Perform special init functions
# N.B.: there may or may not be a MSGID key in args
}
run {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
# Here we retrieve the data from our original message
set msg [msgget $mh]
# Get the argument value
keylget args ARGS.VALUE_1 value_1
keylget args ARGS.VALUE_2 value_2
keylget args ARGS.VALUE_3 value_3
# Now we need to determine our field and subcomponent seperators
set field_sep [csubstr $msg 3 1] ;# HL7 field separator
set sub_sep [csubstr $msg 4 1] ;# HL7 subfield separator
set rep_sep [csubstr $msg 5 1] ;# HL7 field repetition separator
set subsub_sep [csubstr $msg 7 1] ;# HL7 sub subfield separator
# Here we split the original message into a list of the segments contained within
set segmentList [split $msg r]
# Now we iterate over each segment in our list.
foreach segment $segmentList {
if {[cequal [crange $segment 0 2] OBR]} {
set fieldList [split $segment $field_sep]
set obr_4 [lindex $fieldList 4]
set obr_4_list [split $obr_4 $sub_sep]
set obr_4_2 [lindex $obr_4_list
} else {
}
}
if {[string first $value_1 $obr_4] !=-1 || [string first $value_2 $obr_4] !=-1} {
lappend dispList “CONTINUE $mh”
return $dispList
} else {
lappend dispList “KILL $mh”
return $dispList
}
}
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}
shutdown {
# Shutdown mode
echo “kill_non_dietary_orders_sub_sep_arg is shutting down”
}
default {
error “Unknown mode ‘$mode’ in kill_non_dietary_orders_sub_sep_arg”
}
}
return $dispList
}
- The forum ‘Cloverleaf’ is closed to new topics and replies.