Well, that's no ordinary rabbit!

Caution: This has not yet been updated to work with the new spool file graphics format in 5.5

Note: See the MIS.OA.MSG.auto page for an introduction to emailing from attributes and reports.

Sending a scheduled report to a MOX mailbox is possible. If it is a custom report is simply a matter of putting report data in your / variable and calling the OA MSG program (example on MIS.OA.MSG.auto page) in the report trailer or close up macro. For standard reports you need a different approach.

Standard Meditech reports almost always have some kind of graphics commands in them. The email program simply sends these along with the text. Since the email program considers everthing as text the graphics commands need to be removed before sending the message.

The basic steps in the following method of emailing scheduled reports involves scheduling the report you want emailed to a unique spool group and creating a second scheduled report that does these things:

1. Identify the spool file to be sent.
2. Get the spool file from its hiding place (involves opening prefixes)
3. Remove graphics commands and copy the spool file to / file1
4. Reprocess / file1 to remove non-printing characters and save in / file2
5. Send / file2 using the MIS.OA.MSG.auto program

The code below should work for any magic site but I would appreciate any suggestions or improvements anyone has to offer.

Identify the spool file

The easiest way to identify the spool file is to use a unique spool group. If the report gets run once a day it is then as easy as creating a report that finds any spool file for the spool group for a certain date. The report should be in MIS.SPOOL and only needs to select on group and date.created. See the report specifics below.

Get the spool file

Once the report has identified the spool file urn the spool file needs to be retrieved from where Meditech has stored it (%.MIS.spool.rad). This involves opening prefixes so don't ask Meditech for any help on it.

Loop thru the spool file, strip the graphics commands and save in a / file

Get each line from the spool file, run it thru the standard Meditech program Z.rw.strip.graphics to remove any graphics commands, and save the result in / file1.

Reprocess the / file to join split lines and save in a second / file

Meditech splits the spool file into 80 character lines. If the report you want to email is wider that 80 characters lines will need to be concatonated in order to keep the correct output format. This code should work for reports up to 160 characters wide but will need to be modified if the report CPL is greater than that. Save the resulting line in / file2.

Determine the recipients

If the report is being used to email several spool files to different users the report title which is in the first line of the spool file can be used to determine who gets the email.

Send the file

%MIS.OA.MSG.auto("",ARG)X,1

Second Scheduled Report Specifics

This is for the second report, the one that finds and processes the spool file of the report you want emailed. It doesn't need any output, just some selects and a detail macro.

DPM's
Report:  MIS.SPOOL mis.spool.main
Index: None

Selects
1. group    EQ   Group:
2. date.created   EQ   Creation Date:

Footnotes
AL D detail

;--- detail macro ---
;--- clear / files ---
""^XX,
DO{+/MSG[XX]^XX ""^/MSG[XX]},
""^XX,
DO{+/MSG2[XX]^XX ""^/MSG2[XX]},
;--- open the spool file ---
;--- change MEM in the next line to the name of your MIS database
CL(&S,?S),
ZZ%OP(&,%[".MIS.spool.rad","MEM","MIS"]),
;--- Loop thru the SAFs for the spool file
;--- There is a 0 SAF but the actual spool text begins in SAF 1
0^SF,
DO{+&[urn,SF]^SF ZZ%OP(?,&[urn,SF]),
;--- loop thru the spool file ---
DO{+? ?^BUF,
@PROCESS.LINE}},
;--- close the prefixes
CL(&U,?U),
@REPROCESS.FILE,
;-- search report title for text and load appropriate recipients
IF{L(/MSG[1],"Report 1")<L(/MSG[1]) @LOAD.MSG1;
(/MSG[1],"Report 2")<L(/MSG[1]) @LOAD.MSG2;
@LOAD.MSG3},
;--- call the program to email /file2
%MIS.OA.MSG.auto("",ARG)X,1

LOAD.REC1
;--- load /file2 and the recipients for report 1 into ARG ---
Q(^/MSG2,"USER1","USER2")^ARG

LOAD.REC2
;--- load /file2 and the recipients for report 2 into ARG ---
Q(^/MSG2,"USER3")^ARG

LOAD.REC3
;--- load /file2 and the recipients for all other reports into ARG ---
Q(^/MSG2,"USER1","USER3","USER4")^ARG

PROCESS.LINE
;--- define graphics commands
IF{L(BUF,"~*","~g","~H","~G","~Z")<L(BUF);
   BUF^REC,
   ;--- use standard Meditech routine to remove graphics commands ---
   IF{L(REC,"~")<L(REC) %Z.rw.strip.graphics(REC_(""^REC),80,1)^REC},
   ;--- use custom routine to remove printer commands and non-printing characters ---
   %MIS.zcus.pgm.M.strip.np(REC)^REC,
   IF{L(REC)=0;
      REC^/MSG[XX+1^XX]}}

REPROCESS.FILE
;-- format max 80 characters per line for email
""^XX^ZZ,
DO{+/MSG[XX]^XX IF{XX<4 /MSG[XX];
                   L(/MSG[XX]_/MSG[XX+1])>80 /MSG[XX];
                   /MSG[XX]_/MSG[XX+1^XX]}^/MSG2[ZZ+1^ZZ]}

The Macro - MIS.zcus.pgm.M.strip.np

This macro strips non printing characters from the string

;--- the following must all be entered on one line.
;--- you can enter it as 2 and then use F6 to join the 2 lines
A'~(D(255):32_" "_"!"_D(34)_"#$%&'"_D(40,41)_"*+,-./0123456789:;<=>?@ABCDEFGHI
JKLMNOPQRSTUVWXYZ[\]"_D(255,95,96)_"abcdefghijklmnopqrstuvwxyz{~}"_(D(255):2));


Other Magic Pages



Don't see what you need?  Visit one of these other sites


or email me your request (tomt at thomast357.com).