I have a tcl proc that will add an NTE segment directly after every OBR. There could be one but there could be many. The info in the NTE is being based of a table that gets it's value from the OBX.15. How can i get the NTE after the OBR depending on the corresponding OBX.15 info?
As is now it adds the NTE after the OBR but all the OBX.15 info is the same so all NTEs are the same.
######################################################################
# Name: perform_site_nte
# Purpose: This procedure creates a new NTE segment for the message and adds
# performing site.
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode ("start", "run" or "time")
# MSGID message handle
# ARGS user-supplied arguments:
# <describe user-supplied args here>
#
# Returns: tps disposition list:
# <describe dispositions used here>
#
proc perform_site_nte { args } {
global HciConnName
keylget args MODE mode ;# Fetch mode
set dispList {} ;# Nothing to return
set OBRFlag "NO"
set nte ""
set table "poi_performing_site_oru.tbl"
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 [crange $msg 3 3]
set subsep [crange $msg 4 4]
set segments [split $msg r]
set newmh ""
# Roll through all segments of the message
foreach seg $segments {
set segtype [crange $seg 0 2]
# Pull the fields used to build the header from the appropriate
# segments.
switch -exact -- $segtype {
MSH {
set fieldlist [split $seg |]
set msh_4 [lindex $fieldlist 3]
# echo msh_4: $msh_4
set nte [tbllookup $table $msh_4]
# echo nte: $nte
}
OBR {
set OBRFlag "YES"
append newmh $seg r
set fieldlist [split $seg |]
set newnte [join [list NTE 1 {} $nte] |]
append newmh $newnte r
}
OBX {
set fieldlist [split $seg |]
set obx_15_0 [lindex [split [lindex $fieldlist 15] $subsep] 0]
#echo obx_15_0: $obx_15_0
set nte [tbllookup $table $obx_15_0]
#echo nte: $nte
}
default {}
}
if {[cequal $OBRFlag "YES"]} {
set OBRFlag "NO"
} else {
append newmh $seg r
}
}
#regsub command looks for 2 carriage returns at the end of the message and
#replaces it with one.
#regsub -all {x0dx0d} $newmh x0d newmh
msgset $mh $newmh
lappend dispList "CONTINUE $mh"
}
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
}