› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › check_hl7_reply
Could anyone send me a copy of there version of the “Check_hl7_reply” tcl proc? I would like to compare our version with it, as ours is generating an error every time there is a NACK received. It works, but it generates an error.
The error that we encounter in our Error DB is as follows:
message : ‘MSH|^~&||PRMC|TAMTRON|PATH|20070530141422||ACK|9136303|P|2.2||||x0dMSA|AE|9136303|HL7 NACK createdx0d’
Tcl error:
msgId = message0
proc = ‘check_hl7_reply’
args = ”
result = ‘bad msgId “”‘
errorInfo: ‘
bad msgId “”
while executing
“msgget $ob_mh”
(“run” arm line 99)
invoked from within
“switch -exact — $mode {
start {
# Perform special init functions
set nak_ctr 0
return “”
}
…”
(procedure “check_hl7_reply” line 9)
invoked from within
“check_hl7_reply {MSGID message0} {CONTEXT sms_ib_reply} {ARGS {}} {MOD
Thank you all.
Femina
Here is the version of check reply I use most of the time:
# Begin Module Header ==========================================================
#
# —–
# Name:
# —–
#
# tps_check_reply_2.tcl
#
# ——–
# Purpose:
# ——–
#
# evaluate hl7 ack code, if 3 naks, save in file, shut down interface
#
# this verion also, kills the reply and the outbound saved message
#
# ———–
# Input Args:
# ———–
#
# Args: tps keyedlist containing:
#
# MODE run mode (”start” or “run”)
# MSGID reply message handle
# ARGS keyed list of user arguments containing:
#
# ACKTYPE : ack code in MSA segment. Defaults to AA
# if ACKTYPE is ACK, just look for ACK as a reply.
#
# MAXTRIES : number of Naks we get before dumping message.
# Defaults to 3
#
# STOP : yes (to stop thread, this is the default)
# no (to leave thread running)
#
# EMAIL : email_addresses (default page_hub_team)
#
# ———–
# Output Args:
# ———–
#
# Returns: tps keyed list containing dispositions
#
# ——
# Notes:
# ——
#
# UPoC type = TPS
#
# Due to some questions about breif network outages causing false NAK’s,
# there is a 30 second wait after each NAK, before processing resumes.
#
# ——–
# History:
# ——–
#
# 2001.10.18 Russ Ross
# – implemented initial version.
#
# 2002.04.06 Russ Ross
# – modified to search for the first MSA segment in the reply
# instead of making assumption about the location of the MSA segment
#
# 2002.12.09 Russ Ross
# – modified to only turn off thread alert if the STOP argument is “yes”
#
# End Module Header ============================================================
proc tps_check_reply_2 { args } {
global env HciConnName
global ob_save
global nak_ctr
keylget args MODE mode ;# What mode are we in
set dispList {}
set ackCode “”
switch -exact — $mode {
start {
#——————————
# Initialize the ob_save global
#——————————
set ob_save “”
#——————————-
# Perform special init functions
#——————————-
set nak_ctr 0
#—————————————————————————————
# Set up the NAK file counter at thread startup.
# If the counter file exists and its value is 99999, reinitialize it.
# If it doesnt exist, create it.
# This logic prevents the counter file from being reinitialized at every thread startup.
#—————————————————————————————
if {[file exist .tps_check_reply_2.$HciConnName.ctr]} {
set ctr_value [CtrCurrentValue .tps_check_reply_2.$HciConnName file]
if {[cequal $ctr_value 99999]} {
CtrInitCounter .tps_check_reply_2.$HciConnName file 1 99999 1
}
} else {
CtrInitCounter .tps_check_reply_2.$HciConnName file 1 99999 1
}
return “”
}
run {
keylget args MSGID reply_mh
#———————————————-
# get user args, if none provided, set defaults
#———————————————-
if {![keylget args ARGS.ACKTYPE ackType]} {
set ackType AA
}
if {![keylget args ARGS.MAXTRIES max]} {
set max 3
}
if {![keylget args ARGS.STOP stop_thread]} {
set stop_thread no
}
if {![keylget args ARGS.EMAIL email_addresses]} {
set email_addresses page_hub_team
}
#——————————————————
# If user arg for ACKTYPE is ACK, just look for a reply
# of ACK instead of an Hl7 rely.
#——————————————————
if {[cequal $ackType “ACK” ]} {
set ackCode [string trim [msgget $reply_mh]]
} else {
#—————————————————–
# Or else, assume we’re looking for an Hl7 ack message
# and parse it.
#—————————————————–
set msg [string trim [msgget $reply_mh] r]
set fld_spr [csubstr $msg 3 1]
set all_segs [split $msg r]
set msaIndex [lsearch -regexp $all_segs “^MSA”]
set msaSegment [lindex $all_segs $msaIndex]
set ackCode [lindex [split $msaSegment $fld_spr] 1]
}
if { [cequal $ackCode $ackType] || [cequal $ackCode “CA” ] } {
#————————————————————————
# got an ACK so
# reset the NAK counter
# kill the saved message
# kill the reply
# null out the ob_save global
#————————————————————————
set nak_ctr 0
set ob_save_mh $ob_save
set dispList {}
lappend dispList “KILL $ob_save_mh”
lappend dispList “KILLREPLY $reply_mh”
} else {
echo “WARNING:$HciConnName (tps_check_reply_2) got a NAK…”
incr nak_ctr
set ob_save_mh $ob_save
#———————————————————–
# got a NAK so
# resend the saved message
# kill the reply
# null out the ob_sve global
#———————————————————–
set dispList {}
lappend dispList “PROTO $ob_save_mh”
lappend dispList “KILLREPLY $reply_mh”
if {$nak_ctr == $max} {
#——————————————————-
# got 3 naks for the same message, kill and save to file
#——————————————————-
echo “WARNING:$HciConnName Got $max NAKS for same msg, saving to file….”
set nak_ctr 0
set dispList {}
lappend dispList “KILL $ob_save_mh”
lappend dispList “KILLREPLY $reply_mh”
#————————————————–
# build file names as julian date.counter.extension
#————————————————–
set saveDir $HciConnName
append saveDir “_NAKS/”
set julian [fmtclock [getclock] %Y%j]
set fileCounter [format %05d [CtrNextValue “.tps_check_reply_2.$HciConnName”]]
set NakFileSpec $saveDir$julian.$fileCounter.nak
set MsgFileSpec $saveDir$julian.$fileCounter.msg
#———————————————–
# create the save directories if they dont exist
#———————————————–
if {![file exists $saveDir]} {
echo “(tps_check_reply_2) creating $saveDir”
exec mkdir $saveDir
}
#—————————————————
# save the Nak message in a file with extension .nak
#—————————————————
set Nakfd [open $NakFileSpec a+]
puts $Nakfd [msgget $reply_mh]
close $Nakfd
#—————————————————-
# save the original msg in a file with extension .msg
#—————————————————-
set Msgfd [open $MsgFileSpec a+]
puts $Msgfd [msgget $ob_save_mh]
close $Msgfd
#——————————–
# turn off alerts for this thread
#——————————–
if {[cequal $stop_thread yes]} {
system “touch ../../../Alerts/$HciConnName.off”
}
#———————-
# defined email subject
#———————-
set email_subject “shutdown $HciConnName due to NAK”
#——————————————————————-
# append a time stamped entry to the alerts log file for this thread
#——————————————————————-
set logfile “../../../Alerts/$HciConnName.log”
set logfh [open $logfile a+]
set ts [fmtclock [getclock] “%a %b %d %Y %r “]
puts $logfh “$ts($email_subject) ($email_addresses)”
close $logfh
#——————————————————–
# send email notification that the thread has been NACKed
#——————————————————–
system “echo “Subject: $email_subject\n.” | sendmail $email_addresses”
echo “WARNING:$HciConnName recieved $max Naks for this message
stoping thread!!!!!! n[msgget $ob_save_mh]”
#————
# stop thread
#————
if {[cequal $stop_thread yes]} {
set process [file tail [pwd]]
system “hcicmd -p $process -c “$HciConnName pstop””
# exit
}
} ;# end of got max NAKs
}
}
shutdown {
# Doing some clean-up work
}
default {
echo “Unknown mode in tps_check_reply_2: ‘$mode'”
return “” ;# Dont know what to do
}
}
set ob_save “”
return $dispList
}
Russ Ross
RussRoss318@gmail.com