This is the meat of it, the web service call, which is called from sms_ob_data. I use this web call for seven fields within the message, so it became its own TCL proc. At the end, I check for the RETARGS.ERROR item in the return list, and if it is true, I print an error to the log, return “”, else I CONTINUE the message. I will provide a snippet of that code too.
Here’s the code that makes the web call.
######################################################################
# Name: md_ext_id_lkup
# Purpose: This proc will call Epic web service with some
# external provider ID and prefix of second external
# system, and return any matching providers IDs for
# the second system.
# UPoC type: other
# Args: ARGS – user supplied arguments
# ID – Provider ID for an external system
# PREFIX – Prefix for external system
# Returns: RETARGS —
# IDLIST – List of provider IDs found
# ERROR – 0 if error in lookup, else non-zero int.
# Notes:
#
proc md_ext_id_lkup { args } {
package require TclCurl
keylget args ARGS.ID lkpId
keylget args ARGS.PREFIX lkpPre
set retList {}
set url “http://nmffcharttest/mychartdev/webservice/webservice.asp”
set pairs {}
set name “epicRequest”
set value ”
test3
$lkpId
$lkpPre
”
lappend pairs “[curl::escape $name]=[curl::escape $value]”
set data [join $pairs &]
set curlHandle [curl::init]
$curlHandle configure -url $url -bodyvar httpBody -post 1 -postfields $data
catch { $curlHandle perform } curlErrorNumber
set IdList {}
if { $curlErrorNumber == 0 } {
set rExp {(.*?)}
set rExpList [regexp -inline -all — $rExp $httpBody]
for {set x 1; set i 0} {$i<[regexp -all — $rExp $httpBody]} {incr i; incr x 2} {
set Id [lindex $rExpList $x]
lappend IdList $Id
}
}
$curlHandle cleanup
lappend retList "RETARGS" [list "IDLIST [list $IdList]" "ERROR [list $curlErrorNumber]"]
return [list $retList]
}
Here’s the code that checks for the error. The stop_thread TCL call is another proc which executes the hcicmd command Rob specified earlier, however, we do reuse it in other places, so it became its own TCL proc.
if {$iserr == 0} {
msgset $mh [join $newsegs r]
lappend dispList “CONTINUE $mh”
} else {
set module [lindex [info level 0] 0]
package require TclCurl
set curlErr [curl::easystrerror $iserr]
set errmsg “$module/$HciConnName: WEB SERVICE ERROR: $curlErr.”
echo
echo $errmsg
set stopping 1
stop_thread $HciConnName
set dispList “”
}
Here’s the code that gets the value TCLCurl return code to use for checking for an error. This stops the routine from checking the next MD field and is used at the end (see above) for the return value of the proc.
set lkup [md_ext_id_lkup $myargs]
keylget lkup RETARGS.ERROR iserr
And finally, the line in the begginning the routine to stop the next message from processing until the thread stops. Remember to make stopping a global variable.
if { $stopping } { return “” }
Hope this helps,
Robert Milfajt
Northwestern Medicine
Chicago, IL