source: ePrescribing/trunk/p/C0PLKUP.m@ 1742

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

initial release of ePrescribing

File size: 7.5 KB
Line 
1C0PLKUP ; VEN/SMH - Extrinsics to map med numbers ; 5/8/12 4:09pm
2 ;;1.0;C0P;;Apr 25, 2012;Build 103
3 ;Copyright 2009 Sam Habiel. 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 Q
20FDBFN() Q 1130590010 ; First Databank Drugs file number
21RXNFN() Q 1130590011.001 ; RxNorm Concepts file number
22FULLNAME(MEDID) ; $$ Public - Get FDB full name for the drug
23 ; Used in Bulletin
24 ; Input: MEDID By Value
25 ; Output: Extrinsic
26 N C0PIEN S C0PIEN=$$FIND1^DIC($$FDBFN,"","QX",MEDID,"B")
27 Q $$GET1^DIQ($$FDBFN,C0PIEN,"MED MEDID DESC")
28GCN(MEDID) ; $$ Public - Get GCN given MEDID
29 ; Input: MEDID by Value
30 ; Output: Extrinsic
31 ; MEDID is the .01 field in the First Databank Drug file
32 ; GCN is the 1 field = Generic Code Number
33 ; WS supplies MEDID in return. Need Generic Code Number to map to RxNorm.
34 N X,Y,DTOUT,DUOUT,DLAYGO,DIC
35 S DIC=$$FDBFN
36 S X=MEDID
37 S DIC(0)="OXZ" ; One entry only, Exact match, return zero node
38 D ^DIC
39 I Y<0 Q "" ; Failed match
40 Q $P(Y(0),U,2) ; GCN is 2nd piece of zero node
41 ;
42RXNCUI(GCN) ; $$ Public - Get RxNorm CUI using GCN
43 ; Input: GCN by Value
44 ; Output: Extrinsic
45 ; Seach GCN index for an exact match
46 ; One match, quick lookup, Exact matching
47 N C0PIEN S C0PIEN=$$FIND1^DIC($$RXNFN,"","QX",GCN,"GCN")
48 Q $$GET1^DIQ($$RXNFN,C0PIEN,.01)
49 ;
50VUID(RXNCUI) ; $$ Public - Get VUID(s) for given RXNCUI for Clinical Drug
51 ; Input: RXNCUI by Value
52 ; Output: Caret delimited extrinsic. Should not be more than 2 entries.
53 ; @;4 means return IEN and VUID.
54 N C0POUT,C0PVUID
55 I '$D(^DIC($$RXNFN,0,"GL")) Q "" ; RXNORM UMLS NOT INSTALLED
56 D FIND^DIC($$RXNFN,"","@;4","PXQ",RXNCUI,"","VUIDCD","","","C0POUT")
57 ; Example output:
58 ; SAM("DILIST",0)="2^*^0^"
59 ; SAM("DILIST",0,"MAP")="IEN^4"
60 ; SAM("DILIST",1,0)="112482^4010153"
61 ; SAM("DILIST",2,0)="112484^4016607"
62 I +$G(C0POUT("DILIST",0))=0 Q "" ; no matches
63 N I S I=0
64 F S I=$O(C0POUT("DILIST",I)) Q:I="" S C0PVUID=$G(C0PVUID)_$P(C0POUT("DILIST",I,0),U,2)_"^"
65 S C0PVUID=$E(C0PVUID,1,$L(C0PVUID)-1) ; remove trailing ^
66 Q C0PVUID
67VUID2(MEDID) ; $$ Public - Get VUID(s) for given MEDID
68 Q $$VUID($$RXNCUI($$GCN(MEDID)))
69VAPROD(VUID) ; $$ Public - Get VA Product IEN from VUID
70 ; Input VUID by Value
71 ; Output: Extrinsic
72 Q $$FIND1^DIC(50.68,"","QX",VUID,"AVUID")
73DRUG(VAPROD) ; $$ Public - Get Drug(s) using VA Product IEN
74 ; Input: VA Product IEN By Value
75 ; OUtput: Caret delimited extrinsic
76 N C0POUT,C0PDRUG
77 ;D FIND^DIC(50,"","@;4","PXQ",VAPROD,"","C0PVAPROD","","","C0POUT")
78 ;D FIND^DIC(50,"","@;4","PXQ",VAPROD,"","AC0P","","","C0POUT") ;GPL 7/10
79 I +VAPROD=0 Q 0 ;
80 I '$D(^PSDRUG("AC0P",VAPROD)) Q 0 ;W "AC0P cross reference error" Q 0 ;
81 ;S C0PDRUG=$O(^PSDRUG("AC0P",VAPROD,"")) ;GPL ABOVE FIND DOESN'T WORK
82 N I S I=""
83 S C0PDRUG=""
84 F S I=$O(^PSDRUG("AC0P",VAPROD,I)) Q:I="" D ;
85 . S C0PDRUG=C0PDRUG_I_"^"
86 S C0PDRUG=$E(C0PDRUG,1,$L(C0PDRUG)-1) ; remove trailing ^
87 Q C0PDRUG
88 ; Example output:
89 ; C0POUT("DILIST",0)="2^*^0^"
90 ; C0POUT("DILIST",0,"MAP")="IEN^4"
91 ; C0POUT("DILIST",1,0)="1512^"
92 ; C0POUT("DILIST",2,0)="21632^"
93 ; or
94 ; C0POUT("DILIST",0)="0^*^0^"
95 ; C0POUT("DILIST",0,"MAP")="IEN^4"
96 I +$G(C0POUT("DILIST",0))=0 Q "" ; no matches
97 N I S I=0
98 F S I=$O(C0POUT("DILIST",I)) Q:I="" S C0PDRUG=$G(C0PDRUG)_$P(C0POUT("DILIST",I,0),U)_"^"
99 S C0PDRUG=$E(C0PDRUG,1,$L(C0PDRUG)-1) ; remove trailing ^
100 Q C0PDRUG
101DRUG2(MEDID) ; $$ Public - Get Drugs for a FDB MEDID
102 ; Input: MEDID by Value
103 ; Output: Caret delimited extrinsic
104 N OUT S OUT=""
105 N C0PDRUGS ; tmp holding space for drugs
106 N C0PVUIDS S C0PVUIDS=$$VUID2(MEDID)
107 N C0PI
108 F C0PI=1:1:$L(C0PVUIDS,U) D ; for each VUID
109 . N C0PVUID S C0PVUID=$P(C0PVUIDS,U,C0PI)
110 . N C0PVAPROD S C0PVAPROD=$$VAPROD(C0PVUID) ; get VA Product
111 . S C0PDRUGS=$$DRUG(C0PVAPROD)
112 . S:$L(C0PDRUGS) OUT=OUT_C0PDRUGS_"^"
113 S OUT=$E(OUT,1,$L(OUT)-1) ; rm trailing ^
114 Q OUT
115RXNCUI2(BASE) ; $$ Public - Get RxNorm CUI for FDB Ingredient/Base
116 ; Input: BASE By Value
117 ; Output: RxNorm CUI
118 N C0PIEN S C0PIEN=$$FIND1^DIC($$RXNFN,"","QX",BASE,"NDDFBASE")
119 Q $$GET1^DIQ($$RXNFN,C0PIEN,.01)
120VUIDIN(RXNCUI) ; $$ Public - Get VUID Ingredient for RxNorm CUI
121 ; Input: RXNCUI By Value
122 ; Output: VUID
123 N C0PIEN S C0PIEN=$$FIND1^DIC($$RXNFN,"","QX",RXNCUI,"VUIDIN")
124 Q $$GET1^DIQ($$RXNFN,C0PIEN,"CODE")
125VAGEN(VUID) ; $$ Public - Get VA Generic for VUID Ingredient
126 ; Input: VUID By Value
127 ; Output: IEN^VA Generic Name (i.e. .01 field value)
128 N C0PIEN S C0PIEN=$$FIND1^DIC(50.6,"","QX",VUID,"AVUID")
129 N C0P01 S C0P01=$$GET1^DIQ(50.6,C0PIEN,.01)
130 Q C0PIEN_"^"_C0P01
131VAGEN2(BASE) ; $$ Public - Get VA Generic for FDB Ingredient/Base
132 ; Input: BASE By Value
133 ; Output: IEN^VA Generic Name (i.e. .01 field value)
134 Q $$VAGEN($$VUIDIN($$RXNCUI2(BASE)))
135DRUGING(VUID) ; $$ Public - Get Drug Ingredient for VUID Ingredient
136 ; Input: VUID By Value
137 ; Output: IEN^Drug Ingredient Name (i.e. .01 field value)
138 N C0PIEN S C0PIEN=$$FIND1^DIC(50.416,"","QX",VUID,"AVUID")
139 N C0P01 S C0P01=$$GET1^DIQ(50.416,C0PIEN,.01)
140 Q C0PIEN_"^"_C0P01
141DRUGING2(BASE) ; $$ Public - Get Drug Ingredient for FDB Ingredient/Base
142 ; Input: BASE By Value
143 ; Output: IEN^Drug Ingredient Name (i.e. .01 field value)
144 Q $$DRUGING($$VUIDIN($$RXNCUI2(BASE)))
145RXNCUI3(VUID) ; $$ Public - Get RXNCUI for VUID (any VUID)
146 ; Input: VUID By Value
147 ; Output: RXNCUI
148 I $G(VUID)="" Q ""
149 N C0PIEN ; S C0PIEN=$$FIND1^DIC($$RXNFN,"","QX",VUID,"VUID")
150 S C0PIEN=$O(^C0P("RXN","VUID",VUID,"")) ;GPL FIX FOR MULTIPLES
151 Q $$GET1^DIQ($$RXNFN,C0PIEN,.01)
152NDDFBASE(RXNCUI) ; $$ Public - Get NDDF Ingredient for RXNCUI
153 ; Input: RXNCUI By Value
154 ; Output: NDDF Base code
155 N C0PIEN S C0PIEN=$$FIND1^DIC($$RXNFN,"","QX",RXNCUI,"RNDDFBASE")
156 Q +$$GET1^DIQ($$RXNFN,C0PIEN,"CODE") ; strip leading zeros
157NDDFBAS2(VUID) ; $$ Public - Get NDDF Ingredient for VUID
158 ; NB: WILL ONLY WORK IF VUID IS AN INGREDIENT VUID, NOT A CLINICAL DRUG
159 ; Input: VUID By Value
160 ; Output: NDDF Base code
161 Q $$NDDFBASE($$RXNCUI3(VUID))
162 ;
163DRUGNAM(CURRENTMEDS,ZMED) ; EXTRINSIC WHICH RETURNS THE FULL NAME
164 ; OF THE DRUG FROM CURRENTMEDS, PASSED BY REFERENCE
165 ; ZMED IS THE NUMBER OF THE MED IN THE ARRAY
166 ; IF THERE IS A DRUGID, IT IS USED TO LOOKUP THE NAME
167 ; IF THERE IS NO DRUGID, IT IS A FREETEXT MED AND THE NAME IS
168 ; PULLED FROM THE SIG, WHERE IS IT STORED WITH A "|" DELIMITER
169 N ZD
170 I $D(CURRENTMEDS(ZMED,"DRUG")) S ZD=$$FULLNAME(CURRENTMEDS(ZMED,"DRUG"))
171 E D ; pull the name from the first piece of the sig
172 . N ZDSIG
173 . S ZDSIG=$G(CURRENTMEDS(ZMED,"SIG",1,0))
174 . S ZD=$P(ZDSIG,"|",1)
175 Q ZD
176 ;
177CODES(MEDID) ; EXTRINSIC WHICH RETURNS A LINE OF CODES FOR THE MED
178 ; FORMAT IS MEDID:XXX GCN:XXX RXNORM:XXX VUID:XXX DRUG:XXX
179 N ZL
180 S ZL="MEDID:"_MEDID_" "
181 N ZG S ZG=$$GCN(MEDID) ; GCN (GENERIC CONCEPT NUMBER)
182 S ZL=ZL_"GCN:"_ZG_" "
183 N ZR S ZR=$$RXNCUI(ZG) ; RXNORM CONCEPT ID
184 S ZL=ZL_"RXNORM:"_ZR_" "
185 N ZV S ZV=$$VUID(ZR) ; VUID (VA UNIVERSAL ID)
186 S ZL=ZL_"VUID:"_ZV_" "
187 N ZD S ZD=$$DRUG2(MEDID) ; VISTA DRUG FILE IEN
188 I ZD=0 S ZD=""
189 S ZL=ZL_"DRUG:"_ZD_" "
190 Q ZL
191 ;
Note: See TracBrowser for help on using the repository browser.