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)
Comments
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)
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?
I think you need to init msgstream.