Shaun,
Here is your code. I made a couple of changes and have it working as you want it to…I can only guess without knowing more.
proc filter_nonphys_hpf_hpp { args } {
keylget args MODE mode
keylget args ARGS uargs
switch -exact — $mode {
start {
return “”
}
run {
set drcodes UNKNOWN ;# default value
keylget args MSGID mh
keylget uargs DRCODES drcodes
set drcodes “\m($drcodes)\M”
# init – variables
set pv1_7_1 “”;set pv1_8_1 “”;set pv1_9_1 “”;set pv1_17_1 “”
set obr_16_1 “”
# get message
set msg [msgget $mh]
set fldSep [string index $msg 3]
set subSep [string index $msg 4]
set iterSep [string index $msg 5]
set segments [split $msg r]
set pv1Flds [split [lsearch -regexp -inline $segments ^PV1] $fldSep]
lassign $pv1Flds {} {} {} {} {} {} pv1_7_1 pv1_8_1 pv1_9_1
set pv1_17_1 [lindex $pv1Flds 17]
set dr_cd_in_msg {}
# Get PV1.7 and 8
foreach fld
{
lappend dr_cd_in_msg [lindex [split $fld $subSep] 0]
}
# Do PV1.9
foreach fld [split $pv1_9_1 $iterSep] {
lappend dr_cd_in_msg [lindex [split $fld $subSep] 0]
}
# Now PV1.17
lappend dr_cd_in_msg [lindex [split $pv1_17_1 $subSep] 0]
# OBR seg – extract Dr codes from obr – 16.1
set obr_seg [lsearch -regexp -inline $segments {^OBR}]
set obr_16 [lindex [split $obr_seg |] 16]
set obr_16_1 [lindex [split $obr_16 ^] 0]
lappend dr_cd_in_msg $obr_16_1
# Check if the physician codes are in pv1 7.1,8.1,9.1,17.1 or obr16.1
# If found continue message else kill message
if {[regexp $drcodes $dr_cd_in_msg]} {
echo “Found a Match … continue message”
echo DR_CD_IN_MSG: $dr_cd_in_msg
return “{CONTINUE $mh}”
} else {
echo “Dr code not in message .. message killed”
echo “Dr codes in Message: $dr_cd_in_msg”
echo “Wanted Dr codes : $drcodes”
return “{KILL $mh}”
}
}
}
}