Jim
I know I saw it somewhere but can’t find it now.
Last night I put a new code in a Tcl proc that is called from within xlate by CALL. That proc uses Tcl package that I created to access MS SQL server database to pull data and insert them into message.
That package has been working fine for a few weeks. But I never called it from within xlate – I used it pre-xlate and post-xlate procedures.
So last night I decided to give it a try and call it from within xlate and it worked! I was so excited!
This morning I saw lot of errors in the log – package variable not exists.
Here is exact error message:
Tcl callout error
erroCode: NONE
errorInfo:
can’t read “db”: no such variable
while executing
“$db $queries(stmt_$qryname) $queries(args_$qryname) $qryparms”
(procedure “par_sql::run_qry” line 12)
invoked from within
“par_sql::run_qry get_culture_exam_quantity [list $visit_ext_id $order $child_order $seq”
(procedure “get_ce_qnty” line 50)
invoked from within
“get_ce_qnty”
I don’t know why it worked last night, but it’s not so important for me now.
I wonder if my tcl called from within Xlate (using CALL) runs in a new process every time? That would explain why the package variable doesn’t exist. That variable “$db” is handler to the SQL connection.
Here is code of my proc:
######################################################################
# Name: get_ce_qnty – get Culture Exam quantities from SQL database
# Purpose:
# UPoC type: xltp
# Args: none
# Notes: All data is presented through special variables. The initial
# upvar in this proc provides access to the required variables.
#
# This proc style only works when called from a code fragment
# within an XLT.
#
# This proc called from within Xlate and the following fields are passed into it:
#
# Visit External Id – patient visit number
# Paragon Order Number – first four digits are order#, the rest are child order#
# Culture Exam Sequence number
#
package require par_sql
proc get_ce_qnty {} {
global db
global access_paragon
set data_source_name paragon_puwt
set ignore_errors 1
par_sql::setDebug 1
if {![info exists db]} {
# try to connect to paragon db
if {[catch {par_sql::connect $data_source_name} err_msg]} {
if {$ignore_errors} {
set access_paragon 0
echo $err_msg
} else {
set access_paragon 0
error $err_msg
}
} else {
set db $err_msg
set access_paragon 1
}
# if can’t access db – just return
if {!$access_paragon} {
return
}
}
upvar xlateId xlateId
xlateInList xlateInList
xlateInTypes xlateInTypes
xlateInVals xlateInVals
xlateOutList xlateOutList
xlateOutTypes xlateOutTypes
xlateOutVals xlateOutVals
set visit_ext_id [lindex $xlateInVals 0]
set par_order [lindex $xlateInVals 1]
set seq [lindex $xlateInVals 2]
set order “*”
set child_order “*”
regexp — {(d{4})(d{1,4})} $par_order -> order child_order
### echo “visit# $visit_ext_id”
### echo “order $order/$child_order”
### echo “seq $seq”
set cult_exam [par_sql::run_qry get_culture_exam_quantity [list $visit_ext_id $order $child_order $seq]]
### echo “culture exam: $cult_exam”
# return result – quantity is in 1st element of the returned list; seq – in 2nd
set ce_quantity [string trim [lindex [lindex $cult_exam 0] 0]]
xpmstore $xlateId [lindex $xlateOutList 0] c $ce_quantity
}
I wonder if I just should move my access to MS SQL to pre-xlate proc where it works. This is kind of urgent issue so at this point I more concerned about making it working than spending too much time on understanding why it’s not and how to fix it 😕
Thanks,
Sergey