HLEMEP ;ALB/CJM-HL7 - Purge Monitor Events ;02/04/2004
;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
;
PURGE ;
N NOW,WHEN,EVENT,ERROR
S NOW=$$NOW^XLFDT
S WHEN=0
D START^HLEVAPI(.VAR)
;
;delete the old events
F S WHEN=$O(^HLEV(776.4,"AJ",WHEN)) Q:'WHEN Q:WHEN>NOW D
.S EVENT=0
.F S EVENT=$O(^HLEV(776.4,"AJ",WHEN,EVENT)) Q:'EVENT D
..I '$$DELETE^HLEMU(776.4,EVENT,.ERROR),'$D(^HLEV(776.4,EVENT,0)) K ^HLEV(776.4,"AJ",WHEN,EVENT)
;
;delete the old statistics
N STATS,SITE,TYPE,YEAR,MONTH,DAY,CUTMONTH,CUTDAY,CUTHOUR
S STATS="^HLEV(776.4,""AF"")"
S SITE=0
;
;these determine the timeframes within which to delete the old statistics
S CUTMONTH=$E($$FMADD^XLFDT(DT,-65),1,5)
S CUTDAY=$P($$FMADD^XLFDT(DT,-8),".")
S CUTHOUR=$$FMADD^XLFDT(NOW,-2)
;
F S SITE=$O(@STATS@(SITE)) Q:'SITE D
.S TYPE=0
.F S TYPE=$O(@STATS@(SITE,TYPE)) Q:'TYPE D
..S YEAR=""
..F S YEAR=$O(@STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR)) Q:'YEAR D
...S MONTH=""
...F S MONTH=$O(@STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH)) Q:(MONTH="") D
....I ((YEAR-1700)_$$PAD2(MONTH))<CUTMONTH D
.....K @STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH)
....E D
.....S DAY=""
.....F S DAY=$O(@STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH,"DAY",DAY)) Q:(DAY="") D
......I ((YEAR-1700)_$$PAD2(MONTH)_$$PAD2(DAY))<CUTDAY D
.......K @STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH,"DAY",DAY)
......E D
.......S HOUR=0
.......F S HOUR=$O(@STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH,"DAY",DAY,"HOUR",HOUR)) Q:(HOUR="") Q:((YEAR-1700)_$$PAD2(MONTH)_$$PAD2(DAY)_"."_$$PAD2(HOUR))>CUTHOUR D
........K @STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH,"DAY",DAY,"HOUR",HOUR)
;
;
D CHECKOUT^HLEVAPI
K ^TMP("HLEVFLAG",$J)
Q
;
INPERSON ;entry point for running in the foreground
S ^TMP("HLEVFLAG",$J)="STOP"
D PURGE
Q
PAD2(STRING) ;
; pads a number on the left with '0', to a length of 2
Q $$RJ^XLFSTR(STRING,2,"0")
;
HLEMEP ;ALB/CJM-HL7 - Purge Monitor Events ;02/04/2004
+1 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
+2 ;
PURGE ;
+1 NEW NOW,WHEN,EVENT,ERROR
+2 SET NOW=$$NOW^XLFDT
+3 SET WHEN=0
+4 DO START^HLEVAPI(.VAR)
+5 ;
+6 ;delete the old events
+7 FOR
SET WHEN=$ORDER(^HLEV(776.4,"AJ",WHEN))
IF 'WHEN
QUIT
IF WHEN>NOW
QUIT
Begin DoDot:1
+8 SET EVENT=0
+9 FOR
SET EVENT=$ORDER(^HLEV(776.4,"AJ",WHEN,EVENT))
IF 'EVENT
QUIT
Begin DoDot:2
+10 IF '$$DELETE^HLEMU(776.4,EVENT,.ERROR)
IF '$DATA(^HLEV(776.4,EVENT,0))
KILL ^HLEV(776.4,"AJ",WHEN,EVENT)
End DoDot:2
End DoDot:1
+11 ;
+12 ;delete the old statistics
+13 NEW STATS,SITE,TYPE,YEAR,MONTH,DAY,CUTMONTH,CUTDAY,CUTHOUR
+14 SET STATS="^HLEV(776.4,""AF"")"
+15 SET SITE=0
+16 ;
+17 ;these determine the timeframes within which to delete the old statistics
+18 SET CUTMONTH=$EXTRACT($$FMADD^XLFDT(DT,-65),1,5)
+19 SET CUTDAY=$PIECE($$FMADD^XLFDT(DT,-8),".")
+20 SET CUTHOUR=$$FMADD^XLFDT(NOW,-2)
+21 ;
+22 FOR
SET SITE=$ORDER(@STATS@(SITE))
IF 'SITE
QUIT
Begin DoDot:1
+23 SET TYPE=0
+24 FOR
SET TYPE=$ORDER(@STATS@(SITE,TYPE))
IF 'TYPE
QUIT
Begin DoDot:2
+25 SET YEAR=""
+26 FOR
SET YEAR=$ORDER(@STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR))
IF 'YEAR
QUIT
Begin DoDot:3
+27 SET MONTH=""
+28 FOR
SET MONTH=$ORDER(@STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH))
IF (MONTH="")
QUIT
Begin DoDot:4
+29 IF ((YEAR-1700)_$$PAD2(MONTH))<CUTMONTH
Begin DoDot:5
+30 KILL @STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH)
End DoDot:5
+31 IF '$TEST
Begin DoDot:5
+32 SET DAY=""
+33 FOR
SET DAY=$ORDER(@STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH,"DAY",DAY))
IF (DAY="")
QUIT
Begin DoDot:6
+34 IF ((YEAR-1700)_$$PAD2(MONTH)_$$PAD2(DAY))<CUTDAY
Begin DoDot:7
+35 KILL @STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH,"DAY",DAY)
End DoDot:7
+36 IF '$TEST
Begin DoDot:7
+37 SET HOUR=0
+38 FOR
SET HOUR=$ORDER(@STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH,"DAY",DAY,"HOUR",HOUR))
IF (HOUR="")
QUIT
IF ((YEAR-1700)_$$PAD2(MONTH)_$$PAD2(DAY)_"."_$$PAD2(HOUR))>CUTHOUR
QUIT
Begin DoDot:8
+39 KILL @STATS@(SITE,TYPE,"RECEIVED","YEAR",YEAR,"MONTH",MONTH,"DAY",DAY,"HOUR",HOUR)
End DoDot:8
End DoDot:7
End DoDot:6
End DoDot:5
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+40 ;
+41 ;
+42 DO CHECKOUT^HLEVAPI
+43 KILL ^TMP("HLEVFLAG",$JOB)
+44 QUIT
+45 ;
INPERSON ;entry point for running in the foreground
+1 SET ^TMP("HLEVFLAG",$JOB)="STOP"
+2 DO PURGE
+3 QUIT
PAD2(STRING) ;
+1 ; pads a number on the left with '0', to a length of 2
+2 QUIT $$RJ^XLFSTR(STRING,2,"0")
+3 ;