Jan,
This can be accomplished by a Tcl script on the inbound TPS or pre-Xlate.
Since you don’t know which OBX segment will contain the procedure date, you could run a regular expression against the message and search for the string “Release Date Time:”. I would not move the whole string to OBR-8 then drop the prefix. Instead I would use the regular expression to capture the date that comes after the prefix, reformat the date as needed, and copy it to OBR-8. Next you rebuild the OBR segment and the message.
Something like this should work for you:
######################################################################
# Name: tps_move_obs_datetime
#
# Purpose: Copy the Observation End Date/Time from a variable OBX
# segment to OBR-8.
# The receiver expects this date in OBR.8 in the format
# yyyymmddHHMM.
#
# The purpose of this script is to extract the procedure date
# from one of the OBX segments and copy it to OBR-8.
#
#
# UPoC type: tps
# To be used in inbound TPS or in Route Details, pre-Xlate.
#
# Args: tps keyedlist containing the following keys:
# MODE run mode (“start”, “run” or “time”)
# MSGID message handle
# ARGS user-supplied arguments: None for this script
#
#
# Returns: tps disposition list:
# CONTINUE -We always continue the message, modified or not.
#
# Date: 08/12/2009
#
#
# Example of OBX segment with the procedure date:
# OBX||TX||17|Release Date Time: 08/04/2009 13:11||||||F|
proc tps_move_obs_datetime { args } {
keylget args MODE mode ;# Fetch mode
set dispList {}
set signed_flag “”
switch -exact — $mode {
start {
# Perform special init functions
# N.B.: there may or may not be a MSGID key in args
}
run {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
set msg [msgget $mh]
set fieldSep [string index $msg 3]
set segmentList [split $msg r]
# We can use a regular expression to search the message for
# the string “Release Date Time:” and capture the date that
# comes after it.
set all “” ;# for the complete match
set dt “” ;# to capture the date/time only
# The expression within parentheses captures the date/time in
# the variable “dt”. Format dd/dd/dddd dd:dd
regexp “Release Date Time:\s+(\d+/\d+/\d+\s+\d+:\d+)” $msg all dt
echo “Total match: $all”
echo “Matched Date: $dt”
# If we weren’t able to pull the date from the report text,
# just continue the message.
if {[string equal $dt “”]} {
# No extracted date. Bail out.
echo “No extracted date. Just continuing message unmodified”
lappend dispList “CONTINUE $mh”
return $dispList
} ;# end if statement
# Change the date format from mm/dd/yyyy HH:MM to HL7 format yyyymmddhhmm
set dt [clock format [clock scan $dt] -format %Y%m%d%H%M]
echo “Transformed Date: $dt”
# Now that we have the procedure date, it’s just a matter of copying this
# value to OBR-8, rebuilding the message, and continuing the modified message.
set newSegmentList “”
foreach segment $segmentList {
# Change field 8 in the OBR segment only
if {[string equal [string range $segment 0 2] OBR]} {
# Break the segment in a list of fields
set fieldList [split $segment $fieldSep]
# Make the substitution
set fieldList [lreplace $fieldList 8 8 $dt]
# Put the segment back together as a string
set segment [join $fieldList $fieldSep]
} ;# end if statement
# Add each segment to the new list
set newSegmentList [lappend newSegmentList $segment]
} ;# end foreach statement
# Put the message back together as a string
set msg [join $newSegmentList r]
# Change the message stored in the message handle to our modified message!
msgset $mh $msg
# Now continue the modified message
lappend dispList “CONTINUE $mh”
return $dispList
} ;# end run mode
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}
shutdown {
# Doing some clean-up work
}
}
return $dispList
}