source: ePrescribing/trunk/p/C0PTRXN2.m@ 1747

Last change on this file since 1747 was 1595, checked in by George Lilly, 12 years ago

initial release of ePrescribing

File size: 16.3 KB
Line 
1C0PTRXN ; ERX/GPL - Med file eRx analysis routines ; 7/10/10
2 ;;0.1;C0P;nopatch;noreleasedate;Build 77
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 Q
21 ;
22 ; gpl 7/2010 - these routines are to test the Drug file mappings
23 ; to see how well they will work for eRx. None of this code is needed
24 ; for operation of the eRx Package. It is for analysis, debugging and future
25 ; development
26 ;
27FDBFN() Q 1130590010 ; First Databank Drugs file number
28RXNFN() Q 1130590011.001 ; RxNorm Concepts file number
29T1 ; TEST1
30 N ZI
31 S ZI=""
32 F S ZI=$O(^C0P("FDB","B",ZI)) Q:ZI="" D ;
33 . N ZGCN,ZRXNCUI,ZNAME,ZVAIEN,ZDRUGIEN
34 . S (ZGCN,ZRXNCUI,ZNAME,ZVAIEN,ZDRUGIEN)=""
35 . S ZGCN=$$GCN^C0PLKUP(ZI)
36 . S ZRXNCUI=$$RXNCUI^C0PLKUP(ZGCN)
37 . I ZRXNCUI'="" S ZVUID=$$VUID^C0PLKUP(ZRXNCUI)
38 . E S ZRXNCUI="NONE"
39 . S ZNAME=$$FULLNAME^C0PLKUP(ZI)
40 . I ZVUID'="" S ZVAIEN=$$VAPROD^C0PLKUP(ZVUID)
41 . I ZVAIEN'="" S ZDRUGIEN=$$DRUG^C0PLKUP(ZVAIEN)
42 . E S ZDRUGIEN="N/A"
43 . W !,ZI," ",ZGCN," ",ZRXNCUI," ",ZVUID," ",ZVAIEN," ",ZDRUGIEN," ",ZNAME
44 Q
45 ; OK, T1 IS JUST SOME EXPLORITORY WORK. TIME TO GET ORGANIZED
46 ;
47TEST ;
48 ;
49 S GARY=$NA(^TMP("C0PRXN","TYPE2"))
50 S GOUT=$NA(^TMP("C0POUT"))
51 K @GOUT
52 D RNF2CSV^C0CRNF(GOUT,GARY,"VN") ; TURN TYPE 2 INTO A CSV
53 D FILEOUT^C0CRNF(GOUT,"TYPE2_TEST.csv")
54 Q
55 ;
56INDEX2 ; ADD AN INDEX TO TYPE2 DRUGS OF THE VUID
57 ; FOR USE IN FINDING THE CURRENT VA->FDB MAPPING STATUS
58 N ZI S ZI=""
59 N ZBASE
60 S ZBASE=$NA(^TMP("C0PRXN","TYPE2","V")) ; TYPE2 DRUGS ARE HERE
61 S ZINDEX=$NA(^TMP("C0PRXN","TYPE2","INDEX")) ; PUT THE INDEX HERE
62 F S ZI=$O(@ZBASE@(ZI)) Q:ZI="" D ;
63 . N ZVUIDS,ZVUID
64 . S ZVUIDS=@ZBASE@(ZI,"VUID",1) ; LIST OF VUIDS ^ SEPARATED
65 . N ZN S ZN=@ZBASE@(ZI,"VANAME",1)_"^"_@ZBASE@(ZI,"FDBNAME",1)
66 . I ZVUIDS["^" D ;
67 . . N ZJ S ZJ=""
68 . . F S ZJ=$P(ZVUIDS,"^",1) Q:ZJ="" D ; FOR EACH VUID
69 . . . S ZVUID(ZJ)=ZN ;SET INDEX TO NAME
70 . . . S ZVUIDS=$P(ZVUIDS,"^",2) ; DROP THE FIRST IN THE LIST
71 . E S ZVUID(ZVUIDS)=ZN ;SET INDEX TO VA NAME
72 . S ZJ=""
73 . F S ZJ=$O(ZVUID(ZJ)) Q:ZJ="" D ; FOR EACH VUID
74 . . ;S @ZINDEX@(ZJ,ZI)=ZVUID(ZJ) ;SET THE INDEX
75 . . W !,$NA(@ZINDEX@(ZJ,ZI))_"="_ZVUID(ZJ) ;SET THE INDEX
76 Q
77EN ; ENTRY POINT TO CREATE THE ERX DRUG ANALYSIS SPREADSHEETS
78 ; SEE BELOW FOR DOCUMENTATION
79 N GARY
80 S GARY=$NA(^TMP("C0PRXN","ALL")) ; PLACE TO PUT THE ENTIRE ARRAY
81 K @GARY
82 D BLDARY(GARY) ; BUILD THE ENTIRE ARRAY
83 D IDXARY(GARY) ; INDEX THE ARRAY BY TYPE AND DRUG NAME
84 D TYPES
85 Q
86 ;
87TYPES ; BUILD AN ARRAY FOR EACH TYPE
88 I '$D(GARY) S GARY=$NA(^TMP("C0PRXN","ALL"))
89 N C0PN,ZTYPE
90 F C0PN=1:1:4 D ; FOR EACH ANALYSIS TYPE
91 . S ZTYPE=$NA(^TMP("C0PRXN","TYPE"_C0PN))
92 . K @ZTYPE
93 . D BLDTYPE(GARY,ZTYPE,C0PN) ; BUILD AN EXTRACTED ARRAY ACCORDING TO TYPE
94 . S GOUT=$NA(^TMP("C0POUT"))
95 . K @GOUT
96 . D RNF2CSV^C0CRNF(GOUT,ZTYPE,"VN") ; TURN TYPE 2 INTO A CSV
97 . W !
98 . D FILEOUT^C0CRNF(GOUT,"eRx_mapping__Type"_C0PN_".csv")
99 Q
100 ;
101IDXARY(INARY) ; INDEX THE ARRAY BY TYPE AND NAME
102 ;
103 N ZI
104 S ZI=""
105 F S ZI=$O(@INARY@("V",ZI)) Q:ZI="" D ; FOR EACH ELEMENT OF THE ARRAY
106 . S @INARY@("INDEX",@INARY@("V",ZI,"TYPE"),@INARY@("V",ZI,"FDBNAME"),ZI)=""
107 D COUNT
108 Q
109 ;
110COUNT ; COUNT AND REPORT HOW MANY ARE IN EACH TYPE
111 I '$D(INARY) S INARY=$NA(^TMP("C0PRXN","ALL"))
112 N ZN,ZI,ZJ,ZCOUNT
113 S ZN=""
114 F S ZN=$O(@INARY@("INDEX",ZN)) Q:ZN="" D ; FOR EACH TYPE
115 . S ZCOUNT=0
116 . S ZI=""
117 . F S ZI=$O(@INARY@("INDEX",ZN,ZI)) Q:ZI="" D ; FOR EACH INDEX ENTRY
118 . . S ZCOUNT=ZCOUNT+1
119 . W !,"COUNT FOR TYPE "_ZN_" = "_ZCOUNT
120 Q
121 ;
122BLDTYPE(INARY,OARY,ITYPE) ; EXTRACT A TYPE ARRAY
123 ;
124 N C0PI,C0PJ
125 S C0PI=""
126 F S C0PI=$O(@INARY@("INDEX",ITYPE,C0PI)) Q:C0PI="" D ; FOR EACH OF TYPE
127 . S C0PJ=$O(@INARY@("INDEX",ITYPE,C0PI,"")) ; SET RECORD NUMBER
128 . N C0PROW
129 . M C0PROW=@INARY@("V",C0PJ) ; CONTENTS OF ROW
130 . D RNF1TO2B^C0CRNF(OARY,"C0PROW") ; USING THE "B" VERSION TO BE ABLE TO
131 . ; TO CONVERT TO A CSV
132 Q
133 ;
134BLDARY(ZARY) ; BUILDS AN RNF2 ARRAY; ZARY IS PASSED BY NAME
135 ; (SEE C0CRNF.m FOR DOCUMENTATION OF RNF2 FORMAT)
136 ;
137 ; FIRST DATA BANK DRUGS ARE MATCHED TO VISTA DRUGS THROUGH A MULTI-STEP
138 ; PROCESS. THE MEDID IS THE FIRST DATA BANK NUMBER USED TO REFER TO THEIR
139 ; DRUGS. EACH MEDID HAS A GCN (GENERIC CODE NUMBER) WHICH CAN BE USED TO
140 ; LOOK UP THE DRUG IN THE RXNORM UMLS DATABASE. THE GCN IS USED TO FIND
141 ; THE RXNORM CONCEPT NUMBER (RXNCUI). THE RXNCUI IS USED TO FIND THE VUID
142 ; USING THE RXNORM UMLS DATABASE. THE VUID IS USED TO FIND THE IEN OF THE
143 ; DRUG IN THE VA PRODUCTS FILE (ALSO KNOWN AS THE NDF - NATIONAL DRUG FILE).
144 ; THE VAPROD IEN IS THEN USED TO LOOK UP THE DRUG IN THE VA DRUG FILE
145 ; (FILE 50) USING A NEW CROSS REFERENCE (AC0P) CREATED FOR THIS PURPOSE.
146 ; THE RESULT OF THIS CHAIN IS A DRUG MAPPED FROM THE FDB MEDID TO A
147 ; VA DRUG FILE IEN. TO SUMMARIZE:
148 ;
149 ; MEDID->GCN->RXNCUI->VUID->VAPROD->DRUGIEN
150 ;
151 ; (NOTE: THIS PROCESS WILL CHANGE - BE IMPROVED - WHEN THE VERIFIED
152 ; MEDID->RXNORM MAPPING BECOMES AVAILABLE. THIS ANALYSIS WILL ESTABLISH
153 ; A BASELINE WITH WHICH TO COMPARE THE RESULT OF USING THAT MAPPING)
154 ;
155 ; (THE PROCESS IS ACTUALLY MORE COMPLEX THAT THIS, BECAUSE WE ALSO TRY
156 ; AND MATCH DRUGS BY LOOKING AT THEIR CHEMICAL COMPONENTS BUT THIS ANALYSIS
157 ; IGNORES THIS MORE COMPLEX PROCESS.)
158 ;
159 ; NOT ALL DRUGS MAKE IT ALL THE WAY THROUGH THIS MAPPING. IN ADDITION, THERE
160 ; MAY BE DRUGS THAT ARE IN THE DRUG FILE THAT ARE NOT IN THE FDB FILE
161 ; THIS ROUTINE WILL CREATE A SPREADSHEET THAT WILL SHOW THE UNMAPPED DRUGS
162 ; IN BOTH DIRECTIONS (MEDID->...>DRUGIEN AND DRUGIEN->...>MEDID)
163 ; IT WILL ALSO SHOW THE DRUG NAME AS IT APPEARS IN FIRST DATA BANK
164 ; AND THE NAME THAT WILL BE USED FOR THAT DRUG IN VISTA (ERX). OFTEN
165 ; THEY WILL BE DIFFERENT. IF THE FDB DRUG IS NOT A GENERIC, THE GENERIC NAME
166 ; WILL BY USED BY ERX TO LIST THE DRUG IN THE PATIENT'S DRUG LIST IN VISTA
167 ;
168 ; WE ARE GOING TO ORGANIZE AN ARRAY WITH DRUGS BY TYPE. HERE ARE THE TYPES:
169 ;
170 ; TYPE 1 - FDB DRUGS THAT MAP EXACTLY TO THE DRUG FILE, WITH NAMES THAT
171 ; MATCH EXACTLY
172 ;
173 ; TYPE 2 - FDB DRUGS THAT MAP TO THE DRUG FILE, BUT WITH DIFFERENT NAMES.
174 ; THIS CATEGORY INCLUDES DRUGS THAT ARE SHOWN IN VISTA AS GENERICS BUT
175 ; ON FDB AS BRAND NAME DRUGS
176 ;
177 ; TYPE 3 - FDB DRUGS THAT DO NOT MAP TO THE DRUG FILE, BUT DO MAP TO THE
178 ; VA PRODUCT FILE (NDF). IF ANY OF THESE DRUGS MIGHT BE ORDERED VIA ERX,
179 ; IT MIGHT BE A GOOD IDEA TO ADD THEM TO THE DRUG FILE.
180 ; NOTE: FOR TYPE 3 AND ABOVE DRUGS, ERX WILL STILL FUNCTION PROPERLY BUT
181 ; INSTEAD OF MAPPING THE DRUG TO THE DRUG FILE, WILL MAP IT AS A FREE TEXT
182 ; DRUG AND WILL SEND A MAIL MESSAGE ABOUT THE MAPPING ERROR SO THAT THE
183 ; DRUG CAN BE CONSIDERED FOR ADDING TO THE DRUG FILE
184 ;
185 ; TYPE 4 - FDB DRUGS THAT DO NOT MAP TO THE DRUG FILE AND ARE ALSO NOT
186 ; FOUND IN THE NDF. THIS MIGHT BE THE CASE FOR NEWER DRUGS. ERX WILL
187 ; STILL FUNCTION, BUT THESE WILL BE FREE TEXT DRUGS. THE REMEDY IS AN
188 ; UPDATE FROM THE VA OF THE NDF OR ADDING THE DRUGS TO THE NDF AND THE
189 ; DRUG FILE. (THERE ARE COMPLEXITIES IN ADDING DRUGS TO THE NDF BECAUSE
190 ; OF HOW TO THEN HANDLE AN UPDATE FROM THE VA)
191 ;
192 ; TYPE 5 - DRUGS IN THE DRUG FILE THAT ARE NOT FOUND IN THE FDB DRUG DATABASE
193 ; MAPPING. THIS MIGHT INCLUDE BRAND NAME DRUGS IN THE DRUG FILE THAT HAVE
194 ; BEEN MAPPED TO GENERICS WHEN COMING FROM FDB. IN ANY CASE, THESE ARE DRUGS
195 ; FOR WHICH THERE IS NO PATH TO MAP FROM THEM TO FDB. (REDUCING THE NUMBER
196 ; OF DRUGS IN THIS TYPE TO ZERO WILL BE A GOAL BEFORE IMPLEMENTING PHASE II
197 ; OF ERX WHERE DRUGS WILL BE ORDERED ON VISTA AND SENT TO THE ERX
198 ; SERVICE.
199 ;
200 N ZI
201 S ZI=""
202 F S ZI=$O(^C0P("FDB","B",ZI)) Q:ZI="" D ;
203 . N ZGCN,ZRXNCUI,ZNAME,ZVAIEN,ZDRUGIEN,ZROW,ZIEN,ZVANAME
204 . S (ZGCN,ZRXNCUI,ZNAME,ZVAIEN,ZDRUGIEN,ZVANAME)=""
205 . S ZROW("MEDID")=ZI ; FDB MEDID
206 . S ZIEN=$O(^C0P("FDB","B",ZI,"")) ; IEN OF THE FDB MED
207 . S ZROW("FDBNAME")=$$FULLNAME^C0PLKUP(ZI) ; FDB MED NAME
208 . S ZGCN=$$GCN^C0PLKUP(ZI)
209 . I ZGCN=0 D Q ; NO GCN, CAN'T MAP
210 . . S ZROW("TYPE")=4
211 . . D RNF1TO2^C0CRNF(ZARY,"ZROW")
212 . S ZROW("GCN")=ZGCN
213 . S ZRXNCUI=$$RXNCUI^C0PLKUP(ZGCN) ; RETRIEVE THE RXNORM CONCEPT ID
214 . I ZRXNCUI="" W !,"ERROR, NO RXNCUI "_ZGCN B ; SHOULDN'T HAPPEN
215 . S ZROW("RXNCUI")=ZRXNCUI
216 . S ZVUID=$$VUID^C0PLKUP(ZRXNCUI) ; FETCH THE VUID
217 . I ZVUID="" D Q ; NO VUID FOUND
218 . . S ZROW("TYPE")=4
219 . . D RNF1TO2^C0CRNF(ZARY,"ZROW")
220 . S ZROW("VUID")=ZVUID
221 . I ZVUID["^" S ZVUID=$P(ZVUID,"^",1) ; USE THE FIRST ONE
222 . S ZVAIEN=$$VAPROD^C0PLKUP(ZVUID) ; IEN IN VA PRODUCTS (NDF)
223 . I ZVAIEN=0 D Q ; NOT FOUND IN NDF
224 . . S ZROW("TYPE")=4
225 . . D RNF1TO2^C0CRNF(ZARY,"ZROW")
226 . S ZDRUGIEN=$$DRUG^C0PLKUP(ZVAIEN) ; IEN IN DRUG FILE
227 . I ZDRUGIEN=0 D Q ;
228 . . S ZROW("TYPE")=3
229 . . S ZROW("VANDFNAME")=$$GET1^DIQ(50.68,ZVAIEN_",",.01) ;NDF NAME
230 . . D RNF1TO2^C0CRNF(ZARY,"ZROW")
231 . S ZVANAME=$$GET1^DIQ(50,ZDRUGIEN_",",.01) ; VA DRUG NAME
232 . S ZROW("VANAME")=ZVANAME ;
233 . I ZVANAME=$$UP^XLFSTR(ZNAME) S ZROW("TYPE")=1
234 . E S ZROW("TYPE")=2
235 . D RNF1TO2^C0CRNF(ZARY,"ZROW")
236 . ;B
237 Q
238 ;
239BLDFILE() ; BUILDS THE C0P RXNORM FDB VUID MAPPING FILE #113059010.002
240 ;
241 ; FIRST DATA BANK DRUGS ARE MATCHED TO VISTA DRUGS THROUGH A MULTI-STEP
242 ; PROCESS. THE MEDID IS THE FIRST DATA BANK NUMBER USED TO REFER TO THEIR
243 ; DRUGS. EACH MEDID HAS A GCN (GENERIC CODE NUMBER) WHICH CAN BE USED TO
244 ; LOOK UP THE DRUG IN THE RXNORM UMLS DATABASE. THE GCN IS USED TO FIND
245 ; THE RXNORM CONCEPT NUMBER (RXNCUI). THE RXNCUI IS USED TO FIND THE VUID
246 ; USING THE RXNORM UMLS DATABASE. THE VUID IS USED TO FIND THE IEN OF THE
247 ; DRUG IN THE VA PRODUCTS FILE (ALSO KNOWN AS THE NDF - NATIONAL DRUG FILE).
248 ; THE VAPROD IEN IS THEN USED TO LOOK UP THE DRUG IN THE VA DRUG FILE
249 ; (FILE 50) USING A NEW CROSS REFERENCE (AC0P) CREATED FOR THIS PURPOSE.
250 ; THE RESULT OF THIS CHAIN IS A DRUG MAPPED FROM THE FDB MEDID TO A
251 ; VA DRUG FILE IEN. TO SUMMARIZE:
252 ;
253 ; MEDID->GCN->RXNCUI->VUID->VAPROD->DRUGIEN
254 ;
255 ; (NOTE: THIS PROCESS WILL CHANGE - BE IMPROVED - WHEN THE VERIFIED
256 ; MEDID->RXNORM MAPPING BECOMES AVAILABLE. THIS ANALYSIS WILL ESTABLISH
257 ; A BASELINE WITH WHICH TO COMPARE THE RESULT OF USING THAT MAPPING)
258 ;
259 ; (THE PROCESS IS ACTUALLY MORE COMPLEX THAT THIS, BECAUSE WE ALSO TRY
260 ; AND MATCH DRUGS BY LOOKING AT THEIR CHEMICAL COMPONENTS BUT THIS ANALYSIS
261 ; IGNORES THIS MORE COMPLEX PROCESS.)
262 ;
263 ; NOT ALL DRUGS MAKE IT ALL THE WAY THROUGH THIS MAPPING. IN ADDITION, THERE
264 ; MAY BE DRUGS THAT ARE IN THE DRUG FILE THAT ARE NOT IN THE FDB FILE
265 ; THIS ROUTINE WILL CREATE A SPREADSHEET THAT WILL SHOW THE UNMAPPED DRUGS
266 ; IN BOTH DIRECTIONS (MEDID->...>DRUGIEN AND DRUGIEN->...>MEDID)
267 ; IT WILL ALSO SHOW THE DRUG NAME AS IT APPEARS IN FIRST DATA BANK
268 ; AND THE NAME THAT WILL BE USED FOR THAT DRUG IN VISTA (ERX). OFTEN
269 ; THEY WILL BE DIFFERENT. IF THE FDB DRUG IS NOT A GENERIC, THE GENERIC NAME
270 ; WILL BY USED BY ERX TO LIST THE DRUG IN THE PATIENT'S DRUG LIST IN VISTA
271 ;
272 ; WE ARE GOING TO ORGANIZE AN ARRAY WITH DRUGS BY TYPE. HERE ARE THE TYPES:
273 ;
274 ; TYPE 1 - FDB DRUGS THAT MAP EXACTLY TO THE DRUG FILE, WITH NAMES THAT
275 ; MATCH EXACTLY
276 ;
277 ; TYPE 2 - FDB DRUGS THAT MAP TO THE DRUG FILE, BUT WITH DIFFERENT NAMES.
278 ; THIS CATEGORY INCLUDES DRUGS THAT ARE SHOWN IN VISTA AS GENERICS BUT
279 ; ON FDB AS BRAND NAME DRUGS
280 ;
281 ; TYPE 3 - FDB DRUGS THAT DO NOT MAP TO THE DRUG FILE, BUT DO MAP TO THE
282 ; VA PRODUCT FILE (NDF). IF ANY OF THESE DRUGS MIGHT BE ORDERED VIA ERX,
283 ; IT MIGHT BE A GOOD IDEA TO ADD THEM TO THE DRUG FILE.
284 ; NOTE: FOR TYPE 3 AND ABOVE DRUGS, ERX WILL STILL FUNCTION PROPERLY BUT
285 ; INSTEAD OF MAPPING THE DRUG TO THE DRUG FILE, WILL MAP IT AS A FREE TEXT
286 ; DRUG AND WILL SEND A MAIL MESSAGE ABOUT THE MAPPING ERROR SO THAT THE
287 ; DRUG CAN BE CONSIDERED FOR ADDING TO THE DRUG FILE
288 ;
289 ; TYPE 4 - FDB DRUGS THAT DO NOT MAP TO THE DRUG FILE AND ARE ALSO NOT
290 ; FOUND IN THE NDF. THIS MIGHT BE THE CASE FOR NEWER DRUGS. ERX WILL
291 ; STILL FUNCTION, BUT THESE WILL BE FREE TEXT DRUGS. THE REMEDY IS AN
292 ; UPDATE FROM THE VA OF THE NDF OR ADDING THE DRUGS TO THE NDF AND THE
293 ; DRUG FILE. (THERE ARE COMPLEXITIES IN ADDING DRUGS TO THE NDF BECAUSE
294 ; OF HOW TO THEN HANDLE AN UPDATE FROM THE VA)
295 ;
296 ; TYPE 5 - DRUGS IN THE DRUG FILE THAT ARE NOT FOUND IN THE FDB DRUG DATABASE
297 ; MAPPING. THIS MIGHT INCLUDE BRAND NAME DRUGS IN THE DRUG FILE THAT HAVE
298 ; BEEN MAPPED TO GENERICS WHEN COMING FROM FDB. IN ANY CASE, THESE ARE DRUGS
299 ; FOR WHICH THERE IS NO PATH TO MAP FROM THEM TO FDB. (REDUCING THE NUMBER
300 ; OF DRUGS IN THIS TYPE TO ZERO WILL BE A GOAL BEFORE IMPLEMENTING PHASE II
301 ; OF ERX WHERE DRUGS WILL BE ORDERED ON VISTA AND SENT TO THE ERX
302 ; SERVICE.
303 ;
304 N FN S FN=1130590010.002 ;FILE NUMBER FOR C0P RXNORM FDB VUID MAPPING FILE
305 N C0PFDA
306 N ZI
307 S ZI=""
308 F S ZI=$O(^C0P("FDB","B",ZI)) Q:ZI="" D ;
309 . W !,ZI
310 . D DOONE(.C0PFDA,ZI) ;BUILD AN FDA
311 . D UPDIE ;WRITE TO FILE
312 . K C0PDFA
313 Q
314 ;
315DOONE(C0PFDA,ZI) ; RETURN FDA FOR MEDID ZI
316 N FN S FN=1130590010.002 ;FILE NUMBER FOR C0P RXNORM FDB VUID MAPPING FILE
317 N ZGCN,ZRXNCUI,ZNAME,ZVAIEN,ZDRUGIEN,ZROW,ZIEN,ZVANAME,ZRXNIEN,ZRXNTXT
318 S (ZGCN,ZRXNCUI,ZNAME,ZVAIEN,ZDRUGIEN,ZVANAME)=""
319 ;S ZROW("MEDID")=ZI ; FDB MEDID
320 S C0PFDA(FN,"?+1,",.02)=ZI ; FDB MEDID
321 S ZIEN=$O(^C0P("FDB","B",ZI,"")) ; IEN OF THE FDB MED
322 S C0PFDA(FN,"?+1,",1.02)=ZIEN ;POINTER TO FDB MED
323 ;S ZROW("FDBNAME")=$$FULLNAME^C0PLKUP(ZI) ; FDB MED NAME
324 S ZNAME=$$FULLNAME^C0PLKUP(ZI) ; FDB MED NAME
325 S C0PFDA(FN,"?+1,",2.02)=ZNAME ; FDB MED NAME
326 S ZGCN=$$GCN^C0PLKUP(ZI)
327 I ZGCN=0 D Q ; NO GCN, CAN'T GO FURTHER
328 . ;S ZROW("TYPE")=4
329 . S C0PFDA(FN,"?+1,",3)=4 ;TYPE 4, CAN'T MAP FDB TO RXN
330 . S C0PFDA(FN,"?+1,",.01)="MISSING RXN" ;NEED TO HAVE A .01
331 . ;D RNF1TO2^C0CRNF(ZARY,"ZROW")
332 ;S ZROW("GCN")=ZGCN
333 S C0PFDA(FN,"?+1,",.04)=$$GCN^C0PLKUP(ZI) ;GENERIC CATEGORY NUMBER
334 S ZRXNCUI=$$RXNCUI^C0PLKUP(ZGCN) ; RETRIEVE THE RXNORM CONCEPT ID
335 I ZRXNCUI="" W !,"ERROR, NO RXNCUI "_ZGCN B ; SHOULDN'T HAPPEN
336 S C0PFDA(FN,"?+1,",.01)=ZRXNCUI ; RXN CONCEPT
337 S ZRXNIEN=$O(^C0P("RXN","B",ZRXNCUI,"")) ; RXN CONCEPT IEN
338 S C0PFDA(FN,"?+1,",1.01)=ZRXNIEN ; POINTER TO RXN CONCEPT
339 S ZRXNTXT=$G(^C0P("RXN",ZRXNIEN,1,1,0)) ; FIRST LINE OF RXN TEXT
340 S C0PFDA(FN,"?+1,",2.01)=ZRXNTXT ; RXN CONCEPT LABEL
341 ;S ZROW("RXNCUI")=ZRXNCUI
342 S ZVUID=$$VUID^C0PLKUP(ZRXNCUI) ; FETCH THE VUID
343 I ZVUID="" D Q ; NO VUID FOUND
344 . ;S ZROW("TYPE")=4
345 . S C0PFDA(FN,"?+1,",3)=4 ;TYPE 4, CAN'T MAP RXNCUI TO VUID
346 . ;D RNF1TO2^C0CRNF(ZARY,"ZROW")
347 ;S ZROW("VUID")=ZVUID
348 S ZVUID=$TR(ZVUID,"^","|") ; CAN'T HAVE ^ IN FIELDS
349 S C0PFDA(FN,"?+1,",.03)=ZVUID ;SET OF VUIDS
350 I ZVUID["|" S ZVUID=$P(ZVUID,"|",1) ; USE THE FIRST ONE
351 S ZVAIEN=$$VAPROD^C0PLKUP(ZVUID) ; IEN IN VA PRODUCTS (NDF)
352 I +ZVAIEN=0 D Q ; NOT FOUND IN NDF
353 . ;S ZROW("TYPE")=4
354 . S C0PFDA(FN,"?+1,",3)=4 ;TYPE 4, CAN'T MAP VUID TO NDF
355 . ;D RNF1TO2^C0CRNF(ZARY,"ZROW")
356 S ZDRUGIEN=$$DRUG^C0PLKUP(ZVAIEN) ; IEN IN DRUG FILE
357 I ZDRUGIEN["^" S ZDRUGIEN=$P(ZDRUGIEN,"^",1) ; USE THE FIRST ONE
358 I +ZDRUGIEN=0 D Q ;
359 . S ZROW("TYPE")=3
360 . S C0PFDA(FN,"?+1,",3)=3 ;TYPE 3, CAN'T MAP VUID TO DRUG FILE
361 . ;S ZROW("VANDFNAME")=$$GET1^DIQ(50.68,ZVAIEN_",",.01) ;NDF NAME
362 . S C0PFDA(FN,"?+1,",1.04)=ZVAIEN ;POINTER TO NDF
363 . S C0PFDA(FN,"?+1,",2.04)=$$GET1^DIQ(50.68,ZVAIEN_",",.01) ;NDF NAME
364 . ;D RNF1TO2^C0CRNF(ZARY,"ZROW")
365 S ZVANAME=$$GET1^DIQ(50,ZDRUGIEN_",",.01) ; VA DRUG NAME
366 S C0PFDA(FN,"?+1,",2.03)=ZVANAME ; VA DRUG FILE NAME
367 S C0PFDA(FN,"?+1,",1.03)=$G(ZDRUGIEN) ; VA DRUG FILE IEN
368 ;S ZROW("VANAME")=ZVANAME ;
369 I ZVANAME=$$UP^XLFSTR(ZNAME) S ZROW("TYPE")=1
370 E S ZROW("TYPE")=2
371 S C0PFDA(FN,"?+1,",3)=ZROW("TYPE") ; MATCHING TYPE 1 OR 2
372 ;D RNF1TO2^C0CRNF(ZARY,"ZROW")
373 ;B
374 Q
375 ;
376UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
377 ;Q ;//SMH don't want an update
378 ;I C0PFDA(FN,"+1,",3)'=3 Q ;
379 ;I C0PFDA(FN,"+1,",1.02)=1 Q ;
380 ;ZWR C0PFDA ;
381 K ZERR
382 D CLEAN^DILF
383 D UPDATE^DIE("","C0PFDA","","ZERR")
384 ;I $D(ZERR) D ;
385 ;. W "ERROR",!
386 ;. ZWR ZERR
387 ;. B
388 K C0PFDA
389 Q
390 ;
Note: See TracBrowser for help on using the repository browser.