infor.com
concierge
infor u
developer portal
documentation central
customer center
Posts
Categories
Groups
ERPs
CSD
FSM/HRT
LN
M3
Syteline/ CSI
Hubs
Developer
Healthcare
Hospitality
Public Sector
Onboarding
Release Center
CloudSuites
Aerospace & Defense (LN)
Automotive (LN)
Chemicals (M3)
Corporate (FSM/HRT)
Distribution (Sx.e/CSD)
Distribution Enterprise (M3)
Engineering & Construction (LN)
Fashion (M3)
Food & Beverage (M3)
Healthcare (FSM/HRT)
Industrial (Syteline/CSI)
Industrial Enterprise (LN)
Manufacturing (M3)
Public Sector (FSM/HRT)
Solutions
Supply Chain Management (SCM)
Human Capital Management (HCM)
Events
Groups
User Groups
Your Groups
About
Email Community Support
Infor News
Migrated Forums
Home
Clovertech
Clovertech Archive
Read Only Archives
Cloverleaf
Cloverleaf
Append file to HL7 message
Jerry Magrann
Hello All - need some TCL help here. I have a file with HL7 segments created in it that I need to add to the end of certain ADT messages coming through one of my threads. I also have to make some changes to the ADT message.
1. Do I make 2 diff procs, one to make changes to the ADT then one to open the file and append it to the ADT?
2. Running 5.8 on Redhat, and I'm having trouble even opening the file with the switch patterns in my TCL program.
Comments / suggestions? Every time I search "file open" or "file" on the forum here, a million topics come up not even close to what I'm looking for.
Thanks in advance! - Jerry
Find more posts tagged with
Clovertech
Comments
Jeff Dinsmore
I'm assuming you're new to Tcl - so I'll start with basic info. If you need more, I'll be happy to elaborate.
You shouldn't need two procs.
to open a file in read mode:
set infile [open r]
read the whole file:
set wholeFile [read $infile]
close the file:
close $infile
It's usually a good idea to check that the file exists before attempting to open it.
if { [file exists ] } {
# do cool stuff here
} else {
# do less cool stuff here
}
There's a wealth of Tcl info/documentation on the Tcl Developer Exchange
http://www.tcl.tk/man
You can also load Tcl/Tk from ActiveState on your desktop PC and play with Tcl outside of Cloverleaf as well. There's complete Tcl/Tk documentation with that distribution.
Charlie Bursell
I would just make one suggestion Jeff.
When you read in a whole file, whether with read or read_file, it is a good idea to ignore the final linefeed. Otherwise, something like [split $wholeFile n] will always give you an empty string at the end.
read -nonewline $infile
or
read_file -nonewline
Be careful with read_file, or write_file. If HL7 data it tries to be your "friend" and convert CR to LF. As with all things I have a fix
Edit the file $HCIROOT/tcl/lib/tclx8.4/stringfile.tcl
In both the read_file and write_file procs right after:
set fp [open $fileName]
Add this line:
fconfigure $fp -translation lf
And just save the file
I hope it helps
Jerry Magrann
Charlie, you got it right - I got the file open, the data extracted, but friendly LFs instead of the HL7 necessary CRs after each segment. Without editing the tcl library like you suggested, to do it in coding, use a split to append the CR?
Charlie Bursell
I should have mentioned you can read by opening the file as Jeff suggested but if HL7 data tou have to configure it to not change CR to LF
Do this
set fd [file open ]
fconfigure $fd -translation lf
set data [read_file -nonewline $fd]
close $fd
Jeff Dinsmore
Correct.
When reading/writing HL7 from files, you need to be cognizant of end-of-line translations.
Because I'm a control freak, I generally use "fconfigure $infile -translation binary" to avoid any unpleasant surprises - and to know exactly what I'm getting - then split on n and r and explicitly ignore any empty strings.