Question
· Sep 10, 2018

OBX 5 and CRLF

Hello,

I have some issues trying to store a base64 encoded stream into the obx:5 segment.

I'm using  the StoreFieldStreamBase64 method in my business process to store the stream into the segment.

I'm sending the hl7 message containing my stream to an ensemble business operation (EnsLib.HL7.Operation.FileOperation) to write the message on disk.

When i'm reading it with an ensemble business service, it can't parse the stream because it contains multiple CRLF.

Why is my business operation splitting my stream into multiple newlines ?

Ensemble ver : 2016.2

Kami

Discussion (7)1
Log in or sign up to continue

Hi, this is my method to remove the crlf. 
I check every stream and remove it. 

You could also change the operation, but the problem remains if you exchange data with other systems.

ClassMethod PDFfromBase64Stream(pFilename As %String, Base64Stream As %Stream.GlobalCharacter) As %Status
{
 set SGB1=##class(%Stream.GlobalBinary).%New()
 set SGB2=##class(%Stream.GlobalBinary).%New()
 set FBS = ##class(%Stream.FileBinary).%New()
 set sc = FBS.FilenameSet(pFilename)
 
 Do FBS.Rewind()
 Do Base64Stream.Rewind()    
    while 'Base64Stream.AtEnd{
        set temp=Base64Stream.Read()
        set temp=$translate(temp, $c(13,10))
        set temp=$REPLACE(temp, "\r\n","")
        do SGB1.Write(temp)}
do SGB1.Rewind()
    while 'SGB1.AtEnd{
        set temp=SGB1.Read(5700)
        set temp=$system.Encryption.Base64Decode(temp)
        do SGB2.Write(temp)}
do FBS.CopyFrom(SGB2)
set sc = FBS.%Save()
quit sc
}

Hello, thanks for your answer.

Here is how i store the base64 stream inside my obx segment : 

stream=##class(%FileBinaryStream).%New()
stream.Filename = filename
propertyPath = "PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:5(1)"
seg=target.GetMutableSegmentAt($P(propertyPath,":",1),.tSC)
tSC = seg.StoreFieldStreamBase64(.stream,$P(propertyPath,":",2),,0)

Here is the result :

JVBERi0xLjQKJeLjz9MKNCAwIG9iago8PC9UeXBlL1hPYmplY3QvQ29sb3JTcGFjZS9EZXZpY2VH\r\ncmF5L1N1YnR5cGUvSW1hZ2UvQml0c1BlckNvbXBvbmVudCA4L1dpZHRoIDEzOS9MZW5ndGggMTM3\r\nMi9IZWlnaHQgN

EX : OBX|1|RP|5142648||ABCD[CR][LF]EFGH[CR][LF]IJKL....

I don't know why there is multiple extra \r\n in the obx segment.

And when i use a EnsLib.HL7.Service.FileService, my HL7 Object OBX:5(1) hold only ABCD information.

Kami

I'll ask again so I understand you correctly. 

You want to have another OBX segment with each CRLF or another OBX:5(*) field?
More segments would create too much overhead. 
I think the IHE Radiology Profile recommends a new segment every 62k bit.

With repeated fields in OBX:5 it's not HL7 standard conform.

Or would you like an OBX:5 field with the value ABCDEFGHIJKL...

Second option : An OBX:5 with the value ABCDEFGHIJKL (get rid of all crlf)

[Updated last comment with code]

I need to add a file inside the obx:5(1) segment as a base64 encoded stream.

I'm using the StoreFieldStreamBase64 method from EnsLib.HL7.Segment.

This method add extra escaped CRLF inside my OBX segment and i don't know why.

When i write the hl7 message on disk with the new OBX segment, i can't parse it anymore with an EnsLib.HL7.Service.FileService, the extra crlf character is the problem.

Maybe i'm doing something wrong in my way to process the file.

Ok, quick and dirty, try this

stream=##class(%FileBinaryStream).%New()
stream.Filename filename
propertyPath "PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:5(1)"
seg=target.GetMutableSegmentAt($P(propertyPath,":",1),.tSC)
tSC seg.StoreFieldStreamBase64(.stream,$P(propertyPath,":",2),,0)

set tSegString=""
    set tSegStringCleared="" 
    set tSegString = target.GetValueAt("
PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:5(1)")
    set tSegStringCleared = $translate(tSegString,$c(13,10))
    set tSC = target.SetValueAt(tSegStringCleared,"target.{
PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:5(1)}","set")

Don't you think the problem might be StoreFieldStreamBase64 using Base64Encode from %SYSTEM.Encryption with default flags value at 0 ?

I'll try encoding the stream myself and using StoreFieldStreamRaw instead of  StoreFieldStreamBase64

If my solution doesn't work i'll try yours :)

Thanks

Encoding the stream myself using Base64Encode and flags set to 1 fixed my problem.

There is no CRLF anymore in my stream.

Here is my final solution (error handle ommited)

stream=##class(%FileBinaryStream).%New()
stream.Filename = filename
encodedStream = ##class(%GlobalBinaryStream).%New()
while ('stream.AtEnd) {
      d encodedStream.Write(##class(%SYSTEM.Encryption).Base64Encode(stream.Read(12000),1))
}
propertyPath = "PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:5(1)"
seg=target.GetMutableSegmentAt($P(propertyPath,":",1),.tSC)
tSC = seg.StoreFieldStreamRaw(.encodedStream,$P(propertyPath,":",2))

Thanks Armin for your help.