source: ePrescribing/trunk/p/C0PLOAD.m@ 1691

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

initial release of ePrescribing

File size: 9.1 KB
RevLine 
[1595]1C0PLOAD ; VEN/SMH - File Loading Utilties ; 5/8/12 4:53pm
2 ;;1.0;C0P;;Apr 25, 2012;Build 103
3 ; (C) Sam Habiel 2012
4 ;
5 ;Copyright 2012 Sam Habiel. Licensed under the terms of the GNU
6 ;General Public License See attached copy of the License.
7 ;
8 ;This program is free software; you can redistribute it and/or modify
9 ;it under the terms of the GNU General Public License as published by
10 ;the Free Software Foundation; either version 2 of the License, or
11 ;(at your option) any later version.
12 ;
13 ;This program is distributed in the hope that it will be useful,
14 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;GNU General Public License for more details.
17 ;
18 ;You should have received a copy of the GNU General Public License along
19 ;with this program; if not, write to the Free Software Foundation, Inc.,
20 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 ; The routine contains utilities for Reading Files from
22 ; RxNorm and FDB into Fileman files
23 ;
24 ; This is a pretty pretty alpha version. Right now it just has FDB.
25 ;
26 ; These files definitions will be existing already. They should
27 ; be installed as part of the KIDS build containing this routine.
28 ;
29 ; The import templates will be also part of KIDS. They should
30 ; already exist by the time you run this routine.
31 ;
32 ; The drug file is produced by importing a table called 'tblCompositeDrugs'
33 ; provided in an access database from NewCrop accessed using parameter
34 ; '1' for desiredData from this webservice:
35 ; http://preproduction.newcropaccounts.com/V7/WebServices/Update1.asmx?op=GetMostRecentDownloadUrl
36 ;
37 ; The webservice provides a URL to a zip file; when unzipped, it produces an
38 ; access database with tables for allergies, drugs, pharamcies, healthplans, and
39 ; diagnoses.
40 ;
41 ; The following command (from mdb-tools) was used to extract this into an RRF
42 ; format (i.e. '|' delimited).|
43 ;
44 ; mdb-sql -HFp -d'|' -i selecttblCompositeDrug.sql NCFull-200910.mdb > Drug.rrf
45 ;
46 ; The SQL was necessary to skip a word-processing field which I couldn't import
47 ; into fileman using the fileman import tool (this is simply a technical
48 ; restriction; if I hand wrote my import I could have used a word processing
49 ; field and used WP^DIE to file it.) That's field's name is 'etc'.
50
51 ; The SQL statement is as follows: SELECT MEDID, GCN_SEQNO, MED_NAME_ID,
52 ; MED_NAME, MED_ROUTED_MED_ID_DESC, MED_ROUTED_DF_MED_ID_DESC, MED_MEDID_DESC,
53 ; MED_STATUS_CD, MED_ROUTE_ID, ROUTED_MED_ID, ROUTED_DOSAGE_FORM_MED_ID,
54 ; MED_STRENGTH, MED_STRENGTH_UOM, MED_ROUTE_ABBR, MED_ROUTE_DESC,
55 ; MED_DOSAGE_FORM_ABBR, MED_DOSAGE_FORM_DESC, GenericDrugName,
56 ; DosageFormOverride, MED_REF_DEA_CD, MED_REF_DEA_CD_DESC,
57 ; MED_REF_MULTI_SOURCE_CD, MED_REF_MULTI_SOURCE_CD_DESC,
58 ; MED_REF_GEN_DRUG_NAME_CD, MED_REF_GEN_DRUG_NAME_CD_DESC,
59 ; MED_REF_FED_LEGEND_IND, MED_REF_FED_LEGEND_IND_DESC, GENERIC_MEDID,
60 ; MED_NAME_TYPE_CD, GENERIC_MED_REF_GEN_DRUG_NAME_CD, MED_NAME_SOURCE_CD,
61 ; DrugInfo, GenericDrugNameOverride, FormularyDrugID, Manufacturer, Status,
62 ; TouchDate, DrugTypeID FROM tblCompositeDrug
63 ;
64 ; The allergies file is produced by importing the tblCompositeAllergy file
65 ;
66 ; Here's the mdb command to extract the file.
67 ; mdb-export -HQ -d "|" NCFull-201203.mdb tblCompositeAllergy > tblCompositeAllergy.rrf
68 ;
69 ; There is no SQL here.
70 ;
71 ; Once you have both files, you can adjust the routine to where the files are
72 ; and then import them by calling the PEPs below.
73 ;
74 ; Update: I wrote a bash script to automate this: it's called:
75 ; drug_data_extract.sh
76 ;
77FDBIMP ; FDB Drug File Import; PEP. Interactive (for now).
78 ;
79 ;
80 N FILEPATH
81 R "Enter RRF FDB Drug File with Full Path: ",FILEPATH:60,!
82 I '$L(FILEPATH) QUIT
83 ;
84 ; NB: The following will only work on Unix
85 N PATH,FILE
86 N PIECES S PIECES=$L(FILEPATH,"/")
87 S PATH=$P(FILEPATH,"/",1,PIECES-1)
88 S FILE=$P(FILEPATH,"/",PIECES)
89 ;
90 ; Kill off the existing file
91 N %1 S %1=^C0P("FDB",0) ; save zero node
92 S $P(%1,"^",3,4)="" ; zero last record numbers
93 K ^C0P("FDB") ; kill file
94 S ^C0P("FDB",0)=%1 ; restore zero node
95 ;
96 ; Import File from text extract (Please I want an ODBC driver!)
97 ;
98 D CLEAN^DILF
99 N CONTROL
100 S CONTROL("FLAGS")="E" ; External Values...
101 S CONTROL("MSGS")="" ; go as normal in ^TMP("DIERR",$J)
102 S CONTROL("MAXERR")="100" ; abort if you can't file a hundred records
103 ; S CONTROL("IOP")="HOME" ; Send to home device ; smh - don't pass; API no like for HOME output
104 S CONTROL("QTIME")="" ; Don't Queue
105 N SOURCE
106 S SOURCE("FILE")=FILE ; File Name
107 S SOURCE("PATH")=PATH ; Directory
108 N FORMAT
109 S FORMAT("FDELIM")="|" ; Delimiter
110 S FORMAT("FIXED")="" ; Fixed Width?
111 S FORMAT("QUOTED")="" ; Are strings quoted?
112 ;
113 D FILE^DDMP(1130590010,"[C0P FDB TBLCOMPOSITEDRUG]",.CONTROL,.SOURCE,.FORMAT)
114 QUIT
115 ;
116FDBAIMP ; FDB Allergies Import; PEP. Interactive (for now)
117 ;
118 ;
119 N FILEPATH
120 R "Enter RRF FDB Allergy File with Full Path: ",FILEPATH:60,!
121 I '$L(FILEPATH) QUIT
122 ;
123 ; NB: The following will only work on Unix
124 N PATH,FILE
125 N PIECES S PIECES=$L(FILEPATH,"/")
126 S PATH=$P(FILEPATH,"/",1,PIECES-1)
127 S FILE=$P(FILEPATH,"/",PIECES)
128 ;
129 ; Kill off the existing file
130 N %1 S %1=^C0PALGY(0) ; save zero node
131 S $P(%1,"^",3,4)="" ; zero last record numbers
132 K ^C0PALGY ; kill file
133 S ^C0PALGY(0)=%1 ; restore zero node
134 ;
135 ; Import file from text extract
136 D CLEAN^DILF
137 N CONTROL
138 S CONTROL("FLAGS")="E" ; External Values...
139 S CONTROL("MSGS")="" ; go as normal in ^TMP("DIERR",$J)
140 S CONTROL("MAXERR")="100" ; abort if you can't file a hundred records
141 ; S CONTROL("IOP")="HOME" ; Send to home device ; smh - don't pass; API no like for HOME output
142 S CONTROL("QTIME")="" ; Don't Queue
143 N SOURCE
144 S SOURCE("FILE")=FILE ; File Name
145 S SOURCE("PATH")=PATH ; Directory
146 N FORMAT
147 S FORMAT("FDELIM")="|" ; Delimiter
148 S FORMAT("FIXED")="" ; Fixed Width?
149 S FORMAT("QUOTED")="" ; Are strings quoted?
150 ;
151 D FILE^DDMP(113059005,"[C0P FDB TBLCOMPOSITEALLERGY]",.CONTROL,.SOURCE,.FORMAT)
152 QUIT
153RXNIMP ; Import RxNorm Concepts File; Modded from C0CRXNRD
154 N FILEPATH
155 R "Enter RRF RxNorm Conepts File with Full Path: ",FILEPATH:60,!
156 I '$L(FILEPATH) QUIT
157 ;
158 ; NB: The following will only work on Unix
159 N PATH,FILE
160 N PIECES S PIECES=$L(FILEPATH,"/")
161 S PATH=$P(FILEPATH,"/",1,PIECES-1)
162 S FILE=$P(FILEPATH,"/",PIECES)
163 ;
164 N LINES S LINES=$$GETLINES(PATH,FILE)
165 D OPEN^%ZISH("FILE",PATH,FILE,"R")
166 ;
167 IF POP D EN^DDIOL("Error reading file..., Please check...") G EX
168 ;
169 N %1 S %1=^C0P("RXN",0)
170 S $P(%1,"^",3,4)=""
171 K ^C0P("RXN")
172 S ^C0P("RXN",0)=%1
173 ;
174 N C0CCOUNT
175 F C0CCOUNT=1:1 D Q:$$STATUS^%ZISH
176 . U IO
177 . N LINE R LINE:1
178 . IF $$STATUS^%ZISH QUIT
179 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
180 . N RXCUI,RXAUI,SAB,TTY,CODE,STR ; Fileman fields numbers below
181 . S RXCUI=$P(LINE,"|",1) ; .01
182 . S RXAUI=$P(LINE,"|",8) ; 1
183 . S SAB=$P(LINE,"|",12) ; 2
184 . ;
185 . ; Following lines not applicable here:
186 . ; If the source is a restricted source, decide what to do based on what's asked.
187 . ; N SRCIEN S SRCIEN=$$FIND1^DIC(176.003,"","QX",SAB,"B") ; SrcIEN in RXNORM SOURCES file
188 . ; N RESTRIC S RESTRIC=$$GET1^DIQ(176.003,SRCIEN,14,"I") ; 14 is restriction field; values 0-4
189 . ; If RESTRIC is zero, then it's unrestricted. Everything else is restricted.
190 . ; If user didn't ask to include restricted sources, and the source is restricted, then quit
191 . ; I 'INCRES,RESTRIC QUIT
192 . ;
193 . S TTY=$P(LINE,"|",13) ; 3
194 . S CODE=$P(LINE,"|",14) ; 4
195 . S STR=$P(LINE,"|",15) ; 5
196 . ; Remove embedded "^"
197 . S STR=$TR(STR,"^")
198 . ; Convert STR into an array of 80 characters on each line
199 . N STRLINE S STRLINE=$L(STR)\80+1
200 . ; In each line, chop 80 characters off, reset STR to be the rest
201 . N J F J=1:1:STRLINE S STR(J)=$E(STR,1,80) S STR=$E(STR,81,$L(STR))
202 . ; Now, construct the FDA array
203 . N RXNFDA
204 . S RXNFDA(1130590011.001,"+1,",.01)=RXCUI
205 . S RXNFDA(1130590011.001,"+1,",1)=RXAUI
206 . S RXNFDA(1130590011.001,"+1,",2)=SAB
207 . S RXNFDA(1130590011.001,"+1,",3)=TTY
208 . S RXNFDA(1130590011.001,"+1,",4)=CODE
209 . N RXNIEN S RXNIEN(1)=C0CCOUNT
210 . D UPDATE^DIE("","RXNFDA","RXNIEN")
211 . I $D(^TMP("DIERR",$J)) D EN^DDIOL("ERROR") G EX
212 . ; Now, file WP field STR
213 . D WP^DIE(1130590011.001,C0CCOUNT_",",5,,$NA(STR))
214EX D CLOSE^%ZISH("FILE")
215 QUIT
216GETLINES(PATH,FILENAME) ; Get number of lines in a file
217 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
218 U IO
219 N I
220 F I=1:1 R LINE:1 Q:$$STATUS^%ZISH
221 D CLOSE^%ZISH("FILE")
222 Q I-1
Note: See TracBrowser for help on using the repository browser.