BGP3AU1M ; IHS/CMI/LAB - SEND MAIL MESSAGE ;
;;13.0;IHS CLINICAL REPORTING;;NOV 20, 2012;Build 81
;
DESC ;----- ROUTINE DESCRIPTION
;;
;;This routine sends email messages.
;;$$END
N I,X F I=1:1 S X=$P($T(DESC+I),";;",2) Q:X["$$END" D EN^DDIOL(X)
Q
;
EN(BGPMSG,BGPBEGDT,BGPENDDT,BGPFACS,BGPF,BGPDFILE) ;EP
;----- MAIN ENTRY POINT TO SEND MESSAGE
;
; INPUT:
; BGPMSG = WHICH MESSAGE TO SEND
; BGPBEGDT = REPORT PERIOD BEGINNING DATE
; BGPENDDT = REPORT PERIOD ENDING DATE
; BGPFACS = ARRAY CONTAINING LIST OF SITE FILES
; BGPF = ARRAY CONTAINING AGGREGATE FILE LIST
; BGPDFILE = DATA DUMP FILE NAME FOR DEEPSEE
;
;N BGPFILE,BGPOUT,X,Y
;
;D GET(BGPMSG,BGPBEGDT,BGPENDDT,.BGPFACS,.BGPF,BGPDFILE,.BGPFILE,.BGPOUT)
;Q:BGPOUT
;
;D SENDMAIL(BGPFILE)
;
;S X="rm "_$P($G(^BGPGP1PM(1,0)),U)_BGPFILE ;REMOVE FILE
;S X=$$JOBWAIT^%HOSTCMD(X)
;
Q
GET(BGPMSG,BGPBEGDT,BGPENDDT,BGPFACS,BGPF,BGPDFILE,BGPFILE,BGPOUT) ;
;----- GET THE DATA, PUT INTO A TEXT FILE
;
N %FILE
;
S BGPOUT=0
;
D FILE(BGPBEGDT,.%FILE,.BGPFILE,.BGPOUT)
Q:BGPOUT
;
U %FILE
I BGPMSG=1 D MSG1(BGPBEGDT,BGPENDDT,.BGPFACS)
I BGPMSG=2 D MSG2(BGPBEGDT,BGPENDDT,.BGPF,BGPDFILE)
D CLOSE^%ZISH("FILE")
;
Q
SENDMAIL(BGPFILE) ;
;----- SEND THE EMAIL
;
;N BGPERR,BGPFROM,BGPOUT,BGPSUB,BGPTO,I,X
;
;S BGPOUT=0
;
;S BGPTO=$$TO
;Q:BGPTO']""
;
;S BGPFROM=$P($G(^BGPGP1PM(1,99.1)),U)
;I BGPFROM']"" D Q
;. S BGPERR="NO SENDER"
;. ;S $ZE="BGPGP1MM FAILURE" D ^%ZTER
;
;S BGPFILE=$P($G(^BGPGP1PM(1,1)),U)_BGPFILE
;S BGPSUB="MONTHLY AUTOMATIC GPRA UPLOAD"
;
;S X=$ZF(-1,"wsendmail -s"""_BGPSUB_""" -f"_BGPFROM_" -t"_BGPFILE_" "_BGPTO)
;
;I X D
;. S BGPERR="CANNOT SEND EMAIL - wsendmail failure"
;. ;S $ZE="BGPGP1MM FAILURE" D ^%ZTER
Q
TO() ;
;----- CREATE MAIL RECIPIENT STRING
;
N BGPD1,BGPTO
;
S BGPTO=""
S BGPD1=0
F S BGPD1=$O(^BGPGP1PM(1,99.2,BGPD1)) Q:'BGPD1 D
. S BGPTO=BGPTO_","_$G(^BGPGP1PM(1,99.2,BGPD1,0))
I $E(BGPTO)="," S BGPTO=$E(BGPTO,2,999999)
Q BGPTO
;
FILE(BGPBEGDT,%FILE,BGPFILE,BGPOUT) ;
;----- CREATE FILE CONTAINING THE DATA
;
N BGPERR,BGPOUT
;
;I '$G(DUZ) S DUZ=1
D ^XBKVAR
S BGPOUT=0
S BGPERR=""
S BGPFILE="BGPGP1MM"_BGPBEGDT
D HFS(.BGPOUT,.%FILE,BGPFILE)
I BGPOUT D Q
. S BGPERR="CANNOT OPEN FILE" ;FOR ERROR TRAP
. ;S $ZE="BGPGP1MM FAILURE" D ^%ZTER
Q
HFS(BGPOUT,%FILE,BGPFILE) ;EP
;----- CREATE AND OPEN DATA FILE
;
; INPUT:
; FILE = DATA FILE NAME TO CREATE AND OPEN
;
; OUTPUT:
; %FILE = THE DEVICE NUMBER OF THE FILE
; BGPOUT = QUIT INDICATOR
;
N I,POP,X,Y,ZISH1,ZISH2,ZISH3,ZISH4
;
S %FILE=""
S BGPOUT=0
S ZISH1="FILE" ;HANDLE
S ZISH2=$P($G(^BGPGP1PM(1,1)),U) ;DIRECTORY
S ZISH3=BGPFILE ;FILENAME
S ZISH4="W" ;WRITE MODE
D OPEN^%ZISH(ZISH1,ZISH2,ZISH3,ZISH4)
I POP S BGPOUT=1
Q:BGPOUT
S %FILE=IO
Q
EXDT(X) ;
;----- CONVERT INTERNAL FM DATE TO EXTERNAL READABLE DATE
;
N Y
S Y=""
I X D
. S Y=X
. D DD^%DT
Q Y
MSG1(BGPBEGDT,BGPENDDT,BGPFACS) ;EP
;----- MESSAGE 1, MISSING FILES
;
N BGPASU,BGPFAC
;
W !,"Monthly GPRA report period date range: "_$$EXDT(BGPBEGDT)_" to "_$$EXDT(BGPENDDT)
;
W !!,"The site GPRA files could not be uploaded because files are"
W !,"missing from the following facilities:",!!
;
S BGPASU=0
F S BGPASU=$O(BGPFACS(BGPENDDT,BGPASU)) Q:BGPASU="" D
. Q:BGPFACS(BGPENDDT,BGPASU)]""
. S BGPFAC=$O(^BGPGP1PM(1,9,"C",BGPASU,0))
. Q:'BGPFAC
. S BGPFAC=$P($G(^BGPGP1PM(1,9,BGPFAC,0)),U)
. I BGPFAC]"" W !?5,BGPASU," ",$$VAL^XBDIQ1(4,BGPFAC,.01)
;
W !!!,"The aggregate excel files cannot be created until all files"
W !,"are received from all facilities."
Q
MSG2(BGPBEGDT,BGPENDDT,BGPF,BGPDFILE) ;
;----- MESSAGE 2, AGGREGATE EXCEL FILES CREATED
;
N BGP
;
W !,"Monthly GPRA report period date range: "_$$EXDT(BGPBEGDT)_" to "_$$EXDT(BGPENDDT)
;
W !!,"The following aggregate excel files have been created:",!!
;
S BGP=0
F S BGP=$O(BGPF(BGP)) Q:'BGP D
. W !?5,BGPF(BGP)
;
W !!,"The following data file for DeepSee has been created:",!!
W !?5,BGPDFILE
Q
BGP3AU1M ; IHS/CMI/LAB - SEND MAIL MESSAGE ;
+1 ;;13.0;IHS CLINICAL REPORTING;;NOV 20, 2012;Build 81
+2 ;
DESC ;----- ROUTINE DESCRIPTION
+1 ;;
+2 ;;This routine sends email messages.
+3 ;;$$END
+4 NEW I,X
FOR I=1:1
SET X=$PIECE($TEXT(DESC+I),";;",2)
IF X["$$END"
QUIT
DO EN^DDIOL(X)
+5 QUIT
+6 ;
EN(BGPMSG,BGPBEGDT,BGPENDDT,BGPFACS,BGPF,BGPDFILE) ;EP
+1 ;----- MAIN ENTRY POINT TO SEND MESSAGE
+2 ;
+3 ; INPUT:
+4 ; BGPMSG = WHICH MESSAGE TO SEND
+5 ; BGPBEGDT = REPORT PERIOD BEGINNING DATE
+6 ; BGPENDDT = REPORT PERIOD ENDING DATE
+7 ; BGPFACS = ARRAY CONTAINING LIST OF SITE FILES
+8 ; BGPF = ARRAY CONTAINING AGGREGATE FILE LIST
+9 ; BGPDFILE = DATA DUMP FILE NAME FOR DEEPSEE
+10 ;
+11 ;N BGPFILE,BGPOUT,X,Y
+12 ;
+13 ;D GET(BGPMSG,BGPBEGDT,BGPENDDT,.BGPFACS,.BGPF,BGPDFILE,.BGPFILE,.BGPOUT)
+14 ;Q:BGPOUT
+15 ;
+16 ;D SENDMAIL(BGPFILE)
+17 ;
+18 ;S X="rm "_$P($G(^BGPGP1PM(1,0)),U)_BGPFILE ;REMOVE FILE
+19 ;S X=$$JOBWAIT^%HOSTCMD(X)
+20 ;
+21 QUIT
GET(BGPMSG,BGPBEGDT,BGPENDDT,BGPFACS,BGPF,BGPDFILE,BGPFILE,BGPOUT) ;
+1 ;----- GET THE DATA, PUT INTO A TEXT FILE
+2 ;
+3 NEW %FILE
+4 ;
+5 SET BGPOUT=0
+6 ;
+7 DO FILE(BGPBEGDT,.%FILE,.BGPFILE,.BGPOUT)
+8 IF BGPOUT
QUIT
+9 ;
+10 USE %FILE
+11 IF BGPMSG=1
DO MSG1(BGPBEGDT,BGPENDDT,.BGPFACS)
+12 IF BGPMSG=2
DO MSG2(BGPBEGDT,BGPENDDT,.BGPF,BGPDFILE)
+13 DO CLOSE^%ZISH("FILE")
+14 ;
+15 QUIT
SENDMAIL(BGPFILE) ;
+1 ;----- SEND THE EMAIL
+2 ;
+3 ;N BGPERR,BGPFROM,BGPOUT,BGPSUB,BGPTO,I,X
+4 ;
+5 ;S BGPOUT=0
+6 ;
+7 ;S BGPTO=$$TO
+8 ;Q:BGPTO']""
+9 ;
+10 ;S BGPFROM=$P($G(^BGPGP1PM(1,99.1)),U)
+11 ;I BGPFROM']"" D Q
+12 ;. S BGPERR="NO SENDER"
+13 ;. ;S $ZE="BGPGP1MM FAILURE" D ^%ZTER
+14 ;
+15 ;S BGPFILE=$P($G(^BGPGP1PM(1,1)),U)_BGPFILE
+16 ;S BGPSUB="MONTHLY AUTOMATIC GPRA UPLOAD"
+17 ;
+18 ;S X=$ZF(-1,"wsendmail -s"""_BGPSUB_""" -f"_BGPFROM_" -t"_BGPFILE_" "_BGPTO)
+19 ;
+20 ;I X D
+21 ;. S BGPERR="CANNOT SEND EMAIL - wsendmail failure"
+22 ;. ;S $ZE="BGPGP1MM FAILURE" D ^%ZTER
+23 QUIT
TO() ;
+1 ;----- CREATE MAIL RECIPIENT STRING
+2 ;
+3 NEW BGPD1,BGPTO
+4 ;
+5 SET BGPTO=""
+6 SET BGPD1=0
+7 FOR
SET BGPD1=$ORDER(^BGPGP1PM(1,99.2,BGPD1))
IF 'BGPD1
QUIT
Begin DoDot:1
+8 SET BGPTO=BGPTO_","_$GET(^BGPGP1PM(1,99.2,BGPD1,0))
End DoDot:1
+9 IF $EXTRACT(BGPTO)=","
SET BGPTO=$EXTRACT(BGPTO,2,999999)
+10 QUIT BGPTO
+11 ;
FILE(BGPBEGDT,%FILE,BGPFILE,BGPOUT) ;
+1 ;----- CREATE FILE CONTAINING THE DATA
+2 ;
+3 NEW BGPERR,BGPOUT
+4 ;
+5 ;I '$G(DUZ) S DUZ=1
+6 DO ^XBKVAR
+7 SET BGPOUT=0
+8 SET BGPERR=""
+9 SET BGPFILE="BGPGP1MM"_BGPBEGDT
+10 DO HFS(.BGPOUT,.%FILE,BGPFILE)
+11 IF BGPOUT
Begin DoDot:1
+12 ;FOR ERROR TRAP
SET BGPERR="CANNOT OPEN FILE"
+13 ;S $ZE="BGPGP1MM FAILURE" D ^%ZTER
End DoDot:1
QUIT
+14 QUIT
HFS(BGPOUT,%FILE,BGPFILE) ;EP
+1 ;----- CREATE AND OPEN DATA FILE
+2 ;
+3 ; INPUT:
+4 ; FILE = DATA FILE NAME TO CREATE AND OPEN
+5 ;
+6 ; OUTPUT:
+7 ; %FILE = THE DEVICE NUMBER OF THE FILE
+8 ; BGPOUT = QUIT INDICATOR
+9 ;
+10 NEW I,POP,X,Y,ZISH1,ZISH2,ZISH3,ZISH4
+11 ;
+12 SET %FILE=""
+13 SET BGPOUT=0
+14 ;HANDLE
SET ZISH1="FILE"
+15 ;DIRECTORY
SET ZISH2=$PIECE($GET(^BGPGP1PM(1,1)),U)
+16 ;FILENAME
SET ZISH3=BGPFILE
+17 ;WRITE MODE
SET ZISH4="W"
+18 DO OPEN^%ZISH(ZISH1,ZISH2,ZISH3,ZISH4)
+19 IF POP
SET BGPOUT=1
+20 IF BGPOUT
QUIT
+21 SET %FILE=IO
+22 QUIT
EXDT(X) ;
+1 ;----- CONVERT INTERNAL FM DATE TO EXTERNAL READABLE DATE
+2 ;
+3 NEW Y
+4 SET Y=""
+5 IF X
Begin DoDot:1
+6 SET Y=X
+7 DO DD^%DT
End DoDot:1
+8 QUIT Y
MSG1(BGPBEGDT,BGPENDDT,BGPFACS) ;EP
+1 ;----- MESSAGE 1, MISSING FILES
+2 ;
+3 NEW BGPASU,BGPFAC
+4 ;
+5 WRITE !,"Monthly GPRA report period date range: "_$$EXDT(BGPBEGDT)_" to "_$$EXDT(BGPENDDT)
+6 ;
+7 WRITE !!,"The site GPRA files could not be uploaded because files are"
+8 WRITE !,"missing from the following facilities:",!!
+9 ;
+10 SET BGPASU=0
+11 FOR
SET BGPASU=$ORDER(BGPFACS(BGPENDDT,BGPASU))
IF BGPASU=""
QUIT
Begin DoDot:1
+12 IF BGPFACS(BGPENDDT,BGPASU)]""
QUIT
+13 SET BGPFAC=$ORDER(^BGPGP1PM(1,9,"C",BGPASU,0))
+14 IF 'BGPFAC
QUIT
+15 SET BGPFAC=$PIECE($GET(^BGPGP1PM(1,9,BGPFAC,0)),U)
+16 IF BGPFAC]""
WRITE !?5,BGPASU," ",$$VAL^XBDIQ1(4,BGPFAC,.01)
End DoDot:1
+17 ;
+18 WRITE !!!,"The aggregate excel files cannot be created until all files"
+19 WRITE !,"are received from all facilities."
+20 QUIT
MSG2(BGPBEGDT,BGPENDDT,BGPF,BGPDFILE) ;
+1 ;----- MESSAGE 2, AGGREGATE EXCEL FILES CREATED
+2 ;
+3 NEW BGP
+4 ;
+5 WRITE !,"Monthly GPRA report period date range: "_$$EXDT(BGPBEGDT)_" to "_$$EXDT(BGPENDDT)
+6 ;
+7 WRITE !!,"The following aggregate excel files have been created:",!!
+8 ;
+9 SET BGP=0
+10 FOR
SET BGP=$ORDER(BGPF(BGP))
IF 'BGP
QUIT
Begin DoDot:1
+11 WRITE !?5,BGPF(BGP)
End DoDot:1
+12 ;
+13 WRITE !!,"The following data file for DeepSee has been created:",!!
+14 WRITE !?5,BGPDFILE
+15 QUIT