KMPRBD04 ;OAK/RAK - RUM Data Compression ;1/30/13 08:30
;;2.0;CAPACITY MANAGEMENT - RUM;**2**;May 28, 2003;Build 12
;
; Background Driver (cont.)
;
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
;
; ^TMP($J)............. temporary storage for RUM data
; ^TMP("KMPR PROC",$J). entries that have been processed and will be
; updated as 'send to national dabase'
;-----------------------------------------------------------------------
;
Q:'$G(KMPRDT)
;
N DATA,DATE,DELDATE,END,HOURS,I,IEN,J,NODE,OPTION,SITE,START
;
; quit if not sunday
Q:$$DOW^XLFDT(KMPRDT,1)
;
K ^TMP($J),^TMP("KMPR PROC",$J)
;
; 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 ^TMP($J)
.I $$DOW^XLFDT(DATE,1)=6 D
..S END=DATE,START=$$FMADD^XLFDT(DATE,-6)
..K ^TMP($J)
.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(1.1)=$G(^(1.1)),DATA(1.2)=$G(^(1.2)),DATA(2)=$G(^(2)),DATA(2.1)=$G(^(2.1)),DATA(2.2)=$G(^(2.2)),DATA(3)=$G(^(3))
..;
..; 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
..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=""
..;
..; OPTION = OptionName^ProtocolName
..S $P(OPTION,U,2)=$P(DATA(0),U,5)
..;
..S ^TMP($J,START,NODE,OPTION,0)=DATA(0)
..; change first piece to starting date (START)
..S $P(^TMP($J,START,NODE,OPTION,0),U)=START
..; second piece not applicable to national database
..S $P(^TMP($J,START,NODE,OPTION,0),U,2)=""
..; EndingDate^SiteName^SiteNumber
..S ^TMP($J,START,NODE,OPTION,99)=END_U_$P(SITE,U,2)_U_$P(SITE,U,3)
..;
..; add data to get weekly totals
..F I=1,1.1,1.2,2,2.1,2.2,3 I DATA(I)]"" D
...; if subscript 1 or 2 or 3 ('I#1) add pieces 1 - 8
...; else add pieces 1 - 24
...F J=1:1:$S('(I#1):8,1:24) D
....S $P(^TMP($J,START,NODE,OPTION,I),U,J)=$P($G(^TMP($J,START,NODE,OPTION,I)),U,J)+$P(DATA(I),U,J)
....; update "HOURS" subscript
....S:(I#1)&($P(DATA(I),U,J)) $P(^KMPTMP("KMPR","HOURS",DATE,NODE),U,J)=1
..;
..; back to IEN level
..; add to processed array
..S ^TMP("KMPR PROC",$J,IEN)=""
.;
.; back to DATE level
.; if START then transmit data
.I DATE=START I $D(^TMP($J)) D TRANSMIT K ^TMP($J)
;
; transmit data to national database
W:'$D(ZTQUEUED) !,"Transmitting data to national database..."
D:$D(^TMP($J)) TRANSMIT
K ^TMP($J)
;
; 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(^TMP("KMPR PROC",$J,IEN)) Q:'IEN D
.K FDA,ERROR
.S FDA($J,8971.1,IEN_",",.02)=1
.D FILE^DIE("","FDA($J)","ERROR")
K ^TMP("KMPR PROC",$J)
;
; leave two complete weeks of data in file #8971.1
D PURGE^KMPRUTL3(DELDATE,1)
;
Q
;
TRANSMIT ;-- format ^TMP($J) data, put into e-mail and send to cm.
;
Q:'$D(^TMP($J))
;
N HRSDAYS,I,IEN,LN,N,O,S,TL,XMSUB,X,XMTEXT,XMY,XMZ,Y,Z
;
K ^TMP("KMPRBD04-3",$J)
;
S LN=1
; version and patch info and weekly background info
S Z=$G(^KMPTMP("KMPR","BACKGROUND","WEEKLY","TOTAL","START"))_"^"_$G(^("STOP"))_"^"_$G(^("DELTA"))
S ^TMP("KMPRBD04-3",$J,LN)="VERSION="_$$VERSION^KMPRUTL_"^"_Z
;
; get system information
S LN=LN+1
S ^TMP("KMPRBD04-3",$J,LN)="SYSINFO="_$$SYSINFO^KMPDUTL1()
;
; get number of days/hours data for the specified date range
D HRSDAYS^KMPRUTL3(START,END,1,.HRSDAYS)
;
; if ^KMPTMP("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(^KMPTMP("KMPR","HOURS","START"))&($D(HRSDAYS)) D
.K HRSDAYS,^KMPTMP("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
...; ... ^WDDays^WDHours^NWDays^NWHours
...S ^TMP("KMPRBD04-3",$J,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(^TMP($J,S)) Q:S="" S N="" D
.F S N=$O(^TMP($J,S,N)) Q:N="" S O="" D
..F S O=$O(^TMP($J,S,N,O)) Q:O="" S I="",IEN=IEN+1 D
...F S I=$O(^TMP($J,S,N,O,I)) Q:I="" D
....S LN=LN+1
....S ^TMP("KMPRBD04-3",$J,LN)=IEN_","_I_")="_^TMP($J,S,N,O,I)
;
; quit if no data to transmit.
Q:'$D(^TMP("KMPRBD04-3",$J))
S TL=$$TESTLAB^KMPDUT1
; send packman message.
S XMTEXT="^TMP(""KMPRBD04-3"","_$J_","
S XMSUB="RUM DATA~"_$P(TL,U,2)_$P(SITE,U,2)_" ("_$P(SITE,U,3)_")~"_$$FMTE^XLFDT(START)_"~"_$P($$VERSION^KMPRUTL,U)
S XMY("S.KMP2-RUM-SERVER@FO-ALBANY.DOMAIN.EXT")=""
S XMY("CAPACITY,MANAGEMENT@FO-ALBANY.DOMAIN.EXT")=""
D ^XMD
W:'$D(ZTQUEUED) !,"Message #",$G(XMZ)," sent..."
K ^TMP("KMPRBD04-3",$J)
;
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HKMPRBD04 5995 printed Nov 22, 2024@16:51:47 Page 2
KMPRBD04 ;OAK/RAK - RUM Data Compression ;1/30/13 08:30
+1 ;;2.0;CAPACITY MANAGEMENT - RUM;**2**;May 28, 2003;Build 12
+2 ;
+3 ; Background Driver (cont.)
+4 ;
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 ; ^TMP($J)............. temporary storage for RUM data
+12 ; ^TMP("KMPR PROC",$J). entries that have been processed and will be
+13 ; updated as 'send to national dabase'
+14 ;-----------------------------------------------------------------------
+15 ;
+16 if '$GET(KMPRDT)
QUIT
+17 ;
+18 NEW DATA,DATE,DELDATE,END,HOURS,I,IEN,J,NODE,OPTION,SITE,START
+19 ;
+20 ; quit if not sunday
+21 if $$DOW^XLFDT(KMPRDT,1)
QUIT
+22 ;
+23 KILL ^TMP($JOB),^TMP("KMPR PROC",$JOB)
+24 ;
+25 ; site info
+26 SET SITE=$$SITE^VASITE
if SITE=""
QUIT
+27 ;
+28 SET DATE=KMPRDT
+29 SET (START,END)=""
+30 ;
+31 ; date to begin deletion
+32 SET DELDATE=$$FMADD^XLFDT(KMPRDT,-14)
+33 ;
+34 if '$DATA(ZTQUEUED)
WRITE !,"Compressing data into weekly format..."
+35 ; reverse $order to get previous dates
+36 FOR
SET DATE=$ORDER(^KMPR(8971.1,"B",DATE),-1)
if 'DATE
QUIT
Begin DoDot:1
+37 ; if DATE is saturday set START and END dates and kill ^TMP($J)
+38 IF $$DOW^XLFDT(DATE,1)=6
Begin DoDot:2
+39 SET END=DATE
SET START=$$FMADD^XLFDT(DATE,-6)
+40 KILL ^TMP($JOB)
End DoDot:2
+41 if 'START
QUIT
+42 SET IEN=0
+43 FOR
SET IEN=$ORDER(^KMPR(8971.1,"B",DATE,IEN))
if 'IEN
QUIT
Begin DoDot:2
+44 ;
+45 if '$DATA(^KMPR(8971.1,IEN,0))
QUIT
+46 ;
+47 ; data nodes into DATA() array
+48 SET DATA(0)=^KMPR(8971.1,IEN,0)
SET DATA(1)=$GET(^(1))
SET DATA(1.1)=$GET(^(1.1))
SET DATA(1.2)=$GET(^(1.2))
SET DATA(2)=$GET(^(2))
SET DATA(2.1)=$GET(^(2.1))
SET DATA(2.2)=$GET(^(2.2))
SET DATA(3)=$GET(^(3))
+49 ;
+50 ; quit if data has already been sent to national database
+51 if $PIECE(DATA(0),U,2)
QUIT
+52 ;
+53 ; cpu node
+54 SET NODE=$PIECE(DATA(0),U,3)
if NODE=""
QUIT
+55 ;
+56 ; option
+57 SET OPTION=$PIECE(DATA(0),U,4)
+58 ; rpc
+59 if OPTION=""
SET OPTION=$PIECE(DATA(0),U,7)
+60 ; hl7
+61 if OPTION=""
SET OPTION=$PIECE(DATA(0),U,9)
+62 ;
+63 if OPTION=""
QUIT
+64 ;
+65 ; OPTION = OptionName^ProtocolName
+66 SET $PIECE(OPTION,U,2)=$PIECE(DATA(0),U,5)
+67 ;
+68 SET ^TMP($JOB,START,NODE,OPTION,0)=DATA(0)
+69 ; change first piece to starting date (START)
+70 SET $PIECE(^TMP($JOB,START,NODE,OPTION,0),U)=START
+71 ; second piece not applicable to national database
+72 SET $PIECE(^TMP($JOB,START,NODE,OPTION,0),U,2)=""
+73 ; EndingDate^SiteName^SiteNumber
+74 SET ^TMP($JOB,START,NODE,OPTION,99)=END_U_$PIECE(SITE,U,2)_U_$PIECE(SITE,U,3)
+75 ;
+76 ; add data to get weekly totals
+77 FOR I=1,1.1,1.2,2,2.1,2.2,3
IF DATA(I)]""
Begin DoDot:3
+78 ; if subscript 1 or 2 or 3 ('I#1) add pieces 1 - 8
+79 ; else add pieces 1 - 24
+80 FOR J=1:1:$SELECT('(I#1):8,1:24)
Begin DoDot:4
+81 SET $PIECE(^TMP($JOB,START,NODE,OPTION,I),U,J)=$PIECE($GET(^TMP($JOB,START,NODE,OPTION,I)),U,J)+$PIECE(DATA(I),U,J)
+82 ; update "HOURS" subscript
+83 if (I#1)&($PIECE(DATA(I),U,J))
SET $PIECE(^KMPTMP("KMPR","HOURS",DATE,NODE),U,J)=1
End DoDot:4
End DoDot:3
+84 ;
+85 ; back to IEN level
+86 ; add to processed array
+87 SET ^TMP("KMPR PROC",$JOB,IEN)=""
End DoDot:2
+88 ;
+89 ; back to DATE level
+90 ; if START then transmit data
+91 IF DATE=START
IF $DATA(^TMP($JOB))
DO TRANSMIT
KILL ^TMP($JOB)
End DoDot:1
+92 ;
+93 ; transmit data to national database
+94 if '$DATA(ZTQUEUED)
WRITE !,"Transmitting data to national database..."
+95 if $DATA(^TMP($JOB))
DO TRANSMIT
+96 KILL ^TMP($JOB)
+97 ;
+98 ; update field .02 (SENT TO CM NATIONAL DATABASE) to 'YES' for all
+99 ; processed entries
+100 if '$DATA(ZTQUEUED)
WRITE !,"Updating records to reflect transmission..."
+101 SET IEN=0
+102 FOR
SET IEN=$ORDER(^TMP("KMPR PROC",$JOB,IEN))
if 'IEN
QUIT
Begin DoDot:1
+103 KILL FDA,ERROR
+104 SET FDA($JOB,8971.1,IEN_",",.02)=1
+105 DO FILE^DIE("","FDA($J)","ERROR")
End DoDot:1
+106 KILL ^TMP("KMPR PROC",$JOB)
+107 ;
+108 ; leave two complete weeks of data in file #8971.1
+109 DO PURGE^KMPRUTL3(DELDATE,1)
+110 ;
+111 QUIT
+112 ;
TRANSMIT ;-- format ^TMP($J) data, put into e-mail and send to cm.
+1 ;
+2 if '$DATA(^TMP($JOB))
QUIT
+3 ;
+4 NEW HRSDAYS,I,IEN,LN,N,O,S,TL,XMSUB,X,XMTEXT,XMY,XMZ,Y,Z
+5 ;
+6 KILL ^TMP("KMPRBD04-3",$JOB)
+7 ;
+8 SET LN=1
+9 ; version and patch info and weekly background info
+10 SET Z=$GET(^KMPTMP("KMPR","BACKGROUND","WEEKLY","TOTAL","START"))_"^"_$GET(^("STOP"))_"^"_$GET(^("DELTA"))
+11 SET ^TMP("KMPRBD04-3",$JOB,LN)="VERSION="_$$VERSION^KMPRUTL_"^"_Z
+12 ;
+13 ; get system information
+14 SET LN=LN+1
+15 SET ^TMP("KMPRBD04-3",$JOB,LN)="SYSINFO="_$$SYSINFO^KMPDUTL1()
+16 ;
+17 ; get number of days/hours data for the specified date range
+18 DO HRSDAYS^KMPRUTL3(START,END,1,.HRSDAYS)
+19 ;
+20 ; if ^KMPTMP("KMPR","HOURS","START") exists then this is the first time
+21 ; the "HOURS" subscript is being accessed. chances are this is only
+22 ; partial data, so it should be ignored.
+23 IF $GET(^KMPTMP("KMPR","HOURS","START"))&($DATA(HRSDAYS))
Begin DoDot:1
+24 KILL HRSDAYS,^KMPTMP("KMPR","HOURS","START")
End DoDot:1
+25 ;
+26 IF $DATA(HRSDAYS)
SET S=0
Begin DoDot:1
+27 FOR
SET S=$ORDER(HRSDAYS(S))
if 'S
QUIT
SET N=""
Begin DoDot:2
+28 FOR
SET N=$ORDER(HRSDAYS(S,N))
if N=""
QUIT
Begin DoDot:3
+29 SET LN=LN+1
+30 ; StartDate^Node^EndDate^PTDays^PTHours^NPTDays^NPTHours
+31 ; ... ^WDDays^WDHours^NWDays^NWHours
+32 SET ^TMP("KMPRBD04-3",$JOB,LN)="HRSDAYS="_START_"^"_N_"^"_END_"^"_HRSDAYS(S,N)
End DoDot:3
End DoDot:2
End DoDot:1
+33 ;
+34 ; reformat so that data is in ^TMP("KMPR UPLOAD",$J,LN)= format.
+35 SET IEN=0
SET S=""
+36 FOR
SET S=$ORDER(^TMP($JOB,S))
if S=""
QUIT
SET N=""
Begin DoDot:1
+37 FOR
SET N=$ORDER(^TMP($JOB,S,N))
if N=""
QUIT
SET O=""
Begin DoDot:2
+38 FOR
SET O=$ORDER(^TMP($JOB,S,N,O))
if O=""
QUIT
SET I=""
SET IEN=IEN+1
Begin DoDot:3
+39 FOR
SET I=$ORDER(^TMP($JOB,S,N,O,I))
if I=""
QUIT
Begin DoDot:4
+40 SET LN=LN+1
+41 SET ^TMP("KMPRBD04-3",$JOB,LN)=IEN_","_I_")="_^TMP($JOB,S,N,O,I)
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+42 ;
+43 ; quit if no data to transmit.
+44 if '$DATA(^TMP("KMPRBD04-3",$JOB))
QUIT
+45 SET TL=$$TESTLAB^KMPDUT1
+46 ; send packman message.
+47 SET XMTEXT="^TMP(""KMPRBD04-3"","_$JOB_","
+48 SET XMSUB="RUM DATA~"_$PIECE(TL,U,2)_$PIECE(SITE,U,2)_" ("_$PIECE(SITE,U,3)_")~"_$$FMTE^XLFDT(START)_"~"_$PIECE($$VERSION^KMPRUTL,U)
+49 SET XMY("S.KMP2-RUM-SERVER@FO-ALBANY.DOMAIN.EXT")=""
+50 SET XMY("CAPACITY,MANAGEMENT@FO-ALBANY.DOMAIN.EXT")=""
+51 DO ^XMD
+52 if '$DATA(ZTQUEUED)
WRITE !,"Message #",$GET(XMZ)," sent..."
+53 KILL ^TMP("KMPRBD04-3",$JOB)
+54 ;
+55 QUIT