source: WorldVistAEHR/trunk/r/VA_FILEMAN-ARJT-DI-DD-DM-DT-%DT-%RCR/DIAUTL.m@ 1211

Last change on this file since 1211 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 5.1 KB
Line 
1DIAUTL ;GFT;13AUG2004
2 ;;22.0;VA FileMan;**76,140**;Mar 30, 1999
3 ;
4TURNON(DIFILE,FLDS,DIMODE) ;Turn on AUDITING for the FLDS named
5 N D,DIFIELD,DIE,DR,DA,DIQUIET,DIEZS,D0,DQ,DI,DIC,X
6 S DIMODE=$E($G(DIMODE,"y")),DIQUIET=1,DIEZS=1 Q:DIFILE<2 Q:"yen"'[DIMODE
7 F DIFIELD=0:0 S DIFIELD=$O(^DD(DIFILE,DIFIELD)) Q:'DIFIELD D:$$FLDSINC(DIFILE,FLDS,DIFIELD) ON
8 Q
9ON N DIOLD
10 S DIOLD=$G(^DD(DIFILE,DIFIELD,"AUDIT")) I DIOLD=DIMODE Q ;It's already on
11 S D=$P($G(^(0)),U,2) Q:D["C"
12 I D Q:$P($G(^DD(+D,.01,0)),U,2)["W" D TURNON(+D,"**",DIMODE) Q ;Recursive!
13 S DR="1.1////"_DIMODE,DIE="^DD("_DIFILE_",",DA(1)=DIFILE,DA=DIFIELD
14 I DA=.001,DIMODE="y" Q ;CAN'T AUDIT NUMBER FIELD!!
15 D ^DIE
16 D IN^DIU0(DIFILE,DIFIELD),DDAUDIT(DIFILE,DIFIELD,1.1,DIOLD,DIMODE)
17 Q
18 ;
19CHANGED(FILE,FLDS,FLAGS,ARRAY,START,END) ;
20 ;Returns in @ARRAY the list of entries in FILE who had any of the fields in FLDS changed from START to END
21 ;If FLAGS is "O", the Oldest values are saved in @ARRAY@(entry,field)
22 N GLO,E,F,T,D,%I
23 K @ARRAY
24 S FLAGS=$G(FLAGS)
25 S GLO=^DIC(FILE,0,"GL")
26 I '$G(START) S START=0
27 I '$G(END) D NOW^%DTC S END=%
28 S T=START D F S T=$O(^DIA(FILE,"C",T)) Q:T>END!'T D
29 .F D=0:0 S D=$O(^DIA(FILE,"C",T,D)) Q:'D D
30 ..S E=$G(^DIA(FILE,D,0)) Q:'E
31 ..I $D(@ARRAY@(+E)),FLAGS="" Q
32 ..S F=+$P(E,U,3) Q:'$$FLDSINC(FILE,FLDS,F)
33 ..I '$D(@(GLO_"+E)")),FLAGS="" Q
34 ..S @ARRAY@(+E)="" I FLAGS["O",'$D(@ARRAY@(+E,F)) S @ARRAY@(+E,F)=$G(^DIA(FILE,D,2))
35 Q
36 ;
37LAST(DIQGR,ENTRY,FLDS) ;returns DATE^USER who most recently touched any of the FLDS in ENTRY in File DIQGR
38 N E,F,DILAST,DENTRY
39 S DILAST="",DENTRY=ENTRY D E
40 S DENTRY=ENTRY_","
41 F S DENTRY=$O(^DIA(DIQGR,"B",DENTRY)) Q:DENTRY-ENTRY D E
42 Q DILAST
43E S E="" F S E=$O(^DIA(DIQGR,"B",DENTRY,E),-1) Q:'E I $$FLDSINC(DIQGR,FLDS,+$P($G(^DIA(DIQGR,E,0)),U,3)) D Q:DENTRY=ENTRY
44 .N L S L=$P(^DIA(DIQGR,E,0),"^",2)_"^"_$P(^(0),"^",4)
45 .I L>DILAST S DILAST=L
46 Q
47 ;
48DATE(FILE,FIELD) ;
49 D VALUE(FILE,FIELD,2) Q
50 ;
51USER(FILE,FIELD) ;
52 D VALUE(FILE,FIELD,4) Q
53 ;
54VALUE(FILE,FIELD,TU) ;FILE' can be SubFile
55 N DIACMP,ENTRY,I
56 S ENTRY=+$G(D0)
57 F I=1:1 Q:'$D(^DD(FILE,0,"UP")) S ENTRY=ENTRY_","_+$G(@("D"_I)),F=^("UP"),FIELD=$O(^DD(F,"SB",FILE,0))_","_FIELD,FILE=F
58 D PRIOR(FILE,ENTRY,FIELD,.DIACMP)
59 S D="" F S D=$O(DIACMP(D),-1) Q:'D S X=$S($G(TU):$P(^DIA(FILE,D,0),U,TU),1:DIACMP(D)) X DICMX Q:'$D(D)
60 S X="" Q
61 ;
62PRIOR(FILE,ENTRY,FIELD,OUT) ;
63 N E
64 F E=0:0 S E=$O(^DIA(FILE,"B",ENTRY,E)) Q:'E I $P($G(^DIA(FILE,E,0)),U,3)=FIELD,$D(^(2)) S OUT(E)=^(2)
65 Q
66 ;
67FLDSINC(DIQGR,DR,DIAUTLF) ;is DIAUTLF within DR? -- from 'DIQGQ' routine
68 I DR=""!'DIAUTLF Q 0
69 I DR="*" Q 1
70 N DIAUGOT,DIQGCP,DIQGDD,DIQGXDC,DIQGXDF,DIQGXDI,DIQGXDN,DIQGXDD
71 S DIQGXDC=0,DIAUGOT=0,DIQGDD=1,DIQGCP="D"
72 I '$D(DIQGR) N X S X(1)="FILE" G 202
73 S DIQGXDD="^DD("_DIQGR_")"
74 S:DIQGR DIQGR=$S(DIQGDD:$$DD(DIQGR),1:$$ROOT^DIQGU(DIQGR,.DA)) I DIQGR="" N X S X(1)="FILE AND IEN COMBINATION" G 202
75 F DIQGXDI=1:1 S DIQGXDF=$P(DR,";",DIQGXDI),DIQGXDN=$P(DIQGXDF,":") Q:DIQGXDF="" D RANGE G GOT:DIAUGOT
76NOGOT Q 0
77 ;
78RANGE I DIQGXDC,$P(^DD(+DIQGXDC,.01,0),"^",2)'["W" S:DR="**" DIQGXDN=DIQGXDN_"*" Q:$L(DIQGXDN,"*")'=2 ;multiple
79 I DIQGXDN'?.N,$L(DIQGXDN,"*")=2,$P(DIQGXDN,"*")]"",$D(@DIQGXDD@("B",$P(DIQGXDN,"*"))) S DIQGXDN=$O(^($P(DIQGXDN,"*"),""))_"*"
80 I DIQGXDN?1.2"*" S DIAUGOT=1 Q
81 Q:DIAUTLF<DIQGXDN I $P(DIQGXDF,":",2)<DIAUTLF Q:DIAUTLF-DIQGXDN
82 S DIAUGOT=1 Q
83 ;
84GOT Q 1
85 ;
86DD(X) Q:'$D(^DD(X)) "" Q "^DD("_X_","
87202 D BLD^DIALOG(202,.X) Q ;bad parameter
88 ;
89 ;
90GET(FIL,DA,DATE,TMP,FIELD) ;BUILD 'TMP' ARRAY AS OF DATE
91 ;DA is in IEN format FIELD, optional, means just look at one field
92 K @TMP
93 N DAT,FLD,FILE,F,D,E,B,C,T
94 S F=FIL,FILE=$$FNO^DILIBF(F),@TMP=FILE,D=+$P(DA,",",$L(DA,",")-1) I 'D S D=DA
95 I F=FILE F E=0:0 S E=$O(^DIA(FILE,"B",D,E)) Q:'E D L G Q:$G(@TMP@(F,D_","))
96SUBFILES S D=D_"," F S E=D,D=$O(^DIA(FILE,"B",D)) Q:D-E D
97 .F E=0:0 S E=$O(^DIA(FILE,"B",D,E)) Q:'E D L
98 Q
99L I $P($G(^DIA(FILE,E,0)),U)'=D Q
100 S FLD=$P(^(0),U,3),DAT=$P(^(0),U,2),I="",F=FILE
101 F S C=$L(FLD,","),I=I_$P(D,",",C)_"," Q:C=1 S T=+FLD G Q:'$D(^DD(F,T,0)) S T=+$P(^(0),U,2) G Q:T'>F!'$D(^DD(T)) S F=T,FLD=$P(FLD,",",2,C)
102 I FLD=.01,DAT>DATE,$P(^DIA(FILE,E,0),U,5)="A" K @TMP@(F,I) S @TMP@(F,I)=1 Q ;THAT ENTRY OR SUB-ENTRY DIDN'T EXIST AS OF DATE 2nd level will only be defined in this case
103 I $G(FIELD),FLD-FIELD!(F-FIL) Q
104 I '$D(@TMP@(F,I,FLD)) S @TMP@(F,I,FLD)=DAT_U_E Q
105 I DAT>DATE Q
106 I @TMP@(F,I,FLD)<DAT S @TMP@(F,I,FLD)=DAT_U_E
107Q Q
108 ;
109DIA(DAT,FILE,X,DIAUTLEX) ;FROM DIQG AND DIQGQ
110 ;X is a node value from the 'TMP' array built by the GET subroutine, above
111 ;DAT is the date/time as of which we want the audited value
112 ;DIAUTLEX may contain "E" if we want external value
113 I X>DAT Q $$D(2) ;We know what it was before deletion
114 Q $$D(3)
115D(ON) S X=$G(^DIA(FILE,+$P(X,U,2),ON)) I $G(DIAUTLEX)["E" Q X
116 N S,Y S S=$G(^(ON+.1)) I X]"",S="" D I Y>0 Q Y
117 .N %DT S %DT="T" D ^%DT
118 S S=$P(S,U) I S]"" Q S
119 Q X
120 ;
121DDAUDIT(B0,DA,A0,A1,A2) ;B0=File or SubFile, DA=Field, A0=Attribute #, A1=Old value, A2=New value
122 N DDA,%,%T,%D,J,B3,I
123 Q:'$D(DUZ)!'$G(DT)
124 D IJ^DIUTL(B0) I $G(^DD(J(0),0,"DDA"))'["Y" Q ;only if DD audit is on
125 S A0=+$G(A0),A0=$P($G(^DD(0,A0,0)),U)_U_A0
126 K:$G(A1)="" A1 L:$G(A2)="" A2
127 D P^DICATTA Q
Note: See TracBrowser for help on using the repository browser.