;
; Arguments:
; A = MIS.XO.MSG.urn
;
; This code will retrieve an outbox message, save it locally,
; then extract the base64 content out of the message and save it to a
; binary .pdf file
; The file will be saved in the temporary folder pointed to by the outbox message,
; usually this is:
;
; C:\Program Files (x86)\MEDITECH\MagicCS\Data\[UNV]\Ring\[Ring Name]\Temp
;
;
A^MIS.XO.MSG.urn,
; "Y"^TRAP.ON,
0^TRAP.FILE.CNT,
%MIS.XO.MSG.open("!",MIS.XO.MSG.urn),
@Memory.allocate^MB,
@PROCESS.FILE,
IF{ERR @W.err(ERR)},
@CLEANUP,
END;
PROCESS.FILE
%Z.temp.file.directory("")^TMP,
O(!(TMP),TMP),^!(TMP)@Share.name^TMP,
@Memory.load.file(MB,FNAME)^X,
IF{X ("Unable to load file into memory:",X)^ERR;
@Memory.allocate^MB.T,
@Memory.beginning(MB.T),
@Memory.beginning(MB),
@Memory.search(MB,"","Base64")^POS,
@Not(POS) "Unable to find Base64 tag"^ERR;
@Memory.set.cursor(MB,POS+7^POS),
0^B64.TXT,
DO{@CONTINUE @Memory.read.field(MB,200,D(13))^B64.TXT,
@DISPLAY.STATUS,
IF{B64.TXT %Z.base64(B64.TXT)^TXT,
@Memory.write(MB.T,TXT)},
IF{TRAP.ON="Y" @TRAP}},
@W.display(""),
@Memory.store.file(MB.T,TMP_"\"_MIS.XO.MSG.urn_".pdf"^P)^X,
X ("Unable to save file:",P,"ERR:",X)^ERR;
@W.return("File saved:",P),""}^ERR
CONTINUE
IF{@Memory.more(MB)_.=. "";
@Not(B64.TXT) "";
"CONTINUE"}
CLEANUP
IF{@Memory.defined(MB.T) @Memory.free(MB.T)},
IF{@Memory.defined(MB) @Memory.free(MB)},
C(!(TMP)),
%MIS.XO.MSG.close("!",MIS.XO.MSG.urn)
DISPLAY.STATUS
@Add(1,J),
@Add(200,BC),
IF{J\100=0!(J=1) @W.display("Read bytes:",BC)}
#TRAP
@GET.FILE.NAMES,
%Z.first.file(BASE64.TRAP.FILE)^XX,
XX|2>1000000 @Add(1,TRAP.FILE.CNT),
@GET.FILE.NAMES,
%Z.first.file(PDF.TRAP.FILE)^XX,
;
IF{@Not(H) ("Unable to open to file:",BASE64.TRAP.FILE)^ERR;
B64.TXT$100_D(13,10)@File.write,
B64.TXT'$100_D(13,10)@File.write,
@File.close},
IF{@Not(H) ("Unable to open to file:",PDF.TRAP.FILE)^ERR;
TXT$100_D(13,10)@File.write,
TXT'$100_D(13,10)@File.write,
@File.close},
IF{ERR @W.err(ERR)};
GET.FILE.NAMES
TMP_"\TrapBase64-"_TRAP.FILE.CNT_".txt"^BASE64.TRAP.FILE,
TMP_"\TrapPdf-"_TRAP.FILE.CNT_".txt"^PDF.TRAP.FILE