source: ccr/trunk/p/C0CRNF.m@ 1721

Last change on this file since 1721 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

  • Property svn:mergeinfo set to (toggle deleted branches)
    /ccr/branches/ohum/o-old/p/C0CRNF.m1290
    /ccr/branches/ohum/p/C0CRNF.m1291-1543
    /ccr/branches/ohum/p/p/C0CRNF.m1287-1289
File size: 18.5 KB
Line 
1C0CRNF ; CCDCCR/GPL - Reference Name Format (RNF) utilities; 12/6/08
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 ;Copyright 2009 George Lilly.
4 ;
5 ; This program is free software: you can redistribute it and/or modify
6 ; it under the terms of the GNU Affero General Public License as
7 ; published by the Free Software Foundation, either version 3 of the
8 ; License, or (at your option) any later version.
9 ;
10 ; This program is distributed in the hope that it will be useful,
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; GNU Affero General Public License for more details.
14 ;
15 ; You should have received a copy of the GNU Affero General Public License
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
17 ;
18 W "This is the Reference Name Format (RNF) Utility Library ",!
19 W !
20 Q
21 ;
22FIELDS(C0CFRTN,C0CF) ; RETURNS AN ARRAY OF THE FIELDS IN FILE C0CF,
23 ; C0CFRTN IS PASSED BY NAME, C0CF IS PASSED BY VALUE
24 ;
25 N C0CFI,C0CFJ ;INNER LOOP, OUTER LOOP
26 N C0CFN ; FIELD NAME
27 S C0CFI=0 S C0CFJ=C0CF
28 K @C0CFRTN ; CLEAR THE RETURN ARRAY
29 F Q:C0CFJ'[C0CF D ; FOR THE C0CF FILE AND ALL SUBFILES INCLUSIVE
30 . ;W "1: "_C0CFJ," ",C0CFI,!
31 . F S C0CFI=$O(^DD(C0CFJ,C0CFI)) Q:+C0CFI=0 D ; EVERY FIELD
32 . . ;W "2: "_C0CFJ," ",C0CFI,!
33 . . S C0CFN=$P($G(^DD(C0CFJ,C0CFI,0)),"^",1) ;PULL FIELD NAME FROM ^DD
34 . . ;W "N: ",C0CFN,!
35 . . ;I C0CFN="STR" W C0CFN," ",C0CFJ,!
36 . . I $D(@C0CFRTN@(C0CFN)) D ; IS THIS A DUPLICATE?
37 . . . I $G(DEBUG) D ;
38 . . . . W "DUPLICATE FOUND! ",C0CFJ," ",C0CFI," ",C0CFN,!,@C0CFRTN@(C0CFN),!
39 . . . S @C0CFRTN@(C0CFN_"_"_C0CFJ)=C0CFJ_"^"_C0CFI
40 . . E S @C0CFRTN@(C0CFN)=C0CFJ_"^"_C0CFI
41 . S C0CFJ=$O(^DD(C0CFJ)) ; NEXT SUBFILE
42 Q
43 ;
44TESTRNF ; TEST THE RNF1TO2 ROUTINE
45 S G1("ONE")=1
46 S G1("TWO")=2
47 S G1("THREE")=3
48 D RNF1TO2("GPL","G1")
49 S G1("ONE")="NOT1"
50 S G1("TWO")="STILL2"
51 S G1("THREE")=3
52 D RNF1TO2("GPL","G1")
53 ; ZWR GPL
54 Q
55 ;
56RNF1TO2(ZOUT,ZIN) ; ADDS AN RNF1 ARRAY (ZIN) TO THE END OF AN RNF2 ARRAY
57 ; (ZOUT) BOTH ARE PASSED BY NAME
58 ; RNF1 IS OF THE FORM:
59 ; @ZIN@("VAR1")=VAL1
60 ; @ZIN@("VAR2")=VAL2
61 ; RNF2 IS OF THE FORM:
62 ; @ZOUT@("F","VAR1")=""
63 ; @ZOUT@("F","VAR2")=""
64 ; @ZOUT@("V",n,"VAR1")=VAL1
65 ; @ZOUT@("V",n,"VAR2")=VAL2
66 ; WHERE n IS THE "ROW" OF THE ARRAY
67 N ZI S ZI=""
68 N ZN
69 I '$D(@ZOUT@("V",1)) S ZN=1
70 E S ZN=$O(@ZOUT@("V",""),-1)+1
71 F S ZI=$O(@ZIN@(ZI)) Q:ZI="" D ;
72 . S @ZOUT@("F",ZI)=""
73 . S @ZOUT@("V",ZN,ZI)=@ZIN@(ZI)
74 Q
75 ;
76RNF1TO2B(ZOUT,ZIN) ; ADDS AN RNF1 ARRAY (ZIN) TO THE END OF AN RNF2 ARRAY
77 ; THE "B" ROUTINE SUPPORTS WP FIELDS IN THE ARRAY
78 ; EVERY "V" VARIABLE IS FOLLOWED BY A "1"
79 ; FOR EXAMPLE @G@("V",n,"VAR1",1)="VALUE1"
80 ; USE THIS ROUTINE IF YOU WANT TO CONVERT THE RESULT TO A CSV
81 ; WITH RNF2CSV
82 ; (ZOUT) BOTH ARE PASSED BY NAME
83 ; RNF1 IS OF THE FORM:
84 ; @ZIN@("VAR1")=VAL1
85 ; @ZIN@("VAR2")=VAL2
86 ; RNF2 IS OF THE FORM:
87 ; @ZOUT@("F","VAR1")=""
88 ; @ZOUT@("F","VAR2")=""
89 ; @ZOUT@("V",n,"VAR1",1)=VAL1
90 ; @ZOUT@("V",n,"VAR2",1)=VAL2
91 ; WHERE n IS THE "ROW" OF THE ARRAY
92 N ZI S ZI=""
93 N ZN
94 I '$D(@ZOUT@("V",1)) S ZN=1
95 E S ZN=$O(@ZOUT@("V",""),-1)+1
96 F S ZI=$O(@ZIN@(ZI)) Q:ZI="" D ;
97 . S @ZOUT@("F",ZI)=""
98 . S @ZOUT@("V",ZN,ZI,1)=@ZIN@(ZI)
99 Q
100 ;
101GETNOLD(GRTN,GFILE,GIEN,GNN) ; GET FIELDS FOR ACCESS BY NAME
102 ; GRTN IS PASSED BY NAME
103 ;
104 N C0CTMP,C0CI,C0CJ,C0CREF,C0CNAME
105 I $D(GNN) I GNN="ALL" S C0CNN=0 ; NOT NON-NULL (ALL FIELDS TO BE RETURNED)
106 E S C0CNN=1 ; NON-NULL IS TRUE (ONLY POPULATED FIELDS RETURNED)
107 S C0CREF=GIEN_"," ; OPEN ROOT REFERENCE INTO FILE
108 D CLEAN^DILF ; MAKE SURE WE ARE CLEANED UP
109 D GETS^DIQ(GFILE,C0CREF,"**","I","C0CTMP")
110 D FIELDS(GRTN,GFILE) ;GET ALL THE FIELD NAMES FOR THE FILE
111 S @GRTN@(0)=GFILE_"^RNF1^"_GIEN_"^"_DT_"^"_$J ; STRUCTURE SIGNATURE
112 S (C0CI,C0CJ)=""
113 F S C0CJ=$O(C0CTMP(C0CJ)) Q:C0CJ="" D ; FOR ALL SUBFILES
114 . S C0CREF=$O(C0CTMP(C0CJ,"")) ; RECORD REFERENCE
115 . F S C0CI=$O(C0CTMP(C0CJ,C0CREF,C0CI)) Q:C0CI="" D ; ARRAY OF FIELDS
116 . . ;W C0CJ," ",C0CI,!
117 . . S C0CNAME=$P(^DD(C0CJ,C0CI,0),"^",1) ;PULL THE FIELD NAME
118 . . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI) ;
119 . . I C0CVALUE["C0CTMP" S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,1) ;1ST LINE OF WP
120 . . S $P(@GRTN@(C0CNAME),"^",3)=C0CVALUE ;RETURN VALUE IN P3
121 I C0CNN D ; IF ONLY NON-NULL VALUES ARE TO BE RETURNED
122 . S C0CI=""
123 . F S C0CI=$O(@GRTN@(C0CI)) Q:C0CI="" D ; GO THROUGH THE WHOLE ARRAY
124 . . I $P(@GRTN@(C0CI),"^",3)="" K @GRTN@(C0CI) ; KILL THE NULL ENTRIES
125 Q
126 ;
127GETN(GRTN,GFILE,GREF,GNDX,GNN) ; GET BY NAME ; RETURN A FIELD VALUE MAP
128 ; THE FOLLOWING COMMENTS ARE WRONG.. THIS ROUTINE STILL RETURNS AN RNF1
129 ; FORMAT ARRAY @GRTN@("FIELD NAME")="FILE^FIELD#^VALUE" ;GPL
130 ; GETN IS AN EXTRINSIC WHICH RETURNS THE NEXT IEN AFTER THE CURRENT GIEN
131 ; GRTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
132 ; .. FIELD MAP @GRTN@("F","FIELDNAME^FILE^FIELD#")=""
133 ; ... ANY FIELD USED BY ANY RECORD PROCESSED IS IN THE FIELD MAP
134 ; .. VALUE MAP @GRTN@("V","IEN","FIELDNAME")=VALUE
135 ; .. GRTN IS NOT INITIALIZED, SO MULTIPLE CALLS ARE CUMULATIVE
136 ; .. IF GNN="ALL" THEN ALL FIELDS FOR THE FILE ARE IN THE FIELD MAP
137 ; .. EVEN IF GNN="ALL" ONLY POPULATED FIELDS ARE RETURNED IN THE VALUE MAP
138 ; .. NUL FIELDS CAN BE DETERMINED BY CHECKING FIELD MAP - THIS SAVES SPACE
139 ; IF GREF IS "" THE FIRST RECORD IS OBTAINED
140 ; IF GNDX IS NULL, GREF IS AN IEN FOR THE FILE
141 ; GNDX IS THE INDEX TO USE TO OBTAIN THE IEN
142 ; GREF IS THE VALUE FOR THE INDEX
143 ; GANN= NOT NULL - IF GANN IS "ALL" THEN EVEN NULL FIELDS WILL BE RETURNED
144 ; OTHERWISE, ONLY POPULATED FIELDS ARE RETURNED IN GRTN
145 ;
146 ;
147 N GIEN,GF
148 S GF=$$FILEREF(GFILE) ;CLOSED FILE REFERENCE FOR FILE NUMBER GFILE
149 I ('$D(GNDX))!($G(GNDX)="") S GIEN=GREF ; IF NO INDEX USED, GREF IS THE IEN
150 E D ; WE ARE USING AN INDEX
151 . ;N ZG
152 . S ZG=$Q(@GF@(GNDX,GREF)) ;ACCESS INDEX
153 . I ZG'="" D ;
154 . . I $QS(ZG,3)=GREF D ; IS GREF IN INDEX?
155 . . . S GIEN=$QS(ZG,4) ; PULL OUT THE IEN
156 . . E S GIEN="" ; NOT FOUND IN INDEX
157 . E S GIEN="" ;
158 ;W "IEN: ",GIEN,!
159 ;N C0CTMP,C0CI,C0CJ,C0CREF,C0CNAME
160 I $D(GNN) I GNN="ALL" S C0CNN=0 ; NOT NON-NULL (ALL FIELDS TO BE RETURNED)
161 E S C0CNN=1 ; NON-NULL IS TRUE (ONLY POPULATED FIELDS RETURNED)
162 S C0CREF=GIEN_"," ; OPEN ROOT REFERENCE INTO FILE
163 D CLEAN^DILF ; MAKE SURE WE ARE CLEANED UP
164 K C0CTMP
165 D GETS^DIQ(GFILE,C0CREF,"**","IE","C0CTMP")
166 D FIELDS(GRTN,GFILE) ;GET ALL THE FIELD NAMES FOR THE FILE
167 S @GRTN@(0)=GFILE_"^RNF1^"_GIEN_"^"_DT_"^"_$J_"^"_DUZ ; STRUCTURE SIGNATURE
168 S (C0CI,C0CJ)=""
169 F S C0CJ=$O(C0CTMP(C0CJ)) Q:C0CJ="" D ; FOR ALL SUBFILES
170 . S C0CREF=$O(C0CTMP(C0CJ,"")) ; RECORD REFERENCE
171 . F S C0CI=$O(C0CTMP(C0CJ,C0CREF,C0CI)) Q:C0CI="" D ; ARRAY OF FIELDS
172 . . ;W C0CJ," ",C0CI,!
173 . . S C0CNAME=$P(^DD(C0CJ,C0CI,0),"^",1) ;PULL THE FIELD NAME
174 . . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,"E") ;
175 . . I C0CVALUE["C0CTMP" D ; WP FIELD
176 . . . N ZT,ZWP S ZWP=0 ;ITERATOR
177 . . . S ZWP=$O(C0CTMP(C0CJ,C0CREF,C0CI,ZWP)) ; INIT TO FIRST LINE
178 . . . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,ZWP) ; INIT TO FIRST LINE
179 . . . F S ZWP=$O(C0CTMP(C0CJ,C0CREF,C0CI,ZWP)) Q:'ZWP D ;
180 . . . . S ZT=" "_C0CTMP(C0CJ,C0CREF,C0CI,ZWP) ;LINE OF WP
181 . . . . S ZT=$TR(ZT,"^""","|'") ;HACK TO GET RID OF ^ AND " IN TEXT "
182 . . . . S C0CVALUE=C0CVALUE_ZT ;
183 . . S $P(@GRTN@(C0CNAME),"^",3)=C0CVALUE ;RETURN VALUE IN P3
184 . . S $P(@GRTN@(C0CNAME,"I"),"^",3)=$G(C0CTMP(C0CJ,C0CREF,C0CI,"I"))
185 I C0CNN D ; IF ONLY NON-NULL VALUES ARE TO BE RETURNED
186 . S C0CI=""
187 . F S C0CI=$O(@GRTN@(C0CI)) Q:C0CI="" D ; GO THROUGH THE WHOLE ARRAY
188 . . I $P(@GRTN@(C0CI),"^",3)="" K @GRTN@(C0CI) ; KILL THE NULL ENTRIES
189 Q
190 ;
191GETN1(GRTN,GFILE,GREF,GNDX,GNN) ; NEW GET ;GPL ; RETURN A FIELD VALUE MAP
192 ; THE FOLLOWING COMMENTS ARE WRONG.. THIS ROUTINE STILL RETURNS AN RNF1
193 ; FORMAT ARRAY @GRTN@("FIELD NAME")="FILE^FIELD#^VALUE" ;GPL
194 ; GETN IS AN EXTRINSIC WHICH RETURNS THE NEXT IEN AFTER THE CURRENT GIEN
195 ; GRTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
196 ; .. FIELD MAP @GRTN@("F","FIELDNAME^FILE^FIELD#")=""
197 ; ... ANY FIELD USED BY ANY RECORD PROCESSED IS IN THE FIELD MAP
198 ; .. VALUE MAP @GRTN@("V","IEN","FIELDNAME")=VALUE
199 ; .. GRTN IS NOT INITIALIZED, SO MULTIPLE CALLS ARE CUMULATIVE
200 ; .. IF GNN="ALL" THEN ALL FIELDS FOR THE FILE ARE IN THE FIELD MAP
201 ; .. EVEN IF GNN="ALL" ONLY POPULATED FIELDS ARE RETURNED IN THE VALUE MAP
202 ; .. NUL FIELDS CAN BE DETERMINED BY CHECKING FIELD MAP - THIS SAVES SPACE
203 ; IF GREF IS "" THE FIRST RECORD IS OBTAINED
204 ; IF GNDX IS NULL, GREF IS AN IEN FOR THE FILE
205 ; GNDX IS THE INDEX TO USE TO OBTAIN THE IEN
206 ; GREF IS THE VALUE FOR THE INDEX
207 ; GANN= NOT NULL - IF GANN IS "ALL" THEN EVEN NULL FIELDS WILL BE RETURNED
208 ; OTHERWISE, ONLY POPULATED FIELDS ARE RETURNED IN GRTN
209 ;
210 ;
211 N GIEN,GF
212 S GF=$$FILEREF(GFILE) ;CLOSED FILE REFERENCE FOR FILE NUMBER GFILE
213 I ('$D(GNDX))!(GNDX="") S GIEN=GREF ; IF NO INDEX USED, GREF IS THE IEN
214 E D ; WE ARE USING AN INDEX
215 . ;N ZG
216 . S ZG=$Q(@GF@(GNDX,GREF)) ;ACCESS INDEX
217 . I ZG'="" D ;
218 . . I $QS(ZG,3)=GREF D ; IS GREF IN INDEX?
219 . . . S GIEN=$QS(ZG,4) ; PULL OUT THE IEN
220 . . E S GIEN="" ; NOT FOUND IN INDEX
221 . E S GIEN="" ;
222 ;W "IEN: ",GIEN,!
223 ;N C0CTMP,C0CI,C0CJ,C0CREF,C0CNAME
224 I $D(GNN) I GNN="ALL" S C0CNN=0 ; NOT NON-NULL (ALL FIELDS TO BE RETURNED)
225 E S C0CNN=1 ; NON-NULL IS TRUE (ONLY POPULATED FIELDS RETURNED)
226 S C0CREF=GIEN_"," ; OPEN ROOT REFERENCE INTO FILE
227 D CLEAN^DILF ; MAKE SURE WE ARE CLEANED UP
228 K C0CTMP
229 D GETS^DIQ(GFILE,C0CREF,"**","IE","C0CTMP")
230 D FIELDS(GRTN,GFILE) ;GET ALL THE FIELD NAMES FOR THE FILE
231 S @GRTN@(0)=GFILE_"^RNF1^"_GIEN_"^"_DT_"^"_$J_"^"_DUZ ; STRUCTURE SIGNATURE
232 S (C0CI,C0CJ)=""
233 F S C0CJ=$O(C0CTMP(C0CJ)) Q:C0CJ="" D ; FOR ALL SUBFILES
234 . S C0CREF=$O(C0CTMP(C0CJ,"")) ; RECORD REFERENCE
235 . F S C0CI=$O(C0CTMP(C0CJ,C0CREF,C0CI)) Q:C0CI="" D ; ARRAY OF FIELDS
236 . . ;W C0CJ," ",C0CI,!
237 . . S C0CNAME=$P(^DD(C0CJ,C0CI,0),"^",1) ;PULL THE FIELD NAME
238 . . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,"E") ;
239 . . I C0CVALUE["C0CTMP" D ; WP FIELD
240 . . . N ZT,ZWP S ZWP=0 ;ITERATOR
241 . . . S ZWP=$O(C0CTMP(C0CJ,C0CREF,C0CI,ZWP)) ; INIT TO FIRST LINE
242 . . . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,ZWP) ; INIT TO FIRST LINE
243 . . . F S ZWP=$O(C0CTMP(C0CJ,C0CREF,C0CI,ZWP)) Q:'ZWP D ;
244 . . . . S ZT=" "_C0CTMP(C0CJ,C0CREF,C0CI,ZWP) ;LINE OF WP
245 . . . . S ZT=$TR(ZT,"^""","|'") ;HACK TO GET RID OF ^ AND " IN TEXT "
246 . . . . S C0CVALUE=C0CVALUE_ZT ;
247 . . S $P(@GRTN@(C0CNAME),"^",3)=C0CVALUE ;RETURN VALUE IN P3
248 . . S $P(@GRTN@(C0CNAME,"I"),"^",3)=$G(C0CTMP(C0CJ,C0CREF,C0CI,"I"))
249 I C0CNN D ; IF ONLY NON-NULL VALUES ARE TO BE RETURNED
250 . S C0CI=""
251 . F S C0CI=$O(@GRTN@(C0CI)) Q:C0CI="" D ; GO THROUGH THE WHOLE ARRAY
252 . . I $P(@GRTN@(C0CI),"^",3)="" K @GRTN@(C0CI) ; KILL THE NULL ENTRIES
253 Q
254 ;
255GETN2(GARTN,GAFILE,GAIDX,GACNT,GASTRT,GANN) ; RETURN FIELD MAP AND VALUES
256 ; GARTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
257 ; .. FIELD MAP @GARTN@("F","FIELDNAME")="FILE;FIELD#"
258 ; ... ANY FIELD USED BY ANY RECORD PROCESSED IS IN THE FIELD MAP
259 ; .. VALUE MAP @GARTN@("V","IEN","FIELDNAME","N")=VALUE
260 ; .. WHERE N IS THE INDEX FOR MULTIPLES.. 1 FOR SINGLE VALUES
261 ; .. GARTN IS NOT INITIALIZED, SO MULTIPLE CALLS ARE CUMULATIVE
262 ; .. IF GANN="ALL" THEN ALL FIELDS FOR THE FILE ARE IN THE FIELD MAP
263 ; .. EVEN IF GANN="ALL" ONLY POPULATED FIELDS ARE RETURNED IN THE VALUE MAP
264 ; .. NUL FIELDS CAN BE DETERMINED BY CHECKING FIELD MAP - THIS SAVES SPACE
265 ; GAFILE IS THE FILE NUMBER TO BE PROCESSED. IT IS PASSED BY VALUE
266 ; GAIDX IS THE OPTIONAL INDEX TO USE IN THE FILE. IF GAIDX IS "" THE IEN
267 ; .. OF THE FILE WILL BE USED
268 ; GACNT IS THE NUMBER OF RECORDS TO PROCESS. IT IS PASSED BY VALUE
269 ; .. IF GARCNT IS NULL, ALL RECORDS ARE PROCESSED
270 ; GASTRT IS THE IEN OF THE FIRST RECORD TO PROCESS. IT IS PASSED BY VALUE
271 ; .. IF GARSTART IS NULL, PROCESSING STARTS AT THE FIRST RECORD
272 ; GANN= NOT NULL - IF GANN IS "ALL" THEN EVEN NULL FIELDS WILL BE RETURNED
273 ; OTHERWISE, ONLY POPULATED FIELDS ARE RETURNED IN GARFLD AND GARVAL
274 ;N GATMP,GAI,GAF
275 S GAF=$$FILEREF(GAFILE) ; GET CLOSED ROOT FOR THE FILE NUMBER GAFILE
276 I '$D(GAIDX) S GAIDX="" ;DEFAULT
277 I '$D(GANN) S GANN="" ;DEFAULT ONLY POPULATED FIELDS RETURNED
278 I GAIDX'="" S GAF=$NA(@GAF@(GAIDX)) ; IF WE ARE USING AN INDEX
279 W GAF,!
280 W $O(@GAF@(0)) ;
281 S GAI=0 ;ITERATOR
282 F S GAI=$O(@GAF@(GAI)) Q:GAI="" D ;
283 . D GETN1("GATMP",GAFILE,GAI,GAIDX,GANN) ;GET ONE RECORD
284 . N GAX S GAX=0
285 . F S GAX=$O(GATMP(GAX)) Q:GAX="" D ;PULL OUT THE FIELDS
286 . . D ADDNV(GARTN,GAI,GAX,GATMP(GAX)) ;INSERT THE NAME/VALUE INTO GARTN
287 Q
288 ;
289ADDNV(GNV,GNVN,GNVF,GNVV) ; CREATE AN ELEMENT OF THE MATRIX
290 ;
291 S @GNV@("F",GNVF)=$P(GNVV,"^",1)_"^"_$P(GNVV,"^",2) ;NAME=FILE^FIELD#
292 S @GNV@("V",GNVN,GNVF,1)=$P(GNVV,"^",3) ;SET THE VALUE
293 Q
294 ;
295RNF2CSV(RNRTN,RNIN,RNSTY) ;CONVERTS AN RFN2 GLOBAL TO A CSV FORMAT
296 ; READY TO WRITE FOR USE WITH EXCEL @RNRTN@(0) IS NUMBER OF LINES
297 ; RNSTY IS STYLE OF THE OUTPUT -
298 ; .. "NV"= ROWS ARE NAMES, COLUMNS ARE VALUES
299 ; .. "VN"= ROWS ARE VALUES, COLUMNS ARE NAMES
300 ; .. DEFAULT IS "NV" BECAUSE MANY MATRICES HAVE MORE FIELDS THAN VALUES
301 N RNR,RNC ;ROW ROOT,COL ROOT
302 N RNI,RNJ,RNX
303 I '$D(RNSTY) S RNSTY="NV" ;DEFAULT
304 I RNSTY="NV" D NV(RNRTN,RNIN) ; INTERNAL SUBROUTINES DEPENDING ON ORIENTATION
305 E D VN(RNRTN,RNIN) ;
306 Q
307 ;
308NV(RNRTN,RNIN) ;
309 S RNR=$NA(@RNIN@("F"))
310 S RNC=$NA(@RNIN@("V"))
311 ;S RNY=$P(@RNIN@(0),"^",1) ; FILE NUMBER
312 S RNX="""FILE"""_"," ; FIRST COLUMN NAME IS "FIELD"
313 S RNI=""
314 F S RNI=$O(@RNC@(RNI)) Q:RNI="" D ; FOR EACH COLUMN
315 . S RNX=RNX_RNI_"," ;ADD THE COLUMM ELEMENT AND A COMMA
316 S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
317 D PUSH^C0CXPATH(RNRTN,RNX) ; FIRST LINE CONTAINS COLUMN HEADINGS
318 S RNI=""
319 F S RNI=$O(@RNR@(RNI)) Q:RNI="" D ; FOR EACH ROW
320 . S RNX=""""_RNI_""""_"," ; FIRST ELEMENT ON ROW IS THE FIELD
321 . S RNJ=""
322 . F S RNJ=$O(@RNC@(RNJ)) Q:RNJ="" D ; FOR EACH COL
323 . . I $D(@RNC@(RNJ,RNI,1)) D ; THIS ROW HAS THIS COLUMN
324 . . . S RNX=RNX_""""_@RNC@(RNJ,RNI,1)_""""_"," ; ADD THE ELEMENT PLUS A COMMA
325 . . E S RNX=RNX_"," ; NUL COLUMN
326 . S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
327 . D PUSH^C0CXPATH(RNRTN,RNX)
328 Q
329 ;
330VN(RNRTN,RNIN) ;
331 S RNR=$NA(@RNIN@("V"))
332 S RNC=$NA(@RNIN@("F"))
333 ;S RNY=$P(@RNIN@(0),"^",1) ; FILE NUMBER
334 S RNX="""ROW"""_"," ; FIRST COLUMN NAME IS "ROW"
335 S RNI=""
336 F S RNI=$O(@RNC@(RNI)) Q:RNI="" D ; FOR EACH COLUMN
337 . S RNX=RNX_RNI_"," ;ADD THE COLUMM ELEMENT AND A COMMA
338 S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
339 D PUSH^C0CXPATH(RNRTN,RNX) ; FIRST LINE CONTAINS COLUMN HEADINGS
340 S RNI=""
341 F S RNI=$O(@RNR@(RNI)) Q:RNI="" D ; FOR EACH ROW
342 . S RNX=""""_RNI_""""_"," ; FIRST ELEMENT ON ROW IS THE FIELD
343 . S RNJ=""
344 . F S RNJ=$O(@RNC@(RNJ)) Q:RNJ="" D ; FOR EACH COL
345 . . I $D(@RNR@(RNI,RNJ,1)) D ; THIS ROW HAS THIS COLUMN
346 . . . S RNV=$TR(@RNR@(RNI,RNJ,1),"""","")
347 . . . S RNV=$TR(RNV,",","")
348 . . . S RNX=RNX_""""_RNV_""""_"," ; ADD THE ELEMENT PLUS A COMMA
349 . . E S RNX=RNX_"," ; NUL COLUMN
350 . S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
351 . D PUSH^C0CXPATH(RNRTN,RNX)
352 Q
353 ;
354READCSV(PATH,NAME,GLB) ; READ A CSV FILE IN FROM UNIX TO GLB, PASSED BY NAME
355 ;
356 Q $$FTG^%ZISH(PATH,NAME,GLB,1)
357 ;
358FILE2CSV(FNUM,FVN) ; WRITES OUT A FILEMAN FILE TO CSV
359 ;
360 ;N G1,G2
361 I '$D(FVN) S FVN="NV" ; DEFAULT ORIENTATION OF CVS FILE
362 S G1=$NA(^TMP($J,"C0CCSV",1))
363 S G2=$NA(^TMP($J,"C0CCSV",2))
364 D GETN2(G1,FNUM) ; GET THE MATRIX
365 D RNF2CSV(G2,G1,FVN) ; PREPARE THE CVS FILE
366 K @G1
367 D FILEOUT(G2,"FILE_"_FNUM_".csv")
368 K @G2
369 Q
370 ;
371FILEOUT(FOARY,FONAM) ; WRITE OUT A FILE
372 ;
373 W $$OUTPUT^C0CXPATH($NA(@FOARY@(1)),FONAM,^TMP("C0CCCR","ODIR"))
374 Q
375 ;
376FILEREF(FNUM) ; EXTRINSIC THAT RETURNS A CLOSED ROOT FOR FILE NUMBER FNUM
377 ;
378 N C0CF
379 S C0CF=^DIC(FNUM,0,"GL") ;OPEN ROOT TO FILE
380 S C0CF=$P(C0CF,",",1)_")" ; CLOSE THE ROOT
381 I C0CF["()" S C0CF=$P(C0CF,"()",1)
382 Q C0CF
383 ;
384SKIP ;
385 N TXT,DIERR
386 S TXT=$$GET1^DIQ(8925,TIUIEN,"2","","TXT")
387 I $D(DIERR) D CLEAN^DILF Q
388 W " report_text:",! ;Progress Note Text
389 N LN S LN=0
390 F S LN=$O(TXT(LN)) Q:'LN D
391 . W " text"_LN_": "_TXT(LN),!
392 . Q
393 Q
394 ;
395RNF2HNV(ZOUT,ZIN) ;RETURN AN HTML TABLE IN ZOUT, PASSED BY NAME
396 ; OF ZIN, WHICH IS PASSED BY NAME AND IS IN RNF2 FORMAT
397 ; ZOUT IS NOT INITIALIZED, SO THE TABLE WILL GO AT THE END
398 ; THE TABLE WILL BE IN NV FORMAT, ROWS ARE NAMES COLUMNS ARE VALUES
399 D PUSH^C0CXPATH(ZOUT,"<table border=""1"">")
400 N ZI,ZJ,ZV,ZN S ZI="" S ZJ=0
401 D PUSH^C0CXPATH(ZOUT,"<tr><td></td>") ;begin row and leave a blank col
402 F S ZJ=$O(@ZIN@("V",ZJ)) Q:+ZJ=0 D ; FOR EACH OCCURANCE
403 . S ZV="<td>"_ZJ_"</td>" ; OCCURANCE AS COLUMNS HEADER
404 . D PUSH^C0CXPATH(ZOUT,ZV)
405 D PUSH^C0CXPATH(ZOUT,"</tr>") ;end of first row
406 S ZI=""
407 F S ZI=$O(@ZIN@("F",ZI)) Q:ZI="" D ; FOR EACH VARIABLE
408 . S ZN="<tr><td>"_ZI_"</td>" ; VARIABLE NAME IN FIRST COLUMN
409 . D PUSH^C0CXPATH(ZOUT,ZN)
410 . S ZJ=0 ;RESET TO DO IT AGAIN
411 . F S ZJ=$O(@ZIN@("V",ZJ)) Q:+ZJ=0 D ; FOR EACH OCCURANCE
412 . . S ZV="<td>"_$G(@ZIN@("V",ZJ,ZI,1))_"</td>"
413 . . D PUSH^C0CXPATH(ZOUT,ZV)
414 . D PUSH^C0CXPATH(ZOUT,"</tr>") ;END OF ROW
415 D PUSH^C0CXPATH(ZOUT,"</table>") ; end of table
416 Q
417 ;
418RNF2HVN(ZOUT,ZIN) ;RETURN AN HTML TABLE IN ZOUT, PASSED BY NAME
419 ; OF ZIN, WHICH IS PASSED BY NAME AND IS IN RNF2 FORMAT
420 ; ZOUT IS NOT INITIALIZED, SO THE TABLE WILL GO AT THE END
421 ; THE TABLE WILL BE IN VN FORMAT, ROWS ARE VALUES COLUMNS ARE NAMES
422 D PUSH^C0CXPATH(ZOUT,"<table border=""1"">")
423 N ZI,ZJ S ZI="" S ZJ=0
424 D PUSH^C0CXPATH(ZOUT,"<tr>") ;new row for column headers
425 F S ZI=$O(@ZIN@("F",ZI)) Q:ZI="" D ; FOR EACH VARIABLE
426 . S ZV="<td>"_ZI_"</td>"
427 . D PUSH^C0CXPATH(ZOUT,ZV) ; name
428 D PUSH^C0CXPATH(ZOUT,"</tr>") ; end header row
429 S ZI="" ;RESET TO DO AGAIN
430 F S ZJ=$O(@ZIN@("V",ZJ)) Q:+ZJ=0 D ; FOR EACH ROW OF VARIABLES
431 . D PUSH^C0CXPATH(ZOUT,"<tr>") ;begin row
432 . F S ZI=$O(@ZIN@("F",ZI)) Q:ZI="" D ; FOR EACH VARIABLE
433 . . S ZV="<td>"_$G(@ZIN@("V",ZJ,ZI,1))_"</td>" ; value
434 . . D PUSH^C0CXPATH(ZOUT,ZV) ; value
435 . D PUSH^C0CXPATH(ZOUT,"</tr>") ; end header
436 D PUSH^C0CXPATH(ZOUT,"</table>") ;end of table
437 Q
438 ;
439ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
440 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 1 OF @ZTAB@(ZFN)
441 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
442 I '$D(ZTAB) S ZTAB="C0CA"
443 Q $P(@ZTAB@(ZFN),"^",1)
444ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
445 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 2 OF @ZTAB@(ZFN)
446 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
447 I '$D(ZTAB) S ZTAB="C0CA"
448 Q $P(@ZTAB@(ZFN),"^",2)
449ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
450 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF @ZTAB@(ZFN)
451 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
452 I '$D(ZTAB) S ZTAB="C0CA"
453 Q $P($G(@ZTAB@(ZFN)),"^",3)
454 ;
455ZVALUEI(ZFN,ZTAB) ;EXTRINSIC TO RETURN INTERNAL VALUE FOR FIELD NAME PASSED
456 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF @ZTAB@(ZFN)
457 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
458 I '$D(ZTAB) S ZTAB="C0CA"
459 Q $P($G(@ZTAB@(ZFN,"I")),"^",3)
460 ;
Note: See TracBrowser for help on using the repository browser.