I receive clinic lab results (HL7) and using a stored procedure write them to a SQL server DB.
I think stored procedures the best and most efficiant way to go. I am using QDX5.4 and the Quovadx provided Connect 5.0 ODBC driver. I use the ODBC connection with many standalone Tcl scripts, this is the only one I am running directly within the Interface Engine.
Here is the rough outline copied from a tps proc.
switch -exact — $mode {
start {
# Perform special init functions
# N.B.: there may or may not be a MSGID key in args
package require odbc 7
}
run {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
lappend dispList “CONTINUE $mh”
echo “Entering tps_odbc_neodata”
echo [ odbc SQLAllocHandle SQL_HANDLE_ENV SQL_NULL_HANDLE henv ]
echo [ odbc SQLSetEnvAttr $henv SQL_ATTR_ODBC_VERSION SQL_OV_ODBC3 0 ]
echo [ odbc SQLAllocHandle SQL_HANDLE_DBC $henv hdbc ]
echo [ odbc SQLConnect $hdbc EOPC_Lab SQL_NTS USERNAME SQL_NTS PASSWORD SQL_NTS ]
echo [ odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt ]
set msg [msgget $mh]
puts stdout “msg: $msg”
set fieldList [split $msg |]
echo $fieldList
set tDate [ lindex $fieldList 0 ]
set tTime [ lindex $fieldList 1 ]
set MRN [ lindex $fieldList 2 ]
set visit [ lindex $fieldList 3 ]
set sesNum [ lindex $fieldList 4 ]
set lDate [ lindex $fieldList 5 ]
set lTime [ lindex $fieldList 6 ]
set lType [ lindex $fieldList 7 ]
set result [ lindex $fieldList 8 ]
set units [ lindex $fieldList 9 ]
set rRange [ lindex $fieldList 10 ]
set aFlags [ lindex $fieldList 11 ]
#set comments [ lindex $fieldList 12 ]
set SQLTEXT ” insert_LabData ‘$tDate’, ‘$tTime’, ‘$MRN’, ‘$visit’, ‘$sesNum’,
‘$lDate’, ‘$lTime’, ‘$lType’, ‘$result’, ‘$units’,
‘$rRange’, ‘$aFlags’;”
set flag [ odbc SQLExecDirect $hstmt $SQLTEXT SQL_NTS ]
echo $flag
if {$flag != “SQL_SUCCESS” & $flag != “SQL_SUCCESS_WITH_INFO”} {
odbc SQLGetDiagRec SQL_HANDLE_STMT $hstmt 1 SqlState NativeError MessageText 511 TextLength
echo $MessageText
echo “Failed!!!!!!!!”
}
echo $SQLTEXT
odbc SQLFreeHandle SQL_HANDLE_STMT $hstmt
odbc SQLDisconnect $hdbc
odbc SQLFreeHandle SQL_HANDLE_DBC $hdbc
odbc SQLFreeHandle SQL_HANDLE_ENV $henv }
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}
shutdown {
# Doing some clean-up work
}
}
I specifically open new connection for each HL7 message parsed. My volume is small enough that it doesn’t matter. If the volume warrants you may consider opening the connection, setting up the handles in the startup. If you do, you will need checking in the run{} to verify the connection is still open and responsive.
This is in production, but it was my first one and I see lots of opportunities for improvement.