I have an HL7 message, which is a simple text file. It consists of several ‘segments’ delimted with Chr(13). I’m trying to read in the file and store it in an SQLite DB which has been created and encrypted with Xojo. This is a Windows service application. The variables have all been declared properly.
Var InBoundFileStream As TextInputStream
Var InBoundFileFolderItem As FolderItem // (assigned to passed parameter = the FolderItem of the file to be read)
Var InBoundFileText As String
InBoundFileStream = TextInputStream.Open(InBoundFileFolderItem)
InBoundFileStream.Encoding = Encodings.UTF8
InBoundFileStream.BytePosition = 0 // trying this makes no difference
InBoundFileText = InBoundFileStream.ReadAll
Examining the FolderItem in debug confirms the entire message has been read.
A code check for Left(3) = “MSH” passes.
Print(InBoundFileText) to the console truncates the MSH segment and prints from the PID segment.
Using standard DatabaseRow and adding this as a record to the DB also truncates the MSH segment.
Examing InBoundFileText right after the ReadAll via Print(InBoundFileText) = no MSH but the code check for MSH passes.
Latest Xojo, Windows 11, working/running in Administrator account.
Why am I losing the MSH segment text? Did not have this problem on MacOS.
Would greatly appreciate any advice, insight, comments, etc. Many thanks in advance.
Just as a test, what happens if, after reading the contents of the file, you replace the line endings with something that doesn’t otherwise appear, like ~?
The ‘pipe’ character is at 4. “MSH|^~&|…”. Have never had a problem with these characters. Chr(13) has always worked for me; some literature says 0x0D, others Chr(13). All segments are delimited with the same and the remaining message segments come through using them. I was wondering about that too, perhaps Xojo in Windows reads differently but there’s no consistency with the problem. Thanks!
I suspect it is to do with chr(13) being the line delimiter. On Windows chr(13) moves the cursor to the start of line but doesn’t move it down a line. It is then overwritten by the next line. Do the following:
Bingo!, almost. Doing the replace line endings it now returns the entire message. In practice can’t use the tilde as it’s a designated HL7 character but that’s beside the point. This at least points me in the right direction. Kudos!
Yes That’s why ReplaceLineEndings exists. If you’re doing a single platform, then it doesn’t matter, but if you’re doing cross platform, then it’s essential.
This is a really important message. I also had to learn the hard way, that as soon as you have to process Strings from various platforms, ReplaceLineEndings and encoding knowledge are a must