Written by

Enterprise Application Development Consultant at The Ohio State University Wexner Medical Center
MOD
Question Scott Roth · Apr 19, 2023

ERROR #5034: Invalid status code structure - Writing to File

I wrote a function awhile back to take Encoded Base 64 and write the PDF out to a file that could be sent to a faxing system to fax out. We are trying to test this code out in IRIS and I am seeing an error that I have not seen before... ERROR #5034: Invalid status code structure

Here is the code...

ClassMethod DecodeBase64HL7ToFile(base64 As %Stream.GlobalBinary, Ancillary As %String, FileName As %String) As %String

{

 

  set ArchDir = "/ensemble/data/transfer/AncillaryPDF/"

  set ArchAncDir = ArchDir_Ancillary_"/"

  set FaxDateDir = ArchAncDir_$PIECE($ZDATE($HOROLOG,7)," ",1)_"-"_$PIECE($ZDATE($HOROLOG,7)," ",2)_"-1/"

  if '##class(%Library.File).DirectoryExists(ArchDir)

  {

    do ##class(%Library.File).CreateDirectory(ArchDir)

 

  }

  if '##class(%Library.File).DirectoryExists(ArchAncDir)

  {

    do ##class(%Library.File).CreateDirectory(ArchAncDir)

 

  }

  if '##class(%Library.File).DirectoryExists(FaxDateDir)

  {

    do ##class(%Library.File).CreateDirectory(FaxDateDir)

 

  }

 

 

  set Oref = ##class(%FileBinaryStream).%New()

  ///$$$LOGINFO(FaxDateDir_FileName)

  set Oref.Filename = FaxDateDir_FileName

  Do base64.Rewind()

 

  While 'base64.AtEnd {

      set ln = base64.ReadLine()

      set lnDecoded = $system.Encryption.Base64Decode(ln)

    do Oref.Write(lnDecoded)

  }

 

  Do Oref.%Save()

  set PDFFilePath = FaxDateDir_FileName

  return PDFFilePath

}

Why is IRIS throwing an error? I want the Path returned to the DTL that it is being called from. Can I no longer return a string?

Product version: IRIS 2022.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2022.1 (Build 209U) Tue May 31 2022 12:13:24 EDT

Comments

Alex Woodhead · Apr 19, 2023

Hi Scott,

Am wondering whether this is due to migrating from AIX to RedHat, and the stream is defaulting to expecting a different line terminator $C(13,10).

Could try add before the while loop:

set ln=base64.ReadLine() 
set:ln[$C(10) base64.LineTerminator=$C(10)
do base64.Rewind()

Kind regards,

Alex

0
Scott Roth  Apr 19, 2023 to Alex Woodhead

Alex, 

I tried that but now I am receiveing... ERROR #5002: ObjectScript error: <UNDEFINED>zDecodeBase64HL7ToFile+22^osuwmc.Functions.1 *%C(10)

ClassMethod DecodeBase64HL7ToFile(base64 As %Stream.GlobalBinary, Ancillary As %String, FileName As %String) As %String

{

  set ArchDir = "/ensemble/data/transfer/AncillaryPDF/"

  set ArchAncDir = ArchDir_Ancillary_"/"

  set FaxDateDir = ArchAncDir_$PIECE($ZDATE($HOROLOG,7)," ",1)_"-"_$PIECE($ZDATE($HOROLOG,7)," ",2)_"-1/"

  if '##class(%Library.File).DirectoryExists(ArchDir)

  {

    do ##class(%Library.File).CreateDirectory(ArchDir)

  }

  if '##class(%Library.File).DirectoryExists(ArchAncDir)

  {

    do ##class(%Library.File).CreateDirectory(ArchAncDir)

  }

  if '##class(%Library.File).DirectoryExists(FaxDateDir)

  {

    do ##class(%Library.File).CreateDirectory(FaxDateDir)

  }

  set Oref = ##class(%FileBinaryStream).%New()

  ///$$$LOGINFO(FaxDateDir_FileName)

  set Oref.Filename = FaxDateDir_FileName

  Do base64.Rewind()

  While 'base64.AtEnd {

      set ln = base64.ReadLine()

      set:ln[%C(10) base64.LineTerminator=$C(10)

      set lnDecoded = $system.Encryption.Base64Decode(ln)

    do Oref.Write(lnDecoded)

  }

  Do Oref.%Save()

  set PDFFilePath = FaxDateDir_FileName

  return PDFFilePath

}

0
Alex Woodhead  Apr 19, 2023 to Scott Roth

Excuse the typo: Should be "$C(10)" not "%C(10)"

set:ln[$C(10) base64.LineTerminator=$C(10)
0
Robert Cemper  Apr 19, 2023 to Scott Roth

we need to handle 2 types of line terminators. $C(13,10) and $C(10)
+ BASE64 holds only printable characters, $C(13) is a NONO in Base64.
So:
if you always use $c(10) as line terminator 
then set ln=$TRANSLATE(ln,$c(13))  will remove also a leftover $C(13) if existing
or just do nothing.

0
Scott Roth · Apr 20, 2023

I didn't realize I had posted this same error years ago. The answer was in my other post. In the DTL I was setting the Path = tSC which was being used in other ways.

0
Jeffrey Drumm  Apr 20, 2023 to Scott Roth

EDIT: Hah, I guess you posted your solution as I was typing this ... and yeah, sort of what I thought it might be laugh

Are you calling (and testing) this from a DTL? If yes, have you looked through the DTL rules to see if the returned string's variable is being used as an argument to something like $system.Status.GetErrorText()?

Does the same thing happen when you execute it from the IRIS prompt?

Set tStrm=##class(%Stream.GlobalBinary).%New()
Do tStrm.Write("SGVsbG8gV29ybGQh")
Do tStrm.Rewind()
Write ##class(<packagename>).DecodeBase64HL7ToFile(tStrm,"<ancillary>","</path/to/outputfile.ext>")

Replace <packagename>, <ancillary>, and </path/to/outputfile.ext> with values appropriate for what you're testing, of course ...

0
Scott Roth  Apr 20, 2023 to Jeffrey Drumm

I did not get the same error, and it was successful.

0