Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################################
- # Name: oru_file_xfr
- # Purpose: <description>
- # UPoC type: tps
- # Args: tps keyedlist containing the following keys:
- # MODE run mode ("start", "run" or "time")
- # MSGID message handle
- # ARGS user-supplied arguments:
- # <describe user-supplied args here>
- #
- # Returns: tps disposition list:
- # <describe dispositions used here>
- #
- #{ ECODIR /hci/testfiles/epic/incoming/xim } { FTPSERVER austera } { FTPUSER valleymed/hciuser } { FTPPASS xxxxx } { OLDPATH ^//cardioserver } { NEWPATH //austera/xim/test } {CMAXOBDIR /tmp/opt2/cmaxftp/} { USECURL N }
- proc tps_xper_pdf_ext { args } {
- keylget args MODE mode ;# Fetch mode
- global env HciConnName mh_pdf_msg
- 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
- keylget args ARGS.TEMPDIR tempdir
- keylget args ARGS.FTPSERVER ftpserver
- keylget args ARGS.FTPUSER ftpuser
- keylget args ARGS.FTPPASS ftppass
- keylget args ARGS.OLDPATH oldpath
- keylget args ARGS.NEWPATH newpath
- keylget args ARGS.CMAXOBDIR cmaxobdir
- keylget args ARGS.PATHLOC pathloc
- set disposition "CONTINUE"
- set msg [msgget $mh]
- package require hl7
- set hl7 [hl7::parse_msg $msg]
- # Get the file path from the message
- set fpath [hl7::get_field hl7 $pathloc]
- if { [regexp {\\E\\} $fpath] } {
- set fpath [unescape $fpath [string range $msg 3 7]]
- }
- #echo "fpath = $fpath"
- set fpath [string map { "\\" "/" } $fpath]
- echo "fpath = $fpath"
- # replace the cardioserver path with the austera path
- regsub -nocase $oldpath $fpath $newpath ftppath
- echo "ftp path = $ftppath"
- set url "ftp:$ftppath"
- set cmd "/usr/bin/GET -C $ftpuser:$ftppass $url"
- echo "cmd = $cmd"
- set perl5lib $env(PERL5LIB)
- array unset env PERL5LIB
- set mid [msgmetaget $mh MID]
- set file $tempdir/[keylget mid DOMAIN].[keylget mid HUB].[keylget mid NUM].pdf
- echo "file = $file"
- #set errCode 0
- set errCode [catch {exec sh -c $cmd | pdftotext -layout - - | tr -d '\014'} errMsg]
- echo "errCode = $errCode"
- if { $errCode } {
- #parray env
- echo error retrieving PDF from source system: $errMsg ($fpath)
- set env(PERL5LIB) $perl5lib
- #file delete $file
- return "{ERROR $mh}"
- set disposition "ERROR"
- }
- set env(PERL5LIB) $perl5lib
- #The following two lines and commenting out of the following 4 lines
- #are a response to data encoding issues introduced in 5.8
- set txtmsg $errMsg
- set txtmsg [regsub -all {\xA0} $txtmsg " "]
- set txtmsg [regsub -all {\xAD} $txtmsg "-"]
- hl7::set_field hl7 MSH.12 "2.2"
- hl7::delete_seg hl7 ORC
- hl7::delete_seg hl7 ZDS
- hl7::set_field hl7 OBR.2 [hl7::get_field hl7 OBR.18]
- hl7::set_field hl7 OBR.3 [hl7::get_field hl7 OBR.18]
- foreach msgtype { RTF TXT } {
- hl7::set_field hl7 MSH.4 $msgtype
- if { $msgtype eq "RTF" } {
- set lines [split $txtmsg "\n"]
- set new "{\\rtf1\\ansi{\\fonttbl\\f0 Courier;}\\f0\\fs16\\pard "
- for { set i 0 } { $i < [llength $lines] } { incr i } {
- set data [lindex $lines $i]
- if { $i > 1 } {
- append new "\\par "
- }
- set data [string map { "\\" "\\\\" "{" "\\{" "}" "\\}" } $data]
- append new $data
- }
- append new "}"
- set new [string map { "|" "\\F\\" "^" "\\S\\" "~" "\\R\\" "\\" "\\E\\" "&" "\\T\\" } $new]
- hl7::set_field hl7 OBX.2 "FT"
- hl7::set_field hl7 OBX.3 "&GDT"
- hl7::set_field hl7 OBX.4 ""
- hl7::set_field hl7 OBX.5 $new
- } else {
- set linenum 1
- foreach line [split [string trimright $txtmsg " \n"] \n] {
- if { $linenum > 1 } {
- hl7::append_seg hl7 OBX
- }
- hl7::set_field hl7 OBX($linenum).1 $linenum
- hl7::set_field hl7 OBX($linenum).2 "TX"
- hl7::set_field hl7 OBX($linenum).3 "&GDT"
- hl7::set_field hl7 OBX($linenum).4 ""
- hl7::set_field hl7 OBX($linenum).5 $line
- incr linenum
- }
- set mh [msgcopy $mh]
- }
- msgset $mh [hl7::join_msg hl7]
- lappend dispList "$disposition $mh"
- }
- file delete $file
- }
- time {
- # Timer-based processing
- # N.B.: there may or may not be a MSGID key in args
- }
- shutdown {
- # Doing some clean-up work
- }
- }
- echo oru_file_xfer_to_epic complete
- return $dispList
- }
Add Comment
Please, Sign In to add comment