VSITKIL ;ISL/ARS,JVS - NON INTERACTIVE CHECK DEPENDENT ENTRY COUNT ;8/15/97
;;1.0;PCE PATIENT CARE ENCOUNTER;**76**;Aug 12, 1996
; Patch PX*1*76 changes the 2nd line of all VSIT* routines to reflect
; the incorporation of the module into PCE. For historical reference,
; the old (VISIT TRACKING) 2nd line is included below to reference VSIT
; patches.
;
;;2.0;VISIT TRACKING;**1,2**;Aug 12, 1996
;;
KILL(VSITKDFN) ; ENTER THE VSIT YOU WANT CHECKED SET VSITKDFN=IEN
; VSITKDFN = Vsit Ien REQUIRED
;
N DIK,VSITKDEC,VSITKND
S VSITKND=""
;
G:VSITKDFN'=+VSITKDFN!(VSITKDFN="") XIT
G:'$D(^AUPNVSIT(VSITKDFN,0)) XIT
;
L +^AUPNVSIT(VSITKDFN):45
S VSITKDEC=$P(^AUPNVSIT(VSITKDFN,0),"^",9)
S VSITKND=$$DEC^VSITKIL(VSITKDFN)
I VSITKND'=VSITKDEC,VSITKND'=$P(^AUPNVSIT(VSITKDFN,0),"^",9) S $P(^AUPNVSIT(VSITKDFN,0),"^",9)=VSITKND
;Check delete flag and reindex
I VSITKND>0,$P(^AUPNVSIT(VSITKDFN,0),"^",11)=1 D
. S $P(^AUPNVSIT(VSITKDFN,0),"^",11)=0
. S DA=VSITKDFN
. S DIK="^AUPNVSIT("
. D IX^DIK
. K DIK,DA,DR
I VSITKND=0 D
. S DIK="^AUPNVSIT("
. S DA=VSITKDFN
. D ^DIK
. K DIK,DA
. L -^AUPNVSIT(VSITKDFN)
. K VSITKDFN
E L -^AUPNVSIT(VSITKDFN)
XIT ;exit
Q VSITKND
;
DOC ; This routine checks the dependent entry count of the VISIT file for
; accuracy. If it is not correct it is replaced with a correct count
; The count is determined by scanning each of the VISIT related
; files for entries that point to that VISIT. A count is incremented
; each time a "hit" is made.
; The user can enter the visit IEN and if there is not any entries
; pointing to the entry it is deleted. (not logically but totally)
Q
;
DEC(VISIT,VISUAL) ;Test looking through DD to find fields pointing to the visit entries.
; VISIT=Visit ien to looked up and counted
; VISUAL= Set to 1 if you want and interactive display of what is found
;
; Look for file and field
;
N BECKY,COUNT,FIELD,FILE,GET,PIECE,PX,REF,SNDPIECE,STOP,SUB,VAUGHN
N VDD,VDDN,VDDR
;
S FILE=""
F S FILE=$O(^DD(9000010,0,"PT",FILE)) Q:FILE="" D
.S FIELD=""
.F S FIELD=$O(^DD(9000010,0,"PT",FILE,FIELD)) Q:FIELD="" D
..S VDD(FILE,FIELD)=""
D REF,QUE
K VDDN,VDDR
I $G(VISUAL) W !,"COUNT= "
Q COUNT
;
REF ;Look for all of the regular cross references and other
;
S FILE="" F S FILE=$O(VDD(FILE)) Q:FILE="" D
.S FIELD="" F S FIELD=$O(VDD(FILE,FIELD)) Q:FIELD="" D
..D REG
K VDD
Q
;
REG ;Look for regular cross references
;
S STOP=0
I '$D(^DD(FILE,FIELD,1)) S VDDN(FILE,FIELD)="" Q
S SUB=0 F S SUB=$O(^DD(FILE,FIELD,1,SUB)) Q:SUB="" D
.S GET=$G(^DD(FILE,FIELD,1,SUB,0))
.I $P(GET,"^",3)']"" S VDDR(FILE,SUB)=FILE_"^"_FIELD_"^"_SUB S STOP=1
.E S VDDN(FILE,FIELD)=""
Q
QUE ;CHECK OUT CROSS REFERENCE
;
S FILE="",FIELD="",STOP="",COUNT=0
F S FILE=$O(VDDR(FILE)) Q:FILE="" D
.S SUB=0,STOP="" F S SUB=$O(VDDR(FILE,SUB)) Q:SUB="" Q:STOP=1 S GET=$G(VDDR(FILE,SUB)) D
..S REF=$G(^DD($P(GET,"^",1),$P(GET,"^",2),1,$P(GET,"^",3),1))
..I $P(REF,"""",1)["DA(1)" Q
..S PIECE=$P(REF," ",2)
..S SNDPIECE=$P(PIECE,"""",1,2)_""""
..S VAUGHN=$P(PIECE,"""",1,2)_""")"
..I $D(@VAUGHN) D S STOP=1
...S PX=SNDPIECE_",VISIT)"
...I $D(@PX) D
....S BECKY=0 F S BECKY=$O(@PX@(BECKY)) Q:BECKY="" S COUNT=COUNT+1 W:$G(VISUAL) !," ",SNDPIECE_","_VISIT_","_BECKY
Q
;
COMP ;COMPARE DEC WITH WHAT UTILITY SAYS
;Call this entry point to loop through the entire file to see the
;dependent entry points that aren't accurate
;
N CNT,DEC,DEC1,KYRON
;
S CNT=0
S KYRON=0 F S KYRON=$O(^AUPNVSIT(KYRON)) Q:KYRON'>0 D
.S DEC=$P(^AUPNVSIT(KYRON,0),"^",9)
.S DEC1=$$DEC^VSITKIL(KYRON,0)
.I DEC="",DEC1=0 ;ok, both are zero
.E I DEC'=DEC1 D
..W !,"Visit= "_KYRON,?20,"Entry's Dependent Entry Count= "_DEC,?56,"Found= "_DEC1,?68,"BAD"
..S CNT=CNT+1
..S DEC1=$$DEC^VSITKIL(KYRON,1)
W !!,"BAD COUNTS "_CNT
Q
VSITKIL ;ISL/ARS,JVS - NON INTERACTIVE CHECK DEPENDENT ENTRY COUNT ;8/15/97
+1 ;;1.0;PCE PATIENT CARE ENCOUNTER;**76**;Aug 12, 1996
+2 ; Patch PX*1*76 changes the 2nd line of all VSIT* routines to reflect
+3 ; the incorporation of the module into PCE. For historical reference,
+4 ; the old (VISIT TRACKING) 2nd line is included below to reference VSIT
+5 ; patches.
+6 ;
+7 ;;2.0;VISIT TRACKING;**1,2**;Aug 12, 1996
+8 ;;
KILL(VSITKDFN) ; ENTER THE VSIT YOU WANT CHECKED SET VSITKDFN=IEN
+1 ; VSITKDFN = Vsit Ien REQUIRED
+2 ;
+3 NEW DIK,VSITKDEC,VSITKND
+4 SET VSITKND=""
+5 ;
+6 IF VSITKDFN'=+VSITKDFN!(VSITKDFN="")
GOTO XIT
+7 IF '$DATA(^AUPNVSIT(VSITKDFN,0))
GOTO XIT
+8 ;
+9 LOCK +^AUPNVSIT(VSITKDFN):45
+10 SET VSITKDEC=$PIECE(^AUPNVSIT(VSITKDFN,0),"^",9)
+11 SET VSITKND=$$DEC^VSITKIL(VSITKDFN)
+12 IF VSITKND'=VSITKDEC
IF VSITKND'=$PIECE(^AUPNVSIT(VSITKDFN,0),"^",9)
SET $PIECE(^AUPNVSIT(VSITKDFN,0),"^",9)=VSITKND
+13 ;Check delete flag and reindex
+14 IF VSITKND>0
IF $PIECE(^AUPNVSIT(VSITKDFN,0),"^",11)=1
Begin DoDot:1
+15 SET $PIECE(^AUPNVSIT(VSITKDFN,0),"^",11)=0
+16 SET DA=VSITKDFN
+17 SET DIK="^AUPNVSIT("
+18 DO IX^DIK
+19 KILL DIK,DA,DR
End DoDot:1
+20 IF VSITKND=0
Begin DoDot:1
+21 SET DIK="^AUPNVSIT("
+22 SET DA=VSITKDFN
+23 DO ^DIK
+24 KILL DIK,DA
+25 LOCK -^AUPNVSIT(VSITKDFN)
+26 KILL VSITKDFN
End DoDot:1
+27 IF '$TEST
LOCK -^AUPNVSIT(VSITKDFN)
XIT ;exit
+1 QUIT VSITKND
+2 ;
DOC ; This routine checks the dependent entry count of the VISIT file for
+1 ; accuracy. If it is not correct it is replaced with a correct count
+2 ; The count is determined by scanning each of the VISIT related
+3 ; files for entries that point to that VISIT. A count is incremented
+4 ; each time a "hit" is made.
+5 ; The user can enter the visit IEN and if there is not any entries
+6 ; pointing to the entry it is deleted. (not logically but totally)
+7 QUIT
+8 ;
DEC(VISIT,VISUAL) ;Test looking through DD to find fields pointing to the visit entries.
+1 ; VISIT=Visit ien to looked up and counted
+2 ; VISUAL= Set to 1 if you want and interactive display of what is found
+3 ;
+4 ; Look for file and field
+5 ;
+6 NEW BECKY,COUNT,FIELD,FILE,GET,PIECE,PX,REF,SNDPIECE,STOP,SUB,VAUGHN
+7 NEW VDD,VDDN,VDDR
+8 ;
+9 SET FILE=""
+10 FOR
SET FILE=$ORDER(^DD(9000010,0,"PT",FILE))
IF FILE=""
QUIT
Begin DoDot:1
+11 SET FIELD=""
+12 FOR
SET FIELD=$ORDER(^DD(9000010,0,"PT",FILE,FIELD))
IF FIELD=""
QUIT
Begin DoDot:2
+13 SET VDD(FILE,FIELD)=""
End DoDot:2
End DoDot:1
+14 DO REF
DO QUE
+15 KILL VDDN,VDDR
+16 IF $GET(VISUAL)
WRITE !,"COUNT= "
+17 QUIT COUNT
+18 ;
REF ;Look for all of the regular cross references and other
+1 ;
+2 SET FILE=""
FOR
SET FILE=$ORDER(VDD(FILE))
IF FILE=""
QUIT
Begin DoDot:1
+3 SET FIELD=""
FOR
SET FIELD=$ORDER(VDD(FILE,FIELD))
IF FIELD=""
QUIT
Begin DoDot:2
+4 DO REG
End DoDot:2
End DoDot:1
+5 KILL VDD
+6 QUIT
+7 ;
REG ;Look for regular cross references
+1 ;
+2 SET STOP=0
+3 IF '$DATA(^DD(FILE,FIELD,1))
SET VDDN(FILE,FIELD)=""
QUIT
+4 SET SUB=0
FOR
SET SUB=$ORDER(^DD(FILE,FIELD,1,SUB))
IF SUB=""
QUIT
Begin DoDot:1
+5 SET GET=$GET(^DD(FILE,FIELD,1,SUB,0))
+6 IF $PIECE(GET,"^",3)']""
SET VDDR(FILE,SUB)=FILE_"^"_FIELD_"^"_SUB
SET STOP=1
+7 IF '$TEST
SET VDDN(FILE,FIELD)=""
End DoDot:1
+8 QUIT
QUE ;CHECK OUT CROSS REFERENCE
+1 ;
+2 SET FILE=""
SET FIELD=""
SET STOP=""
SET COUNT=0
+3 FOR
SET FILE=$ORDER(VDDR(FILE))
IF FILE=""
QUIT
Begin DoDot:1
+4 SET SUB=0
SET STOP=""
FOR
SET SUB=$ORDER(VDDR(FILE,SUB))
IF SUB=""
QUIT
IF STOP=1
QUIT
SET GET=$GET(VDDR(FILE,SUB))
Begin DoDot:2
+5 SET REF=$GET(^DD($PIECE(GET,"^",1),$PIECE(GET,"^",2),1,$PIECE(GET,"^",3),1))
+6 IF $PIECE(REF,"""",1)["DA(1)"
QUIT
+7 SET PIECE=$PIECE(REF," ",2)
+8 SET SNDPIECE=$PIECE(PIECE,"""",1,2)_""""
+9 SET VAUGHN=$PIECE(PIECE,"""",1,2)_""")"
+10 IF $DATA(@VAUGHN)
Begin DoDot:3
+11 SET PX=SNDPIECE_",VISIT)"
+12 IF $DATA(@PX)
Begin DoDot:4
+13 SET BECKY=0
FOR
SET BECKY=$ORDER(@PX@(BECKY))
IF BECKY=""
QUIT
SET COUNT=COUNT+1
IF $GET(VISUAL)
WRITE !," ",SNDPIECE_","_VISIT_","_BECKY
End DoDot:4
End DoDot:3
SET STOP=1
End DoDot:2
End DoDot:1
+14 QUIT
+15 ;
COMP ;COMPARE DEC WITH WHAT UTILITY SAYS
+1 ;Call this entry point to loop through the entire file to see the
+2 ;dependent entry points that aren't accurate
+3 ;
+4 NEW CNT,DEC,DEC1,KYRON
+5 ;
+6 SET CNT=0
+7 SET KYRON=0
FOR
SET KYRON=$ORDER(^AUPNVSIT(KYRON))
IF KYRON'>0
QUIT
Begin DoDot:1
+8 SET DEC=$PIECE(^AUPNVSIT(KYRON,0),"^",9)
+9 SET DEC1=$$DEC^VSITKIL(KYRON,0)
+10 ;ok, both are zero
IF DEC=""
IF DEC1=0
+11 IF '$TEST
IF DEC'=DEC1
Begin DoDot:2
+12 WRITE !,"Visit= "_KYRON,?20,"Entry's Dependent Entry Count= "_DEC,?56,"Found= "_DEC1,?68,"BAD"
+13 SET CNT=CNT+1
+14 SET DEC1=$$DEC^VSITKIL(KYRON,1)
End DoDot:2
End DoDot:1
+15 WRITE !!,"BAD COUNTS "_CNT
+16 QUIT