Question
Julian Pardoe · Sep 29

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]
00
2 0 2 129
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).

This because the RawContent field is a %String where MAXLEN is 10000. You will need to get the contents out as a stream. So it'll be like:

s msg=##class(EnsLib.HL7.Message).%OpenId(EnsMsgBodyID)

d msg.OutputToLibraryStream(.msgstream)

s newmsg=##class(EnsLib.HL7.Message).ImportFromLibraryStream(msgstream)