LROC ;VA/DALOI/CJS - ORDER LIST CLEAN-UP ; 13-Oct-2017 14:04 ; MKK
;;5.2;LAB SERVICE;**1003,1013,121,1018,295,1030,329,1031,1041**;NOV 1, 1997;Build 23
;
;;VA LR Patch(s): 121,295,329
;
; Modified slc/jer to include set/kill for "D" cross-reference
;
EP ; EP
N DA,DIR,DIROUT,DTOUT,DUOUT,LRAA,LRSAVE,LRX,MSG,X,Y
D ^LROCM
;
S DIR(0)="Y"
S DIR("A")="Do you wish to Purge old Orders and Accessions",DIR("B")="NO"
D ^DIR
I Y'=1 Q
;
D STORPURG^BLRPURGU ; IHS/MSC/MKK - LR*5.2*1041
;
S LRX=+$P($G(^LAB(69.9,1,0)),U,9) S:'LRX LRX=7
S LRSAVE=$$FMADD^XLFDT(DT,"-"_LRX)
;
L1 ; Purge the daily accession areas that meet cutoff
S LRAA=0
F S LRAA=$O(^LRO(68,LRAA)) Q:LRAA<1 D
. I $P(^LRO(68,LRAA,0),U,3)'="D" W !,"Use File Manager to clear ",$P(^(0),U)
;
N ZTSK,ZTRTN,ZTDESC,ZTIO,ZTSAVE
S ZTRTN="DQ^LROC",ZTDESC="Purge old orders and accessions"
S ZTIO="",ZTSAVE("LR*")=""
D ^%ZTLOAD
S MSG=$S($G(ZTSK):"Task #"_ZTSK_" tasked to run",1:"Tasking failed")
D EN^DDIOL(MSG,"","!?2")
Q
;
;
DQ ; Tasked entry point to clean up file #69
N DA,I,J,K,LRDA
;
; Purge the daily accession areas that meet cutoff
S LRAA=0
F S LRAA=$O(^LRO(68,LRAA)) Q:LRAA<1 D Q:$G(ZTSTOP)
. I $P(^LRO(68,LRAA,0),U,3)'="D" Q
. I $$S^%ZTLOAD("Processing accession area: "_LRAA) S ZTSTOP=1 Q
. S DA=0
. F S DA=$O(^LRO(68,LRAA,1,DA)) Q:DA<1!(LRSAVE<DA) K ^LRO(68,LRAA,1,DA)
;
I $G(ZTSTOP) Q
;
S I=0
F S I=$O(^LRO(69,"C",I)) Q:I<1 D Q:$G(ZTSTOP)
. I $$S^%ZTLOAD("Processing 'C' X-REF in file #69") S ZTSTOP=1 Q
. S J=0
. F S J=$O(^LRO(69,"C",I,J)) Q:J>LRSAVE!(J<1) K ^(J)
I $G(ZTSTOP) Q
;
S I=0
F S I=$O(^LRO(69,"D",I)) Q:I<1 D Q:$G(ZTSTOP)
. I $$S^%ZTLOAD("Processing 'D' X-REF in file #69") S ZTSTOP=1 Q
. S J=0
. F S J=$O(^LRO(69,"D",I,J)) Q:J>LRSAVE!(J<1) K ^(J)
I $G(ZTSTOP) Q
;
S LRDA=1
F S LRDA=$O(^LRO(69,LRDA)) D Q:(LRSAVE<LRDA)!(LRDA<1) Q:$G(ZTSTOP)
. I LRDA["0000" Q
. I $$S^%ZTLOAD("Processing orders in file #69 for "_$$FMTE^XLFDT(LRDA)) S ZTSTOP=1 Q
. S ^LRO(69,0)=$P(^LRO(69,0),U,1,2)_U_LRDA_U_($P(^(0),U,4)-1)
. N LRSN
. S LRSN=0
. F S LRSN=$O(^LRO(69,LRDA,1,LRSN)) Q:LRSN<1 D NEW^LR7OB1(LRDA,LRSN,"Z@") ; Call OE/RR
. K ^LRO(69,LRDA),^LRO(69,"B",LRDA,LRDA)
;
I LRDA<1 S ^LRO(69,0)=$P(^(0),U,1,2)
I $G(ZTSTOP) Q
;
D CHKUID
I $G(ZTSTOP) Q
D ^LROC1
K LRSAVE
;
Q
;
;
CENDEL ;
W !,"STARTING CENTRAL ENTRY #: " R LRSTA:DTIME S LRSTA=LRSTA-1
S U="^" W !,"ENDING CENTRAL ENTRY #: " R LRFIN:DTIME
W !,"ARE YOU SURE? N//" D % Q:%'["Y"
S ZTRTN="REENTRY^LROC",ZTIO="",ZTSAVE("L*")=""
D ^%ZTLOAD
K IO("Q"),ZTSK,ZTRTN,ZTIO,ZTSAVE
K %H,%ZA,%ZB,%ZC,DA,I,J,LRAA,LRAN,LRDFN,LRDTM,LRDTN,LRFIN,LRIDT,LRIOZERO,LRLOST,LROCN,LROID,LRORD,LROSN,LRSAVE,LRSN,LRSS,LRSTA,POP,Z
Q
;
;
REENTRY ;
S LRORD=LRSTA
F S LRORD=$O(^LRO(69,"C",LRORD)) Q:LRORD<1!(LRORD>LRFIN) D FDAT
Q
;
;
FDAT ;
S LRDTN=0
F S LRDTN=$O(^LRO(69,"C",LRORD,LRDTN)) Q:LRDTN<1 D ZAP
Q
;
;
ZAP ;
S LRSN=0
F S LRSN=$O(^LRO(69,"C",+LRORD,LRDTN,LRSN)) Q:LRSN<1 D
. D NEW^LR7OB1(LRDTN,LRSN,"Z@") ;Call OE/RR
. K ^LRO(69,"C",+LRORD,LRDTN,LRSN) Q:'$D(^LRO(69,LRDTN,1,LRSN,0)) S LRDFN=+^(0)
. K ^LRO(69,LRDTN,1,LRSN),^LRO(69,LRDTN,1,"AA",LRDFN,LRSN),^LRO(69,"D",LRDFN,LRDTN,LRSN)
S LRAA=0
F S LRAA=$O(^LRO(68,LRAA)) Q:LRAA<1 D:$P(^(LRAA,0),U,10)="Y" LRORD
Q
;
;
LRORD ;
S LRAN=$O(^LRO(68,LRAA,1,LRDTN,1,"D",LRORD,0)) Q:LRAN<1
Q:'$D(^LRO(68,LRAA,1,LRDTN,1,LRAN,0))
S LRSS=$P(^LRO(68,LRAA,0),"^",2)
S LRDFN=+^LRO(68,LRAA,1,LRDTN,1,LRAN,0) G:'$D(^(3)) SKPLR S LRDTM=+^LRO(68,LRAA,1,LRDTN,1,LRAN,3) G:'LRDTM SKPLR S LRIDT=9999999-LRDTM
I $D(^LR(LRDFN,LRSS,LRIDT,0)),$P(^(0),U,3) Q
K ^LR(LRDFN,LRSS,LRIDT)
I LRSS="CH" D CHKILL^LRPX(LRDFN,LRIDT)
;
SKPLR S X=^LRO(68,LRAA,1,LRDTN,1,LRAN,0),LROSN=$P(X,U,5),LROID=$P(X,U,6),LROCN=$S($D(^(.1)):$P(^(.1),U),1:"")
K:$L(LROID) ^LRO(68,LRAA,1,LRDTN,1,"C",LROID,LRAN)
K:$L(LROCN) ^LRO(68,LRAA,1,LRDTN,1,"D",LROCN,LRAN)
K ^LRO(68,LRAA,1,LRDTN,1,LRAN)
W "."
Q
;
;
% R %:DTIME Q:%=""!(%["N")!(%["Y") W !,"Answer 'Y' or 'N': " G %
Q
;
;
CHKUID ; Check UID's for purged accessions
;
N LRAA,LRAD,LRAN,LRCNT,LRROOT
;
; Check "C" cross-reference
S LRROOT="^LRO(68,""C"")",(LRAA,LRAD,LRAN,LRCNT)=0
F S LRROOT=$Q(@LRROOT) Q:LRROOT="" Q:$QS(LRROOT,2)'="C" D CHKACN Q:$G(ZTSTOP)
;
; Check "D" cross-reference
S LRROOT="^LRO(68,""D"")",(LRAA,LRAD,LRAN,LRCNT)=0
F S LRROOT=$Q(@LRROOT) Q:LRROOT="" Q:$QS(LRROOT,2)'="D" D CHKACN Q:$G(ZTSTOP)
Q
;
CHKACN ; Check for deleted corresponding accession.
S LRAA=$QS(LRROOT,4),LRAD=$QS(LRROOT,5),LRAN=$QS(LRROOT,6)
S LRCNT=LRCNT+1
; take a "rest" - allow OS to swap out process
; Check if task has been requested to stop
I '(LRCNT#10000) D Q:$G(ZTSTOP)
. I $$S^%ZTLOAD("Processing UID: "_$QS(LRROOT,3)) S ZTSTOP=1 Q
. H 2
I $D(^LRO(68,LRAA,1,LRAD,1,LRAN,0)) Q
K @LRROOT
Q
LROC ;VA/DALOI/CJS - ORDER LIST CLEAN-UP ; 13-Oct-2017 14:04 ; MKK
+1 ;;5.2;LAB SERVICE;**1003,1013,121,1018,295,1030,329,1031,1041**;NOV 1, 1997;Build 23
+2 ;
+3 ;;VA LR Patch(s): 121,295,329
+4 ;
+5 ; Modified slc/jer to include set/kill for "D" cross-reference
+6 ;
EP ; EP
+1 NEW DA,DIR,DIROUT,DTOUT,DUOUT,LRAA,LRSAVE,LRX,MSG,X,Y
+2 DO ^LROCM
+3 ;
+4 SET DIR(0)="Y"
+5 SET DIR("A")="Do you wish to Purge old Orders and Accessions"
SET DIR("B")="NO"
+6 DO ^DIR
+7 IF Y'=1
QUIT
+8 ;
+9 ; IHS/MSC/MKK - LR*5.2*1041
DO STORPURG^BLRPURGU
+10 ;
+11 SET LRX=+$PIECE($GET(^LAB(69.9,1,0)),U,9)
IF 'LRX
SET LRX=7
+12 SET LRSAVE=$$FMADD^XLFDT(DT,"-"_LRX)
+13 ;
L1 ; Purge the daily accession areas that meet cutoff
+1 SET LRAA=0
+2 FOR
SET LRAA=$ORDER(^LRO(68,LRAA))
IF LRAA<1
QUIT
Begin DoDot:1
+3 IF $PIECE(^LRO(68,LRAA,0),U,3)'="D"
WRITE !,"Use File Manager to clear ",$PIECE(^(0),U)
End DoDot:1
+4 ;
+5 NEW ZTSK,ZTRTN,ZTDESC,ZTIO,ZTSAVE
+6 SET ZTRTN="DQ^LROC"
SET ZTDESC="Purge old orders and accessions"
+7 SET ZTIO=""
SET ZTSAVE("LR*")=""
+8 DO ^%ZTLOAD
+9 SET MSG=$SELECT($GET(ZTSK):"Task #"_ZTSK_" tasked to run",1:"Tasking failed")
+10 DO EN^DDIOL(MSG,"","!?2")
+11 QUIT
+12 ;
+13 ;
DQ ; Tasked entry point to clean up file #69
+1 NEW DA,I,J,K,LRDA
+2 ;
+3 ; Purge the daily accession areas that meet cutoff
+4 SET LRAA=0
+5 FOR
SET LRAA=$ORDER(^LRO(68,LRAA))
IF LRAA<1
QUIT
Begin DoDot:1
+6 IF $PIECE(^LRO(68,LRAA,0),U,3)'="D"
QUIT
+7 IF $$S^%ZTLOAD("Processing accession area: "_LRAA)
SET ZTSTOP=1
QUIT
+8 SET DA=0
+9 FOR
SET DA=$ORDER(^LRO(68,LRAA,1,DA))
IF DA<1!(LRSAVE<DA)
QUIT
KILL ^LRO(68,LRAA,1,DA)
End DoDot:1
IF $GET(ZTSTOP)
QUIT
+10 ;
+11 IF $GET(ZTSTOP)
QUIT
+12 ;
+13 SET I=0
+14 FOR
SET I=$ORDER(^LRO(69,"C",I))
IF I<1
QUIT
Begin DoDot:1
+15 IF $$S^%ZTLOAD("Processing 'C' X-REF in file #69")
SET ZTSTOP=1
QUIT
+16 SET J=0
+17 FOR
SET J=$ORDER(^LRO(69,"C",I,J))
IF J>LRSAVE!(J<1)
QUIT
KILL ^(J)
End DoDot:1
IF $GET(ZTSTOP)
QUIT
+18 IF $GET(ZTSTOP)
QUIT
+19 ;
+20 SET I=0
+21 FOR
SET I=$ORDER(^LRO(69,"D",I))
IF I<1
QUIT
Begin DoDot:1
+22 IF $$S^%ZTLOAD("Processing 'D' X-REF in file #69")
SET ZTSTOP=1
QUIT
+23 SET J=0
+24 FOR
SET J=$ORDER(^LRO(69,"D",I,J))
IF J>LRSAVE!(J<1)
QUIT
KILL ^(J)
End DoDot:1
IF $GET(ZTSTOP)
QUIT
+25 IF $GET(ZTSTOP)
QUIT
+26 ;
+27 SET LRDA=1
+28 FOR
SET LRDA=$ORDER(^LRO(69,LRDA))
Begin DoDot:1
+29 IF LRDA["0000"
QUIT
+30 IF $$S^%ZTLOAD("Processing orders in file #69 for "_$$FMTE^XLFDT(LRDA))
SET ZTSTOP=1
QUIT
+31 SET ^LRO(69,0)=$PIECE(^LRO(69,0),U,1,2)_U_LRDA_U_($PIECE(^(0),U,4)-1)
+32 NEW LRSN
+33 SET LRSN=0
+34 ; Call OE/RR
FOR
SET LRSN=$ORDER(^LRO(69,LRDA,1,LRSN))
IF LRSN<1
QUIT
DO NEW^LR7OB1(LRDA,LRSN,"Z@")
+35 KILL ^LRO(69,LRDA),^LRO(69,"B",LRDA,LRDA)
End DoDot:1
IF (LRSAVE<LRDA)!(LRDA<1)
QUIT
IF $GET(ZTSTOP)
QUIT
+36 ;
+37 IF LRDA<1
SET ^LRO(69,0)=$PIECE(^(0),U,1,2)
+38 IF $GET(ZTSTOP)
QUIT
+39 ;
+40 DO CHKUID
+41 IF $GET(ZTSTOP)
QUIT
+42 DO ^LROC1
+43 KILL LRSAVE
+44 ;
+45 QUIT
+46 ;
+47 ;
CENDEL ;
+1 WRITE !,"STARTING CENTRAL ENTRY #: "
READ LRSTA:DTIME
SET LRSTA=LRSTA-1
+2 SET U="^"
WRITE !,"ENDING CENTRAL ENTRY #: "
READ LRFIN:DTIME
+3 WRITE !,"ARE YOU SURE? N//"
DO %
IF %'["Y"
QUIT
+4 SET ZTRTN="REENTRY^LROC"
SET ZTIO=""
SET ZTSAVE("L*")=""
+5 DO ^%ZTLOAD
+6 KILL IO("Q"),ZTSK,ZTRTN,ZTIO,ZTSAVE
+7 KILL %H,%ZA,%ZB,%ZC,DA,I,J,LRAA,LRAN,LRDFN,LRDTM,LRDTN,LRFIN,LRIDT,LRIOZERO,LRLOST,LROCN,LROID,LRORD,LROSN,LRSAVE,LRSN,LRSS,LRSTA,POP,Z
+8 QUIT
+9 ;
+10 ;
REENTRY ;
+1 SET LRORD=LRSTA
+2 FOR
SET LRORD=$ORDER(^LRO(69,"C",LRORD))
IF LRORD<1!(LRORD>LRFIN)
QUIT
DO FDAT
+3 QUIT
+4 ;
+5 ;
FDAT ;
+1 SET LRDTN=0
+2 FOR
SET LRDTN=$ORDER(^LRO(69,"C",LRORD,LRDTN))
IF LRDTN<1
QUIT
DO ZAP
+3 QUIT
+4 ;
+5 ;
ZAP ;
+1 SET LRSN=0
+2 FOR
SET LRSN=$ORDER(^LRO(69,"C",+LRORD,LRDTN,LRSN))
IF LRSN<1
QUIT
Begin DoDot:1
+3 ;Call OE/RR
DO NEW^LR7OB1(LRDTN,LRSN,"Z@")
+4 KILL ^LRO(69,"C",+LRORD,LRDTN,LRSN)
IF '$DATA(^LRO(69,LRDTN,1,LRSN,0))
QUIT
SET LRDFN=+^(0)
+5 KILL ^LRO(69,LRDTN,1,LRSN),^LRO(69,LRDTN,1,"AA",LRDFN,LRSN),^LRO(69,"D",LRDFN,LRDTN,LRSN)
End DoDot:1
+6 SET LRAA=0
+7 FOR
SET LRAA=$ORDER(^LRO(68,LRAA))
IF LRAA<1
QUIT
IF $PIECE(^(LRAA,0),U,10)="Y"
DO LRORD
+8 QUIT
+9 ;
+10 ;
LRORD ;
+1 SET LRAN=$ORDER(^LRO(68,LRAA,1,LRDTN,1,"D",LRORD,0))
IF LRAN<1
QUIT
+2 IF '$DATA(^LRO(68,LRAA,1,LRDTN,1,LRAN,0))
QUIT
+3 SET LRSS=$PIECE(^LRO(68,LRAA,0),"^",2)
+4 SET LRDFN=+^LRO(68,LRAA,1,LRDTN,1,LRAN,0)
IF '$DATA(^(3))
GOTO SKPLR
SET LRDTM=+^LRO(68,LRAA,1,LRDTN,1,LRAN,3)
IF 'LRDTM
GOTO SKPLR
SET LRIDT=9999999-LRDTM
+5 IF $DATA(^LR(LRDFN,LRSS,LRIDT,0))
IF $PIECE(^(0),U,3)
QUIT
+6 KILL ^LR(LRDFN,LRSS,LRIDT)
+7 IF LRSS="CH"
DO CHKILL^LRPX(LRDFN,LRIDT)
+8 ;
SKPLR SET X=^LRO(68,LRAA,1,LRDTN,1,LRAN,0)
SET LROSN=$PIECE(X,U,5)
SET LROID=$PIECE(X,U,6)
SET LROCN=$SELECT($DATA(^(.1)):$PIECE(^(.1),U),1:"")
+1 IF $LENGTH(LROID)
KILL ^LRO(68,LRAA,1,LRDTN,1,"C",LROID,LRAN)
+2 IF $LENGTH(LROCN)
KILL ^LRO(68,LRAA,1,LRDTN,1,"D",LROCN,LRAN)
+3 KILL ^LRO(68,LRAA,1,LRDTN,1,LRAN)
+4 WRITE "."
+5 QUIT
+6 ;
+7 ;
% READ %:DTIME
IF %=""!(%["N")!(%["Y")
QUIT
WRITE !,"Answer 'Y' or 'N': "
GOTO %
+1 QUIT
+2 ;
+3 ;
CHKUID ; Check UID's for purged accessions
+1 ;
+2 NEW LRAA,LRAD,LRAN,LRCNT,LRROOT
+3 ;
+4 ; Check "C" cross-reference
+5 SET LRROOT="^LRO(68,""C"")"
SET (LRAA,LRAD,LRAN,LRCNT)=0
+6 FOR
SET LRROOT=$QUERY(@LRROOT)
IF LRROOT=""
QUIT
IF $QSUBSCRIPT(LRROOT,2)'="C"
QUIT
DO CHKACN
IF $GET(ZTSTOP)
QUIT
+7 ;
+8 ; Check "D" cross-reference
+9 SET LRROOT="^LRO(68,""D"")"
SET (LRAA,LRAD,LRAN,LRCNT)=0
+10 FOR
SET LRROOT=$QUERY(@LRROOT)
IF LRROOT=""
QUIT
IF $QSUBSCRIPT(LRROOT,2)'="D"
QUIT
DO CHKACN
IF $GET(ZTSTOP)
QUIT
+11 QUIT
+12 ;
CHKACN ; Check for deleted corresponding accession.
+1 SET LRAA=$QSUBSCRIPT(LRROOT,4)
SET LRAD=$QSUBSCRIPT(LRROOT,5)
SET LRAN=$QSUBSCRIPT(LRROOT,6)
+2 SET LRCNT=LRCNT+1
+3 ; take a "rest" - allow OS to swap out process
+4 ; Check if task has been requested to stop
+5 IF '(LRCNT#10000)
Begin DoDot:1
+6 IF $$S^%ZTLOAD("Processing UID: "_$QSUBSCRIPT(LRROOT,3))
SET ZTSTOP=1
QUIT
+7 HANG 2
End DoDot:1
IF $GET(ZTSTOP)
QUIT
+8 IF $DATA(^LRO(68,LRAA,1,LRAD,1,LRAN,0))
QUIT
+9 KILL @LRROOT
+10 QUIT