source: ccr/trunk/p/C0CDIC.m@ 534

Last change on this file since 534 was 307, checked in by George Lilly, 16 years ago

improvements to RNF format routines. FILE2CSVC0CRNF to export files to csv

File size: 7.6 KB
Line 
1C0CDIC ; CCDCCR/GPL - CCR Dictionary utilities; 6/1/08
2 ;;0.1;CCDCCR;nopatch;noreleasedate
3 ;Copyright 2008 WorldVistA. 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 CCR Dictionary Utility Library ",!
21 W !
22 Q
23 ;
24GVARS(C0CVARS,C0CT) ; Get the CCR variables from the CCR template
25 ; and return them in C0CVARS, which is passed by name
26 ; FIRST PIECE OF C0CVARS(x) IS THE VARIABLE NAME, SECOND PIECE
27 ; IS THE LINE NUMBER OF THE VARIABLE IN THE TEMPLATE
28 ; C0CT IS RETURNED AS THE CCR TEMPLATE
29 N C0CTVARS ; ARRAY FOR THE TEMPLATE AND ARRAY FOR THE VARS
30 D LOAD^GPLCCR0(C0CT) ; LOAD THE CCR TEMPLATE
31 D XVARS^GPLXPATH("C0CTVARS",C0CT) ; PULL OUT THE VARS
32 N C0CI,C0CX
33 S @C0CVARS@(0)=C0CTVARS(0) ; SAME COUNT
34 F C0CI=1:1:C0CTVARS(0) D ; FOR EVERY LINE IN THE ARRAY
35 . S C0CX=C0CTVARS(C0CI) ; THE VARIABLE - 3 PIECES, FIRST ONE NULL
36 . S @C0CVARS@(C0CI)=$P(C0CX,"^",2)_"^"_$P(C0CX,"^",3) ; VAR NAME^LINE NUMBER
37 ;D PARY^GPLXPATH("C0CVARS")
38 Q
39 ;
40GXPATH(C0CPVARS,C0CPT) ; LOAD THE CCR TEMPLATE INTO C0CPT, PULL OUT VARIABLES
41 ; AND THE XPATH TO THE VARIABLES INTO C0CPVARS
42 ; BY INDEXING THE TEMPLATE C0CT AND MATCHING THE XPATH TO THE VARIABLE
43 ; BOTH ARE PASSED BY NAME
44 ; C0CPVARS(x) IS VAR^LINENUM^XPATH SORTED BY LINENUM
45 ; C0CPVARS(0) IS NUMBER OF VARIABLES
46 ; C0CPT(0) IS NUMBER OF LINES IN THE TEMPLATE
47 D GVARS(C0CPVARS,C0CPT) ; GET THE VARIABLES AND LINE NUMBERS
48 ;N C0CTVARS ; HASH TABLE FOR VARIABLE BY LINE NUMBER
49 D HASHV ; PUT THE VARIABLES IN A LINE NUMBER HASH FOR MATCHING TO XPATHS
50 ; NOW GO GET THE XPATH INDEXES
51 D INDEX^GPLXPATH(C0CPT) ; ADD THE XPATH INDEXES TO THE TEMPLATE ARRAY
52 S C0CI="" ; GOING TO LOOP THROUGH THE WHOLE ARRAY LOOKING AT XPATHS
53 F S C0CI=$O(@C0CPT@(C0CI)) Q:C0CI="" D ; VISIT EVERY LINE
54 . I +C0CI'=0 Q ; SKIP EVERYTHING BUT THE XPATH INDEX
55 . I C0CI=0 Q ; SKIP THE ZERO NODE
56 . S C0CX=@C0CPT@(C0CI) ; PULL OUT THE LINE NUMBERS X^Y
57 . S C0CY=$P(C0CX,"^",1) ; STARTING LINE NUMBER
58 . S C0CZ=$P(C0CX,"^",2) ; ENDING LINE NUMBER
59 . I C0CY=C0CZ D ; THIS IS AN XPATH END NODE, HAS A VARIABLE (WE HOPE)
60 . . ; W "FOUND ",C0CI,!
61 . . I $D(C0CTVARS(C0CY)) D ; IF THERE IS A VARIABLE THERE
62 . . . S $P(C0CTVARS(C0CY),"^",3)=C0CI ; INSERT THE XPATH FOR THE VAR
63 D SORTV ; SORT THE ARRAY BY LINE NUMBER
64 Q
65 ;
66HASHV ; INTERNAL ROUTINE TO PUT VARIABLE NAMES IN A LINE NUMBER HASH
67 ;N C0CI,C0CTVARS,C0CX,C0CY
68 F C0CI=1:1:@C0CPVARS@(0) D ; FOR THE ENTIRE ARRAY
69 . S C0CX=$P(@C0CPVARS@(C0CI),"^",2) ; LINE NUMBER
70 . S C0CY=$P(@C0CPVARS@(C0CI),"^",1) ; VARIABLE NAME
71 . S C0CTVARS(C0CX)=C0CY ; BUILD HASH OF VARIABLES BY LINE NUMBER
72 Q
73 ;
74SORTV ; INTERNAL ROUTINE TO OUTPUT VARIABLES (AND XPATHS) IN LINE NUMBER ORDER
75 ;N C0CV2 ; SCRACTH SPACE FOR BUILDING SORTED ARRAY
76 S C0CI="" ;
77 F S C0CI=$O(C0CTVARS(C0CI)) Q:C0CI="" D ; BY LINE NUMBER
78 . S C0CX=C0CTVARS(C0CI) ;VARIABLE NAME
79 . S $P(C0CX,"^",2)=C0CI ; LINE NUMBER IS SECOND PIECE
80 . D PUSH^GPLXPATH("C0C2",C0CX) ; PUT ONTO ARRAY
81 K @C0CPVARS
82 M @C0CPVARS=C0C2
83 Q
84 ;
85LOAD ; LOAD VARIABLE NAMES AND XPATH IN ^C0CDIC(170
86 ; INITIAL LOAD OF THE CCR DICTIONARY
87 ;
88 N C0CDIC,C0CARY,C0CXML,C0CFDA,C0CI
89 S C0CDIC="^C0CDIC(170," ; ROOT OF THE CCR DICTIONARY
90 D GXPATH("C0CARY","C0CXML") ; FETCH THE VARIABLES AND XPATH INTO C0CARY
91 ; C0CXML WILL CONTAIN THE TEMPLATE - NOT NEEDED FOR LOAD
92 D PARY^GPLXPATH("C0CARY") ;TEST
93 F C0CI=1:1:C0CARY(0) D ; LOAD EACH VARIABLE
94 . S C0CFDA(170,"+"_C0CI_",",.01)=$P(C0CARY(C0CI),"^",1) ; VAR NAME
95 . S C0CFDA(170,"+"_C0CI_",",2)=$P(C0CARY(C0CI),"^",3) ; XPATH
96 . D UPDATE^DIE("","C0CFDA")
97 . I $D(^TMP("DIERR",$J)) U $P BREAK
98 . W "LOADING:",C0CI," ",C0CARY(C0CI),!
99 Q
100 ;
101INIT ; INITIALIZE CCR DICTIONARY BASED ON VARIABLE NAMES
102 ;
103 ; CHEAT SHEET FOR VARIABLE NAMES IN ^C0CDIC(170.xx,
104 ; THIS IS WHAT WILL BE IN C0CA FOR EACH DICTIONARY ENTRY
105 ;G1("CODING")="170^8"
106 ;G1("DATA ELEMENT")="170^7"
107 ;G1("DESCRIPTION")="170^3"
108 ;G1("ID")="170^1"
109 ;G1("M","170^8","CODING")="170.08^.01"
110 ;G1("MAPPING METHOD")="170.08^1"
111 ;G1("SECTION")="170^10"
112 ;G1("SOURCE")="170^4"
113 ;G1("STATUS")="170^9"
114 ;G1("TYPE")="170^6"
115 ;G1("VARIABLE")="170^.01"
116 ;G1("XPATH")="170^2"
117 ;
118 N C0CZA,C0CZX,C0CN,C0CSTAT
119 S C0CZX=0
120 S C0CSTAT=0 ; INIT STATUS SET FLAG
121 F S C0CZX=$O(^C0CDIC(170,C0CZX)) Q:+C0CZX=0 D ; FOR EACH DICT ENTRY
122 . ;W C0CZX,!
123 . K C0CA,C0CN ; CLEAR OUT THE LAST ONE
124 . D GETN1^C0CRNF("C0CA",170,C0CZX,"","ALL") ; GET VARIABLE HASH
125 . ;ZWR C0CA B ;
126 . S C0CN=$$ZVALUE("VARIABLE") ;NAME OF THE VARIABLE
127 . W "VARIABLE: ",C0CN,!
128 . I $E(C0CN,1,5)="ACTOR" D SETFDA("SECTION","ACTORS") ;
129 . I $E(C0CN,1,6)="SOCIAL" D ;
130 . . D SETFDA("SECTION","SOC") ;
131 . . D SETFDA("STATUS","X") ;SOCIAL HISTORY NOT IMPLEMENTED
132 . . S C0CSTAT=1
133 . I $E(C0CN,1,6)="FAMILY" D ;
134 . . D SETFDA("SECTION","FAM") ;
135 . . D SETFDA("STATUS","X") ;FAMILY HISTORY NOT IMPLEMENTED
136 . . S C0CSTAT=1
137 . ;D SETFDA("TYPE","") ;CORRECT FOR TYPE ERRORS
138 . I $E(C0CN,1,5)="ALERT" D SETFDA("SECTION","ALERTS")
139 . I $E(C0CN,1,5)="VITAL" D SETFDA("SECTION","VITALS")
140 . I $E(C0CN,1,7)="PROBLEM" D SETFDA("SECTION","PROBLEMS")
141 . I $E(C0CN,1,10)="RESULTTEST" D SETFDA("SECTION","TEST")
142 . E I $E(C0CN,1,6)="RESULT" D SETFDA("SECTION","LABS")
143 . I C0CN["CODEVALUE" D SETFDA("TYPE","CD") ;CODES
144 . I C0CN["CODEVERSION" D SETFDA("TYPE","CV") ; CODE VERSION
145 . I C0CN["CODINGSYSTEM" D SETFDA("TYPE","CS") ;CODING SYSTEM
146 . I $$ZVALUE("STATUS")=""!'C0CSTAT D SETFDA("STATUS","N") ;BLANK STATUS TO N
147 . I $$ZVALUE("XPATH")["/Medication/Directions/" D ; MEDS DIRECTIONS VAR
148 . . D SETFDA("SECTION","DIR") ; SPECIAL SECTION FOR DIRECTIONS
149 . E I $$ZVALUE("XPATH")["/Medications/Medication/" D ; ALL OTHER MEDS
150 . . D SETFDA("SECTION","MEDS") ; A MEDS VAR
151 . I $E(C0CN,($L(C0CN)-1),$L(C0CN))="ID" D SETFDA("TYPE","ID") ;CATCH THE IDS
152 . I C0CN["DATETIME" D SETFDA("TYPE","DT") ; DATE/TIME VARIABLE
153 . W "VARIABLE: ",C0CZX," ",C0CA("VARIABLE"),!
154 . ;ZWR C0CFDA
155 . I $D(C0CFDA) D ; WE HAVE CHANGES ON THIS VARIABLE
156 . . ;ZWR C0CFDA
157 . . D UPDATE^DIE("","C0CFDA(C0CZX)")
158 . . I $D(^TMP("DIERR",$J)) U $P BREAK
159 . . D CLEAN^DILF ; CLEAN UP
160 . ;ZWR C0CFDA
161 Q
162 ;
163SETFDA(C0CSN,C0CSV) ; INTERNAL ROUTINE TO MAKE AN FDA ENTRY FOR FIELD C0CSN
164 ; TO SET TO VALUE C0CSV.
165 ; C0CFDA,C0CA,C0CZX ARE ASSUMED FROM THE CALLING ROUTINE
166 ; C0CSN,C0CSV ARE PASSED BY VALUE
167 ;
168 N C0CSI,C0CSJ
169 S C0CSI=$$ZFILE(C0CSN,"C0CA") ; FILE NUMBER
170 S C0CSJ=$$ZFIELD(C0CSN,"C0CA") ; FIELD NUMBER
171 S C0CFDA(C0CZX,C0CSI,C0CZX_",",C0CSJ)=C0CSV
172 Q
173ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
174 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 1 OF C0CA(ZFN)
175 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
176 I '$D(ZTAB) S ZTAB="C0CA"
177 Q $P(@ZTAB@(ZFN),"^",1)
178ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
179 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 2 OF C0CA(ZFN)
180 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
181 I '$D(ZTAB) S ZTAB="C0CA"
182 Q $P(@ZTAB@(ZFN),"^",2)
183ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
184 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF C0CA(ZFN)
185 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
186 I '$D(ZTAB) S ZTAB="C0CA"
187 Q $P(@ZTAB@(ZFN),"^",3)
188 ;
Note: See TracBrowser for help on using the repository browser.