Create a sample table. Go to the table directory on the server and look at the table format. Then you can use a tcl script (with reading in your csv values) and create that file format.
Here is a script I used. Test your output though as I had several revisions of this and I hope this was the latest one.
proc create_table_from_file { } {
#Set file names
set filedate [clock format [clock seconds] -format “%B %d, %Y %I:%M:%S %p”]
set input_dir “C:/Data_Files/”
#set input_dir [glob -dir $input_dir *.csv]
#set read_file [lindex $input_dir 0] ;#Assuming one file is to be read
set read_file “C:/Data_Files/diagnosiscodes_master.txt”
set output_file “C:/Data_Files/TumorReg_DiagCodes_Lookup_master.tbl”
set fldSeparator “#”
set output “”
set newline “n”
#Does the read file exist?
if {[file exists $read_file] == 0} {
#1 is success, 0 is failure
puts stdout “File Does Not Exist: $read_file.”
return;
}
#Can we open the original file?
if [catch {open $read_file r}] {
puts stdout “Error Opening File: $read_file.”
return;
} else {
set dataIn [open $read_file r]
puts stdout “Reading File $read_file…”
}
#Get and Set file data
set filedata [read $dataIn]
#Get length of file
set filelen [string length $filedata]
#Does file have data?
if {$filelen == 0} {
puts stdout “Message length in $read_file is 0. No data to be processed.”
} else {
#Create a new file to write results to. Can we open it?
if [catch {open $output_file w}] {
puts stdout “Error Opening File: $output_file.”
return;
} else {
set dataOut [open $output_file w]
puts stdout “Opening File $output_file…”
}
#Output the header information for the table.
set output “# Translation lookup table$newline”
append output “#$newline”
append output “prologue$newline”
append output ” who: Hospital – imported table$newline”
append output ” date: $filedate$newline”
append output ” outname: output$newline”
append output ” inname: input$newline”
append output ” bidir: 0$newline”
append output ” type: tbl$newline”
append output ” version: 3.0$newline”
append output “end_prologue$newline”
set record [split $filedata n]
foreach line $record {
if {$line != “”} {
set linevalue [split $line “,”]
puts stdout “linevalue = $linevalue”
set fldOne [lindex $linevalue 0]
set fldTwo [lindex $linevalue 1]
set checkval [string range $fldOne 0 3]
if {$checkval == “dflt”} {
#Row is default -> dflt=$fldOne
if {$fldOne == “dflt”} {
#write the values to the output file in this order
append output $fldSeparator $newline
append output “dflt=$fldTwo$newline”
}
} else {
if {$fldOne != “” && $fldTwo != “”} {
#write the values to the output file in this order
append output $fldSeparator $newline
append output $fldOne $newline
append output $fldTwo $newline
}
}
}
}
}
puts stdout “Finished Processing!”
puts $dataOut $output
close $dataOut
close $dataIn
}