· Oct 16, 2023

Problem encoding pdf content stream to base 64 using the StoreFieldStreamBase64 method


I have a problem attempting to store a base 64 encode stream into the OBX:5 field of a HL7 message, by using the StoreFieldStreamBase64 method.

I'm using a transformer to input the contents of a pdf within a stream container (Ens.StreamContainer). The output is a HL7 message (EnsLib.HL7.Message 2.5:ORU_R01).

The transformer is being used in a business process.

This is the code used in the transformer to encode the stream to base 64:

Try {
     Set pdfStreamObj = source.StreamGet()
   } Catch {

 //Set PDF stream object into OBX:5
   Set status = target.StoreFieldStreamBase64(pdfStreamObj,"PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:ObservationValue(1)")

This is the next transformer step to include a prefix to OBX:5:

to value
"DOC^Application^PDF^Base64^" _ target.{PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:ObservationValue(1)}

Occasionally, the transformer process does not do the encoding to base 64, therefore no base 64 content is saved to OBX:5 field, even though the pdf content is present in the stream input that is passed into the transformer.

No error is generated when this situation occurs.

I'm interested to know why this problem is occurring and what could fix it?

The input service component is using EnsLib.File.PassThroughService and the output operation component is using EnsLib.HL7.Operation.TCPOperation.

I have tested an affected pdf file in our test environment. The pdf content has successfully been encoded to base 64 and passed to the HL7 message. So I don't think there is a problem with the affected pdf file.


Product version: IRIS 2021.1
$ZV: HealthConnect 3.3.0
Discussion (2)2
Log in or sign up to continue

Hello Adrian,

I think the problem is that you are concatenate a String with a Stream?

"DOC^Application^PDF^Base64^" _ target.{PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:ObservationValue(1)}

You need to create a new Stream, call method write of the new Stream with the value "DOC^Application^PDF^Base64", after append the old Stream to the new one.

Hi Cristiano,

Thanks for your post.

I think this code is working in principle, as I'm successfully getting the prefix concatenated to the encoded base 64 value for most PDF files that are processed.

The problem seems to be with the base 64 encoding procedure not getting completed for a small number of PDF files, and therefore not getting output in OBX:5. On these occasions only the prefix "DOC^Application^PDF^Base64^" is output in OBX:5.