I’m working on a proc to determine the LAB Section ID for OBR.24 and I have two issues and a brain freeze.
Issue 1: I’ve got something amiss with curly braces.
Issue 2: I haven’t been able to put the segments back together with the new OBR.
The code is below.. Yep I’m aware that I’ve commented out several lines. Just trying to step through the code. Any help appreciated.. Thanks..!!
######################################################################
# Name: preXLT_DetermineDEPT
# Purpose: TPS proc used to take the accession number from a LAB
# report and break it apart to determine the SECTION ID
# and populate OBR.24. Can be removed when Meditech
# adds department to OBR.24 per request. E
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (“start”, “run” or “time”)
# MSGID message handle
# ARGS None
#
# Returns: Message with LAB Section ID in OBR.24
######################################################################
proc preXLT_DetermineDEPT { args } {
global HciConnName
keylget args MODE mode ;# Fetch Mode
switch -exact — $mode {
start {}
run {
# run mode always has a MSGID; fetch and process it
keylget args MSGID mh ;# Get message handle
set msg [msgget $mh] ;# Get a copy of the message
set segs [split $msg r] ;# Split the message into segments
set fldSep [string index $msg 3] ;# Field Separator
set subSep [string index $msg 4] ;# Sub-Field Separator
# Set variables for later use
set Dept “”
set Delim “:”
# Get the OBR Segment and Determine what the Lab Section
# LOOP through the message and modify each OBR segment.
foreach OBR [lsearch -all -inline -regexp $segs {^OBR}] {
set OBRflds [split $OBR $fldSep] ;# Field List
set OBR3 [lindex $OBRflds 3] ;# Accession Number
set FldList [split $OBR3 $Delim] ;# Split on a delimeter of “:”
set Prefix [lindex $FldList 0] ;# Get Data before the “:”
set Suffix [lindex $FldList 1] ;# Get Data after the “:”
set Suf1 [string range $Suffix 0 1] ;# Get the first two bytes of Suffix
set OBR24 [lindex $FldList 24] ;# Get the OBR24 field for later
# echo “OBR is $OBR”
# echo “OBRflds are $OBRflds”
echo “OBR3 is $OBR3”
echo “Prefix is $Prefix”
if { [string length $Prefix] < 3 } { ;# if only 2 digits; it's MICRO set Dept MIC ;# Set OBR24 to “MIC” } else { if { [string match $Suf1 “BB”] } { ;# if it’s ‘BB’, its Blood Bank set Dept BBK ;# Set OBR24 to “BBK” } else { set Dept LAB ;# Everthing else is General LAB } set OBRflds [lreplace $OBRflds 24 24 $Dept] ;# Put the updated value back in OBR.24 set OBR [join $OBRflds $fldSep] ;# Put the OBR segment back together } ;# End foreach Loop echo “New Dept is $Dept” #echo “OBR24 is $OBR24” echo “Modified OBR segment: $OBR” } msgset $mh [join $segs r] ;# Create a new message return “{CONTINUE $mh}” } time {} #shutdown {} #default {} } # return $dispList } }