Forum Replies Created
-
AuthorReplies
-
Hi Max. Here is the code.
proc tps_labcorp_check_db_new { args } {
global HciConnName HciSiteDir ;# Name of thread, site
keylget args MODE mode
set ctx “” ; keylget args CONTEXT ctx
set uargs {} ; keylget args ARGS uargs
set debug 0
set module “tps_labcorp_check_db_new/$HciConnName/$ctx”
set dispList {}switch -exact — $mode {
start {}
run {
if {$debug} {echo DEBUG: $module: Begin.}keylget args MSGID mh
set msg [msgget $mh]set db $HciSiteDir/data/sqlite/labcorp.db
sqlite DBCMD $db
DBCMD timeout 10000 ;#timeout controls db locking parameterset mrn [hl7get $msg PID 3 0] ;# Database column: mrn
set csn [hl7get $msg PV1 19 0] ;# Database column: csn
set admDate [hl7get $msg PID 18 0] ;# Database column: har
set orderNum [hl7get $msg OBR 2 0] ;# Database column: order
set labTest [hl7get $msg OBR 4 0] ;# Database column: labTest
set query “select admDate, orderNum from labcorp where mrn = ‘$mrn’ and csn = ‘$csn’ and labTest = $labTest”
set record “”if {[catch {
set record [DBCMD eval $query] ;# Returning a list of 3 elements (mrn, csn, and admDate)
#echo <record: $record>
} err]} {
echo “ERROR: $module: Error in db processing: $err”
}# If match found, copy admDate value found in sqlite into msg PV1-44
if {[llength $record] > 0 } {
# Get the HL7 encoding characters
set fld [string range $msg 3 3]
set com [string range $msg 4 4]
set rep [string range $msg 5 5]
set esc [string range $msg 6 6]
set sub [string range $msg 7 7]# Split the message into into segments
set segments [split $msg \r]
#echo segments <$segments># Get the segment and split it into fields
set loc [lsearch -regexp $segments {^PV1}] ;# Get the element number of the PV1 segment
set PV1 [lindex $segments $loc] ;# Get the PV1 segment
set PV1 [split $PV1 $fld] ;# Create a list of PV1 fields# Making additional fields to get to PV1-44. If list length is less than 19 than increment field
for { set i [llength $PV1]} { $i < 45} { incr i} {
lappend PV1 {}
}# Make the modifications
set PV1 [lreplace $PV1 44 44 [lindex $record 0]]
set PV1 [join $PV1 $fld]
set segments [lreplace $segments $loc $loc $PV1]# Get the ORCsegment and split it into fields
set loc2 [lsearch -regexp $segments {^ORC}] ;# Get the element number of the ORC segment
set PV1 [lindex $segments $loc] ;# Get the ORC segment
set PV1 [split $PV1 $fld] ;# Create a list of ORC fields# Rebuild the message
set msg [join $segments \r]
msgset $mh $msg
} else {
#echo “Not modifying the message”
#return “{KILL $mh}”
# What to do if no records found in db?
}# Disconnect from sqlite db
if {[catch { DBCMD close } err]} {
echo “ERROR: $module: Error closing database: $err”
}set dispList “{CONTINUE $mh}”
}time {}
shutdown {}
default {}
}return $dispList
}Hi Max. I have written a number of scripts to update and read sqlite databases, but now I need to do a loop. I need to write a record to the database for ORMs containing PID-3, PV1-19, PV1-44, OBR-2.1, and OBR-4.1 for each OBR segment. I attached my proc to do a single insert. How do I loop it to insert for multiple OBRs?
Thanks, Jerry.
Jim, thanks for the clarification on that. I built the variant, but did not run it. I do learn a lot on here:)
Hi Andres. I am fairly new to cloverleaf, but I think I have an idea for you. You should be able to create a variant with a user defined segment preceding the MSH (I just did one to test it out), and one or more other user defined segments at the end, or wherever else you need them. You could than copy the values you need into the fields in those segments in the translation, along with the real data you wish to pass. Jerry.
Which types of A31 messages did you decide to suppress?
James and Keith, thank you for the input. That is good information to be aware of. Have a great weekend. Jerry.
-
AuthorReplies