› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Reusing variable from one segment to another
} elseif [cequal [crange $segment 0 2] GT1] {
set fieldList [split $segment $field_sep]
set gt1_5 [lindex $fieldList 5]
echo $gt1_5 (this returns a value)
set segment [join $fieldList $field_sep]
append outbuf ${segment}r
} else if [cequal [crange $segment 0 2] PID] {
echo $gt1_5 (this returns nothing)
}
The echo does not work in the PID segment area. I need to reuse the contents of $gt1_5 within the PID segment ‘elseif’ statement. I can pull a variable defined within the MSH ‘if’ statement defined earlier and use it just fine in a ‘cequal’ condition.
Is this part of some sort of iteration/looping? Can you post the full uproc?
Tom
######################################################################
# Name: ccsci_a_centricity.tcl
# Purpose:
#
# UPoC type: Pre Xlate
# 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:
# CONTINUE – Message was processed normally – continue into engine.
# ERROR – Message processing failed – put message into the error database.
#
# This proc creates the ADT message for Centricity.
proc ccsci_a_centricity { args } {
global HciConnName
keylget args MODE mode ;# Fetch mode
keylget args CONTEXT context ;# Fetch context
# if { ! [info exists HciConnName] } {
# set HciConnName “UNKNOWN_TD”
# }
set dispList {} ;# Nothing to return
switch -exact — $mode {
start {
# Perform special init functions
# N.B.: there may or may not be a MSGID key in args
}
run {
keylget args MSGID mh ;# Fetch the MSGID
set msg [msgget $mh] ;# Get the Message Handle
set outbuf {}
# Now we need to determine our field and sub components
set field_sep [csubstr $msg 3 1] ;# HL7 field separator
set sub_sep [csubstr $msg 4 1] ;# HL7 subfield separator
set sub_sub_sep [csubstr $msg 7 1] ;# HL7 sub-subfield separator
set rep_sep [csubstr $msg 5 1] ;# HL7 repetition separator
set segmentList [split $msg r]
set msgDisp “CONTINUE”
set A04 “A04”
set A08 “A08”
foreach segment $segmentList {
#MSH
if [cequal [crange $segment 0 2] MSH] {
set fieldList [split $segment $field_sep]
catch {set fieldList [lreplace $fieldList 2 2 “CCSCI”]}
catch {set fieldList [lreplace $fieldList 7 7 “NO SECURITY”]}
set msh_9 [lindex $fieldList 8]
set msh_9_list [split $msh_9 $sub_sep]
set msh_9_1 [lindex $msh_9_list 1]
if [cequal “A28” $msh_9_1] {
catch {set msh_9_list [lreplace $msh_9_list 1 1 $A04]}
} elseif [cequal “A31” $msh_9_1] {
catch {set msh_9_list [lreplace $msh_9_list 1 1 $A08]}
}
set new_msh_9 [join $msh_9_list $sub_sep]
catch {set fieldList [lreplace $fieldList 8 8 $new_msh_9]}
set segment [join $fieldList $field_sep]
append outbuf ${segment}r
#EVN
} elseif [cequal [crange $segment 0 2] EVN] {
set fieldList [split $segment $field_sep]
if [cequal “A28” $msh_9_1] {
catch {set fieldList [lreplace $fieldList 1 1 $A04]}
} elseif [cequal “A31” $msh_9_1] {
catch {set fieldList [lreplace $fieldList 1 1 $A08]}
}
catch {set fieldList [lreplace $fieldList 4 4 “”]}
set segment [join $fieldList $field_sep]
append outbuf ${segment}r
#GT1
} elseif [cequal [crange $segment 0 2] GT1] {
set fieldList [split $segment $field_sep]
catch {set fieldList [lreplace $fieldList 11 11 “”]}
set segment [join $fieldList $field_sep]
append outbuf ${segment}r
#PID
} elseif [cequal [crange $segment 0 2] PID] {
set fieldList [split $segment $field_sep]
set pid_3 [lindex $fieldList 3]
set pid_3_rep [split $pid_3 $rep_sep]
set pid_3_rep2 [lindex $pid_3_rep 2]
set pid_3_rep2_list [split $pid_3_rep2 $sub_sep]
set pid_3_rep2_id [lindex $pid_3_rep2_list 0]
set ssn_first [crange $pid_3_rep2_list 0 2]
set ssn_middle [crange $pid_3_rep2_list 4 5]
set ssn_last [crange $pid_3_rep2_list 7 10]
set ssn $ssn_first$ssn_middle$ssn_last
catch {set fieldList [lreplace $fieldList 2 2 $ssn]}
catch {set fieldList [lreplace $fieldList 3 3 $ssn]}
set pid_10 [lindex $fieldList 10]
set pid_10_list [split $pid_10 $sub_sep]
set pid_10_race [lindex $pid_10_list 0]
set new_pid_10 [tbllookup -side input Centricity_race.tbl $pid_10_race]
if [cequal $new_pid_10 -1] {
set new_pid_10 $pid_10
}
catch {set fieldList [lreplace $fieldList 10 10 $new_pid_10]}
set pid_11 [lindex $fieldList 11]
if [cequal $pid_11 “”] {
catch {set fieldList [lreplace $fieldList 11 11 $gt1_5]} I want to reuse the contents of GT1_5 in this field if it meets the conditions of the ‘if’ statement)
}
set pid_16 [lindex $fieldList 16]
set pid_16_list [split $pid_16 $sub_sep]
set pid_16_ms [lindex $pid_16_list 0]
set new_pid_16 [tbllookup -side input Centricity_marital_status.tbl $pid_16_ms]
if [cequal $new_pid_16 -1] {
set new_pid_16 $pid_16
}
catch {set fieldList [lreplace $fieldList 16 16 $new_pid_16]}
set segment [join $fieldList $field_sep]
append outbuf ${segment}r
#PV1
} elseif [cequal [crange $segment 0 2] PV1] {
set fieldList [split $segment $field_sep]
catch {set fieldList [lreplace $fieldList 3 3 “CCSCI”]}
catch {set fieldList [lreplace $fieldList 7 7 “”]}
set segment [join $fieldList $field_sep]
append outbuf ${segment}r
#DG1 – Suppress
} elseif [cequal [crange $segment 0 2] DG1] {
#ROL – Suppress
} elseif [cequal [crange $segment 0 0] R] {
#Z-segments – Suppress
} elseif [cequal [crange $segment 0 0] Z] {
#OTHER
} else {
append outbuf ${segment}r
}
}
regsub -all {“”} $outbuf {} outbuf
set outbuf [string trimright $outbuf “r”]
set outbuf “$outbufr”
msgset $mh $outbuf
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
}
default {
error “Unknown mode ‘$mode’ in ccsci_a_centricity”
}
}
return $dispList
}
Sorry, GT1 should have this in it:
set gt1_5 [lindex $fieldList 5]
I’ve been testing and posted a version without it. Should clear up any obvious problems.
This is weird. I can resuse any other variable defined earlier in the proc except this one. Special name?
Mike,
I usually put a set of delimiters around my echoes so that if I am echoing a null value I will know it.
Maybe the value is null.
I do something like this echo”>$var<"
Then if I have null in $var I get >< and it becomes obvious.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
Mike,
I guess it is also possible you are not passing the if and thus the echo is not getting executed.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
I got word from another programmer that the GT1 segment occurs after the PID segment, thus the variable was not intialized at that point. He gave me some code that loops through the segments in this case so that you can initialize the variable within a segment if the segment occurs after the segment you are in:
set gt1val “^GT1\|”
set segList $segmentList
set finx [lsearch -regexp $segList $gt1val ]
if {![cequal $finx -1]} {
set gt1 [lvarpop segList $finx]
set gt1_5 [lindex [split $gt1 $field_sep] 5]
}
Actually I wonder why you are not doing this in an Xlate.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
Also, you could clean the little piece of code that was given to you by doing this:
set gt1seg [lsearch -regexp -inline $segmentlist ^GT1 ]
set gt1_5 [lindex [split $gt1seg $field_sep] 5]
The -inline will pull the entire GT1 segment instead of just it’s index. The two “set” commands at the beginning aren’t even needed.
Hope this helps…Tom
Pretty slick Tom. Works! I like less code… 😀