How do i replace a subfield. i can do a field but not sure how to get the subfield. I am appending the date/time to the first subfield in the OBR-4. But it just appears appears as the whole OBR-4 field. Any ideas would be great, thanks.
below is what it is:
OBR|1||201004201124-18^RI|ABS^CLIN ABSTRACT PDF^INPC||201004201124|
this is what i want:
OBR|1||201004201124-18^RI|ABS {04/20/2010 11:24}^CLIN ABSTRACT PDF^INPC||201004201124|
Below is my current code:
######################################################################
# Name: tpsBDI_OBX
# Purpose: This tclproc is for the INPC Clinical Abstact. It fixes the
# OBX-5 issue.
#
# 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 the messages
# or
# Errors message if OBR, ORC is missing
#
# Created: Kevin Crist, John Zalesak 05/27/2009
#
#
#########################################################################################
#########################################################################################
#########################################################################################
proc tpsBDI_OBX { 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 OBRpos -1 ;# Position of OBR Segment in msg
set OBRList
- ;# OBR Segment Fields in List Form
set OBXpos -1 ;# Position of OBX Segment in msg
set OBXList
- ;# OBX Segment Fields in List Form
set OBXPDF 5 ;# Field in the OBX that the PDF encoding is in
set OBRDateTime 6 ;# Field in the OBR that the date/time is in
set OBRTestCode 4 ;# Field in the OBR that the test code is in
#########################################################################################
# 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
;# 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 Seperatorset segList [split $msg r] ;# Split message into segList########################################################################################## Find Position of Segements - If missing -> Error out Message and Return#########################################################################################set OBRpos [lsearch -regexp $segList {^OBR}] set OBXpos [lsearch -regexp $segList {^OBX}] if {$OBXpos < 0} { msgmetaset $mh USERDATA "Required Segment OBX Missing!" echo n n n echo ":WARN - $OBXpos 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
return $dispList} ########################################################################################## Split out the OBR and get the OBR-7 date/time so that it can be reformatted#########################################################################################set OBRList [split [lindex $segList $OBRpos] $fldSep]echo OBRList: $OBRList set datetime [lindex $OBRList $OBRDateTime] #The below regsub formats the date so that the following clock scan can be performed. regsub -- {(d{8})(d+)} $datetime {1 2} datetime set datetime [clock format [clock scan $datetime] -format "%m/%d/%Y %H:%M"]echo datetime: $datetime ########################################################################################## Get the OBR-4 so that we can append that date and time to it.######################################################################################### set testcode [lindex [split [lindex $OBRList $OBRTestCode] $subSep] 0]echo testcode: $testcode lappend newtestcode $testcode $datetimeecho newtestcode: $newtestcode set OBRList [lreplace $OBRList 4 4 $newtestcode] ########################################################################################## Split out the OBX and get the OBX-5 and fill in the field with the .######################################################################################### set OBXList [split [lindex $segList $OBXpos] $fldSep] set pdfcode [lindex [split [lindex $OBXList $OBXPDF] $subSep] 4]########################################################################################## Replacing the OBR DXCode code in the OBR-19######################################################################################### set OBXList [lreplace $OBXList 5 5 $pdfcode]########################################################################################## Putting the OBR segment back together with the DXCode code in the OBR-19######################################################################################### lset segList $OBRpos [join $OBRList $fldSep] lset segList $OBXpos [join $OBXList $fldSep] msgset $mh [join $segList r] ########################################################################################## Rebuild msg and store at mh for engine#########################################################################################} time { } shutdown { }} ;# End Switchreturn $dispList} ;# End Proc