› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Need a TCL proc to compare fields
The part that I’m having issues with is the comparison of pv1 7 or pv1 8 or pv1 9, etc…
Any suggestions?
Not sure if this will help. It is primitive and you may have to change to look for what you need but logic may work. Im sure others have better ways of doing/writing this.
#########################################################################################
#########################################################################################
#########################################################################################
# Name: tpsKillAlls_Dr.tcl
# Purpose: This proc will KILL the mesages based on if the Consulting, Admitting Dr.,
# and Service of CCC code is in the Alls_Dr.tbl. If the code is in the table
# the CONTINUE the else we want to kill it.
#
#
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (”start”, “run” or “time”)
# MSGID message handle
# ARGS user-supplied arguments:
#
#
#
# Returns: tps disposition list:
# Continues message if the Admitting or Consulting Dr. Code is in the
# in Alls_Dr.tbl, if not then KILL the message
#
# Created: Kevin Crist 09/2/2009
#
#
#########################################################################################
#########################################################################################
#########################################################################################
proc tpsKillAlls_Dr { 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 PV1pos -1 ;# Position of PV1 Segment in msg
set PV1List [list] ;# PV1 Segment Fields in List Form
set ConsDrList [list] ;# PV1-3 subfields in List Form
set AdmDrList [list] ;# PV1-3 subfields in List Form
set defaultvalue {} ;# Value in table when no his is found
set ConsDrLocation 9 ;# Cons Dr is in field 9 in PV1
set AdmDrLocation 17 ;# Admit Dr. is in field 17 in PV1
set Service 10 ;# Service code looking for CCC
set table “Alls_Dr” ;# Table with Dr. number in it.
#########################################################################################
# Switch based on what mode the engine was in when it called the procedure
#########################################################################################
keylget args MODE mode ;# The mode the engine called from
switch -exact — $mode {
start { }
run {
set mh [keylget args MSGID] ;# Get message handle from args
# set dispList [list “CONTINUE $mh”] ;# 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 Seperator
set segList [split $msg r] ;# Split message into segList
#########################################################################################
# Find Position of Segments – If missing -> Error out Message and Return
#########################################################################################
set PV1pos [lsearch -regexp $segList {^PV1}]
if { $PV1pos < 0 } {
msgmetaset $mh USERDATA "Required Segment PV1 Missing!"
echo n n n
echo ":WARN – PV1 Segment Missing !"
echo ":WARN – Sending Message to error db."
echo ":WARN – Here Is: $myname"
echo ":WARN – Now Is: $nowis"
echo $msg
echo n n n
set dispList [list "ERROR $mh"]
return $dispList
}
#########################################################################################
# Pull out the dr fields and get the Affinity Dr. code
#########################################################################################
set PV1List [split [lindex $segList $PV1pos] $fldSep]
set ConsDrList [split [lindex $PV1List $ConsDrLocation] $subSep]
set AdmDrList [split [lindex $PV1List $AdmDrLocation] $subSep]
set ConsDr [split [lindex $ConsDrList 0] $subSep]
set AdmDr [split [lindex $AdmDrList 0] $subSep]
set Ser [split [lindex $PV1List $Service] $subSep]
#########################################################################################
# Rebuild msg and store at mh for engine
#########################################################################################
# lset ConsDrList [join $ConsDr $subSep]
# lset AdmDrList [join $AdmDr $subSep]
# echo ConsDrList:$ConsDrList
# lset PV1List $ConsDrLocation $ConsDrList
# lset PV1List $AdmDrLocation $AdmDrList
# lset segList $PV1pos [join $PV1List $fldSep]
msgset $mh [join $segList r]
#########################################################################################
# Check the Dr. Code with the Alls_Dr.tbl and see if it is a match. If there is a match
# then the message would pass, else kill it.
#########################################################################################
set value [tbllookup $table $ConsDr]
set value2 [tbllookup $table $AdmDr]
set value3 [tbllookup $table $Ser]
if {[string equal $value "YES"] || [string equal $value2 "YES"] || [string equal $value3 "YES"]} {
lappend dispList "CONTINUE $mh"
} else {
lappend dispList "KILL $mh"
}
}
time { }
shutdown { }
} ;# End Switch
return $dispList
} ;# End Proc
Thanks… That worked!
I was getting bogged down with the details, and the number of fields that I needed to work with. Once I saw your code, it ended up being fairly easy!
Glad it worked. That is a primitive way to do that and im sure there are “better” ways to write it but it works.