2009-05-21 13:12:11 -04:00
|
|
|
C0CRNF ; CCDCCR/GPL - Reference Name Format (RNF) utilities; 12/6/08
|
|
|
|
;;1.0;C0C;;May 19, 2009;
|
2009-03-16 18:08:55 -04:00
|
|
|
;Copyright 2009 George Lilly. Licensed under the terms of the GNU
|
2008-12-06 20:50:51 -05:00
|
|
|
;General Public License See attached copy of the License.
|
|
|
|
;
|
|
|
|
;This program is free software; you can redistribute it and/or modify
|
|
|
|
;it under the terms of the GNU General Public License as published by
|
|
|
|
;the Free Software Foundation; either version 2 of the License, or
|
|
|
|
;(at your option) any later version.
|
|
|
|
;
|
|
|
|
;This program is distributed in the hope that it will be useful,
|
|
|
|
;but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;GNU General Public License for more details.
|
|
|
|
;
|
|
|
|
;You should have received a copy of the GNU General Public License along
|
|
|
|
;with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
;
|
|
|
|
W "This is the Reference Name Format (RNF) Utility Library ",!
|
|
|
|
W !
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
FIELDS(C0CFRTN,C0CF) ; RETURNS AN ARRAY OF THE FIELDS IN FILE C0CF,
|
2008-12-06 20:50:51 -05:00
|
|
|
; C0CFRTN IS PASSED BY NAME, C0CF IS PASSED BY VALUE
|
|
|
|
;
|
|
|
|
N C0CFI,C0CFJ ;INNER LOOP, OUTER LOOP
|
|
|
|
N C0CFN ; FIELD NAME
|
|
|
|
S C0CFI=0 S C0CFJ=C0CF
|
|
|
|
K @C0CFRTN ; CLEAR THE RETURN ARRAY
|
|
|
|
F Q:C0CFJ'[C0CF D ; FOR THE C0CF FILE AND ALL SUBFILES INCLUSIVE
|
|
|
|
. ;W "1: "_C0CFJ," ",C0CFI,!
|
|
|
|
. F S C0CFI=$O(^DD(C0CFJ,C0CFI)) Q:+C0CFI=0 D ; EVERY FIELD
|
|
|
|
. . ;W "2: "_C0CFJ," ",C0CFI,!
|
2009-01-25 15:53:20 -05:00
|
|
|
. . S C0CFN=$P($G(^DD(C0CFJ,C0CFI,0)),"^",1) ;PULL FIELD NAME FROM ^DD
|
2008-12-06 20:50:51 -05:00
|
|
|
. . ;W "N: ",C0CFN,!
|
|
|
|
. . ;I C0CFN="STR" W C0CFN," ",C0CFJ,!
|
|
|
|
. . I $D(@C0CFRTN@(C0CFN)) D ; IS THIS A DUPLICATE?
|
2009-04-03 12:11:29 -04:00
|
|
|
. . . I DEBUG D ;
|
|
|
|
. . . . W "DUPLICATE FOUND! ",C0CFJ," ",C0CFI," ",C0CFN,!,@C0CFRTN@(C0CFN),!
|
2008-12-06 20:50:51 -05:00
|
|
|
. . . S @C0CFRTN@(C0CFN_"_"_C0CFJ)=C0CFJ_"^"_C0CFI
|
|
|
|
. . E S @C0CFRTN@(C0CFN)=C0CFJ_"^"_C0CFI
|
|
|
|
. S C0CFJ=$O(^DD(C0CFJ)) ; NEXT SUBFILE
|
|
|
|
Q
|
|
|
|
;
|
2010-01-22 02:45:25 -05:00
|
|
|
TESTRNF ; TEST THE RNF1TO2 ROUTINE
|
|
|
|
S G1("ONE")=1
|
|
|
|
S G1("TWO")=2
|
|
|
|
S G1("THREE")=3
|
|
|
|
D RNF1TO2("GPL","G1")
|
|
|
|
S G1("ONE")="NOT1"
|
|
|
|
S G1("TWO")="STILL2"
|
|
|
|
S G1("THREE")=3
|
|
|
|
D RNF1TO2("GPL","G1")
|
|
|
|
ZWR GPL
|
|
|
|
Q
|
|
|
|
;
|
|
|
|
RNF1TO2(ZOUT,ZIN) ; ADDS AN RNF1 ARRAY (ZIN) TO THE END OF AN RNF2 ARRAY
|
|
|
|
; (ZOUT) BOTH ARE PASSED BY NAME
|
|
|
|
; RNF1 IS OF THE FORM:
|
|
|
|
; @ZIN@("VAR1")=VAL1
|
|
|
|
; @ZIN@("VAR2")=VAL2
|
|
|
|
; RNF2 IS OF THE FORM:
|
|
|
|
; @ZOUT@("F","VAR1")=""
|
|
|
|
; @ZOUT@("F","VAR2")=""
|
|
|
|
; @ZOUT@("V",n,"VAR1")=VAL1
|
|
|
|
; @ZOUT@("V",n,"VAR2")=VAL2
|
|
|
|
; WHERE n IS THE "ROW" OF THE ARRAY
|
|
|
|
N ZI S ZI=""
|
|
|
|
N ZN
|
|
|
|
I '$D(@ZOUT@("V",1)) S ZN=1
|
|
|
|
E S ZN=$O(@ZOUT@("V",""),-1)+1
|
|
|
|
F S ZI=$O(@ZIN@(ZI)) Q:ZI="" D ;
|
|
|
|
. S @ZOUT@("F",ZI)=""
|
|
|
|
. S @ZOUT@("V",ZN,ZI)=@ZIN@(ZI)
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
GETNOLD(GRTN,GFILE,GIEN,GNN) ; GET FIELDS FOR ACCESS BY NAME
|
2008-12-08 12:59:46 -05:00
|
|
|
; GRTN IS PASSED BY NAME
|
2008-12-06 20:50:51 -05:00
|
|
|
;
|
|
|
|
N C0CTMP,C0CI,C0CJ,C0CREF,C0CNAME
|
|
|
|
I $D(GNN) I GNN="ALL" S C0CNN=0 ; NOT NON-NULL (ALL FIELDS TO BE RETURNED)
|
|
|
|
E S C0CNN=1 ; NON-NULL IS TRUE (ONLY POPULATED FIELDS RETURNED)
|
|
|
|
S C0CREF=GIEN_"," ; OPEN ROOT REFERENCE INTO FILE
|
|
|
|
D CLEAN^DILF ; MAKE SURE WE ARE CLEANED UP
|
2009-01-25 15:29:07 -05:00
|
|
|
D GETS^DIQ(GFILE,C0CREF,"**","I","C0CTMP")
|
2008-12-06 20:50:51 -05:00
|
|
|
D FIELDS(GRTN,GFILE) ;GET ALL THE FIELD NAMES FOR THE FILE
|
2008-12-09 17:19:48 -05:00
|
|
|
S @GRTN@(0)=GFILE_"^RNF1^"_GIEN_"^"_DT_"^"_$J ; STRUCTURE SIGNATURE
|
2008-12-06 20:50:51 -05:00
|
|
|
S (C0CI,C0CJ)=""
|
|
|
|
F S C0CJ=$O(C0CTMP(C0CJ)) Q:C0CJ="" D ; FOR ALL SUBFILES
|
|
|
|
. S C0CREF=$O(C0CTMP(C0CJ,"")) ; RECORD REFERENCE
|
|
|
|
. F S C0CI=$O(C0CTMP(C0CJ,C0CREF,C0CI)) Q:C0CI="" D ; ARRAY OF FIELDS
|
|
|
|
. . ;W C0CJ," ",C0CI,!
|
|
|
|
. . S C0CNAME=$P(^DD(C0CJ,C0CI,0),"^",1) ;PULL THE FIELD NAME
|
|
|
|
. . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI) ;
|
|
|
|
. . I C0CVALUE["C0CTMP" S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,1) ;1ST LINE OF WP
|
|
|
|
. . S $P(@GRTN@(C0CNAME),"^",3)=C0CVALUE ;RETURN VALUE IN P3
|
|
|
|
I C0CNN D ; IF ONLY NON-NULL VALUES ARE TO BE RETURNED
|
|
|
|
. S C0CI=""
|
|
|
|
. F S C0CI=$O(@GRTN@(C0CI)) Q:C0CI="" D ; GO THROUGH THE WHOLE ARRAY
|
|
|
|
. . I $P(@GRTN@(C0CI),"^",3)="" K @GRTN@(C0CI) ; KILL THE NULL ENTRIES
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
GETN(GRTN,GFILE,GREF,GNDX,GNN) ; GET BY NAME ; RETURN A FIELD VALUE MAP
|
2009-01-29 11:26:56 -05:00
|
|
|
; THE FOLLOWING COMMENTS ARE WRONG.. THIS ROUTINE STILL RETURNS AN RNF1
|
|
|
|
; FORMAT ARRAY @GRTN@("FIELD NAME")="FILE^FIELD#^VALUE" ;GPL
|
|
|
|
; GETN IS AN EXTRINSIC WHICH RETURNS THE NEXT IEN AFTER THE CURRENT GIEN
|
|
|
|
; GRTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
|
|
|
|
; .. FIELD MAP @GRTN@("F","FIELDNAME^FILE^FIELD#")=""
|
|
|
|
; ... ANY FIELD USED BY ANY RECORD PROCESSED IS IN THE FIELD MAP
|
|
|
|
; .. VALUE MAP @GRTN@("V","IEN","FIELDNAME")=VALUE
|
|
|
|
; .. GRTN IS NOT INITIALIZED, SO MULTIPLE CALLS ARE CUMULATIVE
|
|
|
|
; .. IF GNN="ALL" THEN ALL FIELDS FOR THE FILE ARE IN THE FIELD MAP
|
|
|
|
; .. EVEN IF GNN="ALL" ONLY POPULATED FIELDS ARE RETURNED IN THE VALUE MAP
|
|
|
|
; .. NUL FIELDS CAN BE DETERMINED BY CHECKING FIELD MAP - THIS SAVES SPACE
|
|
|
|
; IF GREF IS "" THE FIRST RECORD IS OBTAINED
|
|
|
|
; IF GNDX IS NULL, GREF IS AN IEN FOR THE FILE
|
|
|
|
; GNDX IS THE INDEX TO USE TO OBTAIN THE IEN
|
|
|
|
; GREF IS THE VALUE FOR THE INDEX
|
|
|
|
; GANN= NOT NULL - IF GANN IS "ALL" THEN EVEN NULL FIELDS WILL BE RETURNED
|
|
|
|
; OTHERWISE, ONLY POPULATED FIELDS ARE RETURNED IN GRTN
|
|
|
|
;
|
|
|
|
;
|
|
|
|
N GIEN,GF
|
|
|
|
S GF=$$FILEREF(GFILE) ;CLOSED FILE REFERENCE FOR FILE NUMBER GFILE
|
2009-08-27 12:22:58 -04:00
|
|
|
I ('$D(GNDX))!($G(GNDX)="") S GIEN=GREF ; IF NO INDEX USED, GREF IS THE IEN
|
2009-01-29 11:26:56 -05:00
|
|
|
E D ; WE ARE USING AN INDEX
|
|
|
|
. ;N ZG
|
|
|
|
. S ZG=$Q(@GF@(GNDX,GREF)) ;ACCESS INDEX
|
|
|
|
. I ZG'="" D ;
|
|
|
|
. . I $QS(ZG,3)=GREF D ; IS GREF IN INDEX?
|
|
|
|
. . . S GIEN=$QS(ZG,4) ; PULL OUT THE IEN
|
|
|
|
. . E S GIEN="" ; NOT FOUND IN INDEX
|
2009-03-16 18:08:55 -04:00
|
|
|
. E S GIEN="" ;
|
2009-01-29 11:26:56 -05:00
|
|
|
;W "IEN: ",GIEN,!
|
|
|
|
;N C0CTMP,C0CI,C0CJ,C0CREF,C0CNAME
|
|
|
|
I $D(GNN) I GNN="ALL" S C0CNN=0 ; NOT NON-NULL (ALL FIELDS TO BE RETURNED)
|
|
|
|
E S C0CNN=1 ; NON-NULL IS TRUE (ONLY POPULATED FIELDS RETURNED)
|
|
|
|
S C0CREF=GIEN_"," ; OPEN ROOT REFERENCE INTO FILE
|
|
|
|
D CLEAN^DILF ; MAKE SURE WE ARE CLEANED UP
|
|
|
|
K C0CTMP
|
|
|
|
D GETS^DIQ(GFILE,C0CREF,"**","IE","C0CTMP")
|
|
|
|
D FIELDS(GRTN,GFILE) ;GET ALL THE FIELD NAMES FOR THE FILE
|
|
|
|
S @GRTN@(0)=GFILE_"^RNF1^"_GIEN_"^"_DT_"^"_$J_"^"_DUZ ; STRUCTURE SIGNATURE
|
|
|
|
S (C0CI,C0CJ)=""
|
|
|
|
F S C0CJ=$O(C0CTMP(C0CJ)) Q:C0CJ="" D ; FOR ALL SUBFILES
|
|
|
|
. S C0CREF=$O(C0CTMP(C0CJ,"")) ; RECORD REFERENCE
|
|
|
|
. F S C0CI=$O(C0CTMP(C0CJ,C0CREF,C0CI)) Q:C0CI="" D ; ARRAY OF FIELDS
|
|
|
|
. . ;W C0CJ," ",C0CI,!
|
|
|
|
. . S C0CNAME=$P(^DD(C0CJ,C0CI,0),"^",1) ;PULL THE FIELD NAME
|
|
|
|
. . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,"E") ;
|
|
|
|
. . I C0CVALUE["C0CTMP" D ; WP FIELD
|
|
|
|
. . . N ZT,ZWP S ZWP=0 ;ITERATOR
|
|
|
|
. . . S ZWP=$O(C0CTMP(C0CJ,C0CREF,C0CI,ZWP)) ; INIT TO FIRST LINE
|
|
|
|
. . . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,ZWP) ; INIT TO FIRST LINE
|
|
|
|
. . . F S ZWP=$O(C0CTMP(C0CJ,C0CREF,C0CI,ZWP)) Q:'ZWP D ;
|
|
|
|
. . . . S ZT=" "_C0CTMP(C0CJ,C0CREF,C0CI,ZWP) ;LINE OF WP
|
|
|
|
. . . . S ZT=$TR(ZT,"^""","|'") ;HACK TO GET RID OF ^ AND " IN TEXT "
|
|
|
|
. . . . S C0CVALUE=C0CVALUE_ZT ;
|
|
|
|
. . S $P(@GRTN@(C0CNAME),"^",3)=C0CVALUE ;RETURN VALUE IN P3
|
|
|
|
. . S $P(@GRTN@(C0CNAME,"I"),"^",3)=$G(C0CTMP(C0CJ,C0CREF,C0CI,"I"))
|
|
|
|
I C0CNN D ; IF ONLY NON-NULL VALUES ARE TO BE RETURNED
|
|
|
|
. S C0CI=""
|
|
|
|
. F S C0CI=$O(@GRTN@(C0CI)) Q:C0CI="" D ; GO THROUGH THE WHOLE ARRAY
|
|
|
|
. . I $P(@GRTN@(C0CI),"^",3)="" K @GRTN@(C0CI) ; KILL THE NULL ENTRIES
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
GETN1(GRTN,GFILE,GREF,GNDX,GNN) ; NEW GET ;GPL ; RETURN A FIELD VALUE MAP
|
2008-12-16 14:10:26 -05:00
|
|
|
; THE FOLLOWING COMMENTS ARE WRONG.. THIS ROUTINE STILL RETURNS AN RNF1
|
|
|
|
; FORMAT ARRAY @GRTN@("FIELD NAME")="FILE^FIELD#^VALUE" ;GPL
|
2008-12-08 12:59:46 -05:00
|
|
|
; GETN IS AN EXTRINSIC WHICH RETURNS THE NEXT IEN AFTER THE CURRENT GIEN
|
|
|
|
; GRTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
|
|
|
|
; .. FIELD MAP @GRTN@("F","FIELDNAME^FILE^FIELD#")=""
|
|
|
|
; ... ANY FIELD USED BY ANY RECORD PROCESSED IS IN THE FIELD MAP
|
|
|
|
; .. VALUE MAP @GRTN@("V","IEN","FIELDNAME")=VALUE
|
|
|
|
; .. GRTN IS NOT INITIALIZED, SO MULTIPLE CALLS ARE CUMULATIVE
|
|
|
|
; .. IF GNN="ALL" THEN ALL FIELDS FOR THE FILE ARE IN THE FIELD MAP
|
|
|
|
; .. EVEN IF GNN="ALL" ONLY POPULATED FIELDS ARE RETURNED IN THE VALUE MAP
|
|
|
|
; .. NUL FIELDS CAN BE DETERMINED BY CHECKING FIELD MAP - THIS SAVES SPACE
|
2008-12-06 20:50:51 -05:00
|
|
|
; IF GREF IS "" THE FIRST RECORD IS OBTAINED
|
|
|
|
; IF GNDX IS NULL, GREF IS AN IEN FOR THE FILE
|
|
|
|
; GNDX IS THE INDEX TO USE TO OBTAIN THE IEN
|
|
|
|
; GREF IS THE VALUE FOR THE INDEX
|
|
|
|
; GANN= NOT NULL - IF GANN IS "ALL" THEN EVEN NULL FIELDS WILL BE RETURNED
|
|
|
|
; OTHERWISE, ONLY POPULATED FIELDS ARE RETURNED IN GRTN
|
|
|
|
;
|
2008-12-08 12:59:46 -05:00
|
|
|
;
|
|
|
|
N GIEN,GF
|
|
|
|
S GF=$$FILEREF(GFILE) ;CLOSED FILE REFERENCE FOR FILE NUMBER GFILE
|
2008-12-10 17:15:44 -05:00
|
|
|
I ('$D(GNDX))!(GNDX="") S GIEN=GREF ; IF NO INDEX USED, GREF IS THE IEN
|
2008-12-06 20:50:51 -05:00
|
|
|
E D ; WE ARE USING AN INDEX
|
2008-12-08 12:59:46 -05:00
|
|
|
. ;N ZG
|
|
|
|
. S ZG=$Q(@GF@(GNDX,GREF)) ;ACCESS INDEX
|
2009-01-29 11:26:56 -05:00
|
|
|
. I ZG'="" D ;
|
|
|
|
. . I $QS(ZG,3)=GREF D ; IS GREF IN INDEX?
|
|
|
|
. . . S GIEN=$QS(ZG,4) ; PULL OUT THE IEN
|
|
|
|
. . E S GIEN="" ; NOT FOUND IN INDEX
|
2009-03-16 18:08:55 -04:00
|
|
|
. E S GIEN="" ;
|
2009-01-29 11:26:56 -05:00
|
|
|
;W "IEN: ",GIEN,!
|
2009-01-19 18:24:00 -05:00
|
|
|
;N C0CTMP,C0CI,C0CJ,C0CREF,C0CNAME
|
2008-12-06 20:50:51 -05:00
|
|
|
I $D(GNN) I GNN="ALL" S C0CNN=0 ; NOT NON-NULL (ALL FIELDS TO BE RETURNED)
|
|
|
|
E S C0CNN=1 ; NON-NULL IS TRUE (ONLY POPULATED FIELDS RETURNED)
|
|
|
|
S C0CREF=GIEN_"," ; OPEN ROOT REFERENCE INTO FILE
|
|
|
|
D CLEAN^DILF ; MAKE SURE WE ARE CLEANED UP
|
2008-12-16 14:10:26 -05:00
|
|
|
K C0CTMP
|
2009-01-25 15:29:07 -05:00
|
|
|
D GETS^DIQ(GFILE,C0CREF,"**","IE","C0CTMP")
|
2008-12-06 20:50:51 -05:00
|
|
|
D FIELDS(GRTN,GFILE) ;GET ALL THE FIELD NAMES FOR THE FILE
|
2008-12-09 17:19:48 -05:00
|
|
|
S @GRTN@(0)=GFILE_"^RNF1^"_GIEN_"^"_DT_"^"_$J_"^"_DUZ ; STRUCTURE SIGNATURE
|
2008-12-06 20:50:51 -05:00
|
|
|
S (C0CI,C0CJ)=""
|
|
|
|
F S C0CJ=$O(C0CTMP(C0CJ)) Q:C0CJ="" D ; FOR ALL SUBFILES
|
|
|
|
. S C0CREF=$O(C0CTMP(C0CJ,"")) ; RECORD REFERENCE
|
|
|
|
. F S C0CI=$O(C0CTMP(C0CJ,C0CREF,C0CI)) Q:C0CI="" D ; ARRAY OF FIELDS
|
|
|
|
. . ;W C0CJ," ",C0CI,!
|
|
|
|
. . S C0CNAME=$P(^DD(C0CJ,C0CI,0),"^",1) ;PULL THE FIELD NAME
|
2009-01-25 15:29:07 -05:00
|
|
|
. . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,"E") ;
|
2008-12-16 14:10:26 -05:00
|
|
|
. . I C0CVALUE["C0CTMP" D ; WP FIELD
|
|
|
|
. . . N ZT,ZWP S ZWP=0 ;ITERATOR
|
2008-12-19 11:54:05 -05:00
|
|
|
. . . S ZWP=$O(C0CTMP(C0CJ,C0CREF,C0CI,ZWP)) ; INIT TO FIRST LINE
|
|
|
|
. . . S C0CVALUE=C0CTMP(C0CJ,C0CREF,C0CI,ZWP) ; INIT TO FIRST LINE
|
2008-12-16 14:10:26 -05:00
|
|
|
. . . F S ZWP=$O(C0CTMP(C0CJ,C0CREF,C0CI,ZWP)) Q:'ZWP D ;
|
|
|
|
. . . . S ZT=" "_C0CTMP(C0CJ,C0CREF,C0CI,ZWP) ;LINE OF WP
|
|
|
|
. . . . S ZT=$TR(ZT,"^""","|'") ;HACK TO GET RID OF ^ AND " IN TEXT "
|
|
|
|
. . . . S C0CVALUE=C0CVALUE_ZT ;
|
2008-12-06 20:50:51 -05:00
|
|
|
. . S $P(@GRTN@(C0CNAME),"^",3)=C0CVALUE ;RETURN VALUE IN P3
|
2009-01-25 15:29:07 -05:00
|
|
|
. . S $P(@GRTN@(C0CNAME,"I"),"^",3)=$G(C0CTMP(C0CJ,C0CREF,C0CI,"I"))
|
2008-12-06 20:50:51 -05:00
|
|
|
I C0CNN D ; IF ONLY NON-NULL VALUES ARE TO BE RETURNED
|
|
|
|
. S C0CI=""
|
|
|
|
. F S C0CI=$O(@GRTN@(C0CI)) Q:C0CI="" D ; GO THROUGH THE WHOLE ARRAY
|
|
|
|
. . I $P(@GRTN@(C0CI),"^",3)="" K @GRTN@(C0CI) ; KILL THE NULL ENTRIES
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
GETN2(GARTN,GAFILE,GAIDX,GACNT,GASTRT,GANN) ; RETURN FIELD MAP AND VALUES
|
2008-12-08 12:59:46 -05:00
|
|
|
; GARTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
|
2008-12-14 14:35:31 -05:00
|
|
|
; .. FIELD MAP @GARTN@("F","FIELDNAME")="FILE;FIELD#"
|
2008-12-08 12:59:46 -05:00
|
|
|
; ... ANY FIELD USED BY ANY RECORD PROCESSED IS IN THE FIELD MAP
|
2008-12-14 14:35:31 -05:00
|
|
|
; .. VALUE MAP @GARTN@("V","IEN","FIELDNAME","N")=VALUE
|
|
|
|
; .. WHERE N IS THE INDEX FOR MULTIPLES.. 1 FOR SINGLE VALUES
|
2008-12-08 12:59:46 -05:00
|
|
|
; .. GARTN IS NOT INITIALIZED, SO MULTIPLE CALLS ARE CUMULATIVE
|
2008-12-06 20:50:51 -05:00
|
|
|
; .. IF GANN="ALL" THEN ALL FIELDS FOR THE FILE ARE IN THE FIELD MAP
|
2008-12-08 12:59:46 -05:00
|
|
|
; .. EVEN IF GANN="ALL" ONLY POPULATED FIELDS ARE RETURNED IN THE VALUE MAP
|
|
|
|
; .. NUL FIELDS CAN BE DETERMINED BY CHECKING FIELD MAP - THIS SAVES SPACE
|
|
|
|
; GAFILE IS THE FILE NUMBER TO BE PROCESSED. IT IS PASSED BY VALUE
|
2008-12-14 14:35:31 -05:00
|
|
|
; GAIDX IS THE OPTIONAL INDEX TO USE IN THE FILE. IF GAIDX IS "" THE IEN
|
|
|
|
; .. OF THE FILE WILL BE USED
|
2008-12-08 12:59:46 -05:00
|
|
|
; GACNT IS THE NUMBER OF RECORDS TO PROCESS. IT IS PASSED BY VALUE
|
2008-12-06 20:50:51 -05:00
|
|
|
; .. IF GARCNT IS NULL, ALL RECORDS ARE PROCESSED
|
2008-12-08 12:59:46 -05:00
|
|
|
; GASTRT IS THE IEN OF THE FIRST RECORD TO PROCESS. IT IS PASSED BY VALUE
|
2008-12-06 20:50:51 -05:00
|
|
|
; .. IF GARSTART IS NULL, PROCESSING STARTS AT THE FIRST RECORD
|
|
|
|
; GANN= NOT NULL - IF GANN IS "ALL" THEN EVEN NULL FIELDS WILL BE RETURNED
|
|
|
|
; OTHERWISE, ONLY POPULATED FIELDS ARE RETURNED IN GARFLD AND GARVAL
|
2008-12-14 14:35:31 -05:00
|
|
|
;N GATMP,GAI,GAF
|
2008-12-06 20:50:51 -05:00
|
|
|
S GAF=$$FILEREF(GAFILE) ; GET CLOSED ROOT FOR THE FILE NUMBER GAFILE
|
2008-12-14 14:35:31 -05:00
|
|
|
I '$D(GAIDX) S GAIDX="" ;DEFAULT
|
|
|
|
I '$D(GANN) S GANN="" ;DEFAULT ONLY POPULATED FIELDS RETURNED
|
|
|
|
I GAIDX'="" S GAF=$NA(@GAF@(GAIDX)) ; IF WE ARE USING AN INDEX
|
2008-12-06 20:50:51 -05:00
|
|
|
W GAF,!
|
|
|
|
W $O(@GAF@(0)) ;
|
|
|
|
S GAI=0 ;ITERATOR
|
2008-12-14 14:35:31 -05:00
|
|
|
F S GAI=$O(@GAF@(GAI)) Q:GAI="" D ;
|
|
|
|
. D GETN1("GATMP",GAFILE,GAI,GAIDX,GANN) ;GET ONE RECORD
|
|
|
|
. N GAX S GAX=0
|
|
|
|
. F S GAX=$O(GATMP(GAX)) Q:GAX="" D ;PULL OUT THE FIELDS
|
|
|
|
. . D ADDNV(GARTN,GAI,GAX,GATMP(GAX)) ;INSERT THE NAME/VALUE INTO GARTN
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
ADDNV(GNV,GNVN,GNVF,GNVV) ; CREATE AN ELEMENT OF THE MATRIX
|
2008-12-14 14:35:31 -05:00
|
|
|
;
|
|
|
|
S @GNV@("F",GNVF)=$P(GNVV,"^",1)_"^"_$P(GNVV,"^",2) ;NAME=FILE^FIELD#
|
|
|
|
S @GNV@("V",GNVN,GNVF,1)=$P(GNVV,"^",3) ;SET THE VALUE
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
RNF2CSV(RNRTN,RNIN,RNSTY) ;CONVERTS AN RFN2 GLOBAL TO A CSV FORMAT
|
2008-12-14 14:35:31 -05:00
|
|
|
; READY TO WRITE FOR USE WITH EXCEL @RNRTN@(0) IS NUMBER OF LINES
|
|
|
|
; RNSTY IS STYLE OF THE OUTPUT -
|
|
|
|
; .. "NV"= ROWS ARE NAMES, COLUMNS ARE VALUES
|
|
|
|
; .. "VN"= ROWS ARE VALUES, COLUMNS ARE NAMES
|
|
|
|
; .. DEFAULT IS "NV" BECAUSE MANY MATRICES HAVE MORE FIELDS THAN VALUES
|
|
|
|
N RNR,RNC ;ROW ROOT,COL ROOT
|
|
|
|
N RNI,RNJ,RNX
|
|
|
|
I '$D(RNSTY) S RNSTY="NV" ;DEFAULT
|
|
|
|
I RNSTY="NV" D NV(RNRTN,RNIN) ; INTERNAL SUBROUTINES DEPENDING ON ORIENTATION
|
|
|
|
E D VN(RNRTN,RNIN) ;
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
NV(RNRTN,RNIN) ;
|
2008-12-14 14:35:31 -05:00
|
|
|
S RNR=$NA(@RNIN@("F"))
|
|
|
|
S RNC=$NA(@RNIN@("V"))
|
|
|
|
;S RNY=$P(@RNIN@(0),"^",1) ; FILE NUMBER
|
|
|
|
S RNX="""FILE"""_"," ; FIRST COLUMN NAME IS "FIELD"
|
|
|
|
S RNI=""
|
|
|
|
F S RNI=$O(@RNC@(RNI)) Q:RNI="" D ; FOR EACH COLUMN
|
|
|
|
. S RNX=RNX_RNI_"," ;ADD THE COLUMM ELEMENT AND A COMMA
|
|
|
|
S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
|
2010-01-09 23:09:54 -05:00
|
|
|
D PUSH^C0CXPATH(RNRTN,RNX) ; FIRST LINE CONTAINS COLUMN HEADINGS
|
2008-12-14 14:35:31 -05:00
|
|
|
S RNI=""
|
|
|
|
F S RNI=$O(@RNR@(RNI)) Q:RNI="" D ; FOR EACH ROW
|
|
|
|
. S RNX=""""_RNI_""""_"," ; FIRST ELEMENT ON ROW IS THE FIELD
|
|
|
|
. S RNJ=""
|
|
|
|
. F S RNJ=$O(@RNC@(RNJ)) Q:RNJ="" D ; FOR EACH COL
|
|
|
|
. . I $D(@RNC@(RNJ,RNI,1)) D ; THIS ROW HAS THIS COLUMN
|
|
|
|
. . . S RNX=RNX_""""_@RNC@(RNJ,RNI,1)_""""_"," ; ADD THE ELEMENT PLUS A COMMA
|
|
|
|
. . E S RNX=RNX_"," ; NUL COLUMN
|
|
|
|
. S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
|
2010-01-09 23:09:54 -05:00
|
|
|
. D PUSH^C0CXPATH(RNRTN,RNX)
|
2008-12-14 14:35:31 -05:00
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
VN(RNRTN,RNIN) ;
|
2008-12-14 14:35:31 -05:00
|
|
|
S RNR=$NA(@RNIN@("V"))
|
|
|
|
S RNC=$NA(@RNIN@("F"))
|
|
|
|
;S RNY=$P(@RNIN@(0),"^",1) ; FILE NUMBER
|
|
|
|
S RNX="""FILE"""_"," ; FIRST COLUMN NAME IS "FIELD"
|
|
|
|
S RNI=""
|
|
|
|
F S RNI=$O(@RNC@(RNI)) Q:RNI="" D ; FOR EACH COLUMN
|
|
|
|
. S RNX=RNX_RNI_"," ;ADD THE COLUMM ELEMENT AND A COMMA
|
|
|
|
S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
|
2010-01-09 23:09:54 -05:00
|
|
|
D PUSH^C0CXPATH(RNRTN,RNX) ; FIRST LINE CONTAINS COLUMN HEADINGS
|
2008-12-14 14:35:31 -05:00
|
|
|
S RNI=""
|
|
|
|
F S RNI=$O(@RNR@(RNI)) Q:RNI="" D ; FOR EACH ROW
|
|
|
|
. S RNX=""""_RNI_""""_"," ; FIRST ELEMENT ON ROW IS THE FIELD
|
|
|
|
. S RNJ=""
|
|
|
|
. F S RNJ=$O(@RNC@(RNJ)) Q:RNJ="" D ; FOR EACH COL
|
|
|
|
. . I $D(@RNR@(RNI,RNJ,1)) D ; THIS ROW HAS THIS COLUMN
|
|
|
|
. . . S RNX=RNX_""""_@RNR@(RNI,RNJ,1)_""""_"," ; ADD THE ELEMENT PLUS A COMMA
|
|
|
|
. . E S RNX=RNX_"," ; NUL COLUMN
|
|
|
|
. S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
|
2010-01-09 23:09:54 -05:00
|
|
|
. D PUSH^C0CXPATH(RNRTN,RNX)
|
2008-12-14 14:35:31 -05:00
|
|
|
Q
|
|
|
|
;
|
2009-09-22 20:48:19 -04:00
|
|
|
READCSV(PATH,NAME,GLB) ; READ A CSV FILE IN FROM UNIX TO GLB, PASSED BY NAME
|
|
|
|
;
|
|
|
|
Q $$FTG^%ZISH(PATH,NAME,GLB,1)
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
FILE2CSV(FNUM,FVN) ; WRITES OUT A FILEMAN FILE TO CSV
|
2008-12-14 14:35:31 -05:00
|
|
|
;
|
|
|
|
;N G1,G2
|
|
|
|
I '$D(FVN) S FVN="NV" ; DEFAULT ORIENTATION OF CVS FILE
|
|
|
|
S G1=$NA(^TMP($J,"C0CCSV",1))
|
|
|
|
S G2=$NA(^TMP($J,"C0CCSV",2))
|
|
|
|
D GETN2(G1,FNUM) ; GET THE MATRIX
|
|
|
|
D RNF2CSV(G2,G1,FVN) ; PREPARE THE CVS FILE
|
|
|
|
K @G1
|
2008-12-16 14:10:26 -05:00
|
|
|
D FILEOUT(G2,"FILE_"_FNUM_".csv")
|
2008-12-14 14:35:31 -05:00
|
|
|
K @G2
|
2008-12-06 20:50:51 -05:00
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
FILEOUT(FOARY,FONAM) ; WRITE OUT A FILE
|
2008-12-16 14:10:26 -05:00
|
|
|
;
|
2010-01-09 23:09:54 -05:00
|
|
|
W $$OUTPUT^C0CXPATH($NA(@FOARY@(1)),FONAM,^TMP("GPLCCR","ODIR"))
|
2008-12-16 14:10:26 -05:00
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
FILEREF(FNUM) ; EXTRINSIC THAT RETURNS A CLOSED ROOT FOR FILE NUMBER FNUM
|
2008-12-06 20:50:51 -05:00
|
|
|
;
|
2008-12-08 12:59:46 -05:00
|
|
|
N C0CF
|
2008-12-06 20:50:51 -05:00
|
|
|
S C0CF=^DIC(FNUM,0,"GL") ;OPEN ROOT TO FILE
|
|
|
|
S C0CF=$P(C0CF,",",1)_")" ; CLOSE THE ROOT
|
2008-12-14 14:35:31 -05:00
|
|
|
I C0CF["()" S C0CF=$P(C0CF,"()",1)
|
2008-12-06 20:50:51 -05:00
|
|
|
Q C0CF
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
SKIP ;
|
2008-12-16 14:10:26 -05:00
|
|
|
N TXT,DIERR
|
|
|
|
S TXT=$$GET1^DIQ(8925,TIUIEN,"2","","TXT")
|
|
|
|
I $D(DIERR) D CLEAN^DILF Q
|
|
|
|
W " report_text:",! ;Progress Note Text
|
|
|
|
N LN S LN=0
|
|
|
|
F S LN=$O(TXT(LN)) Q:'LN D
|
|
|
|
. W " text"_LN_": "_TXT(LN),!
|
|
|
|
. Q
|
|
|
|
Q
|
|
|
|
;
|
2010-01-09 23:09:54 -05:00
|
|
|
RNF2HNV(ZOUT,ZIN) ;RETURN AN HTML TABLE IN ZOUT, PASSED BY NAME
|
|
|
|
; OF ZIN, WHICH IS PASSED BY NAME AND IS IN RNF2 FORMAT
|
|
|
|
; ZOUT IS NOT INITIALIZED, SO THE TABLE WILL GO AT THE END
|
|
|
|
; THE TABLE WILL BE IN NV FORMAT, ROWS ARE NAMES COLUMNS ARE VALUES
|
2010-01-10 13:13:34 -05:00
|
|
|
D PUSH^C0CXPATH(ZOUT,"<table border=""1"">")
|
2010-01-09 23:09:54 -05:00
|
|
|
N ZI,ZJ,ZV,ZN S ZI="" S ZJ=0
|
|
|
|
D PUSH^C0CXPATH(ZOUT,"<tr><td></td>") ;begin row and leave a blank col
|
|
|
|
F S ZJ=$O(@ZIN@("V",ZJ)) Q:+ZJ=0 D ; FOR EACH OCCURANCE
|
|
|
|
. S ZV="<td>"_ZJ_"</td>" ; OCCURANCE AS COLUMNS HEADER
|
2010-01-10 13:13:34 -05:00
|
|
|
. D PUSH^C0CXPATH(ZOUT,ZV)
|
2010-01-09 23:09:54 -05:00
|
|
|
D PUSH^C0CXPATH(ZOUT,"</tr>") ;end of first row
|
2010-01-10 13:13:34 -05:00
|
|
|
S ZI=""
|
2010-01-09 23:09:54 -05:00
|
|
|
F S ZI=$O(@ZIN@("F",ZI)) Q:ZI="" D ; FOR EACH VARIABLE
|
|
|
|
. S ZN="<tr><td>"_ZI_"</td>" ; VARIABLE NAME IN FIRST COLUMN
|
2010-01-10 13:13:34 -05:00
|
|
|
. D PUSH^C0CXPATH(ZOUT,ZN)
|
2010-01-09 23:09:54 -05:00
|
|
|
. S ZJ=0 ;RESET TO DO IT AGAIN
|
|
|
|
. F S ZJ=$O(@ZIN@("V",ZJ)) Q:+ZJ=0 D ; FOR EACH OCCURANCE
|
|
|
|
. . S ZV="<td>"_$G(@ZIN@("V",ZJ,ZI,1))_"</td>"
|
|
|
|
. . D PUSH^C0CXPATH(ZOUT,ZV)
|
|
|
|
. D PUSH^C0CXPATH(ZOUT,"</tr>") ;END OF ROW
|
|
|
|
D PUSH^C0CXPATH(ZOUT,"</table>") ; end of table
|
|
|
|
Q
|
|
|
|
;
|
|
|
|
RNF2HVN(ZOUT,ZIN) ;RETURN AN HTML TABLE IN ZOUT, PASSED BY NAME
|
|
|
|
; OF ZIN, WHICH IS PASSED BY NAME AND IS IN RNF2 FORMAT
|
|
|
|
; ZOUT IS NOT INITIALIZED, SO THE TABLE WILL GO AT THE END
|
|
|
|
; THE TABLE WILL BE IN VN FORMAT, ROWS ARE VALUES COLUMNS ARE NAMES
|
2010-01-10 13:13:34 -05:00
|
|
|
D PUSH^C0CXPATH(ZOUT,"<table border=""1"">")
|
2010-01-09 23:09:54 -05:00
|
|
|
N ZI,ZJ S ZI="" S ZJ=0
|
|
|
|
D PUSH^C0CXPATH(ZOUT,"<tr>") ;new row for column headers
|
|
|
|
F S ZI=$O(@ZIN@("F",ZI)) Q:ZI="" D ; FOR EACH VARIABLE
|
|
|
|
. S ZV="<td>"_ZI_"</td>"
|
|
|
|
. D PUSH^C0CXPATH(ZOUT,ZV) ; name
|
|
|
|
D PUSH^C0CXPATH(ZOUT,"</tr>") ; end header row
|
|
|
|
S ZI="" ;RESET TO DO AGAIN
|
|
|
|
F S ZJ=$O(@ZIN@("V",ZJ)) Q:+ZJ=0 D ; FOR EACH ROW OF VARIABLES
|
|
|
|
. D PUSH^C0CXPATH(ZOUT,"<tr>") ;begin row
|
|
|
|
. F S ZI=$O(@ZIN@("F",ZI)) Q:ZI="" D ; FOR EACH VARIABLE
|
|
|
|
. . S ZV="<td>"_$G(@ZIN@("V",ZJ,ZI,1))_"</td>" ; value
|
|
|
|
. . D PUSH^C0CXPATH(ZOUT,ZV) ; value
|
|
|
|
. D PUSH^C0CXPATH(ZOUT,"</tr>") ; end header
|
|
|
|
D PUSH^C0CXPATH(ZOUT,"</table>") ;end of table
|
|
|
|
Q
|
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
|
2008-12-06 20:50:51 -05:00
|
|
|
; BY VALUE IN ZFN. FILE NUMBER IS PIECE 1 OF @ZTAB@(ZFN)
|
|
|
|
; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
|
|
|
|
I '$D(ZTAB) S ZTAB="C0CA"
|
|
|
|
Q $P(@ZTAB@(ZFN),"^",1)
|
2009-05-21 13:12:11 -04:00
|
|
|
ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
|
2008-12-06 20:50:51 -05:00
|
|
|
; BY VALUE IN ZFN. FILE NUMBER IS PIECE 2 OF @ZTAB@(ZFN)
|
|
|
|
; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
|
|
|
|
I '$D(ZTAB) S ZTAB="C0CA"
|
|
|
|
Q $P(@ZTAB@(ZFN),"^",2)
|
2009-05-21 13:12:11 -04:00
|
|
|
ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
|
2008-12-06 20:50:51 -05:00
|
|
|
; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF @ZTAB@(ZFN)
|
|
|
|
; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
|
|
|
|
I '$D(ZTAB) S ZTAB="C0CA"
|
2009-02-03 10:29:44 -05:00
|
|
|
Q $P($G(@ZTAB@(ZFN)),"^",3)
|
2008-12-08 12:59:46 -05:00
|
|
|
;
|
2009-05-21 13:12:11 -04:00
|
|
|
ZVALUEI(ZFN,ZTAB) ;EXTRINSIC TO RETURN INTERNAL VALUE FOR FIELD NAME PASSED
|
2009-01-25 15:29:07 -05:00
|
|
|
; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF @ZTAB@(ZFN)
|
|
|
|
; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
|
|
|
|
I '$D(ZTAB) S ZTAB="C0CA"
|
2009-02-03 10:29:44 -05:00
|
|
|
Q $P($G(@ZTAB@(ZFN,"I")),"^",3)
|
2009-01-25 15:29:07 -05:00
|
|
|
;
|