source: cprs/branches/tmg-cprs/m_files/TMGNDF4E.m@ 1582

Last change on this file since 1582 was 796, checked in by Kevin Toppenberg, 14 years ago

Initial upload

File size: 14.3 KB
RevLine 
[796]1TMGNDF4E ;TMG/kst/FDA Import -- Copy Orderable --> OQV ;03/25/06
2 ;;1.0;TMG-LIB;**1**;11/21/07
3
4 ;" FDA - NATIONAL DRUG FILES COMPILING FUNCTIONS
5 ;" Copy of ORDERABLE ITEMS into ORDER QUICK VIEW file
6 ;"Kevin Toppenberg MD
7 ;"GNU General Public License (GPL) applies
8 ;"11-21-2006
9
10 ;"=======================================================================
11 ;" API -- Public Functions.
12 ;"=======================================================================
13 ;"Menu
14
15 ;"Sync2OQV -- ensure ALL ORDERABLE ITEMS (101.43) items are added to the ORDER QUICK VIEW (101.44)
16 ;"Fix1OQV(IEN101d43,Option) -- alter one entry in OQV file to reflect changes in ORDERABLE ITEM file (101.43)
17
18 ;"=======================================================================
19 ;" Private Functions.
20 ;"=======================================================================
21 ;"MakeNewQOVS -- save the old QUICK ORDER VIEW set, and create a new one.
22 ;"Add(RxSet,pOI) -- add 'name' to ORWDSET O RX record in ORDER QUICK VIEW file
23 ;"KillPrior(RxSet) -- kill ALL records in the RxSet in 101.44
24 ;"Check4BadOQV -- Scan through all ORDER QUICK VIEWS cheking fro pointers to bad records
25
26 ;"=======================================================================
27
28Menu
29 new Menu,UsrSlct
30 set Menu(0)="Pick Option to Sync ORDER QUICK VIEW (OQV) (4E)"
31 set Menu(1)="Sync imports to ORDER QUICK VIEW."_$char(9)_"Sync2OQV"
32 set Menu(2)="Check for BAD entries in ORDER QUICK VIEW file"_$char(9)_"Check4BadOQV"
33 set Menu("P")="Prev Stage"_$char(9)_"Prev"
34 set Menu("N")="Next Stage"_$char(9)_"Next"
35
36M1 write #
37 set UsrSlct=$$Menu^TMGUSRIF(.Menu,"^")
38
39 if UsrSlct="Sync2OQV" do Sync2OQV goto M1
40 if UsrSlct="Check4BadOQV" do Check4BadOQV goto M1
41 if UsrSlct="Prev" goto Menu^TMGNDF4C ;"quit can occur from there...
42 if UsrSlct="Next" goto Menu^TMGNDF4F ;"quit can occur from there...
43 if UsrSlct="^" goto MenuDone
44 goto M1
45
46MenuDone
47 quit
48
49
50Sync2OQV
51 ;"Purpose: To cycle through all items in the ORDERABLE ITEMS (101.43) file and
52 ;" ensure that they have been added to the ORDER QUICK VIEW (101.44) file
53 ;"Result: none.
54
55 ;"NOTE: This function will KILL prior entries in ORWD O RX record
56 ;" There are no pointers IN to this file, so deleting will not
57 ;" leave dangling pointers.
58
59 ;"NOTE: this function must ensure that the drugs are put into 101.44
60 ;" in alphabetical order
61 ;" ALSO, drugs should be added both with their generic and brand names.
62
63 ;"Here is an example of drugs that have been added 'properly'
64 ;" 1) ^ORD(101.44,16,20,0) = ^101.442PA^20^20
65 ;" 2) ^ORD(101.44,16,20,1,0) = 49^AMITRIPTYLINE TAB
66 ;" 3) ^ORD(101.44,16,20,2,0) = 53^CHLORPROMAZINE TAB
67 ;" 4) ^ORD(101.44,16,20,3,0) = 50^DIGOXIN TAB
68 ;" 5) ^ORD(101.44,16,20,4,0) = 44^DILTIAZEM TAB
69 ;" 6) ^ORD(101.44,16,20,5,0) = 49^ELAVIL <AMITRIPTYLINE TAB >
70 ;" 7) ^ORD(101.44,16,20,6,0) = 49^ENDEP <AMITRIPTYLINE TAB >
71 ;" 8) ^ORD(101.44,16,20,7,0) = 47^HCTZ <HYDROCHLOROTHIZIDE TAB >
72 ;" 9) ^ORD(101.44,16,20,8,0) = 47^HYDROCHLOROTHIZIDE TAB
73 ;" 10) ^ORD(101.44,16,20,9,0) = 50^LANOXIN <DIGOXIN TAB >
74 ;" 11) ^ORD(101.44,16,20,10,0) = 54^LEVOTHYROXINE TAB
75 ;" 12) ^ORD(101.44,16,20,11,0) = 54^LEVOXYL <LEVOTHYROXINE TAB >
76 ;" 13) ^ORD(101.44,16,20,12,0) = 46^LISINOPRIL TAB
77 ;" 14) ^ORD(101.44,16,20,13,0) = 52^PRAZOSIN CAP,ORAL
78 ;" 15) ^ORD(101.44,16,20,14,0) = 46^PRINIVIL <LISINOPRIL TAB >
79 ;" 16) ^ORD(101.44,16,20,15,0) = 48^SILDENAFIL TAB
80 ;" 17) ^ORD(101.44,16,20,16,0) = 54^SYNTHROID <LEVOTHYROXINE TAB >
81 ;" 18) ^ORD(101.44,16,20,17,0) = 48^VIAGRA <SILDENAFIL TAB >
82 ;" 19) ^ORD(101.44,16,20,18,0) = 46^ZESTRIL <LISINOPRIL TAB >
83 ;" 20) ^ORD(101.44,16,20,19,0) = 20
84 ;"21) ^ORD(101.44,16,20,20,0) = 54
85 ;"22) ^ORD(101.44,16,20,"B",20,19) =
86 ;"23) ^ORD(101.44,16,20,"B",54,20) =
87 ;"24) ^ORD(101.44,16,20,"C","AMITRIPTYLINE TAB ",1) =
88 ;"25) ^ORD(101.44,16,20,"C","CHLORPROMAZINE TAB ",2) =
89 ;"26) ^ORD(101.44,16,20,"C","DIGOXIN TAB ",3) =
90 ;"27) ^ORD(101.44,16,20,"C","DILTIAZEM TAB ",4) =
91 ;"28) ^ORD(101.44,16,20,"C","ELAVIL <AMITRIPTYLINE TAB >",5) =
92 ;"29) ^ORD(101.44,16,20,"C","ENDEP <AMITRIPTYLINE TAB >",6) =
93 ;"30) ^ORD(101.44,16,20,"C","HCTZ <HYDROCHLOROTHIZIDE TAB >",7) =
94 ;"31) ^ORD(101.44,16,20,"C","HYDROCHLOROTHIZIDE TAB ",8) =
95 ;"32) ^ORD(101.44,16,20,"C","LANOXIN <DIGOXIN TAB >",9) =
96 ;"33) ^ORD(101.44,16,20,"C","LEVOTHYROXINE TAB ",10) =
97 ;"34) ^ORD(101.44,16,20,"C","LEVOXYL <LEVOTHYROXINE TAB >",11) =
98 ;"35) ^ORD(101.44,16,20,"C","LISINOPRIL TAB ",12) =
99 ;"36) ^ORD(101.44,16,20,"C","PRAZOSIN CAP,ORAL ",13) =
100 ;"37) ^ORD(101.44,16,20,"C","PRINIVIL <LISINOPRIL TAB >",14) =
101 ;"38) ^ORD(101.44,16,20,"C","SILDENAFIL TAB ",15) =
102 ;"39) ^ORD(101.44,16,20,"C","SYNTHROID <LEVOTHYROXINE TAB >",16) =
103
104 do MakeNewQOVS ;"Get a fresh order set to work in.
105
106 set RxSet=$$GetOQVSet^TMGNDFUT
107 if RxSet'>0 do goto AADone
108 . write "Can't find record 'ORWDSET O RX' in ORDER QUICK VIEW (101.44) file.",!
109 . write "Aborting.",!
110
111 ;"Kill all prior display data in ORDER QUICK VIEW file: ORWDSET O RX record
112 do KillPrior(RxSet)
113
114 new pAddArray set pAddArray=$name(^TMG("TMP","KILL","Add 101.44 Temp"))
115 kill @pAddArray
116
117 write "Organizing drugs for addition to ORDER QUICK VIEW...",!
118 new Itr,IEN22706d9
119 new abort set abort=0
120 set IEN22706d9=$$ItrInit^TMGITR(22706.9,.Itr)
121 do PrepProgress^TMGITR(.Itr,20,0,"IEN22706d9")
122 if IEN22706d9'="" for do quit:(+$$ItrNext^TMGITR(.Itr,.IEN22706d9)'>0)!abort
123 . if $$UserAborted^TMGUSRIF set abort=1 quit
124 . if $piece($get(^TMG(22706.9,IEN22706d9,1)),"^",4)=1 quit ;" 1=skip
125 . new tIEN101d43,gIEN101d43
126 . set tIEN101d43=+$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",5)
127 . set gIEN101d43=+$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",6)
128 . if tIEN101d43>0 do
129 . . new name set name=$piece($get(^ORD(101.43,tIEN101d43,0)),"^",1)
130 . . if (name="")!(name="<DUPLICATE>") do KillOI^TMGNDFUT(tIEN101d43) quit
131 . . set @pAddArray@(name,tIEN101d43)=""
132 . . new SynIEN set SynIEN=0
133 . . for set SynIEN=$order(^ORD(101.43,tIEN101d43,2,SynIEN)) quit:(+SynIEN'>0) do
134 . . . new SynName set SynName=$get(^ORD(101.43,tIEN101d43,2,SynIEN,0))
135 . . . set SynName=$$Trim^TMGSTUTL(SynName)
136 . . . set SynName=SynName_" <"_name_">"
137 . . . set @pAddArray@(SynName,tIEN101d43)=""
138 . if gIEN101d43>0 do
139 . . new name set name=$piece($get(^ORD(101.43,gIEN101d43,0)),"^",1)
140 . . if (name="")!(name="<DUPLICATE>") do KillOI^TMGNDFUT(gIEN101d43) quit
141 . . set @pAddArray@(name,gIEN101d43)=""
142 . . new SynIEN set SynIEN=0
143 . . for set SynIEN=$order(^ORD(101.43,gIEN101d43,2,SynIEN)) quit:(+SynIEN'>0) do
144 . . . new SynName set SynName=$get(^ORD(101.43,gIEN101d43,2,SynIEN,0))
145 . . . set SynName=$$Trim^TMGSTUTL(SynName)
146 . . . set SynName=SynName_" <"_name_">"
147 . . . set @pAddArray@(SynName,gIEN101d43)=""
148 do ProgressDone^TMGITR(.Itr)
149 if abort=1 goto AADone
150
151 ;"Now add all drugs
152 write "Adding drugs to ORDER QUICK VIEW...",!
153 new Itr,DispName
154 set abort=0
155 set DispName=$$ItrAInit^TMGITR(pAddArray,.Itr)
156 do PrepProgress^TMGITR(.Itr,20,1,"DispName")
157 if DispName'="" for do quit:($$ItrANext^TMGITR(.Itr,.DispName)="")!abort
158 . if $$UserAborted^TMGUSRIF set abort=1 quit
159 . new IEN set IEN=$order(@pAddArray@(DispName,""))
160 . set pOQV=$$Add(RxSet,IEN,DispName)
161 do ProgressDone^TMGITR(.Itr)
162
163AADone
164 write "Done.",!
165 do PressToCont^TMGUSRIF
166 quit
167
168
169MakeNewQOVS
170 ;"Purpose: To save the old QUICK ORDER VIEW set, and create a new one.
171 ;"Note: Because the drugs have to be added to the file in alphabetical order,
172 ;" it is required to create a NEW order set. I will save the old one
173 ;" for future reference.
174
175 new DIC,X,Y,%,RxSet
176
177 set RxSet=$$GetOQVSet^TMGNDFUT
178 if RxSet'>0 do goto MNQSDone
179 . write "Can't find record 'ORWDSET O RX' in ORDER QUICK VIEW (101.44) file.",!
180 . write "Aborting.",!
181
182 new nowS
183 do NOW^%DTC
184 S Y=X ;"% current fileman date returned in X (no time)
185 D DD^%DT ;"convert to external format.
186 set nowS=Y
187
188 new newName set newName="ORWDSET O RX -- "_nowS
189 write "Saving old ORDER QUICK VIEW set as: ",newName,!
190 new TMGFDA,TMGMSG,TMGIEN
191 set TMGFDA(101.44,RxSet_",",.01)=newName
192 do FILE^DIE("K","TMGFDA","TMGMSG")
193 do ShowIfDIERR^TMGDEBUG(.TMGMSG)
194
195 set TMGFDA(101.44,"+1,",.01)="ORWDSET O RX"
196 set TMGFDA(101.44,"+1,",6)="NOW"
197 do UPDATE^DIE("EK","TMGFDA","TMGIEN","TMGMSG")
198 do ShowIfDIERR^TMGDEBUG(.TMGMSG)
199
200MNQSDone
201 quit
202
203
204Add(RxSet,pOI,RxName)
205 ;"Purpose: to add 'name' to ORWDSET O RX record in ORDER QUICK VIEW ('OQV')file
206 ;"Input: RxSet -- the record number in OQV to add records to.
207 ;" pOI -- a pointer to (i.e. the IEN of) record in ORDERABLE ITEM (101.43) file
208 ;" RxName -- The name to display in CPRS
209 ;"Results: returns the IEN of the new record.
210
211 new TMGFDA,TMGMSG,TMGIEN,PriorErrorFound
212 new result set result=0
213
214 if pOI=0 do goto AdDone
215 . write !,"Skipping addition of ",RxName," because it doesn't",!
216 . write "seem linked to a PHARMACY ORDERABLE ITEM.",!
217 set TMGFDA(101.442,"+1,"_RxSet_",",.01)=pOI
218 set TMGFDA(101.442,"+1,"_RxSet_",",2)=RxName
219
220 new $etrap set $etrap="write !,""ERROR TRAPPED."",! quit"
221Ad1 do UPDATE^DIE("S","TMGFDA","TMGIEN","TMGMSG")
222 if $$ShowIfError^TMGDBAPI(.TMGMSG,.PriorErrorFound) goto AdDone
223 set result=+$get(TMGIEN(1))
224
225AdDone
226 quit result
227
228
229KillPrior(RxSet)
230 ;"Purpose: To kill ALL records in the RxSet in 101.44
231 ;"Note: I am fairly certain that no other files point to this file
232 ;" (there are no pointers IN). So I can just kill.
233 ;" CAUTION: this might not be the right thing to do in another system.
234
235 new temp merge temp=^ORD(101.44,RxSet,20,0)
236 kill ^ORD(101.44,RxSet,20)
237 merge ^ORD(101.44,RxSet,20,0)=temp
238 set $piece(^ORD(101.44,RxSet,20,0),"^",3)=0 ;"most recently assigned IEN
239 set $piece(^ORD(101.44,RxSet,20,0),"^",4)=0 ;"current total number of records
240
241 quit
242
243
244 ;"==============================
245Fix1OQV(IEN101d43,Option)
246 ;"Purpose: to alter one entry in OQV file to reflect changes
247 ;" in ORDERABLE ITEM file (101.43)
248 ;"Input: IEN101d43 -- IEN in ORDERABLE ITEM file (101.43)
249 ;" Option -- OPTIONAL. Format:
250 ;" Option("FIX CHAIN")=1 <--- changes will be propigate forward
251 ;" to file POI, OI, OQV etc.
252 ;" OPTION("FIX CHAIN","IEN22706d9")=Source IEN
253 ;" Option("QUIET")=1 <-- supress text output
254 ;" Option("IEN50","TRADE")=IEN50 for Trade Name
255 ;" Option("IEN50","GENERIC")=IEN50 for Generic Name
256 ;" Option("DRUG NAME AND FORM","TRADE")=tradeNameAF
257 ;" Option("DRUG NAME AND FORM","GENERIC")=genericNameAF
258 ;" Option("IEN50.7","TRADE")=IEN50d7
259 ;" Option("IEN50.7","GENERIC")=IEN50d7
260 ;" Option("IEN101.43","TRADE")=IEN101d43
261 ;" Option("IEN101.43","GENERIC")=IEN101d43
262 ;" Option("DELETING")=1 <-- deleting chain (not IEN22706d9)
263 ;"NOTE: The entries in the OQV file have to be set up in ALPHABETICAL order.
264 ;" This function will NOT reorder these. If name is completely changed, then
265 ;" it will likely appear out of alphabetical order. This may hinder finding it.
266 ;" -- Such a problem could be fixed by runnin: Sync2OQV^TMGNDF4E
267 ;"Result: 1 if error, 0 if OK.
268
269 new result set result=0
270 new RxSet,quiet
271 set quiet=$get(Option("QUIET"))=1
272 set RxSet=$$GetOQVSet^TMGNDFUT(quiet)
273 if RxSet=0 goto F1OQVDone
274
275 new OQVIENS set OQVIENS=$$GetOQVIENS^TMGNDFUT(IEN101d43,RxSet)
276 if OQVIENS=0 do goto F1OQVDone
277 . if quiet quit
278 . write "Can't find link ORDERABLE ITEM--> ORDER QUICK VIEW (OQV).",!
279 . write "Try do a batch add of imports into OQV.",!
280 . write "Can't insert OQV with out reordering...",!
281
282 new drugName set drugName=$piece($get(^ORD(101.43,IEN101d43,0)),"^",1)
283 if ($get(Option("DELETING"))=1)!(drugName="") set drugName="<DELETED>"
284
285 new TMGFDA,TMGMSG
286 set TMGFDA(101.442,OQVIENS,2)=drugName
287 new temp set temp=$$TrimFDA^TMGDBAPI(.TMGFDA)
288 if $data(TMGFDA) do
289 . do FILE^DIE("KS","TMGFDA","TMGMSG")
290 . set result=$$ShowIfError^TMGDBAPI(.TMGMSG) ;"show FM errors, even if quiet.
291
292F1OQVDone
293 quit result
294
295
296Check4BadOQV
297 ;"Purpose: Scan through all ORDER QUICK VIEWS and see if any are pointing
298 ;" to bad records
299
300 new RxSet set RxSet=$$GetOQVSet^TMGNDFUT
301 if RxSet=0 goto C4BOQVDone
302 new totalCt set totalCt=0
303 new count set count=0
304
305 new index set index=0
306 for set index=$order(^ORD(101.44,RxSet,20,index)) quit:(+index'>0) do
307 . set totalCt=totalCt+1
308 . new s set s=$get(^ORD(101.44,RxSet,20,index,0))
309 . new ptr set ptr=+s
310 . if ptr=0 quit
311 . new name set name=$piece(s,"^",2)
312 . if $piece($get(^ORD(101.43,ptr,0)),"^",1)'="" quit
313 . write !,"BAD: ",name,!
314 . write "OQV 101.44:#",index,",",RxSet,", --> OI 101.43:#",ptr," which is empty",!
315 . do KillOQV^TMGNDFUT(index_","_RxSet_",")
316 . write " ... deleted.",!
317 . set count=count+1
318
319 write !,totalCt," entries scanned.",!
320 write count," bad entries found.",!
321 do PressToCont^TMGUSRIF
322
323C4BOQVDone
324 quit
325
Note: See TracBrowser for help on using the repository browser.