ORWGTASK ; SLC/STAFF - Graph Task ;3/17/08 10:48
;;3.0;ORDER ENTRY/RESULTS REPORTING;**243**;Dec 17, 1997;Build 242
;
SETLAST(PAT) ; from ORWGAPI - set whenever patient is graphed
N NOW,USER
S PAT=+$G(PAT)
S USER=+$G(DUZ)
S NOW=$$NOW^ORWGAPIX
I USER,PAT D
. S ^XTMP("ORGDATA","TP",PAT)=NOW
. S ^XTMP("ORGDATA","TP",PAT,"U",USER)=NOW
. S ^XTMP("ORGDATA","TU",USER)=NOW
. D COUNT("G",PAT,USER)
Q
;
INIT(OK) ; from ORMTIM02 - run by ORMTIME (OK=0)
N BACKTO,CNT,DFN,ITEM,LASTDFN,NOW,PURGE,TASKED,TIME
S OK=+$G(OK,0)
I $G(^XTMP("ORGRAPH","FORCE"))="ON" D ; set in ORY243 (post-init v27)
. S OK=1
. D CLEANALL
I 'OK D ; unless forced, run one time on Saturday
. I $P($G(^XTMP("ORGRAPH",0)),U,2)=DT Q
. I $E(DT,6)="0",$$DOW^XLFDT(DT)="Saturday",$L($G(^XTMP("ORGRAPH",0))) D Q ; cleanup on 1st Sat of the month
.. S OK=1
.. D CLEANALL
. I $$DOW^XLFDT(DT)="Saturday",$L($G(^XTMP("ORGRAPH",0))) S OK=1 Q
I 'OK Q
S BACKTO=$$FMADD^XLFDT(DT,-30) ;clear old data on non-graphed patients backto this date
S PURGE=$$FMADD^XLFDT(DT,180) ; when to purge XTMP nodes
S NOW=$$NOW^ORWGAPIX
S ^XTMP("ORGDATA",0)=PURGE_U_DT_U_"CPRS Graphing - Patient Data Cache Stats"_U_NOW
S ^XTMP("ORGRAPH",0)=PURGE_U_DT_U_"CPRS Graphing - Patient Data Cache"
S CNT=0
S LASTDFN=0
S DFN=""
F S DFN=$O(^XTMP("ORGDATA","TP",DFN)) Q:DFN="" D
. S TIME=$O(^XTMP("ORGDATA","TP",DFN))
. I '$L(TIME) Q
. I TIME<BACKTO D CLRDATA(DFN) Q
. S ^XTMP("ORGRAPH","QUEUE",NOW_"^0^"_DFN)=NOW ; put patients to update on queue
. S LASTDFN=DFN
. S CNT=CNT+1
. S OK=1
D UPDATE(.TASKED,LASTDFN,0,0) ; last patient starts the updates
S ^XTMP("ORGRAPH","INIT")=NOW_U_$$NOW^ORWGAPIX_U_CNT
S ^XTMP("ORGDATA",0)=^XTMP("ORGDATA",0)_U_$$NOW^ORWGAPIX_U_CNT
Q
;
CLEANALL ;
K ^XTMP("ORGDATA")
K ^XTMP("ORGRAPH")
Q
;
CLRDATA(DFN) ;
N PATUSER,USER
S USER=.9
F S USER=$O(^XTMP("ORGDATA","TP",DFN,"U",USER)) Q:USER<1 D
. S PATUSER=DFN_U_USER
. K ^XTMP("ORGRAPH","ALL DATA",PATUSER)
. K ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
. K ^XTMP("ORGRAPH","ALL LABS",PATUSER)
. K ^XTMP("ORGRAPH","OLD DATA",DFN)
. K ^XTMP("ORGRAPH","OLD LABS",DFN)
K ^XTMP("ORGDATA","TP",DFN)
Q
;
UPDATE(TASKED,DFN,USER,OLDDFN) ; from ORWGAPI
; whenever patient is selected
; to update, cache must exist and user/patient combo has used graphs
;D CLEANALL Q ; ******** temporary disabled BA 1/16/08 *********
N NOW,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE K ZTSAVE
;S ^XTMP("ZZZBOB")=$G(TASKED)_U_$G(DFN)_U_$G(USER)_U_$G(OLDDFN)
S TASKED=-1 ; cache turned off
I '$L($G(^XTMP("ORGRAPH",0))) Q
S TASKED=0 ; not building cache
I USER,DFN D COUNT("P",DFN,USER)
I USER,'$G(^XTMP("ORGDATA","TU",USER)) Q ; user must use graphing to cache
I USER,OLDDFN D CLEARPT(OLDDFN,USER)
I 'DFN Q
I '$G(^XTMP("ORGDATA","TP",DFN)) Q ; patient must be used with graphing to cache
I USER,'$G(^XTMP("ORGDATA","TP",DFN,"U",USER)) Q ; pat/user combo to cache **** comment this out for better graph speed - but more cache
S TASKED=1 ; building cache
S NOW=$$NOW^ORWGAPIX
I USER D CLEARPT(DFN,USER)
S ZTIO="ORWG GRAPHING RESOURCE",ZTDTH=$H,ZTDESC="process graph data"
S ZTSAVE("ORMTIME")=$$MNOW
S ZTSAVE("ORPAT")=DFN
S ZTSAVE("ORTSTMP")=NOW
S ZTSAVE("ORUSER")=USER
S ZTRTN="UP^ORWGTASK"
D ^%ZTLOAD
Q
;
COUNT(EVENT,DFN,USER) ;
I EVENT="P" D Q
. S ^("C")=1+$G(^XTMP("ORGDATA","P",DFN,"C"))
. S ^(USER)=1+$G(^XTMP("ORGDATA","P",DFN,"C-U",USER))
. S ^("C")=1+$G(^XTMP("ORGDATA","U",USER,"C"))
. S ^(DFN)=1+$G(^XTMP("ORGDATA","U",USER,"C-P",DFN))
I EVENT="G" D Q
. S ^("CG")=1+$G(^XTMP("ORGDATA","P",DFN,"CG"))
. S ^(USER)=1+$G(^XTMP("ORGDATA","P",DFN,"CG-U",USER))
. S ^("CG")=1+$G(^XTMP("ORGDATA","U",USER,"CG"))
. S ^(DFN)=1+$G(^XTMP("ORGDATA","U",USER,"CG-P",DFN))
Q
;
CLEARPT(DFN,USER) ;
N PATUSER
S PATUSER=DFN_U_USER
K ^XTMP("ORGRAPH","ALL DATA",PATUSER)
K ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
K ^XTMP("ORGRAPH","ALL LABS",PATUSER)
Q
;
UP ; dequeued from ORWGTASK
; ORUSER, ORPAT, ORTSTMP were saved
N GNOW,GSTAMP,NOW,STAMP
S STAMP=ORTSTMP_U_ORUSER_U_ORPAT
S GSTAMP=ORMTIME_U_ORUSER_U_ORPAT
S NOW=$$NOW^ORWGAPIX
S GNOW=$$MNOW
I $D(ZTQUEUED) S ZTREQ="@"
S ^XTMP("ORGRAPH","QUEUE",STAMP)=NOW_U_ORMTIME
S ^XTMP("ORGDATA","Q",GSTAMP)=GSTAMP
S ^XTMP("ORGDATA","QT",ORUSER_U_ORPAT)=ORMTIME
D GSTAMP(GSTAMP,ORMTIME,GNOW,4)
I 'ORUSER S $P(^XTMP("ORGRAPH","INIT"),U,4)=NOW
I $G(^XTMP("ORGRAPH","STATUS"))'="ACTIVE" D START
S ^XTMP("ORGRAPH","STATUS")="INACTIVE"
Q
;
START ;
S ^XTMP("ORGRAPH","STATUS")="ACTIVE"
N COUNT,MAX,NEXT,STOP,TIMES
S MAX=5
S COUNT=0
S STOP=0
S NEXT=""
F S NEXT=$O(^XTMP("ORGRAPH","QUEUE",NEXT)) D Q:STOP
. I NEXT="" D Q
.. H 1
.. S COUNT=COUNT+1
.. I COUNT>MAX S STOP=1 Q
. S TIMES=^XTMP("ORGRAPH","QUEUE",NEXT)
. K ^XTMP("ORGRAPH","QUEUE",NEXT)
. D PROCESS(NEXT,TIMES)
. K ^XTMP("ORGRAPH","QUEUE",NEXT)
Q
;
PROCESS(NEXT,TIMES) ;
N DFN,GSTAMP,IN,OUT,TSTMP,USER
S TSTMP=+$P(NEXT,U)
S USER=+$P(NEXT,U,2)
S DFN=$P(NEXT,U,3)
S GSTAMP=$P(TIMES,U,2)_U_USER_U_DFN
D ALL(GSTAMP,DFN,USER)
I 'USER S $P(^XTMP("ORGRAPH","INIT"),U,5)=$$NOW^ORWGAPIX
Q
;
ALL(GSTAMP,DFN,USER) ;
N BACKTO,CNT,LASTDATE,NUM,PATUSER,PREV,START,TIMED,TIMEI,TIMEL,TIMEZ,TYPE
K ^TMP("ORGAI",$J),^TMP("ORGI",$J),^TMP("ORGT",$J)
S START=$$NOW^ORWGAPIX
S DFN=+$G(DFN) I 'DFN Q
S USER=+$G(USER)
S PATUSER=DFN_U_USER
S TIMEI=START
D GSTAMP(GSTAMP,+GSTAMP,$$MNOW,5)
S GTIME=$$MNOW
D TYPES^ORWGAPI("ORGT",DFN)
I '$L($O(^TMP("ORGT",$J,""))) Q
S NUM=""
F S NUM=$O(^TMP("ORGT",$J,NUM)) Q:NUM="" D
. S TYPE=$P(^TMP("ORGT",$J,NUM),U)
. K ^TMP("ORGI",$J)
. S CNT=0
. D ITEMS^ORWGAPIR("ORGI",DFN,TYPE,3,,,.CNT,2)
. M ^TMP("ORGAI",$J)=^TMP("ORGI",$J)
K ^TMP("ORGI",$J)
S PREV=1
I '$D(^XTMP("ORGRAPH","OLD DATA",DFN)) S PREV=0
I '$D(^XTMP("ORGRAPH","OLD LABS",DFN)) S PREV=0
I USER D ; user is 0 when doing init
. L +^XTMP("ORGRAPH","ALL ITEMS",PATUSER):1 I '$T Q
. M ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)=^TMP("ORGAI",$J)
. L -^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
S LASTDATE=+$G(^XTMP("ORGRAPH","LAST BUILD",DFN))
I 'LASTDATE S LASTDATE=DT
S BACKTO=$$FMADD^XLFDT(LASTDATE,-30) ; *** backto value is 30 days ********************
S TIMED=$$NOW^ORWGAPIX
D GETDATA("DATA",GSTAMP,GTIME,PATUSER,START,BACKTO)
S TIMEL=$$NOW^ORWGAPIX
D GETDATA("LABS",GSTAMP,GTIME,PATUSER,START,BACKTO)
S TIMEZ=$$NOW^ORWGAPIX
S ^XTMP("ORGRAPH","LAST BUILD",DFN)=DT
K ^TMP("ORGAI",$J),^TMP("ORGI",$J),^TMP("ORGT",$J)
Q
;
GETDATA(TYPES,GSTAMP,GTIME,PATUSER,START,BACKTO) ;
N ALLSUBS,CNT,DATA,DFN,NUM,NUM1,OLDSUBS,SUB,TYPEITEM,USER
K ^TMP("ORGD",$J),^TMP("ORGID",$J),^TMP("ORGNI",$J)
S OLDSUBS="OLD "_TYPES
S ALLSUBS="ALL "_TYPES
S DFN=+PATUSER
S USER=+$P(PATUSER,U,2)
S SIZE=0
I $D(^XTMP("ORGRAPH",OLDSUBS,DFN)) D
. S SUB=""
. F S SUB=$O(^TMP("ORGAI",$J,SUB)) Q:SUB="" D
.. S TYPEITEM=$G(^TMP("ORGAI",$J,SUB))
.. I TYPES="DATA",$P(TYPEITEM,U)=63 Q
.. I TYPES="LABS",$P(TYPEITEM,U)'=63 Q
.. I $P(TYPEITEM,U,6)>BACKTO S ^TMP("ORGNI",$J,SUB)=TYPEITEM
. S CNT=0
. S NUM=""
. F S NUM=$O(^TMP("ORGNI",$J,NUM)) Q:NUM="" D
.. S TYPEITEM=^TMP("ORGNI",$J,NUM)
.. D SIZE(TYPEITEM,START,DFN,BACKTO,.SIZE)
. D GSTAMP(GSTAMP,GTIME,$$MNOW,6)
. S $P(^XTMP("ORGDATA","Q",GSTAMP),U,16)=SIZE+$P(^XTMP("ORGDATA","Q",GSTAMP),U,16)
E D
. S NUM=""
. F S NUM=$O(^TMP("ORGAI",$J,NUM)) Q:NUM="" D
.. S TYPEITEM=^TMP("ORGAI",$J,NUM)
.. I TYPES="DATA",$P(TYPEITEM,U)=63 Q
.. I TYPES="LABS",$P(TYPEITEM,U)'=63 Q
.. D SIZE(TYPEITEM,START,DFN,2700101,.SIZE)
. D GSTAMP(GSTAMP,GTIME,$$MNOW,7)
. S $P(^XTMP("ORGDATA","Q",GSTAMP),U,17)=SIZE+$P(^XTMP("ORGDATA","Q",GSTAMP),U,17)
S GTIME=$$MNOW
M ^XTMP("ORGRAPH",OLDSUBS,DFN)=^TMP("ORGD",$J)
I USER D ; user is 0 when doing init
. L +^XTMP("ORGRAPH",ALLSUBS,PATUSER):1 I '$T Q
. M ^XTMP("ORGRAPH",ALLSUBS,PATUSER)=^XTMP("ORGRAPH",OLDSUBS,DFN)
. L -^XTMP("ORGRAPH",ALLSUBS,PATUSER)
K ^TMP("ORGD",$J),^TMP("ORGID",$J),^TMP("ORGNI",$J)
D GSTAMP(GSTAMP,GTIME,$$MNOW,8)
Q
;
SIZE(TYPEITEM,START,DFN,BACKTO,SIZE) ;
N DATA,NUM
K ^TMP("ORGID",$J)
D ITEMDATA^ORWGAPI("ORGID",TYPEITEM,START,DFN,BACKTO)
S NUM=""
F S NUM=$O(^TMP("ORGID",$J,NUM)) Q:NUM="" D
. S DATA=^TMP("ORGID",$J,NUM)
. S ^TMP("ORGD",$J,$P(DATA,U,1,3))=DATA
. S SIZE=$L(DATA)+SIZE
Q
;
RESOURCE ; from ORWGAPIU on post init, setup graphing resource device
N X
S X=$$RES^XUDHSET("ORWG GRAPHING RESOURCE",,3,"CPRS GUI graphing data retrieval")
Q
;
GSTAMP(GSTAMP,TIME1,TIME2,PIECE) ;
S $P(^XTMP("ORGDATA","Q",GSTAMP),"^",PIECE)=TIME2-TIME1
Q
;
MNOW() ;
Q $$ZZ^ORWGAPIX
;
CLEAN ;
K ^XTMP("ORGRAPH")
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HORWGTASK 8811 printed Oct 16, 2024@18:37:06 Page 2
ORWGTASK ; SLC/STAFF - Graph Task ;3/17/08 10:48
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**243**;Dec 17, 1997;Build 242
+2 ;
SETLAST(PAT) ; from ORWGAPI - set whenever patient is graphed
+1 NEW NOW,USER
+2 SET PAT=+$GET(PAT)
+3 SET USER=+$GET(DUZ)
+4 SET NOW=$$NOW^ORWGAPIX
+5 IF USER
IF PAT
Begin DoDot:1
+6 SET ^XTMP("ORGDATA","TP",PAT)=NOW
+7 SET ^XTMP("ORGDATA","TP",PAT,"U",USER)=NOW
+8 SET ^XTMP("ORGDATA","TU",USER)=NOW
+9 DO COUNT("G",PAT,USER)
End DoDot:1
+10 QUIT
+11 ;
INIT(OK) ; from ORMTIM02 - run by ORMTIME (OK=0)
+1 NEW BACKTO,CNT,DFN,ITEM,LASTDFN,NOW,PURGE,TASKED,TIME
+2 SET OK=+$GET(OK,0)
+3 ; set in ORY243 (post-init v27)
IF $GET(^XTMP("ORGRAPH","FORCE"))="ON"
Begin DoDot:1
+4 SET OK=1
+5 DO CLEANALL
End DoDot:1
+6 ; unless forced, run one time on Saturday
IF 'OK
Begin DoDot:1
+7 IF $PIECE($GET(^XTMP("ORGRAPH",0)),U,2)=DT
QUIT
+8 ; cleanup on 1st Sat of the month
IF $EXTRACT(DT,6)="0"
IF $$DOW^XLFDT(DT)="Saturday"
IF $LENGTH($GET(^XTMP("ORGRAPH",0)))
Begin DoDot:2
+9 SET OK=1
+10 DO CLEANALL
End DoDot:2
QUIT
+11 IF $$DOW^XLFDT(DT)="Saturday"
IF $LENGTH($GET(^XTMP("ORGRAPH",0)))
SET OK=1
QUIT
End DoDot:1
+12 IF 'OK
QUIT
+13 ;clear old data on non-graphed patients backto this date
SET BACKTO=$$FMADD^XLFDT(DT,-30)
+14 ; when to purge XTMP nodes
SET PURGE=$$FMADD^XLFDT(DT,180)
+15 SET NOW=$$NOW^ORWGAPIX
+16 SET ^XTMP("ORGDATA",0)=PURGE_U_DT_U_"CPRS Graphing - Patient Data Cache Stats"_U_NOW
+17 SET ^XTMP("ORGRAPH",0)=PURGE_U_DT_U_"CPRS Graphing - Patient Data Cache"
+18 SET CNT=0
+19 SET LASTDFN=0
+20 SET DFN=""
+21 FOR
SET DFN=$ORDER(^XTMP("ORGDATA","TP",DFN))
if DFN=""
QUIT
Begin DoDot:1
+22 SET TIME=$ORDER(^XTMP("ORGDATA","TP",DFN))
+23 IF '$LENGTH(TIME)
QUIT
+24 IF TIME<BACKTO
DO CLRDATA(DFN)
QUIT
+25 ; put patients to update on queue
SET ^XTMP("ORGRAPH","QUEUE",NOW_"^0^"_DFN)=NOW
+26 SET LASTDFN=DFN
+27 SET CNT=CNT+1
+28 SET OK=1
End DoDot:1
+29 ; last patient starts the updates
DO UPDATE(.TASKED,LASTDFN,0,0)
+30 SET ^XTMP("ORGRAPH","INIT")=NOW_U_$$NOW^ORWGAPIX_U_CNT
+31 SET ^XTMP("ORGDATA",0)=^XTMP("ORGDATA",0)_U_$$NOW^ORWGAPIX_U_CNT
+32 QUIT
+33 ;
CLEANALL ;
+1 KILL ^XTMP("ORGDATA")
+2 KILL ^XTMP("ORGRAPH")
+3 QUIT
+4 ;
CLRDATA(DFN) ;
+1 NEW PATUSER,USER
+2 SET USER=.9
+3 FOR
SET USER=$ORDER(^XTMP("ORGDATA","TP",DFN,"U",USER))
if USER<1
QUIT
Begin DoDot:1
+4 SET PATUSER=DFN_U_USER
+5 KILL ^XTMP("ORGRAPH","ALL DATA",PATUSER)
+6 KILL ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
+7 KILL ^XTMP("ORGRAPH","ALL LABS",PATUSER)
+8 KILL ^XTMP("ORGRAPH","OLD DATA",DFN)
+9 KILL ^XTMP("ORGRAPH","OLD LABS",DFN)
End DoDot:1
+10 KILL ^XTMP("ORGDATA","TP",DFN)
+11 QUIT
+12 ;
UPDATE(TASKED,DFN,USER,OLDDFN) ; from ORWGAPI
+1 ; whenever patient is selected
+2 ; to update, cache must exist and user/patient combo has used graphs
+3 ;D CLEANALL Q ; ******** temporary disabled BA 1/16/08 *********
+4 NEW NOW,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE
KILL ZTSAVE
+5 ;S ^XTMP("ZZZBOB")=$G(TASKED)_U_$G(DFN)_U_$G(USER)_U_$G(OLDDFN)
+6 ; cache turned off
SET TASKED=-1
+7 IF '$LENGTH($GET(^XTMP("ORGRAPH",0)))
QUIT
+8 ; not building cache
SET TASKED=0
+9 IF USER
IF DFN
DO COUNT("P",DFN,USER)
+10 ; user must use graphing to cache
IF USER
IF '$GET(^XTMP("ORGDATA","TU",USER))
QUIT
+11 IF USER
IF OLDDFN
DO CLEARPT(OLDDFN,USER)
+12 IF 'DFN
QUIT
+13 ; patient must be used with graphing to cache
IF '$GET(^XTMP("ORGDATA","TP",DFN))
QUIT
+14 ; pat/user combo to cache **** comment this out for better graph speed - but more cache
IF USER
IF '$GET(^XTMP("ORGDATA","TP",DFN,"U",USER))
QUIT
+15 ; building cache
SET TASKED=1
+16 SET NOW=$$NOW^ORWGAPIX
+17 IF USER
DO CLEARPT(DFN,USER)
+18 SET ZTIO="ORWG GRAPHING RESOURCE"
SET ZTDTH=$HOROLOG
SET ZTDESC="process graph data"
+19 SET ZTSAVE("ORMTIME")=$$MNOW
+20 SET ZTSAVE("ORPAT")=DFN
+21 SET ZTSAVE("ORTSTMP")=NOW
+22 SET ZTSAVE("ORUSER")=USER
+23 SET ZTRTN="UP^ORWGTASK"
+24 DO ^%ZTLOAD
+25 QUIT
+26 ;
COUNT(EVENT,DFN,USER) ;
+1 IF EVENT="P"
Begin DoDot:1
+2 SET ^("C")=1+$GET(^XTMP("ORGDATA","P",DFN,"C"))
+3 SET ^(USER)=1+$GET(^XTMP("ORGDATA","P",DFN,"C-U",USER))
+4 SET ^("C")=1+$GET(^XTMP("ORGDATA","U",USER,"C"))
+5 SET ^(DFN)=1+$GET(^XTMP("ORGDATA","U",USER,"C-P",DFN))
End DoDot:1
QUIT
+6 IF EVENT="G"
Begin DoDot:1
+7 SET ^("CG")=1+$GET(^XTMP("ORGDATA","P",DFN,"CG"))
+8 SET ^(USER)=1+$GET(^XTMP("ORGDATA","P",DFN,"CG-U",USER))
+9 SET ^("CG")=1+$GET(^XTMP("ORGDATA","U",USER,"CG"))
+10 SET ^(DFN)=1+$GET(^XTMP("ORGDATA","U",USER,"CG-P",DFN))
End DoDot:1
QUIT
+11 QUIT
+12 ;
CLEARPT(DFN,USER) ;
+1 NEW PATUSER
+2 SET PATUSER=DFN_U_USER
+3 KILL ^XTMP("ORGRAPH","ALL DATA",PATUSER)
+4 KILL ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
+5 KILL ^XTMP("ORGRAPH","ALL LABS",PATUSER)
+6 QUIT
+7 ;
UP ; dequeued from ORWGTASK
+1 ; ORUSER, ORPAT, ORTSTMP were saved
+2 NEW GNOW,GSTAMP,NOW,STAMP
+3 SET STAMP=ORTSTMP_U_ORUSER_U_ORPAT
+4 SET GSTAMP=ORMTIME_U_ORUSER_U_ORPAT
+5 SET NOW=$$NOW^ORWGAPIX
+6 SET GNOW=$$MNOW
+7 IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+8 SET ^XTMP("ORGRAPH","QUEUE",STAMP)=NOW_U_ORMTIME
+9 SET ^XTMP("ORGDATA","Q",GSTAMP)=GSTAMP
+10 SET ^XTMP("ORGDATA","QT",ORUSER_U_ORPAT)=ORMTIME
+11 DO GSTAMP(GSTAMP,ORMTIME,GNOW,4)
+12 IF 'ORUSER
SET $PIECE(^XTMP("ORGRAPH","INIT"),U,4)=NOW
+13 IF $GET(^XTMP("ORGRAPH","STATUS"))'="ACTIVE"
DO START
+14 SET ^XTMP("ORGRAPH","STATUS")="INACTIVE"
+15 QUIT
+16 ;
START ;
+1 SET ^XTMP("ORGRAPH","STATUS")="ACTIVE"
+2 NEW COUNT,MAX,NEXT,STOP,TIMES
+3 SET MAX=5
+4 SET COUNT=0
+5 SET STOP=0
+6 SET NEXT=""
+7 FOR
SET NEXT=$ORDER(^XTMP("ORGRAPH","QUEUE",NEXT))
Begin DoDot:1
+8 IF NEXT=""
Begin DoDot:2
+9 HANG 1
+10 SET COUNT=COUNT+1
+11 IF COUNT>MAX
SET STOP=1
QUIT
End DoDot:2
QUIT
+12 SET TIMES=^XTMP("ORGRAPH","QUEUE",NEXT)
+13 KILL ^XTMP("ORGRAPH","QUEUE",NEXT)
+14 DO PROCESS(NEXT,TIMES)
+15 KILL ^XTMP("ORGRAPH","QUEUE",NEXT)
End DoDot:1
if STOP
QUIT
+16 QUIT
+17 ;
PROCESS(NEXT,TIMES) ;
+1 NEW DFN,GSTAMP,IN,OUT,TSTMP,USER
+2 SET TSTMP=+$PIECE(NEXT,U)
+3 SET USER=+$PIECE(NEXT,U,2)
+4 SET DFN=$PIECE(NEXT,U,3)
+5 SET GSTAMP=$PIECE(TIMES,U,2)_U_USER_U_DFN
+6 DO ALL(GSTAMP,DFN,USER)
+7 IF 'USER
SET $PIECE(^XTMP("ORGRAPH","INIT"),U,5)=$$NOW^ORWGAPIX
+8 QUIT
+9 ;
ALL(GSTAMP,DFN,USER) ;
+1 NEW BACKTO,CNT,LASTDATE,NUM,PATUSER,PREV,START,TIMED,TIMEI,TIMEL,TIMEZ,TYPE
+2 KILL ^TMP("ORGAI",$JOB),^TMP("ORGI",$JOB),^TMP("ORGT",$JOB)
+3 SET START=$$NOW^ORWGAPIX
+4 SET DFN=+$GET(DFN)
IF 'DFN
QUIT
+5 SET USER=+$GET(USER)
+6 SET PATUSER=DFN_U_USER
+7 SET TIMEI=START
+8 DO GSTAMP(GSTAMP,+GSTAMP,$$MNOW,5)
+9 SET GTIME=$$MNOW
+10 DO TYPES^ORWGAPI("ORGT",DFN)
+11 IF '$LENGTH($ORDER(^TMP("ORGT",$JOB,"")))
QUIT
+12 SET NUM=""
+13 FOR
SET NUM=$ORDER(^TMP("ORGT",$JOB,NUM))
if NUM=""
QUIT
Begin DoDot:1
+14 SET TYPE=$PIECE(^TMP("ORGT",$JOB,NUM),U)
+15 KILL ^TMP("ORGI",$JOB)
+16 SET CNT=0
+17 DO ITEMS^ORWGAPIR("ORGI",DFN,TYPE,3,,,.CNT,2)
+18 MERGE ^TMP("ORGAI",$JOB)=^TMP("ORGI",$JOB)
End DoDot:1
+19 KILL ^TMP("ORGI",$JOB)
+20 SET PREV=1
+21 IF '$DATA(^XTMP("ORGRAPH","OLD DATA",DFN))
SET PREV=0
+22 IF '$DATA(^XTMP("ORGRAPH","OLD LABS",DFN))
SET PREV=0
+23 ; user is 0 when doing init
IF USER
Begin DoDot:1
+24 LOCK +^XTMP("ORGRAPH","ALL ITEMS",PATUSER):1
IF '$TEST
QUIT
+25 MERGE ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)=^TMP("ORGAI",$JOB)
+26 LOCK -^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
End DoDot:1
+27 SET LASTDATE=+$GET(^XTMP("ORGRAPH","LAST BUILD",DFN))
+28 IF 'LASTDATE
SET LASTDATE=DT
+29 ; *** backto value is 30 days ********************
SET BACKTO=$$FMADD^XLFDT(LASTDATE,-30)
+30 SET TIMED=$$NOW^ORWGAPIX
+31 DO GETDATA("DATA",GSTAMP,GTIME,PATUSER,START,BACKTO)
+32 SET TIMEL=$$NOW^ORWGAPIX
+33 DO GETDATA("LABS",GSTAMP,GTIME,PATUSER,START,BACKTO)
+34 SET TIMEZ=$$NOW^ORWGAPIX
+35 SET ^XTMP("ORGRAPH","LAST BUILD",DFN)=DT
+36 KILL ^TMP("ORGAI",$JOB),^TMP("ORGI",$JOB),^TMP("ORGT",$JOB)
+37 QUIT
+38 ;
GETDATA(TYPES,GSTAMP,GTIME,PATUSER,START,BACKTO) ;
+1 NEW ALLSUBS,CNT,DATA,DFN,NUM,NUM1,OLDSUBS,SUB,TYPEITEM,USER
+2 KILL ^TMP("ORGD",$JOB),^TMP("ORGID",$JOB),^TMP("ORGNI",$JOB)
+3 SET OLDSUBS="OLD "_TYPES
+4 SET ALLSUBS="ALL "_TYPES
+5 SET DFN=+PATUSER
+6 SET USER=+$PIECE(PATUSER,U,2)
+7 SET SIZE=0
+8 IF $DATA(^XTMP("ORGRAPH",OLDSUBS,DFN))
Begin DoDot:1
+9 SET SUB=""
+10 FOR
SET SUB=$ORDER(^TMP("ORGAI",$JOB,SUB))
if SUB=""
QUIT
Begin DoDot:2
+11 SET TYPEITEM=$GET(^TMP("ORGAI",$JOB,SUB))
+12 IF TYPES="DATA"
IF $PIECE(TYPEITEM,U)=63
QUIT
+13 IF TYPES="LABS"
IF $PIECE(TYPEITEM,U)'=63
QUIT
+14 IF $PIECE(TYPEITEM,U,6)>BACKTO
SET ^TMP("ORGNI",$JOB,SUB)=TYPEITEM
End DoDot:2
+15 SET CNT=0
+16 SET NUM=""
+17 FOR
SET NUM=$ORDER(^TMP("ORGNI",$JOB,NUM))
if NUM=""
QUIT
Begin DoDot:2
+18 SET TYPEITEM=^TMP("ORGNI",$JOB,NUM)
+19 DO SIZE(TYPEITEM,START,DFN,BACKTO,.SIZE)
End DoDot:2
+20 DO GSTAMP(GSTAMP,GTIME,$$MNOW,6)
+21 SET $PIECE(^XTMP("ORGDATA","Q",GSTAMP),U,16)=SIZE+$PIECE(^XTMP("ORGDATA","Q",GSTAMP),U,16)
End DoDot:1
+22 IF '$TEST
Begin DoDot:1
+23 SET NUM=""
+24 FOR
SET NUM=$ORDER(^TMP("ORGAI",$JOB,NUM))
if NUM=""
QUIT
Begin DoDot:2
+25 SET TYPEITEM=^TMP("ORGAI",$JOB,NUM)
+26 IF TYPES="DATA"
IF $PIECE(TYPEITEM,U)=63
QUIT
+27 IF TYPES="LABS"
IF $PIECE(TYPEITEM,U)'=63
QUIT
+28 DO SIZE(TYPEITEM,START,DFN,2700101,.SIZE)
End DoDot:2
+29 DO GSTAMP(GSTAMP,GTIME,$$MNOW,7)
+30 SET $PIECE(^XTMP("ORGDATA","Q",GSTAMP),U,17)=SIZE+$PIECE(^XTMP("ORGDATA","Q",GSTAMP),U,17)
End DoDot:1
+31 SET GTIME=$$MNOW
+32 MERGE ^XTMP("ORGRAPH",OLDSUBS,DFN)=^TMP("ORGD",$JOB)
+33 ; user is 0 when doing init
IF USER
Begin DoDot:1
+34 LOCK +^XTMP("ORGRAPH",ALLSUBS,PATUSER):1
IF '$TEST
QUIT
+35 MERGE ^XTMP("ORGRAPH",ALLSUBS,PATUSER)=^XTMP("ORGRAPH",OLDSUBS,DFN)
+36 LOCK -^XTMP("ORGRAPH",ALLSUBS,PATUSER)
End DoDot:1
+37 KILL ^TMP("ORGD",$JOB),^TMP("ORGID",$JOB),^TMP("ORGNI",$JOB)
+38 DO GSTAMP(GSTAMP,GTIME,$$MNOW,8)
+39 QUIT
+40 ;
SIZE(TYPEITEM,START,DFN,BACKTO,SIZE) ;
+1 NEW DATA,NUM
+2 KILL ^TMP("ORGID",$JOB)
+3 DO ITEMDATA^ORWGAPI("ORGID",TYPEITEM,START,DFN,BACKTO)
+4 SET NUM=""
+5 FOR
SET NUM=$ORDER(^TMP("ORGID",$JOB,NUM))
if NUM=""
QUIT
Begin DoDot:1
+6 SET DATA=^TMP("ORGID",$JOB,NUM)
+7 SET ^TMP("ORGD",$JOB,$PIECE(DATA,U,1,3))=DATA
+8 SET SIZE=$LENGTH(DATA)+SIZE
End DoDot:1
+9 QUIT
+10 ;
RESOURCE ; from ORWGAPIU on post init, setup graphing resource device
+1 NEW X
+2 SET X=$$RES^XUDHSET("ORWG GRAPHING RESOURCE",,3,"CPRS GUI graphing data retrieval")
+3 QUIT
+4 ;
GSTAMP(GSTAMP,TIME1,TIME2,PIECE) ;
+1 SET $PIECE(^XTMP("ORGDATA","Q",GSTAMP),"^",PIECE)=TIME2-TIME1
+2 QUIT
+3 ;
MNOW() ;
+1 QUIT $$ZZ^ORWGAPIX
+2 ;
CLEAN ;
+1 KILL ^XTMP("ORGRAPH")
+2 QUIT
+3 ;