KMPRBD02 ;SF/RAK - RUM Data Compression ;1/20/00 07:36
;;1.0;CAPACITY MANAGEMENT - RUM;**1**;Dec 09, 1998
;
; Background Driver (cont.)
;
DAILY(KMPRTDAY) ;-- daily data compression and storage
;----------------------------------------------------------------------
; KMPRTDAY.. Day in $H format (+$H). This represents the
; ending point for compression. Only dates LESS than
; KMPRTDAY will be compressed.
;
; At midnight compress hourly info into daily stats. Daily stats are
; stored in file #8971.1. Hourly data is killed.
;----------------------------------------------------------------------
;
Q:'$G(KMPRTDAY)
;
N ARRAY,COUNT,DATA,DOW,HDATE,HTIME,I,JOB,MESSAGE,NODE,OKAY,OPTION
N NP,PT,PTM,X,VAR
;
; make sure DT is defined.
S:'$G(DT) DT=$$DT^XLFDT
; where daily data is located.
S ARRAY=$NA(^XTMP("KMPR","DLY"))
S NODE=""
F S NODE=$O(@ARRAY@(NODE)) Q:NODE="" D
.S HDATE=""
.F S HDATE=$O(@ARRAY@(NODE,HDATE)) Q:HDATE=""!(HDATE'<KMPRTDAY) D
..S OPTION=""
..F S OPTION=$O(@ARRAY@(NODE,HDATE,OPTION)) Q:OPTION="" D
...S JOB=0,(COUNT,NP,PT)=""
...F S JOB=$O(@ARRAY@(NODE,HDATE,OPTION,JOB)) Q:'JOB D
....S PTM=""
....F S PTM=$O(@ARRAY@(NODE,HDATE,OPTION,JOB,PTM)) Q:PTM="" D
.....; PTM: non-prime time = 0 prime time = 1
.....S DATA=@ARRAY@(NODE,HDATE,OPTION,JOB,PTM)
.....; prime time or non-prime time.
.....S VAR=$S(PTM:"PT",1:"NP") Q:VAR=""
.....; accumulate totals.
.....F I=1:1:8 S $P(@VAR,U,I)=$P(@VAR,U,I)+$P(DATA,U,I)
.....; piece 1 non-prime time - piece 2 prime time
.....S $P(COUNT,U,(PTM+1))=$P(COUNT,U,(PTM+1))+1
.....; remove data from array.
.....K @ARRAY@(NODE,HDATE,OPTION,JOB,PTM)
...;
...; back to OPTION level.
...; file data into file #8971.1
...D FILE^KMPRBD03(HDATE,NODE,OPTION,PT,NP,$P(COUNT,U,2),$P(COUNT,U),.OKAY,.MESSAGE)
...; if not filed successfully set into 'ERR' node.
...I 'OKAY D
....S ^XTMP("KMPR","ERR",HDATE,NODE,OPTION,0)=NP_$P(COUNT,U)
....S ^XTMP("KMPR","ERR",HDATE,NODE,OPTION,1)=PT_$P(COUNT,U,2)
....F I=0:0 S I=$O(MESSAGE(I)) Q:'I D
.....S ^XTMP("KMPR","ERR",HDATE,NODE,OPTION,"MSG",I)=MESSAGE(I)
;
Q
;
WEEKLY(KMPRDT) ;-- compress daily stats to weekly
;-----------------------------------------------------------------------
; KMPRDT... Compression date in internal fileman formt. This date
; must be a Sunday. It represents the date from which the
; previous weeks data should be compressed.
; Example: if KMPRDT = 2981011 then compression will begin
; on 2981010 (KMPRDT-1)
;
; Every Sunday compress the daily stats in file #8971.1 into weekly
; and upload the data to the CM RUM National Database
;-----------------------------------------------------------------------
;
Q:'$G(KMPRDT)
;
N DATA,DATE,DELDATE,END,HOURS,I,IEN,J,SITE,START,TMPARRY,TMPARRY1
;
; quit if not sunday.
Q:$$DOW^XLFDT(KMPRDT,1)
; storage array.
S TMPARRY=$NA(^TMP($J))
; processed entries.
S TMPARRY1=$NA(^TMP("KMPR PROC",$J))
K @TMPARRY,@TMPARRY1
; site info.
S SITE=$$SITE^VASITE Q:SITE=""
S DATE=KMPRDT
S (START,END)=""
; Date to begin deletion.
S DELDATE=$$FMADD^XLFDT(KMPRDT,-14)
;
W:'$D(ZTQUEUED) !,"Compressing data into weekly format..."
; Reverse $order to get previous dates.
F S DATE=$O(^KMPR(8971.1,"B",DATE),-1) Q:'DATE D
.; If DATE is saturday set START and END dates and kill TMPARRY.
.I $$DOW^XLFDT(DATE,1)=6 D
..S END=DATE,START=$$FMADD^XLFDT(DATE,-6)
..K @TMPARRY
.Q:'START
.S IEN=0
.F S IEN=$O(^KMPR(8971.1,"B",DATE,IEN)) Q:'IEN D
..Q:'$D(^KMPR(8971.1,IEN,0))
..; data nodes into DATA() array.
..S DATA(0)=^KMPR(8971.1,IEN,0),DATA(1)=$G(^(1)),DATA(2)=$G(^(2))
..; Quit if data has already been sent to national database.
..Q:$P(DATA(0),U,2)
..; Cpu node.
..S NODE=$P(DATA(0),U,3) Q:NODE=""
..; OPTION = OptionName^ProtocolName.
..; option.
..S OPTION=$P(DATA(0),U,4)
..; rpc.
..S:OPTION="" OPTION=$P(DATA(0),U,7)
..; hl7.
..S:OPTION="" OPTION=$P(DATA(0),U,9)
..Q:OPTION=""
..S $P(OPTION,U,2)=$P(DATA(0),U,5)
..S @TMPARRY@(START,NODE,OPTION,0)=DATA(0)
..; change first piece to starting date (START)
..S $P(@TMPARRY@(START,NODE,OPTION,0),U)=START
..; second piece not applicable to national database
..S $P(@TMPARRY@(START,NODE,OPTION,0),U,2)=""
..; EndingDate^SiteName^SiteNumber.
..S @TMPARRY@(START,NODE,OPTION,99)=END_U_$P(SITE,U,2)_U_$P(SITE,U,3)
..; Nodes 1 and 2.
..F I=1,2 I DATA(I)]"" D
...; Add data to get weekly totals.
...F J=1:1:8 S $P(@TMPARRY@(START,NODE,OPTION,I),U,J)=$P($G(@TMPARRY@(START,NODE,OPTION,I)),U,J)+$P(DATA(I),U,J)
..;
..; Back to IEN level.
..; Add to processed array.
..S @TMPARRY1@(IEN)=""
.;
.; Back to DATE level.
.; If START then transmit data.
.I DATE=START I $D(@TMPARRY) D TRANSMIT K @TMPARRY
;
; Transmit data to national database.
W:'$D(ZTQUEUED) !,"Transmitting data to national database..."
D:$D(@TMPARRY) TRANSMIT
K @TMPARRY
;
; update field .02 (SENT TO CM NATIONAL DATABASE) to 'YES' for all
; processed entries.
W:'$D(ZTQUEUED) !,"Updating records to reflect transmission..."
S IEN=0
F S IEN=$O(@TMPARRY1@(IEN)) Q:'IEN D
.K FDA,ERROR
.S FDA($J,8971.1,IEN_",",.02)=1
.D FILE^DIE("","FDA($J)","ERROR")
K @TMPARRY1
;
; leave two complete weeks of data in file #8971.1
D PURGE^KMPRUTL3(DELDATE,1)
;
Q
;
TRANSMIT ;-- format TMPARRY data, put into e-mail and send to cm.
;
Q:$G(TMPARRY)=""
;
N HRSDAYS,I,IEN,LN,N,O,S,UPLDARRY,XMSUB,X,XMTEXT,XMY,XMZ,Y,Z
;
S UPLDARRY=$NA(^TMP("KMPR UPLOAD",$J))
K @UPLDARRY
;
S LN=0
; version and patch info.
S LN=LN+1,@UPLDARRY@(LN)="VERSION="_$$VERSION^KMPRUTL
;
; get hours/days data
D HRSDAYS^KMPRUTL3(START,END,1,.HRSDAYS)
; if ^XTMP("KMPR","HOURS","START") exists then this is the first time
; the "HOURS" subscript is being accessed. chances are this is only
; partial data, so it should be ignored.
I $G(^XTMP("KMPR","HOURS","START"))&($D(HRSDAYS)) D
.K HRSDAYS,^XTMP("KMPR","HOURS","START")
;
I $D(HRSDAYS) S S=0 D
.F S S=$O(HRSDAYS(S)) Q:'S S N="" D
..F S N=$O(HRSDAYS(S,N)) Q:N="" D
...S LN=LN+1
...; StartDate^Node^EndDate^PTDays^PTHours^NPTDays^NPTHours
...S @UPLDARRY@(LN)="HRSDAYS="_START_"^"_N_"^"_END_"^"_HRSDAYS(S,N)
;
; reformat so that data is in ^TMP("KMPR UPLOAD",$J,LN)= format.
S IEN=0,S=""
F S S=$O(@TMPARRY@(S)) Q:S="" S N="" D
.F S N=$O(@TMPARRY@(S,N)) Q:N="" S O="" D
..F S O=$O(@TMPARRY@(S,N,O)) Q:O="" S I="",IEN=IEN+1 D
...F S I=$O(@TMPARRY@(S,N,O,I)) Q:I="" D
....S LN=LN+1
....S @UPLDARRY@(LN)=IEN_","_I_")="_@TMPARRY@(S,N,O,I)
;
; quit if no data to transmit.
Q:'$D(@UPLDARRY)
; send packman message.
S XMTEXT="^TMP(""KMPR UPLOAD"","_$J_","
S XMSUB="RUM DATA - "_$P(SITE,U,2)_" ("_$P(SITE,U,3)_") - "_$$FMTE^XLFDT(START)
S XMY("S.KMP2-RUM-SERVER@DOMAIN.NAME")=""
S XMY("CAPACITY,MANAGEMENT@DOMAIN.NAME")=""
D ^XMD
W:'$D(ZTQUEUED) !,"Message #",$G(XMZ)," sent..."
K @UPLDARRY
;
Q
KMPRBD02 ;SF/RAK - RUM Data Compression ;1/20/00 07:36
+1 ;;1.0;CAPACITY MANAGEMENT - RUM;**1**;Dec 09, 1998
+2 ;
+3 ; Background Driver (cont.)
+4 ;
DAILY(KMPRTDAY) ;-- daily data compression and storage
+1 ;----------------------------------------------------------------------
+2 ; KMPRTDAY.. Day in $H format (+$H). This represents the
+3 ; ending point for compression. Only dates LESS than
+4 ; KMPRTDAY will be compressed.
+5 ;
+6 ; At midnight compress hourly info into daily stats. Daily stats are
+7 ; stored in file #8971.1. Hourly data is killed.
+8 ;----------------------------------------------------------------------
+9 ;
+10 IF '$GET(KMPRTDAY)
QUIT
+11 ;
+12 NEW ARRAY,COUNT,DATA,DOW,HDATE,HTIME,I,JOB,MESSAGE,NODE,OKAY,OPTION
+13 NEW NP,PT,PTM,X,VAR
+14 ;
+15 ; make sure DT is defined.
+16 IF '$GET(DT)
SET DT=$$DT^XLFDT
+17 ; where daily data is located.
+18 SET ARRAY=$NAME(^XTMP("KMPR","DLY"))
+19 SET NODE=""
+20 FOR
SET NODE=$ORDER(@ARRAY@(NODE))
IF NODE=""
QUIT
Begin DoDot:1
+21 SET HDATE=""
+22 FOR
SET HDATE=$ORDER(@ARRAY@(NODE,HDATE))
IF HDATE=""!(HDATE'<KMPRTDAY)
QUIT
Begin DoDot:2
+23 SET OPTION=""
+24 FOR
SET OPTION=$ORDER(@ARRAY@(NODE,HDATE,OPTION))
IF OPTION=""
QUIT
Begin DoDot:3
+25 SET JOB=0
SET (COUNT,NP,PT)=""
+26 FOR
SET JOB=$ORDER(@ARRAY@(NODE,HDATE,OPTION,JOB))
IF 'JOB
QUIT
Begin DoDot:4
+27 SET PTM=""
+28 FOR
SET PTM=$ORDER(@ARRAY@(NODE,HDATE,OPTION,JOB,PTM))
IF PTM=""
QUIT
Begin DoDot:5
+29 ; PTM: non-prime time = 0 prime time = 1
+30 SET DATA=@ARRAY@(NODE,HDATE,OPTION,JOB,PTM)
+31 ; prime time or non-prime time.
+32 SET VAR=$SELECT(PTM:"PT",1:"NP")
IF VAR=""
QUIT
+33 ; accumulate totals.
+34 FOR I=1:1:8
SET $PIECE(@VAR,U,I)=$PIECE(@VAR,U,I)+$PIECE(DATA,U,I)
+35 ; piece 1 non-prime time - piece 2 prime time
+36 SET $PIECE(COUNT,U,(PTM+1))=$PIECE(COUNT,U,(PTM+1))+1
+37 ; remove data from array.
+38 KILL @ARRAY@(NODE,HDATE,OPTION,JOB,PTM)
End DoDot:5
End DoDot:4
+39 ;
+40 ; back to OPTION level.
+41 ; file data into file #8971.1
+42 DO FILE^KMPRBD03(HDATE,NODE,OPTION,PT,NP,$PIECE(COUNT,U,2),$PIECE(COUNT,U),.OKAY,.MESSAGE)
+43 ; if not filed successfully set into 'ERR' node.
+44 IF 'OKAY
Begin DoDot:4
+45 SET ^XTMP("KMPR","ERR",HDATE,NODE,OPTION,0)=NP_$PIECE(COUNT,U)
+46 SET ^XTMP("KMPR","ERR",HDATE,NODE,OPTION,1)=PT_$PIECE(COUNT,U,2)
+47 FOR I=0:0
SET I=$ORDER(MESSAGE(I))
IF 'I
QUIT
Begin DoDot:5
+48 SET ^XTMP("KMPR","ERR",HDATE,NODE,OPTION,"MSG",I)=MESSAGE(I)
End DoDot:5
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+49 ;
+50 QUIT
+51 ;
WEEKLY(KMPRDT) ;-- compress daily stats to weekly
+1 ;-----------------------------------------------------------------------
+2 ; KMPRDT... Compression date in internal fileman formt. This date
+3 ; must be a Sunday. It represents the date from which the
+4 ; previous weeks data should be compressed.
+5 ; Example: if KMPRDT = 2981011 then compression will begin
+6 ; on 2981010 (KMPRDT-1)
+7 ;
+8 ; Every Sunday compress the daily stats in file #8971.1 into weekly
+9 ; and upload the data to the CM RUM National Database
+10 ;-----------------------------------------------------------------------
+11 ;
+12 IF '$GET(KMPRDT)
QUIT
+13 ;
+14 NEW DATA,DATE,DELDATE,END,HOURS,I,IEN,J,SITE,START,TMPARRY,TMPARRY1
+15 ;
+16 ; quit if not sunday.
+17 IF $$DOW^XLFDT(KMPRDT,1)
QUIT
+18 ; storage array.
+19 SET TMPARRY=$NAME(^TMP($JOB))
+20 ; processed entries.
+21 SET TMPARRY1=$NAME(^TMP("KMPR PROC",$JOB))
+22 KILL @TMPARRY,@TMPARRY1
+23 ; site info.
+24 SET SITE=$$SITE^VASITE
IF SITE=""
QUIT
+25 SET DATE=KMPRDT
+26 SET (START,END)=""
+27 ; Date to begin deletion.
+28 SET DELDATE=$$FMADD^XLFDT(KMPRDT,-14)
+29 ;
+30 IF '$DATA(ZTQUEUED)
WRITE !,"Compressing data into weekly format..."
+31 ; Reverse $order to get previous dates.
+32 FOR
SET DATE=$ORDER(^KMPR(8971.1,"B",DATE),-1)
IF 'DATE
QUIT
Begin DoDot:1
+33 ; If DATE is saturday set START and END dates and kill TMPARRY.
+34 IF $$DOW^XLFDT(DATE,1)=6
Begin DoDot:2
+35 SET END=DATE
SET START=$$FMADD^XLFDT(DATE,-6)
+36 KILL @TMPARRY
End DoDot:2
+37 IF 'START
QUIT
+38 SET IEN=0
+39 FOR
SET IEN=$ORDER(^KMPR(8971.1,"B",DATE,IEN))
IF 'IEN
QUIT
Begin DoDot:2
+40 IF '$DATA(^KMPR(8971.1,IEN,0))
QUIT
+41 ; data nodes into DATA() array.
+42 SET DATA(0)=^KMPR(8971.1,IEN,0)
SET DATA(1)=$GET(^(1))
SET DATA(2)=$GET(^(2))
+43 ; Quit if data has already been sent to national database.
+44 IF $PIECE(DATA(0),U,2)
QUIT
+45 ; Cpu node.
+46 SET NODE=$PIECE(DATA(0),U,3)
IF NODE=""
QUIT
+47 ; OPTION = OptionName^ProtocolName.
+48 ; option.
+49 SET OPTION=$PIECE(DATA(0),U,4)
+50 ; rpc.
+51 IF OPTION=""
SET OPTION=$PIECE(DATA(0),U,7)
+52 ; hl7.
+53 IF OPTION=""
SET OPTION=$PIECE(DATA(0),U,9)
+54 IF OPTION=""
QUIT
+55 SET $PIECE(OPTION,U,2)=$PIECE(DATA(0),U,5)
+56 SET @TMPARRY@(START,NODE,OPTION,0)=DATA(0)
+57 ; change first piece to starting date (START)
+58 SET $PIECE(@TMPARRY@(START,NODE,OPTION,0),U)=START
+59 ; second piece not applicable to national database
+60 SET $PIECE(@TMPARRY@(START,NODE,OPTION,0),U,2)=""
+61 ; EndingDate^SiteName^SiteNumber.
+62 SET @TMPARRY@(START,NODE,OPTION,99)=END_U_$PIECE(SITE,U,2)_U_$PIECE(SITE,U,3)
+63 ; Nodes 1 and 2.
+64 FOR I=1,2
IF DATA(I)]""
Begin DoDot:3
+65 ; Add data to get weekly totals.
+66 FOR J=1:1:8
SET $PIECE(@TMPARRY@(START,NODE,OPTION,I),U,J)=$PIECE($GET(@TMPARRY@(START,NODE,OPTION,I)),U,J)+$PIECE(DATA(I),U,J)
End DoDot:3
+67 ;
+68 ; Back to IEN level.
+69 ; Add to processed array.
+70 SET @TMPARRY1@(IEN)=""
End DoDot:2
+71 ;
+72 ; Back to DATE level.
+73 ; If START then transmit data.
+74 IF DATE=START
IF $DATA(@TMPARRY)
DO TRANSMIT
KILL @TMPARRY
End DoDot:1
+75 ;
+76 ; Transmit data to national database.
+77 IF '$DATA(ZTQUEUED)
WRITE !,"Transmitting data to national database..."
+78 IF $DATA(@TMPARRY)
DO TRANSMIT
+79 KILL @TMPARRY
+80 ;
+81 ; update field .02 (SENT TO CM NATIONAL DATABASE) to 'YES' for all
+82 ; processed entries.
+83 IF '$DATA(ZTQUEUED)
WRITE !,"Updating records to reflect transmission..."
+84 SET IEN=0
+85 FOR
SET IEN=$ORDER(@TMPARRY1@(IEN))
IF 'IEN
QUIT
Begin DoDot:1
+86 KILL FDA,ERROR
+87 SET FDA($JOB,8971.1,IEN_",",.02)=1
+88 DO FILE^DIE("","FDA($J)","ERROR")
End DoDot:1
+89 KILL @TMPARRY1
+90 ;
+91 ; leave two complete weeks of data in file #8971.1
+92 DO PURGE^KMPRUTL3(DELDATE,1)
+93 ;
+94 QUIT
+95 ;
TRANSMIT ;-- format TMPARRY data, put into e-mail and send to cm.
+1 ;
+2 IF $GET(TMPARRY)=""
QUIT
+3 ;
+4 NEW HRSDAYS,I,IEN,LN,N,O,S,UPLDARRY,XMSUB,X,XMTEXT,XMY,XMZ,Y,Z
+5 ;
+6 SET UPLDARRY=$NAME(^TMP("KMPR UPLOAD",$JOB))
+7 KILL @UPLDARRY
+8 ;
+9 SET LN=0
+10 ; version and patch info.
+11 SET LN=LN+1
SET @UPLDARRY@(LN)="VERSION="_$$VERSION^KMPRUTL
+12 ;
+13 ; get hours/days data
+14 DO HRSDAYS^KMPRUTL3(START,END,1,.HRSDAYS)
+15 ; if ^XTMP("KMPR","HOURS","START") exists then this is the first time
+16 ; the "HOURS" subscript is being accessed. chances are this is only
+17 ; partial data, so it should be ignored.
+18 IF $GET(^XTMP("KMPR","HOURS","START"))&($DATA(HRSDAYS))
Begin DoDot:1
+19 KILL HRSDAYS,^XTMP("KMPR","HOURS","START")
End DoDot:1
+20 ;
+21 IF $DATA(HRSDAYS)
SET S=0
Begin DoDot:1
+22 FOR
SET S=$ORDER(HRSDAYS(S))
IF 'S
QUIT
SET N=""
Begin DoDot:2
+23 FOR
SET N=$ORDER(HRSDAYS(S,N))
IF N=""
QUIT
Begin DoDot:3
+24 SET LN=LN+1
+25 ; StartDate^Node^EndDate^PTDays^PTHours^NPTDays^NPTHours
+26 SET @UPLDARRY@(LN)="HRSDAYS="_START_"^"_N_"^"_END_"^"_HRSDAYS(S,N)
End DoDot:3
End DoDot:2
End DoDot:1
+27 ;
+28 ; reformat so that data is in ^TMP("KMPR UPLOAD",$J,LN)= format.
+29 SET IEN=0
SET S=""
+30 FOR
SET S=$ORDER(@TMPARRY@(S))
IF S=""
QUIT
SET N=""
Begin DoDot:1
+31 FOR
SET N=$ORDER(@TMPARRY@(S,N))
IF N=""
QUIT
SET O=""
Begin DoDot:2
+32 FOR
SET O=$ORDER(@TMPARRY@(S,N,O))
IF O=""
QUIT
SET I=""
SET IEN=IEN+1
Begin DoDot:3
+33 FOR
SET I=$ORDER(@TMPARRY@(S,N,O,I))
IF I=""
QUIT
Begin DoDot:4
+34 SET LN=LN+1
+35 SET @UPLDARRY@(LN)=IEN_","_I_")="_@TMPARRY@(S,N,O,I)
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+36 ;
+37 ; quit if no data to transmit.
+38 IF '$DATA(@UPLDARRY)
QUIT
+39 ; send packman message.
+40 SET XMTEXT="^TMP(""KMPR UPLOAD"","_$JOB_","
+41 SET XMSUB="RUM DATA - "_$PIECE(SITE,U,2)_" ("_$PIECE(SITE,U,3)_") - "_$$FMTE^XLFDT(START)
+42 SET XMY("S.KMP2-RUM-SERVER@DOMAIN.NAME")=""
+43 SET XMY("CAPACITY,MANAGEMENT@DOMAIN.NAME")=""
+44 DO ^XMD
+45 IF '$DATA(ZTQUEUED)
WRITE !,"Message #",$GET(XMZ)," sent..."
+46 KILL @UPLDARRY
+47 ;
+48 QUIT