2008-12-06 20:50:51 -05:00
|
|
|
C0CRNF ; CCDCCR/GPL - Reference Name Format (RNF) utilities; 12/6/08
|
|
|
|
;;0.1;CCDCCR;nopatch;noreleasedate
|
|
|
|
;Copyright 2008 WorldVistA. Licensed under the terms of the GNU
|
|
|
|
;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
|
|
|
|
;
|
|
|
|
FIELDS(C0CFRTN,C0CF) ; RETURNS AN ARRAY OF THE FIELDS IN FILE C0CF,
|
|
|
|
; 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,!
|
|
|
|
. . S C0CFN=$P(^DD(C0CFJ,C0CFI,0),"^",1) ;PULL FIELD NAME FROM ^DD
|
|
|
|
. . ;W "N: ",C0CFN,!
|
|
|
|
. . ;I C0CFN="STR" W C0CFN," ",C0CFJ,!
|
|
|
|
. . I $D(@C0CFRTN@(C0CFN)) D ; IS THIS A DUPLICATE?
|
|
|
|
. . . W "DUPLICATE FOUND! ",C0CFJ," ",C0CFI," ",C0CFN,!,@C0CFRTN@(C0CFN),!
|
|
|
|
. . . S @C0CFRTN@(C0CFN_"_"_C0CFJ)=C0CFJ_"^"_C0CFI
|
|
|
|
. . E S @C0CFRTN@(C0CFN)=C0CFJ_"^"_C0CFI
|
|
|
|
. S C0CFJ=$O(^DD(C0CFJ)) ; NEXT SUBFILE
|
|
|
|
Q
|
|
|
|
;
|
2008-12-08 12:59:46 -05:00
|
|
|
GETN(GRTN,GFILE,GIEN,GNN) ; GET FIELDS FOR ACCESS BY NAME
|
|
|
|
; 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
|
|
|
|
D GETS^DIQ(GFILE,C0CREF,"**","","C0CTMP")
|
|
|
|
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
|
|
|
|
;
|
2008-12-08 12:59:46 -05:00
|
|
|
GETN2(GRTN,GFILE,GREF,GNDX,GNN) ; NEW GET ;GPL ; RETURN A FIELD VALUE MAP
|
|
|
|
; 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
|
2008-12-09 17:19:48 -05:00
|
|
|
|
2008-12-08 12:59:46 -05:00
|
|
|
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
|
|
|
|
. 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
|
|
|
|
W "IEN: ",GIEN,!
|
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
|
|
|
|
D GETS^DIQ(GFILE,C0CREF,"**","","C0CTMP")
|
|
|
|
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
|
|
|
|
. . 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
|
|
|
|
;
|
2008-12-08 12:59:46 -05:00
|
|
|
GETALL(GARTN,GAFILE,GACNT,GASTRT,GANN) ; RETURN FIELD MAP AND VALUES
|
|
|
|
; GARTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
|
|
|
|
; .. FIELD MAP @GARTN@("F","FIELDNAME^FILE^FIELD#")=""
|
|
|
|
; ... ANY FIELD USED BY ANY RECORD PROCESSED IS IN THE FIELD MAP
|
|
|
|
; .. VALUE MAP @GARTN@("V","IEN","FIELDNAME")=VALUE
|
|
|
|
; .. 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
|
|
|
|
; 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
|
|
|
|
N GATMP,GAI,GAF
|
|
|
|
S GAF=$$FILEREF(GAFILE) ; GET CLOSED ROOT FOR THE FILE NUMBER GAFILE
|
|
|
|
W GAF,!
|
|
|
|
W $O(@GAF@(0)) ;
|
|
|
|
S GAI=0 ;ITERATOR
|
|
|
|
; F S GAI=$O(@GAF@
|
|
|
|
Q
|
|
|
|
;
|
|
|
|
FILEREF(FNUM) ; EXTRINSIC THAT RETURNS A CLOSED ROOT FOR FILE NUMBER FNUM
|
|
|
|
;
|
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
|
|
|
|
Q C0CF
|
|
|
|
;
|
|
|
|
ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
|
|
|
|
; 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)
|
|
|
|
ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
|
|
|
|
; 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)
|
|
|
|
ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
|
|
|
|
; 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"
|
|
|
|
Q $P(@ZTAB@(ZFN),"^",3)
|
2008-12-08 12:59:46 -05:00
|
|
|
;
|