Question
· Nov 15

Base 64 message is taking considering as a new segment

Hi Team,

I am converting xml message into HL7 message but the input XML message contains pdf which is converting into base 64 and getting mapped to OBX:5.5 in HL7 message and sending it to downstream 

In Downstream service i am using normal HL7 TCP class EnsLib.HL7.Service.TCPService but the message looks like below i am not sure why stream is taking as another segment in HL7 message,

Any thoughts on this?

 

Thanks,

Smythee

Product version: Ensemble 2018.1
$ZV: Cache for Windows (x86-64) 2018.1.1 (Build 312_1_18937U) Fri Apr 26 2019 17:58:36 EDT
Discussion (15)3
Log in or sign up to continue

hi ,

this is how i am converting pdf to base 64

Set pInput.LineTerminator = $C(10)
Set tMax=$$$MaxLocalLength*.5\1
Set tMax=tMax-(tMax#57)
If $IsObject(pInput) {
$$$TRACE("pInput = object")
Set tCurrLineLen = 0
Set tStream = ##class(%Stream.FileBinary).%New()
While 'pInput.AtEnd 
$$$TRACE("Reading filestream")
Set tData = pInput.Read(tMax)
Set tValue = $SYSTEM.Encryption.Base64Encode(tData)
Set tSC = tStream.Write(tValue)
If 'pInput.AtEnd {
Set tSC = tStream.Write($C(10))
$$$TRACE("Adding terminator.")
}
 

So to do what you're trying to do in your DTL, add in a code block and paste in the following:

  Set CHUNKSIZE = 2097144
  Set outputStream=##class(%Stream.TmpCharacter).%New()
  Do source.EncodedPdf.Rewind()
  While ('source.EncodedPdf.AtEnd) {
    Set tReadLen=CHUNKSIZE
    Set tChunk=source.EncodedPdf.Read(.tReadLen)
    Do outputStream.Write($SYSTEM.Encryption.Base64Encode(tChunk,1))
  }
  Do outputStream.Rewind()
  Set Status = target.StoreFieldStreamRaw(outputStream,"OBXgrp(1).OBX:5.5")
  )

Yours is almost doing the same thing but, as Enrico points out with your code sample, you have the "Set tSC = tStream.Write($C(10))" line adding in the line breaks whereas my example has this excluded.

Separately, as alluded to by Scott, when adding the base 64 encoded PDF stream to the HL7, you'll want to use the StoreFieldStreamRaw method for the HL7. Trying to do a traditional set with a .Read() risks the input being truncated.

<if condition='source.{ORCgrp(1).OBRgrp(1).OBXgrp(k1).OBX:ValueType}="ED"' >
<true>
<assign value='source.GetFieldStreamRaw(.tStream,"ORCgrp(1).OBRgrp(1).OBXgrp("_k1_").OBX:ObservationValue(1).AlternateText",.tRemainder)' property='tSC' action='set' />
</true>
</if>
</foreach>
<if condition='..Length($get(tSC))&gt;0' >
<true>
<assign value='"1"' property='target.{OBXgrp(1).OBX:SetIDOBX}' action='set' />
<assign value='"ED"' property='target.{OBXgrp(1).OBX:ValueType}' action='set' />
<assign value='"7"' property='target.{OBXgrp(1).OBX:ObservationIdentifier.Identifier}' action='set' />
<assign value='"URL"' property='target.{OBXgrp(1).OBX:ObservationIdentifier.Text}' action='set' />
<assign value='"EXTLRR"' property='target.{OBXgrp(1).OBX:ObservationIdentifier.NameofCodingSystem}' action='set' />
<assign value='"1"' property='target.{OBXgrp(1).OBX:ObservationSubID}' action='set' />
<assign value='"PDF"' property='target.{OBXgrp(1).OBX:ObservationValue(1).Identifier}' action='set' />
<assign value='"PDF"' property='target.{OBXgrp(1).OBX:ObservationValue(1).NameofCodingSystem}' action='set' />
<assign value='"PDF"' property='target.{OBXgrp(1).OBX:ObservationValue(1).AlternateIdentifier}' action='set' />
<assign value='target.StoreFieldStreamRaw(tStream,"OBXgrp(1).OBX:ObservationValue(1).AlternateText",tRemainder)' property='tSC' action='set' />
<assign value='"F"' property='$P(tRemainder,"|",11)' action='set' />
</true>
</if>

This is an example of what we pretty much do for any system that sends us a Base64 encoded PDF that we have to reformat to send to Epic EMR.

My transformation is pretty much simple  actually 

<assign value='"Procedure notes"' property='target.{OBXgrp(1).OBX:5.2}' action='set' />
<assign value='"PDF"' property='target.{OBXgrp(1).OBX:5.3}' action='set' />
<assign value='"base64"' property='target.{OBXgrp(1).OBX:5.4}' action='set' />
<assign value='source.EncodedPdf.Read(9999999999)' property='target.{OBXgrp(1).OBX:5.5}' action='set' />
 

how do i avoid line breaks 

In Service class(by using record map as input) i am converting pdf to base 64 using below code  and the same source.encodedpdf is getting converted to HL7 in data transformation

Set pInput.LineTerminator $C(10)
Set tMax=$$$MaxLocalLength*.5\1
Set tMax=tMax-(tMax#57)
If $IsObject(pInput{
$$$TRACE("pInput = object")
Set tCurrLineLen = 0
Set tStream ##class(%Stream.FileBinary).%New()
While 'pInput.AtEnd 
$$$TRACE("Reading filestream")
Set tData pInput.Read(tMax)
Set tValue $SYSTEM.Encryption.Base64Encode(tData)
Set tSC tStream.Write(tValue)
If 'pInput.AtEnd {
Set tSC tStream.Write($C(10))
$$$TRACE("Adding terminator.")
}