Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: KMPRBD04

KMPRBD04.m

Go to the documentation of this file.
  1. KMPRBD04 ;OAK/RAK - RUM Data Compression ;1/30/13 08:30
  1. ;;2.0;CAPACITY MANAGEMENT - RUM;**2**;May 28, 2003;Build 12
  1. ;
  1. ; Background Driver (cont.)
  1. ;
  1. WEEKLY(KMPRDT) ;-- compress daily stats to weekly
  1. ;-----------------------------------------------------------------------
  1. ; KMPRDT... Compression date in internal fileman formt. This date
  1. ; must be a Sunday. It represents the date from which the
  1. ; previous weeks data should be compressed.
  1. ; Example: if KMPRDT = 2981011 then compression will begin
  1. ; on 2981010 (KMPRDT-1)
  1. ;
  1. ; Every Sunday compress the daily stats in file #8971.1 into weekly
  1. ; and upload the data to the CM RUM National Database
  1. ;
  1. ; ^TMP($J)............. temporary storage for RUM data
  1. ; ^TMP("KMPR PROC",$J). entries that have been processed and will be
  1. ; updated as 'send to national dabase'
  1. ;-----------------------------------------------------------------------
  1. ;
  1. Q:'$G(KMPRDT)
  1. ;
  1. N DATA,DATE,DELDATE,END,HOURS,I,IEN,J,NODE,OPTION,SITE,START
  1. ;
  1. ; quit if not sunday
  1. Q:$$DOW^XLFDT(KMPRDT,1)
  1. ;
  1. K ^TMP($J),^TMP("KMPR PROC",$J)
  1. ;
  1. ; site info
  1. S SITE=$$SITE^VASITE Q:SITE=""
  1. ;
  1. S DATE=KMPRDT
  1. S (START,END)=""
  1. ;
  1. ; date to begin deletion
  1. S DELDATE=$$FMADD^XLFDT(KMPRDT,-14)
  1. ;
  1. W:'$D(ZTQUEUED) !,"Compressing data into weekly format..."
  1. ; reverse $order to get previous dates
  1. F S DATE=$O(^KMPR(8971.1,"B",DATE),-1) Q:'DATE D
  1. .; if DATE is saturday set START and END dates and kill ^TMP($J)
  1. .I $$DOW^XLFDT(DATE,1)=6 D
  1. ..S END=DATE,START=$$FMADD^XLFDT(DATE,-6)
  1. ..K ^TMP($J)
  1. .Q:'START
  1. .S IEN=0
  1. .F S IEN=$O(^KMPR(8971.1,"B",DATE,IEN)) Q:'IEN D
  1. ..;
  1. ..Q:'$D(^KMPR(8971.1,IEN,0))
  1. ..;
  1. ..; data nodes into DATA() array
  1. ..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))
  1. ..;
  1. ..; quit if data has already been sent to national database
  1. ..Q:$P(DATA(0),U,2)
  1. ..;
  1. ..; cpu node
  1. ..S NODE=$P(DATA(0),U,3) Q:NODE=""
  1. ..;
  1. ..; option
  1. ..S OPTION=$P(DATA(0),U,4)
  1. ..; rpc
  1. ..S:OPTION="" OPTION=$P(DATA(0),U,7)
  1. ..; hl7
  1. ..S:OPTION="" OPTION=$P(DATA(0),U,9)
  1. ..;
  1. ..Q:OPTION=""
  1. ..;
  1. ..; OPTION = OptionName^ProtocolName
  1. ..S $P(OPTION,U,2)=$P(DATA(0),U,5)
  1. ..;
  1. ..S ^TMP($J,START,NODE,OPTION,0)=DATA(0)
  1. ..; change first piece to starting date (START)
  1. ..S $P(^TMP($J,START,NODE,OPTION,0),U)=START
  1. ..; second piece not applicable to national database
  1. ..S $P(^TMP($J,START,NODE,OPTION,0),U,2)=""
  1. ..; EndingDate^SiteName^SiteNumber
  1. ..S ^TMP($J,START,NODE,OPTION,99)=END_U_$P(SITE,U,2)_U_$P(SITE,U,3)
  1. ..;
  1. ..; add data to get weekly totals
  1. ..F I=1,1.1,1.2,2,2.1,2.2,3 I DATA(I)]"" D
  1. ...; if subscript 1 or 2 or 3 ('I#1) add pieces 1 - 8
  1. ...; else add pieces 1 - 24
  1. ...F J=1:1:$S('(I#1):8,1:24) D
  1. ....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)
  1. ....; update "HOURS" subscript
  1. ....S:(I#1)&($P(DATA(I),U,J)) $P(^KMPTMP("KMPR","HOURS",DATE,NODE),U,J)=1
  1. ..;
  1. ..; back to IEN level
  1. ..; add to processed array
  1. ..S ^TMP("KMPR PROC",$J,IEN)=""
  1. .;
  1. .; back to DATE level
  1. .; if START then transmit data
  1. .I DATE=START I $D(^TMP($J)) D TRANSMIT K ^TMP($J)
  1. ;
  1. ; transmit data to national database
  1. W:'$D(ZTQUEUED) !,"Transmitting data to national database..."
  1. D:$D(^TMP($J)) TRANSMIT
  1. K ^TMP($J)
  1. ;
  1. ; update field .02 (SENT TO CM NATIONAL DATABASE) to 'YES' for all
  1. ; processed entries
  1. W:'$D(ZTQUEUED) !,"Updating records to reflect transmission..."
  1. S IEN=0
  1. F S IEN=$O(^TMP("KMPR PROC",$J,IEN)) Q:'IEN D
  1. .K FDA,ERROR
  1. .S FDA($J,8971.1,IEN_",",.02)=1
  1. .D FILE^DIE("","FDA($J)","ERROR")
  1. K ^TMP("KMPR PROC",$J)
  1. ;
  1. ; leave two complete weeks of data in file #8971.1
  1. D PURGE^KMPRUTL3(DELDATE,1)
  1. ;
  1. Q
  1. ;
  1. TRANSMIT ;-- format ^TMP($J) data, put into e-mail and send to cm.
  1. ;
  1. Q:'$D(^TMP($J))
  1. ;
  1. N HRSDAYS,I,IEN,LN,N,O,S,TL,XMSUB,X,XMTEXT,XMY,XMZ,Y,Z
  1. ;
  1. K ^TMP("KMPRBD04-3",$J)
  1. ;
  1. S LN=1
  1. ; version and patch info and weekly background info
  1. S Z=$G(^KMPTMP("KMPR","BACKGROUND","WEEKLY","TOTAL","START"))_"^"_$G(^("STOP"))_"^"_$G(^("DELTA"))
  1. S ^TMP("KMPRBD04-3",$J,LN)="VERSION="_$$VERSION^KMPRUTL_"^"_Z
  1. ;
  1. ; get system information
  1. S LN=LN+1
  1. S ^TMP("KMPRBD04-3",$J,LN)="SYSINFO="_$$SYSINFO^KMPDUTL1()
  1. ;
  1. ; get number of days/hours data for the specified date range
  1. D HRSDAYS^KMPRUTL3(START,END,1,.HRSDAYS)
  1. ;
  1. ; if ^KMPTMP("KMPR","HOURS","START") exists then this is the first time
  1. ; the "HOURS" subscript is being accessed. chances are this is only
  1. ; partial data, so it should be ignored.
  1. I $G(^KMPTMP("KMPR","HOURS","START"))&($D(HRSDAYS)) D
  1. .K HRSDAYS,^KMPTMP("KMPR","HOURS","START")
  1. ;
  1. I $D(HRSDAYS) S S=0 D
  1. .F S S=$O(HRSDAYS(S)) Q:'S S N="" D
  1. ..F S N=$O(HRSDAYS(S,N)) Q:N="" D
  1. ...S LN=LN+1
  1. ...; StartDate^Node^EndDate^PTDays^PTHours^NPTDays^NPTHours
  1. ...; ... ^WDDays^WDHours^NWDays^NWHours
  1. ...S ^TMP("KMPRBD04-3",$J,LN)="HRSDAYS="_START_"^"_N_"^"_END_"^"_HRSDAYS(S,N)
  1. ;
  1. ; reformat so that data is in ^TMP("KMPR UPLOAD",$J,LN)= format.
  1. S IEN=0,S=""
  1. F S S=$O(^TMP($J,S)) Q:S="" S N="" D
  1. .F S N=$O(^TMP($J,S,N)) Q:N="" S O="" D
  1. ..F S O=$O(^TMP($J,S,N,O)) Q:O="" S I="",IEN=IEN+1 D
  1. ...F S I=$O(^TMP($J,S,N,O,I)) Q:I="" D
  1. ....S LN=LN+1
  1. ....S ^TMP("KMPRBD04-3",$J,LN)=IEN_","_I_")="_^TMP($J,S,N,O,I)
  1. ;
  1. ; quit if no data to transmit.
  1. Q:'$D(^TMP("KMPRBD04-3",$J))
  1. S TL=$$TESTLAB^KMPDUT1
  1. ; send packman message.
  1. S XMTEXT="^TMP(""KMPRBD04-3"","_$J_","
  1. S XMSUB="RUM DATA~"_$P(TL,U,2)_$P(SITE,U,2)_" ("_$P(SITE,U,3)_")~"_$$FMTE^XLFDT(START)_"~"_$P($$VERSION^KMPRUTL,U)
  1. S XMY("S.KMP2-RUM-SERVER@FO-ALBANY.DOMAIN.EXT")=""
  1. S XMY("CAPACITY,MANAGEMENT@FO-ALBANY.DOMAIN.EXT")=""
  1. D ^XMD
  1. W:'$D(ZTQUEUED) !,"Message #",$G(XMZ)," sent..."
  1. K ^TMP("KMPRBD04-3",$J)
  1. ;
  1. Q