😳 OK, I hope you can bear with me… I realize that there may be “better” or more “efficient” ways to code and I hope to get there, eventually. My goal is to first learn how to modify the existing script – keeping it as close to the original as possible. I came into this job recently and inherited a bunch of scripts, most of which, I think, were written by McKesson when we went live a few years back – and another subset written by my predecessor by tweaking the McKesson scripts.
My logic tells me that I should learn the basics – (things like how to turn a positive statement negative) – make sure I can operate that way and as time goes on learn the “better” ways. It’s just a bit too much for me at this time.
For instance – As I did not give you the full code – I don’t know if I can just drop in what you gave me into the existing code – or if more of it will have to be re-written.
Let me put the entire scripts here – first, the one that kills any non-A03 message with a discharge date – then the one I am coming up with now to kill any A04’s with no account number:
First script – kill non-A03s with discharge date:
######################################################################################
# Name: kill_nonA03wDCDate.tcl
# Description Kills a message where discharge date is not on A03 message.
#
# Assumptions This proc assumes that the message contains an MSH segment.
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (“start”, “run” or “time”)
# MSGID message handle
# ARGS user-supplied arguments:
# There are no user supplied arguments
#
# Returns: tps disposition list:
#
#
proc kill_nonA03wDCDate { 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
# Here we retrieve the data from our original message
set msg [msgget $mh]
# Now we need to determine our field and subcomponent seperatoprs
set field_sep [csubstr $msg 3 1] ;# HL7 field separator
set sub_sep [csubstr $msg 4 1] ;# HL7 subfield separator
set disposition “KILL”
# Here we spilt the original message into a list of the segments contained within
set segmentList [split $msg r]
foreach segment $segmentList {
if {[cequal [crange $segment 0 2] MSH]} {
set fieldList [split $segment $field_sep]
set msh_9 [lindex $fieldList 8]
set msh_9_list [split $msh_9 $sub_sep]
set msh_9_1 [lindex $msh_9_list 0]
set msh_9_2 [lindex $msh_9_list 1]
if {[cequal $msh_9_2 “A03”]} {
set disposition “CONTINUE”
}
} elseif {[cequal [crange $segment 0 2] PV1]} {
set fieldList [split $segment $field_sep]
set pv1_45 [lindex $fieldList 45]
if {[string length $pv1_45] == 0 } {
set disposition “CONTINUE”
} elseif {[cequal $pv1_45 “”””]} {
set disposition “KILL”
}
}
}
lappend dispList “$disposition $mh”
return $dispList
}
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}
shutdown {
echo “kill_nonA03wDCDate is shutting down”
}
default {
error “Unknown mode ‘$mode’ in kill_nonA03wDCDate”
}
}
return $dispList
}
******************************************************
Second script – kill A04’s without account number:
######################################################################################
# Name: kill_A04wNoAccount.tcl
# Description Kills A04 message where account number is null.
#
# Assumptions This proc assumes that the message contains an MSH segment.
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (“start”, “run” or “time”)
# MSGID message handle
# ARGS user-supplied arguments:
# There are no user supplied arguments
#
# Returns: tps disposition list:
#
#
proc kill_A04wNoAccount { 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
# Here we retrieve the data from our original message
set msg [msgget $mh]
# Now we need to determine our field and subcomponent seperatoprs
set field_sep [csubstr $msg 3 1] ;# HL7 field separator
set sub_sep [csubstr $msg 4 1] ;# HL7 subfield separator
set disposition “KILL”
# Here we spilt the original message into a list of the segments contained within
set segmentList [split $msg r]
foreach segment $segmentList {
if {[cequal [crange $segment 0 2] MSH]} {
set fieldList [split $segment $field_sep]
set msh_9 [lindex $fieldList 8]
set msh_9_list [split $msh_9 $sub_sep]
set msh_9_1 [lindex $msh_9_list 0]
set msh_9_2 [lindex $msh_9_list 1]
if {![cequal $msh_9_2 “A04”]} {
set disposition “CONTINUE”
}
} elseif {[cequal [crange $segment 0 2] PID]} {
set fieldList [split $segment $field_sep]
set pid_18 [lindex $fieldList 18]
if {[string length $pid_18] == 0 } {
set disposition “CONTINUE”
} elseif {[cequal $pid_18 “”””]} {
set disposition “KILL”
}
}
}
lappend dispList “$disposition $mh”
return $dispList
}
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}
shutdown {
echo “kill_A04wNoAccount is shutting down”
}
default {
error “Unknown mode ‘$mode’ in kill_A04wNoAccount”
}
}
return $dispList
}
****************************************************
Not sure if I should be specific to the PID-18.1 or if PID-18 is sufficient…..