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

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

revised back to 6/30/08 version

File size: 7.2 KB
Line 
1DIEZ2 ;SFISC/GFT-COMPILE INPUT TEMPLATE ;12:45 PM 17 Sep 2002
2 ;;22.0;VA FileMan;**11,95**;Mar 30, 1999
3 ;Per VHA Directive 10-93-142, this routine should not be modified.
4 K DIEZAR D RECXR^DIEZ4(.DIEZAR)
5 K ^DIE(DIEZ,"AR") M:$D(DIEZAR) ^DIE(DIEZ,"AR")=DIEZAR
6 S %X="^UTILITY($J,""AF"",",%Y="^DIE(""AF""," D %XY^%RCR
7 K ^DIE(DIEZ,"AB") S %X="^UTILITY($J,""AB"",",%Y="^DIE(DIEZ,""AB""," D %XY^%RCR
8 S ^DIE(DIEZ,"ROUOLD")=DNM,^("ROU")=U_DNM
9K K ^DIBT(.402,1,DIEZ),^UTILITY($J)
10 K @DIEZTMP,DIEZTMP,DIEZAR
11 K DIE,DINC,DK,DL,DMAX,DNR,DP,DQ,DQFF,DRD,DS,DSN,DV,DW,DI,DH,%,%X,%Y,%H,X,Y
12 K DIEZ,DIEZDUP,DIEZR,Q,DPP,DPR,DM,DR,DU,T,F,DRN,DOV,DIEZL,DIEZP,DIEZAB
13 Q
14 ;
15XREF ;
16 N DIEZR,DIEZX,DIEZLN
17 S X="C"_DQ_" G C"_DQ_"S:$D(DE("_DQ_"))[0 K DB" D L
18 S DIEZX=L,DIEZLN=0 ;remember cross-refs will start after 'L'
19 F %=0:0 S %=$O(^DD(DP,DI,1,%)) Q:%'>0 S DW=^(%,2),X=" S X=DE("_DQ_"),DIC=DIE" D SK ;first build the KILL XREFS
20 I DV["a" S X=" S X=DE("_DQ_"),DIIX=2_U_DIFLD D AUDIT^DIET" D X
21 ;I X]"" S X="C"_DQ_" ;" D L
22 D OVERFLO
23 S X="C"_DQ_"S S X="""" G:DG(DQ)=X C"_DQ_"F1 K DB" D L S X=""
24 S DIEZX=L,DIEZLN=L
25 F %=0:0 S %=$O(^DD(DP,DI,1,%)) Q:%'>0 S DW=^(%,1),X=X_" S X=DG(DQ),DIC=DIE" D SK ;then the SET XREFS
26 I DV["a" S X=X_" I $D(DE("_DQ_"))'[0!(^DD(DP,DIFLD,""AUDIT"")'=""e"") S X=DG(DQ),DIIX=3_U_DIFLD D AUDIT^DIET" D X
27 D OVERFLO
28 ;Build index code and code to check key
29 D INDEX
30 S X=X_" Q" D L
31 I $D(DIEZKEY) D GETKEY^DIEZ3(DP,DI,.DIEZKEY,DQ) K DIEZKEY
32 Q
33 ;
34SK D X I "Q"[DW S X=" ;" G X
35 I DW["Q",^DD(DP,DI,1,%,0)["MUMPS" S Q=DW,F=0 D QFF S X=" X "_Q G X
36 S X=" "_DW
37X D L S DIEZLN=DIEZLN+$L(X),X="" Q
38 ;
39OVERFLO I DIEZLN+T+100<DMAX!'DIEZLN Q
40 K ^UTILITY($J,"DIEZXR") M ^UTILITY($J,"DIEZXR")=^UTILITY($J,0)
41 S DIEZR=DRN,(DIEZR(1),DRN)=$O(DRN(""),-1)+1 D
42 .N T,DQ,L
43 .D NEWROU^DIEZ ;make a new routine holding just the X-REFS
44 .F T=2:1 S DIEZX=DIEZX+1 Q:'$D(^UTILITY($J,"DIEZXR",DIEZX)) S ^UTILITY($J,0,T)=^(DIEZX) K ^UTILITY($J,"DIEZXR",DIEZX)
45 .F K ^UTILITY($J,0,T) S T=$O(^(T)) Q:'T
46 .D SAVE^DIEZ1
47 K ^UTILITY($J,0) M ^UTILITY($J,0)=^UTILITY($J,"DIEZXR")
48 S DRN=DIEZR,T=T-DIEZLN,X=" D ^"_DNM_DIEZR(1) D L
49 Q
50 ;
51MUL ;
52 S DNR=%,DW=$P(DW,";",1),X=$P(^DD(+DV,0),U,4)_U_DV_U_DW_U,%=^(.01,0),DV=+DV_$P(%,U,2)
53 G 1:DV'["W" I DPR]"" S F=0,Q=DPR D QFF S X=" S DE(1,0)="_Q D L
54 S X=" S Y="""_$S(DIEZP]"":DIEZP_U_$P(%,U,2,9),1:%)_""",DG="""_DW_""",DC=""^"_+DV_""" D DIEN^DIWE K DE(1) G A" D L S X=" ;" D L,AF
55 S ^UTILITY($J,"AF",+DV,.01,DIEZ)="" D AB G NX^DIEZ0
56 ;
571 S X=" S DIFLD="_DI_",DGO=""^"_DNM_DNR_""",DC="""_X_""",DV="""_DV_""",DW=""0;1"",DOW="""_$S(DIEZP]"":DIEZP,1:$P(^(0),U,1))_""",DLB=""Select ""_DOW S:D DC=DC_D",DPP=DV["M",DU=$P(^(0),U,3) D L,DU:DU]""
58 S X=$P(" G RE:D",U,DPP)_" I $D(DSC("_+DV_"))#2,$P(DSC("_+DV_"),""I $D(^UTILITY("",1)="""" X DSC("_+DV_") S D=$O(^(0)) S:D="""" D=-1 G M"_DQ D L
59 S:+DW'=DW DW=""""_DW_"""" S X=" S D=$S($D("_DIE_"DA,"_DW_",0)):$P(^(0),U,3,4),$O(^(0))'="""":$O(^(0)),1:-1)" D L
60 S X="M"_DQ_" I D>0 S DC=DC_D I $D("_DIE_"DA,"_DW_",+D,0)) S DE("_DQ_")=$P(^(0),U,1)" D L
61 D PR^DIEZ0 S X="R"_DQ_" D DE" D L
62 S X=$S(DPP:" S D=$S($D("_DIE_"DA,"_DW_",0)):$P(^(0),U,3,4),1:1) G "_DQ_"+1",1:" G A") D L S X=" ;" D L,AF
63 S DRN(DNR)=+DV_U_(DL+1)_DIE_"D"_DIEZL_","_DW_","_U_(DIEZL+1)_U_DQ_U_DRN G NX^DIEZ0
64 ;
65AF ;
66 S ^UTILITY($J,"AF",DP,DI,DIEZ)=""
67AB I '$D(^UTILITY($J,"AB",DIEZAB,DI)) S ^(DI)=DQ_U_DNM_DRN S:DPR?1"/".E ^(DI,"///")=""
68 Q
69 ;
70DU S F=0,Q=DU D QFF S X=" S DU="_Q,DU=""
71L S L=L+1,^UTILITY($J,0,L)=X,T=T+$L(X)+2 Q
72 ;
73O ;
74 S F=0,Q=^(2) D QFF S DIEZOT=" S DQ("_DQ_",2)="_Q Q
75 ;
76PR ;
77 F %=1,2,3 Q:$E(DPR,%)'="/"
78 S X=$E(DPR,%,999),Q=X,F=0 D QFF I $A(X)-94 S X=" S Y="_Q
79 E S X=" "_$E(X,2,999) D L S X=" S Y=X"
80 D L S X=" G Y" I %>1 S DPP=0,X=" S X=Y,DB(DQ)=1"_$S(%=3:",DE(DW,""4/"")=""""",1:"")_" G:X="""" N^DIE17:DV,A I $D(DE(DQ)),DV[""I""!(DV[""#"") D E^DIE0 G A:'$D(X)" D L S X=" G "_$S(%=3:"RD:X=""@"",Z",1:"RD")
81 Q
82QF ;
83 S F=0,Q=DIE
84QFF ;
85 S F=$F(Q,"""",F) I F S Q=$E(Q,1,F-1)_$E(Q,F-1,999),F=F+1 G QFF
86 S Q=""""_Q_""""
87 Q
88 ;
89INDEX ;Build code field and record level cross references.
90 ;In:
91 ; DP = file #
92 ; DI = field #
93 ; DIEZKEY(xref#) = "" : for each xref that is a Uniqueness Index
94 ; for a simple (single-field key)
95 N DIEZCNT,DIEZFLST,DIEZI,DIEZRLST,DIEZXR,DIEZXREF
96 S DIEZCNT=0
97 ;
98 ;Get field- and record-level xrefs
99 D LOADFLD^DIKC1(DP,DI,"KS","","@DIEZTMP@(""V"",","DIEZXREF",$NA(@DIEZTMP@("R")),.DIEZFLST,.DIEZRLST)
100 I DIEZFLST="",DIEZRLST="" S X="C"_DQ_"F1" Q
101 ;
102 ;Build code for each field-level xref
103 ;Save DIEZKEY(uniquenessIndex)=index tag # (DIEZCNT)
104 I DIEZFLST]"" S DIEZXR=0 F S DIEZXR=$O(DIEZXREF(DP,DIEZXR)) Q:'DIEZXR D
105 . D GETXR(DIEZXR,.DIEZCNT)
106 . S:$D(DIEZKEY(DIEZXR))#2 DIEZKEY(DIEZXR)=DIEZCNT
107 ;
108 ;Build code to set the DIEZRXR array for each record-level xref
109 S X="C"_DQ_"F"_(DIEZCNT+1)
110 Q:DIEZRLST=""
111 S X=X_" S DIEZRXR("_DP_",DIIENS)=$$OREF^DILF($NA(@$$CREF^DILF(DIE)))" D L
112 S X=" F DIXR="_$TR(DIEZRLST,U,",")_" S DIEZRXR("_DP_",DIXR)=""""" D L
113 S DIEZI=0 F S DIEZI=$O(DIEZRLST(DIEZI)) Q:'DIEZI D
114 . S X=" F DIXR="_$TR(DIEZRLST(DIEZI),U,",")_" S DIEZRXR("_DP_",DIEZIENS)=""""" D L
115 ;
116 S X=""
117 Q
118 ;
119GETXR(DIEZXR,DIEZCNT) ;Get code for one index DIEZXR
120 N DIEZCOD,DIEZF,DIEZKLOG,DIEZNSS,DIEZSLOG,DIEZO
121 S DIEZCNT=$G(DIEZCNT)+1
122 ;
123 ;Build code to call subroutine to set X array
124 S X="C"_DQ_"F"_DIEZCNT_$S(DIEZCNT=1:" N X,X1,X2",1:"")_" S DIXR="_DIEZXR_" D C"_DQ_"X"_DIEZCNT_"(U) K X2 M X2=X D C"_DQ_"X"_DIEZCNT_"(""O"") K X1 M X1=X"
125 D L
126 ;
127 ;Build code to check for null subscripts
128 S DIEZNSS="",DIEZO=0
129 F S DIEZO=$O(DIEZXREF(DP,DIEZXR,DIEZO)) Q:'DIEZO D
130 . Q:'$G(DIEZXREF(DP,DIEZXR,DIEZO,"SS"))
131 . I DIEZNSS="" S DIEZNSS="$G(X("_DIEZO_"))]"""""
132 . E S DIEZNSS=DIEZNSS_",$G(X("_DIEZO_"))]"""""
133 I DIEZNSS]"" S DIEZNSS=" I "_DIEZNSS_" D"
134 E S DIEZNSS=" D"
135 ;
136 ;Get kill logic and condition
137 S DIEZKLOG=$G(DIEZXREF(DP,DIEZXR,"K"))
138 I DIEZKLOG'?."^" D
139 . S X=DIEZNSS D L
140 . ;Get kill condition code
141 . S DIEZCOD=$G(DIEZXREF(DP,DIEZXR,"KC"))
142 . I DIEZCOD'?."^" D
143 .. S X=" . N DIEXARR M DIEXARR=X S DIEZCOND=1" D L
144 .. S X=" . "_DIEZCOD D L
145 .. S X=" . S DIEZCOND=$G(X) K X M X=DIEXARR Q:'DIEZCOND" D L
146 . ;Get kill logic
147 . S X=" . "_DIEZKLOG D L
148 ;
149 ;Get set logic and condition
150 S DIEZSLOG=$G(DIEZXREF(DP,DIEZXR,"S"))
151 I DIEZSLOG'?."^" D
152 . S X=" K X M X=X2"_DIEZNSS D L
153 . ;Get set condition code
154 . S DIEZCOD=$G(DIEZXREF(DP,DIEZXR,"SC"))
155 . I DIEZCOD'?."^" D
156 .. S X=" . N DIEXARR M DIEXARR=X S DIEZCOND=1" D L
157 .. S X=" . "_DIEZCOD D L
158 .. S X=" . S DIEZCOND=$G(X) K X M X=DIEXARR Q:'DIEZCOND" D L
159 . ;Get set logic
160 . S X=" . "_DIEZSLOG D L
161 ;
162 S X=" G C"_DQ_"F"_(DIEZCNT+1) D L
163 ;
164 ;Build code to set X array
165 S DIEZF=$O(DIEZXREF(DP,DIEZXR,0))
166 S X="C"_DQ_"X"_DIEZCNT_"(DION) K X" D L
167 S DIEZO=0
168 F S DIEZO=$O(DIEZXREF(DP,DIEZXR,DIEZO)) Q:'DIEZO D
169 . D BLDDEC(DP,DIEZXR,DIEZO)
170 S X=" S X=$G(X("_DIEZF_"))" D L
171 S X=" Q" D L
172 Q
173 ;
174BLDDEC(DP,DIEZXR,DIEZO) ;Build data extraction code
175 N CODE,NODE,TRANS
176 ;
177 S CODE=$G(DIEZXREF(DP,DIEZXR,DIEZO)) Q:CODE?."^"
178 S TRANS=$G(DIEZXREF(DP,DIEZXR,DIEZO,"T"))
179 I TRANS'?."^" D
180 . S X=" "_CODE D L
181 . D DOTLINE(" I $D(X)#2 "_TRANS)
182 . S X=" S:$D(X)#2 X("_DIEZO_")=X" D L
183 E I $D(DIEZXREF(DP,DIEZXR,DIEZO,"F"))#2,CODE?1"S X=".E D
184 . S X=" S X("_DIEZO_")"_$E(CODE,4,999) D L
185 E D
186 . S X=" "_CODE D L
187 . S X=" S:$D(X)#2 X("_DIEZO_")=X" D L
188 Q
189 ;
190DOTLINE(CODE) ;
191 I CODE[" Q"!(CODE[" Q:") D
192 . S X=" D" D L
193 . S X=" ."_CODE D L
194 E S X=CODE D L
195 Q
Note: See TracBrowser for help on using the repository browser.