Extract and Convert Base64 Data from MEDITECH Outbox Message

Extract and Convert Base64 Data from MEDITECH Outbox Message

This is a C/S NPR utility. Run this program from the front end:


;
; 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,
                BASE64.TRAP.FILE@File.create},
%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


    • Related Articles

    • Resulting LAB Orders in MEDITECH

      in order to enter a result on a LAB order, the site that the user is signed on to needs to be entered into Page 3 of the LAB Test Dictionary, for the test that is associated to the order. According to MEDITECH – the resulting site doesn’t matter.  ...
    • Using Sentry Alerts In Your C/S NPR Code

      This document may be outdated. It was moved to the HCI Wiki: https://wiki.thehcisolution.com/w/index.php?title=Adding_Sentry_Alerts_to_your_CS_NPR_Code Anytime we setup an HCI Universe on-site, we setup our Sentry application. There should be a ...
    • Report Designer Rule Functions - Date/Time and Other String Conversion Functions

      When building Report Designer rules there a re a bunch of date/time functions (and others) available in the string conversion functions. Here are some MEDITECH articles that are a great reference when using these functions. I have also included the ...
    • Report Designer Export Report Records

      When creating a MEDITECH Report Designer "Export" format type of report, you must define record names for each data row in the report download file. Each record name will force a new row to be created on the report. Typically you don't want this. ...
    • List of MEDITECH Reports that we have Archived for Customers

      This is a list of some of the more popular reports that we have run out of MEDITECH and archived to PaperStore or another archive solution, like MEDITECH Scanning and Archiving. Whenever we start working on MEDITECH archiving projects, customers ...