source: BMXNET_RPMS_dotNET_UTILITIES-BMX/trunk/m/BMXADOV1.m

Last change on this file was 1209, checked in by Sam Habiel, 13 years ago

BMXMON fix; updated all routines to v 2.31

File size: 9.3 KB
RevLine 
[1087]1BMXADOV1 ; IHS/CIHA/GIS - RPC CALL: GENERATE DATA FOR AN ADO DATASET ; 12/7/10 4:12pm
[1209]2 ;;2.31;BMX;;Jul 25, 2011
[645]3 ; CONTINUATION FILE FOR BMXADOV
4 ; MANAGES ITERATION FOR INDIVIDUAL INDEX TYPES
5 ; ASSUMES CERTAIN LOCAL VARS: CREF,FIEN,IENS,DAS (<-THESE CAN'T BE NULL),START,STOP,MAX,TOT,NUM,IX
6 ;
[1087]7 ; Change Log
8 ; Sam Habiel 3101212 v. 2.21
9 ; Change line 140 from:
10 ; I IX="AA" G AA to
11 ; I IX="AA" Q $$AA
12 ; to fix compilation error
[645]13 ;
14 ;
15DATA(IENS,DA,XCNT) ;EP - ADD DATA NODES TO ARRAY
16 ; ASSUMES THAT VSTG VARIABLES AND THE OUT ARRAY ARE PRESENT
17 I '$G(DA) Q
18 I '$L(IENS) Q
19 S $P(IENS,C)=DA
20 N STG,X,Y,%,FLD,STOP,VAL,CNT,FIEN,LINE,IFLAG,IDEP,TFLD,TNO,TEF
21 S STG=DA
22 I $G(DAS),$E(DAS,$L(DAS))="," S STG=$TR(DAS,",",U)_STG ; FIX FOR SUBFILE
23 S CNT=$L(IENS,",") ; START AFTER THE .001 FIELD
24 I $G(SUB) S STG=$P(IENS,C,2)_U_DA ; MAKE DAS FOR A SUBFILE. THIS WILL BE THE IST PIECE OF THE DATA STRING
25 I $G(XCNT) S CNT=XCNT ; USED WITH JOINS
26 F S CNT=$O(@OUT@(CNT)) Q:'CNT Q:$G(STOP) D I @OUT@(CNT)[$C(30) Q ; LOOP TO CREATE THE DATA STRING
27 . K IFLAG,IDEP
28 . S FIEN=+@OUT@(CNT) I '$D(^DD(FIEN,0)) S STOP=1 Q
29 . S FLD=$P(@OUT@(CNT),B,2)
30 . I FLD=".01ID" D Q ; PROCESS THE IDENTIFIER FIELD
31 .. I '$G(SIEN) Q
32 .. S %=$O(^BMXADO(SIEN,1,"B",".01ID",0)) I '% Q
33 .. S IDEP=$G(^BMXADO(SIEN,1,%,1)) I '$L(IDEP) Q
34 .. X ("S VAL=$$"_IDEP_"("_+STG_")") ; PASS THE DA TO THE IDENTIFIER EXTRINSIC FUNCTION, RETURN IDENTIFIERS
35 .. S VAL=$TR(VAL,"^",""),VAL=$TR(VAL,B,"")
36 .. S STG=STG_U_VAL
37 .. Q
38 . I $G(SIEN),FLD S %=$O(^BMXADO(SIEN,1,"B",FLD,0)) I %,$P($G(^BMXADO(SIEN,1,%,0)),U,9) S IFLAG=1 ; SCHEMA FILE SAYS FORCE INTERNAL VALUE FOR THIS FIELD
39 . K TFLD
40 . I FLD["TRIGGER" S TFLD=FLD,FLD=+FLD,IFLAG=1
41 . I FLD["IEN" S FLD=+FLD,IFLAG=1 ; LOOKUP VALUE FIELD (IEN)
42 . I '$D(^DD(FIEN,FLD,0)),FLD'=.001 S STOP=1 Q
43 . I $D(TFLD),FLD=.001 S VAL=+IENS
44 . E S VAL=$$GET1^DIQ(FIEN,IENS,FLD,$S($G(IFLAG):"I",$G(TFLAG):"I",1:$G(FMT)))
45 . I $G(TFLD) D S STG=STG_U_VAL Q ; GENERATE A TRIGGERED VALUE FOR THIS FIELD
46 .. S TNO=$O(^BMXADO(SIEN,1,"B",TFLD,0)) I 'TNO S VAL="" Q
47 .. S TEF=$G(^BMXADO(SIEN,1,TNO,3)) I '$L(TEF) S VAL="" Q ; GET EXTR FUNCT THAT GENERATES A SECONDARY VALUE
48 .. X ("S VAL=$$"_TEF_"(VAL)")
49 .. Q
50 . I FLD=.01,VAL="" S STOP=1 Q ; INVALID FILEMAN ENTRY! SKIP IT
51 . S VAL=$TR(VAL,"^",""),VAL=$TR(VAL,B,"")
52 . S STG=STG_U_VAL
53 . Q
54 I $G(STOP) Q ; DON'T ADD NODE IF DD INFO IS INVALID
55 F S LINE=$E(STG,1,250),STG=$E(STG,251,999999) D I '$L(STG) Q ; PREVENTS DATA LENGTH FROM EXCEEDING 250 BYTES
56 . S TOT=TOT+1
57 . I '$L(STG) S LINE=LINE_$C(30),NUM=NUM+1 ; END OF RECORD, RECORD TOTAL IS UPDATED
58 . S @OUT@(TOT)=LINE ; NODE IS ADDED
59 . Q
60 Q
61 ;
62NUMIT(DA) ; EP-ITERATE BY NUMBER
63 N XIT,LDA
64 I IENS S DA=+IENS ; RE-ENTRY FROM SEED
65 I '$G(DA),$G(START) S DA=START-1
66 I '$G(DA) S DA=0
67 S LDA=""
68 F S DA=$O(@CREF@(DA)) D I $G(XIT) Q
69 . I 'DA S XIT=1,LDA="" Q ; NO MORE IENS - THE END OF THE LINE
70 . D DATA(IENS,DA,+$G(XCNT))
71 . I $G(STOP),$O(@CREF@(DA))>STOP S LDA="",XIT=1 Q ; AS FAR AS YOU ARE ALLOWED TO GO FOR NUMBER ITERATION
72 . I NUM=MAX S LDA=DA,XIT=1 Q ; REACHED THE MAX TRANSACTION LIMIT - GET MORE NEXT TIME
73 . Q
74 I LDA,'$O(@CREF@(LDA)) S LDA="" ; END OF THE LINE SO SET LDA TO NULL
75 Q LDA
76 ;
77LOOK(LIEN) ; EP-ITERATE BY A SINGLE STANDARD INDEX THAT IS A POINTER VALUE
78 N XIT,LDA
79 S DA=+IENS
80 F S DA=$O(@CREF@(IX,LIEN,DA)) D I $G(XIT) Q
81 . I 'DA S XIT=1,LDA="" Q ; NO MORE IENS - THE END OF THE LINE
82 . D DATA(IENS,DA,$G(XCNT))
83 . I NUM=MAX S LDA=DA,XIT=1 Q ; REACHED THE MAX TRANSACTION LIMIT - GET MORE NEXT TIME
84 . Q
85 I '$O(@CREF@(IX,LIEN,DA)) Q ""
86 Q LDA
87 ;
88LOOK1() ; EP-ITERATE USING A STANDARD INDEX
89 N XIT,LDA,VAL,DA,%
90 S DA=+IENS I 'DA G SCRATCH ; CHECK FOR RE-RENTRY
91REENTER ; RE-ENTER STD ITERATION USING DA AS THE SEED
92 S %=$$IXVAL(FIEN,IX,DAS) I '$L(%) Q "" ; GET STARTUP INFO
93LR S VAL=$P(%,B,3)
94 I VAL="" Q "" ; NO VAL FOUND FOR INITIAL ITERATION, SO QUIT
95 F S DA=$O(@CREF@(IX,VAL,DA)) Q:'DA D DATA(IENS,DA,+$G(XCNT)) I NUM=MAX S LDA=DA,XIT=1 Q ; SWEEP UP ALL THE REMAINING DAS UNDER THE CURRENT VALUE
96 I $G(XIT) Q:'$O(@CREF@(IX,VAL,LDA)) "" Q LDA ; IF NO MORE AFTER MAX, SET LDA = NULL
97 G LOOK1R ; SEED IS DEFINED
98SCRATCH S VAL="" ; STD LOOKUP STARTING FROM SCRATCH
99 I $L(START) S VAL=$O(@CREF@(IX,START),-1) ; GET SEED FOR ITERATION
100LOOK1R F S VAL=$O(@CREF@(IX,VAL)) D I $G(XIT) Q ; EP - RE-ENTRY POINT IF SEED IS DEFINED
101 . I VAL="" S LDA="",XIT=1 Q ; END OF THE LINE
102 . I STOP=+STOP,VAL=+VAL,VAL>STOP S LDA="",XIT=1 Q
103 . I $L(STOP),VAL]STOP S LDA="",XIT=1 Q ; LOOKUP LIMITS
104 . S DA=0
105 . F S DA=$O(@CREF@(IX,VAL,DA)) Q:'DA D I $G(XIT) Q
106 .. D DATA(IENS,DA,+$G(XCNT))
107 .. I NUM=MAX S LDA=DA,XIT=1 D ; TRANSACTION LIMIT ; CHECK FOR MORE
108 ... I $O(@CREF@(IX,VAL,DA)) Q
109 ... S %=$O(@CREF@(IX,VAL)) I %="" S LDA="" Q
110 ... I $L(STOP),%]STOP S LDA="" Q
111 ... I '$O(@CREF@(IX,%,0)) S LDA="" Q
112 ... Q
113 .. Q
114 . Q
115 Q LDA
116 ;
117LOOK2(LFILE) ; EP-TEXT POINTER LOOKUP
118 ; CHANGE THE GLOBAL REFERENCE FOR THE LOOKUP TO THE POINTED-TO FILE BEFORE PROCEEDING
119 N XIT,LDA,OREF,CREF,VAL,DA
120 S OREF=$$ROOT^DILFD(LFILE,IENS) I '$L(OREF) Q ""
121 S CREF=$$CREF^DILF(OREF) I '$L(CREF) Q ""
122 S DA=+IENS
123 I '$G(DA) G SCRATCH ; START FROM SCRATCH
124 S %=$$IXVAL(LFILE,IX,DAS) I '$L(%) Q ""
125 G LR ; RE-ENTER
126 ;
127IXVAL(FIEN,IX,DAS) ; GIVEN A FILE IEN, INDEX NAME, AND DAS STRING, RETURN THE VALUE USED IN THE INDEX
128 N DA,FLD,IENS,OREF,CREF,XREF,VAL,UP,LEV,L
129 I '$D(^DD(+$G(FIEN),0)) Q "" ; MISSING OR INVALID FILE NUMBER
130 I '$L($G(IX)) Q "" ; NO INDEX SPECIFIED
131 S UP=FIEN F LEV=1:1 S UP=$G(^DD(UP,0,"UP")) Q:'UP
132 I LEV'=$L(DAS,C) Q "" ; DAS LEVELS MUST MATCH FILE OR SUBFILE LEVEL
133 S IENS=$$IENS^BMXADOV($G(DAS)) I IENS=U Q ""
134 S OREF=$$ROOT^DILFD(FIEN,IENS) I '$L(OREF) Q ""
135 S CREF=$$CREF^DILF(OREF) I '$L(CREF) Q ""
136 I '$D(@CREF@(IX)) Q CREF_"||" ; NO INDEX VALUES TO CHECK
137 S XREF=OREF_IX_")"
138 S DA=+IENS I 'DA Q CREF_"||"
139 I '$D(@CREF@(DA)) Q CREF_"||" ; NO ENTRY EXISTS
[1087]140 I IX="AA" Q $$AA ; SMH v. 2.21
[645]141 S FLD=+$$IXFLD^BMXADOV(FIEN,IX) I 'FLD Q "" ; INVALID DD
142 S VAL=$$GET1^DIQ(FIEN,IENS,FLD,"I") I VAL="" Q "" ; VALUE IS NULL - NOTHING TO INDEX
143 I '$D(@CREF@(IX,VAL,DA)) Q "" ; INVALID INDEX
144 Q XREF_B_DA_B_VAL
145 ;
146AA() ;EP - VISIT/V-FILE ITERATION USING THE 'AA' INDEX
147 N LDA,XIT,AAINFO,DA,%,X,Y,DFN,TYPE,ORD,ISTART,ISTOP,IDT,AAREF,%DT,DIC
148 S X=OREF_"""AA"")",%=$Q(@X) I %="" Q ""
149 S TYPE="" I $L(%,C)=5 S TYPE=$P(PARAM,B,2) I TYPE="" Q "" ; FOR CERTAIN V FILES, TYPE MUST BE DEFINED
150 I $E(TYPE)="`" S TYPE=$E(TYPE,2,99) I 'TYPE Q "" ; REMOVE ` FROM TYPE IEN
151 I $L(TYPE),'TYPE D I TYPE'>0 Q "" ; QUIT IF INVALID TYPE
152 . S %=$P($G(^DD(FIEN,.01,0)),U,2)
153 . S DIC=+$P(%,"P",2) I '$D(^DD(DIC,.01,0)) Q
154 . S X=TYPE,DIC(0)="M" D ^DIC I Y=-1 Q
155 . S TYPE=+Y
156 . Q
157 S DFN=+PARAM
158 I '$D(^DPT(DFN,0)) Q "" ; PATIENT DFN MUST BE DEFINED
159 I 'TYPE S AAREF=OREF_"""AA"","_DFN_")"
160 E S AAREF=OREF_"""AA"","_DFN_","_TYPE_")"
161 I '$D(@AAREF) Q "" ; IF NOTHING UNDER AA INDEX, DON'T BOTHER LOOKING
162 S ISTART=9999999 I START S X=START,%DT="P" D ^%DT S ISTART=9999999-Y
163 S ISTOP=0 I STOP S X=STOP,%DT="P" D ^%DT S ISTOP=9999999-Y
164 S ORD=-1 I $P(PARAM,B,$L(PARAM,B))="R" S ORD=1 ; SORT IN CHRONOLOGICAL OR REVERSE CHRONOLOGICAL ORDER
165 I ORD=-1 S X=$G(ISTART),Y=$G(ISTOP),ISTOP=X,ISTART=Y ; CHANGES REQUIRED TO PRESENT DATA IN CHRONOLIGICAL ORDER
166 S IDT=0,LDA=""
167 I ISTOP S IDT=ISTOP-.0000001
168 S DA=+IENS
169 I DA S IDT=$$AAR I 'IDT Q LDA ; SWEEP UP REMAINING IENS FOR CURRENT IDT AND RESET IDT FOR RE-ENTRY
170 F S IDT=$O(@AAREF@(IDT),ORD) Q:'IDT D I $G(XIT) Q
171 . I ORD=1,IDT>ISTART S LDA="",XIT=1 Q
172 . I ORD=-1,IDT<ISTART S LDA="",XIT=1 Q
173 . S DA=0
174 . F S DA=$O(@AAREF@(IDT,DA)) Q:'DA D I $G(XIT) Q
175 .. D DATA(IENS,DA,+$G(XCNT))
176 .. I NUM=MAX S LDA=DA,XIT=1 I '$$AAMORE S LDA="" ; TRANSACTION LIMIT
177 .. Q
178 . Q
179 Q LDA
180 ;
181AAR() ; SWEEP UP REMAINING IENS FOR CURRENT IDT AND RESET IDT FOR RE-ENTRY
182 N %,X,Y,XIT
183 S %=$$AAVAL(FIEN,DAS) I '$L(%) Q ""
184 S IDT=$P(%,B,5) I 'IDT Q ""
185 F S DA=$O(@AAREF@(IDT,DA)) Q:'DA D I $G(XIT) Q
186 . D DATA(IENS,DA,+$G(XCNT))
187 . I NUM=MAX S LDA=DA,IDT="",XIT="" I '$$AAMORE S LDA=""
188 . Q
189 Q IDT
190 ;
191AAMORE() ; RETURN A '1' IF MORE ITERATION IS POSSIBLE
192 N X
193 I $O(@AAREF@(IDT,DA)) Q 1
194 S X=$O(@AAREF@(IDT),ORD) I 'X Q 0
195 I $O(@AAREF@(X,0)) Q 1
196 Q 0
197 ;
198AAVAL(FIEN,DAS) ; GIVEN A FILE AND DAS, RETURN INFO NECESSARY TO RE-CREATE THE 'AA' INDEX
199 N DATE,IDT,DFN,TYPE,VIEN,%,OREF,CREF,DA,IENS
200 I '$D(^DD(FIEN,.01,0)) Q ""
201 S IENS=$$IENS^BMXADOV($G(DAS)) I IENS=U Q ""
202 S OREF=$$ROOT^DILFD(FIEN,IENS) I '$L(OREF) Q ""
203 S CREF=$$CREF^DILF(OREF) I '$L(CREF) Q ""
204 S DA=+IENS I '$D(@CREF@(DA)) Q ""
205 I FIEN=9000010 S DFN=$P(@CREF@(DA,0),U,5),VIEN=DA
206 E S DFN=$P(@CREF@(DA,0),U,2),VIEN=$P(@CREF@(DA,0),U,3)
207 I $D(^DPT(DFN,0)),$D(^AUPNVSIT(VIEN,0))
208 E Q ""
209 S DATE=+$P($G(^AUPNVSIT(VIEN,0)),U) I 'DATE Q ""
210 S IDT=(9999999-(DATE\1))
211 S %=$P(DATE,".",2) I % S IDT=+(IDT_"."_%) I 'IDT Q ""
212 S X=OREF_"""AA"")",%=$Q(@X) I %="" Q ""
213 S TYPE="" I $L(%,C)=5 S TYPE=$P(@CREF@(DA,0),U)
214 Q X_B_DA_B_DFN_B_TYPE_B_IDT
215 ;
216AAP() ;EP - ITERATOR FOR PROBLEM FILE: AA INDEX
217 I '$D(^AUPNPROB("AA",+$G(START))) Q ""
218 N LOC,PNUM,DFN,IEN
219 S LOC=0,DFN=START
220 F S LOC=$O(^AUPNPROB("AA",DFN,LOC)) Q:'LOC D
221 . S PNUM=""
222 . F S PNUM=$O(^AUPNPROB("AA",DFN,LOC,PNUM)) Q:PNUM="" D
223 .. S IEN=0
224 .. F S IEN=$O(^AUPNPROB("AA",DFN,LOC,PNUM,IEN)) Q:'IEN D DATA(",",IEN,+$G(XCNT))
225 .. Q
226 .Q
227 Q ""
228 ;
229TESTID(DA) ; TEST IDENTIFIERS
230 N %,Y,SEX
231 S %=$G(^DIZ(2160010,+$G(DA),0)) I '$L(%) Q ""
232 S SEX=$P(%,U,2) I '$L(SEX) S SEX="??"
233 S Y=$P(%,U,3) X ^DD("DD")
234 Q (SEX_" "_Y)
235 ;
Note: See TracBrowser for help on using the repository browser.