Sorry,
Upload of tcl didn’t format well
Code to format HL7 batch is below
Thanks
Bill
######################################################################
# Name: tpsMDPHtest
# Purpose: Batch Header & Trailer and Output File for Cerner Results to MDPH ELR
#
#
#
#
#
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (“start”, “run” or “time”)
# MSGID message handle
# ARGS user-supplied arguments:
#
#
# Returns: tps disposition list:
#
#
#
#
# *********************************************************************
# on RUN mode: Appends msgs to temp file TUFTS_MDPH_ELR_tmp_in.txt
#
# Make sure to set Process name to “cerner” for TEST/PROD
#
# on TIMER mode: Writes header, reads/write msgs from temp file to
# TUFTS_MDPH_ELR_OUT.yyyymmddhhmm file, writes trailer
#
# Deletes .tmp file upon completion
#
# ***********************************************************************
#
#
# Modifications:
#
# date init mod desc
#
#
#
proc tpsMDPHtest { args } {
keylget args MODE mode ;# Fetch mod
set dispList {} ;# Nothing to return
#Make sure to set Process name to “cerner” for TEST/PROD
#set Process “cerner”
set Process “testing”
set Outpath “/mdph_to_send/”
switch -exact — $mode {
start {
# startup stuff
# 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
set msg [msgget $mh]
# Get rid of all x1c and x0b
regsub -all — {[x1cx0b]} $msg {} msg
#Get the time in system seconds
set systemTime [clock seconds]
#Set the time using the hour, minute and second descriptors.
set CurDate [clock format $systemTime -format {%Y%m%d}]
set CurDateTime [clock format $systemTime -format {%Y%m%d%H%M}]
# set directory path
set root_path [exec env HCIROOT]
set site_path [exec env HCISITEDIR]
set subdir “exec/processes/$Process”
append site_path “/$subdir/”
# set the user data… for the message
set filename “TUFTS_MDPH_ELR_tmp”
set filenameextension “txt”
set fullname $site_path$filename.$filenameextension
# open tmp file, write record
set curFileID [open $fullname a]
puts -nonewline $curFileID $msgr
# close tmp File
close $curFileID
# return message
lappend $dispList {CONTINUE “$mh”}
return $dispList
}
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
# Build envelope
set cloverclock [clock format [clock second] -format %Y%m%d%H%M%S]
set fhs “FHS|^~\&|Cerner Lab|TUFTS|ELR|MDPH|$cloverclock||$cloverclock|||r”
set bhs “BHS|^~\&|Cerner Lab|TUFTS|ELR|MDPH|$cloverclock||$cloverclock|||r”
# set file header
set fileheader $fhs$bhs
# set directory path
set root_path [exec env HCIROOT]
set site_path [exec env HCISITEDIR]
set subdir “exec/processes/$Process”
append site_path “/$subdir/”
#Get the time in system seconds
set systemTime [clock seconds]
#Set the time using the hour, minute and second descriptors.
set CurDate [clock format $systemTime -format {%Y%m%d}]
set CurDateTime [clock format $systemTime -format {%Y%m%d%H%M}]
# input file parameters
# set the user data… for the message
set filein “TUFTS_MDPH_ELR_tmp”
set fileInExt “txt”
set fullnameIn $site_path$filein.$fileInExt
# set output path and filename
# NOTE: “mdph_to_send” defined as Outpath, from beginning of proc
set sub_path_out $Outpath
append site_path $sub_path_out
set fileout “TUFTS_MDPH_ELR_OUT”
set fileoutExt $CurDateTime
set outFile $site_path$fileout.$fileoutExt
# get input
set tempfileFlagIn [file exists $fullnameIn]
if {$tempfileFlagIn == 1} {
set outFileID [open $outFile a+]
# write header
puts -nonewline $outFileID $fileheader
set inFileID [open $fullnameIn r]
set wholefile1 [read $inFileID]
#
# split the file into its transactions
# remove any blank transactions (extra newlines)
set BatchTrnxCount 0
foreach BatchRec [split $wholefile1 “n”] {
if {[clength $BatchRec] == 0} {
continue
} else {
puts -nonewline $outFileID $BatchRec
set BatchTrnxCount [regexp -all {MSH} $BatchRec]
}
}
# set file TRAILER
set bts “BTS|$BatchTrnxCount|r”
set fts “FTS|1|r”
set filetrailer $bts$fts
### Write TRAILER
set EOFcurr [eof $inFileID]
if {$EOFcurr == 1} {
puts -nonewline $outFileID $filetrailer
close $outFileID
}
close $inFileID
# delete tmp Input file
file delete $fullnameIn
}
}
}
###return $dispList
}