I am trying to write a simple proc that we can use for table lookups by using arguments. I know that i can do this in an xlate but we have some feeds that dont require xlates and i dont want to make one just for a table lookup. I was thinking of making the args, just an example{SEGMENT OBR} {FIELD 15} {TABLE specimanSource} , but i am getting a little lost on where to go. any help or ideas are appreciated.
thanks.
proc tpsSetTableValue { args } {
#########################################################################################
# Get the Connection/Proc Name for Error/Debug Messages
#########################################################################################
global HciConnName
set myname "$HciConnName/[lindex [info level 1] 0]"
set nowis [clock format [clock scan now] -format "%D - %T"]
#########################################################################################
# Initialize Variables Used
#########################################################################################
set dispList
- ;# Disposition List Returned to Engine
set fldSep "" ;# Field Seperator - get from MSH
set subSep "" ;# SubField Seperator - get from MSH
set repSep "" ;# Repeating Field Seperator - get from MSH
set SegName "" ;# User Supplied Segment to Change
set FieldNum 0 ;# User Supplied Field Num to Change
set FieldVal "" ;# User Supplied Value to set in Field Num
set TableName "" ;# User Supplied Table to use
set segList
- ;# Message Segments in List Form
set SegPos
- ;# List of Seg Pos in segList that match
;# the User Supplied Segment Name
#########################################################################################
# Load in the arguments we need that were passed from the caller
#########################################################################################
keylget args MODE mode ;# The mode the engine called from
keylget args ARGS.SEGMENT SegName ;# Segment Name
set SegName [string toupper $SegName] ;# Force to uppercase
keylget args ARGS.FIELDNUM FieldNum ;# Field Number to Change
# keylget args ARGS.FIELDVAL FieldVal ;# Value to Set Field To
keylget args ARGS.TABLE TableName ;# Table to use
#########################################################################################
# Switch based on what mode the engine was in when it called the procedure
#########################################################################################
switch -exact -- $mode {
run {
set mh [keylget args MSGID] ;# Get message handle from args
set dispList
;# Initialize to good message set msg [msgget $mh] ;# Get a copy of the message set fldSep [string index $msg 3] ;# Field Seperator set subSep [string index $msg 4] ;# Sub-Field Seperator set repSep [string index $msg 5] ;# Repeating Field Seperatorset segList [split $msg r] ;# Split message into segList########################################################################################## Validate the user supplied values#########################################################################################if { $SegName == "" } { echo n n echo "==========================================================" echo ":WARN - No Segement Name Was Supplied !" echo ":WARN - Message Continued As Is." echo ":WARN - Here Is: $myname" echo ":WARN - Now Is: $nowis" echo $msg echo "==========================================================" echo n n return $dispList}if { $FieldNum == "" || $FieldNum == 0 } { echo n n echo "==========================================================" echo ":WARN - Invalid or No Field Number Was Supplied !" echo ":WARN - Field Number is: "$FieldNum"" echo ":WARN - Message Continued As Is." echo ":WARN - Here Is: $myname" echo ":WARN - Now Is: $nowis" echo $msg echo "==========================================================" echo n n return $dispList}########################################################################################## Find Position of Segement(s) - If missing -> Continue Message and Return#########################################################################################set SegPos [lsearch -all -regexp $segList "^$SegName"]if { [lindex $SegPos 0] < 0 } { echo n n echo "==========================================================" echo ":WARN - Segment "$SegName" Is Missing !" echo ":WARN - Message Continued As Is." echo ":WARN - Here Is: $myname" echo ":WARN - Now Is: $nowis" echo $msg echo "==========================================================" echo n n return $dispList}########################################################################################## Take the value of the field and change it according to the table.#########################################################################################foreach Seg $SegPos {set fldList [split [lindex $segList $Seg] $fldSep]set fldCnt [llength $fldList] for { set flds $fldCnt } { $flds < [expr $FieldNum + 1] } { incr flds } {lappend fldList {} } set value [tbllookup $TableName $FieldVal] lset fldList $FieldNum $FieldVal lset segList $Seg [join $fldList $fldSep] }########################################################################################## Recreate the message and store back at msg handle######################################################################################### set msg [join $segList r] msgset $mh $msg } start { } time { } shutdown { } default { echo ":WARN" echo ":WARN ======================================" echo ":WARN - tps called with invalid mode !"echo ":WARN - Mode Is: $mode"echo ":WARN - Here Is: $myname"echo ":WARN - Now Is: $nowis"echo ":WARN ======================================"echo ":WARN" }} ;# End Switchreturn $dispList} ;# End Proc