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

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

some new RNF processing tools

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