Question
· Sep 29, 2021

RawContent only has first 10k of the message, how do I pull out the full message?

We have the following code, but recently had a few issues with messages sent to downstream systems being rejected. 
After investigating, seems that the message being sent is being truncated, the RawContent that we are pulling from Ens.EnsLib_HL7.Message only has the first 10k of the message

We are storing message body IDs in a table, then when we receive later messages, we look up the corresponding record in the table, 
extract the message and alter some fields from the saved message based on the received message and send onto downstream systems

Is there a simple way of getting the full message into RawContent rather than just the first 10k?

example of the code...

        EnsMsgBodyID has the value of the previously saved message body id
        
        &SQL(SELECT RawContent into :RawContent FROM Ens.EnsLib_HL7.Message  WHERE ID = :EnsMsgBodyID)
        
        set newHl7 = ##class(EnsLib.HL7.Message).ImportFromString(RawContent)
        Do newHl7.PokeDocType("Hl7Template_2.4:"_"Hl7_General")
            
        Do newHl7.%Save()

        Alter various fields in newHl7

        set status = ..SendRequestAsync(downstreamsystem,newHl7)

Product version: HealthShare 2016.1
$ZV: Cache for Windows (x86-64) 2017.2 (Build 744U) Fri Sep 29 2017 10:58:27 EDT [HealthShare Modules:Core:15.03.3105 + Linkage Engine:15.03.3105]
Discussion (4)0
Log in or sign up to continue

Yep, RawContent is potentially truncated and isn't meant for accessing the full message.

You can use the OutputTo* methods to get the whole message. OutputToLibraryStream is going to be the best option because a stream object can be of unlimited size. OutputToString will work, but only for messages that are smaller than the maximum string size (around 3 megabytes, assuming you have long strings enabled in the Caché config. If not, then 32k).

Cache for UNIX (IBM AIX for System Power System-64) 2018.1.3 (Build 414U) Mon Oct 28 2019 11:24:02 EDT
 

I tried 

TESTCLIN>set msg = ##class(EnsLib.HL7.Message).%OpenId(2725582908)

TESTCLIN>d msg.OutputToLibraryStream(.msgstream)

 Set tIOStream=$S(pLibStream.%Extends("%IO.I.CharacterStream"):pLibStream, 1:##C
 ^
lass(%IO.MetaCharacterStream).%New(pLibStream))
<UNDEFINED>zOutputToLibraryStream+1^EnsLib.HL7.Message.1 *pLibStream

but OutputToLibraryStream generated the error above. Can you tell me why?