Thomas, Here is a portion of a script I use that takes a message, pulls the account number then saves two files, using acct nmber as the base of the file name with the .dat file containing the message and the .ctl file containing the timedate stamp of the message.
This is just the part of the script that I thought showed what you where looking for, I removed all the field manipulation that I had to do to the message before writing it back out.
Let me know if you have any questions. I hope it helps.
######################################################################
# Name: cvu_a08_resend
# Purpose: Write all trans to files
# 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:
#
#
proc cvu_a08_resend { args } {
keylget args MODE mode ;# Fetch mode
set dispList {} ;# Nothing to return
set datList [datlist]
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
set message [msgget $mh]
set pwd /hci/cvudata
#### GET ACCOUNT NUMBER FROM HL7 MESSAGE ####
set gh [grmcreate -msg $mh hl7 2.1 cvu ADT_A08]
set dh [grmfetch $gh {0(0).PID.00035.[0]}]
set val [datget $dh VALUE]
if [file exists $pwd/$val.ctl] {
file delete $pwd/$val.dat
set ch [open $pwd/$val.dat w]
puts $ch $message
close $ch
} else {
set ch1 [open $pwd/$val.ctl w]
set timestamp [exec date]
puts $ch1 $timestamp
close $ch1
set ch2 [open $pwd/$val.dat w]
puts $ch2 $message
close $ch2
}
lappend dispList “CONTINUE $mh”
grmdestroy $gh
}
time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}
shutdown {
# Doing some clean-up work
}
}
hcidatlistreset $datList
return $dispList
}
Craig Weldy
Senior Interface Analyst
Beacon Health System
South Bend, In, 46615