I’m still a tcl newbie so let me first say I am thankful for any assistance that is provided. I have been working on a tcl script for RDE messages. It appears Pharmacy performs tasks which ultimately puts two drug orders in one RDE message. The receiving application wants me to write a script to look at the orders and if the orders are for the same drug, they want the doses to be added together and send as one order.
The problem I’m having is setting a variable for the multiple instances of the order so that I can write an if statement to compare the fields.
The field I’m looking at for the comparison is RXE 2.1 – drug name.
This is where I currently am at with my script:
proc RDE_calculate_dose_for_same_drug { args } {
keylget args MODE mode ;# Fetch mode
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 {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
#####################################################
###############SETTING PRELIMINARY VALUES############
#####################################################
set msg [msgget $mh]
set field_sep [csubstr $msg 3 1] ;# HL7 field separator. Normally |
set sub_sep [csubstr $msg 4 1] ;# HL7 subfield separator. Normally ^
set sssub_sep [csubstr $msg 7 1] ;# HL7 SUB-subfield separator
set fieldList [split $msg $field_sep] ;# Split the message into fields
set msg_type [lindex $fieldList 8] ;# HL7 Message Type
set subfieldList [split $msg_type $sub_sep] ;# Split the field into subflds
set msg_type_1 [lindex $subfieldList 0] ;# HL7 Message Type part 1
set msg_type_2 [lindex $subfieldList 1] ;# HL7 Message Type part 2
set outbuf {}
set segments [split $msg r] ;# Get a list of HL7 segments, split message on CR
if {[cequal $msg_type_1 “RDE”]} {
foreach seg $segments {
set segtype [csubstr $seg 0 3] ;# segment type
if [cequal $segtype MSH] {
append outbuf ${seg}r
#msgset $mh $outbuf
}
if [cequal $segtype PID] {
append outbuf ${seg}r
#msgset $mh $outbuf
}
if {[cequal $segtype RXE]} {
set fieldList [split $seg $field_sep]
set rxe2 [lindex $fieldList 2]
set rxe2_1 [split $rxe2 $sub_sep]
set rxe2_1_1 [lindex $rxe2_1 1]
set rxeVal1 “”
set rxeVal2 “”
set rxeVal “^RXE\|”
set segList $segments
set findrxe [lsearch -all -inline -regexp $segList $rxeVal]
foreach drugName $rxe2_1_1 {