Written by

Developer at Symplr
Question Vachan C Rannore · Feb 3, 2025

Base64 decoding and storing it in a local path

Dear Community,

I am trying to convert a base64 encoded string to a pdf. I have tried a lot of possible ways, but never succeeded. I am able to decode the base64 using $System.Encryption.Base64Decode but I am not able to convert it and store this in a path.

Can anybody help me out here?

Thanks.

Product version: IRIS 2022.3

Comments

Scott Roth · Feb 3, 2025

With some help from the Developer community, below is a Function I wrote for our needs to take a Base64 and write it out to a PDF.

ClassMethod DecodeBase64HL7ToFileFaxing(base64 As%Stream.GlobalBinary, Ancillary As%String, FileName As%String) As%String
{
	set ArchDir = <directory>
	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(%Stream.FileBinary).%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()
	do##class(%File).SetAttributes(Oref,33261,.return)
	set Oref = ""// Close fileset PDFFilePath = "/Fax/PDFFiles/"_Ancillary_"/"_$PIECE($ZDATE($HOROLOG,7)," ",1)_"-"_$PIECE($ZDATE($HOROLOG,7)," ",2)_"-1/"_FileName
	return PDFFilePath
}
0
Vachan C Rannore  Feb 4, 2025 to Scott Roth

Hi, Thanks for your reply.

Could you also let me know how do I pass the base64 string in %Stream.GlobalBinary?

0
Scott Roth  Feb 4, 2025 to Vachan C Rannore

Within our DTC...

<assign value='source.GetFieldStreamRaw(.tStream,"ORCgrp(1).OBRgrp(1).OBXgrp(1).OBX:ObservationValue(1).AlternateText",.tRemainder)' property='tSC' action='set' />
<assign value='##class(osuwmc.Utils.Functions).DecodeBase64HL7ToFileFaxing(tStream,source.{MSH:SendingApplication.NamespaceID},source.{PID:PatientIdentifierList(1).IDNumber}_context.TextIDTemp_".PDF")' property='a' action='set' />
0