source: cprs/branches/tmg-cprs/m_files/TMGNDF1F.m@ 1406

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

Initial upload

File size: 17.8 KB
Line 
1TMGNDF1F ;TMG/kst/FDA Import: Work with drug ROUTES ;03/25/06
2 ;;1.0;TMG-LIB;**1**;02/26/07
3
4 ;" FDA - NATIONAL DRUG FILES COMPILING FUNCTIONS
5 ;" -- Working with Dosage ROUTES
6 ;"Kevin Toppenberg MD
7 ;"GNU General Public License (GPL) applies
8 ;"2-26-07
9
10 ;"=======================================================================
11 ;" API -- Public Functions.
12 ;"=======================================================================
13 ;"Menu
14
15 ;"=======================================================================
16 ;" Private Functions.
17 ;"=======================================================================
18
19 ;"=======================================================================
20 ;"=======================================================================
21
22 ;"ScrnAll -- Fix missing Dose ROUTES from DRUG file
23
24 ;"=======================================================================
25 ;" Private Functions.
26 ;"=======================================================================
27Menu
28 ;"Purpose: Provide menu to entry points of main routines
29
30 new Menu,UsrSlct
31 set Menu(0)="Pick Option for Ensuring correct DOSE ROUTES (1F)"
32
33 new i set i=1
34 set Menu(i)="Find new import ROUTES"_$char(9)_"FINDNEW" set i=i+1
35 set Menu(i)="Match imports ROUTE --> VA ROUTE"_$char(9)_"MATCH" set i=i+1
36 set Menu(i)="Fix imports with missing ROUTE"_$char(9)_"FixMissingRoute" set i=i+1
37 set Menu(i)="Screen ALL imports for INCORRECT ROUTE"_$char(9)_"ScreenAll" set i=i+1
38 set Menu(i)="Edit match file (IF NEEDED)"_$char(9)_"EditMatch" set i=i+1
39 set Menu(i)="Edit VA ROUTES (file 51.2) (ONLY IF NEEDED)"_$char(9)_"EDITVA" set i=i+1
40 set Menu(i)="USE links for import ROUTE --> VA ROUTE (DO THIS LAST)"_$char(9)_"FillVARoute" set i=i+1
41
42 set Menu("P")="Prev Stage"_$char(9)_"Prev"
43 set Menu("N")="Next Stage"_$char(9)_"Next"
44
45MC1 write #
46 set UsrSlct=$$Menu^TMGUSRIF(.Menu,"^")
47 if UsrSlct="^" goto MCDone
48 if UsrSlct=0 set UsrSlct=""
49
50 if UsrSlct="FixMissingRoute" do FixMissingRoute goto MC1
51 if UsrSlct="ScreenAll" do ScrnAll goto MC1
52
53 if UsrSlct="FillVARoute" do FillVARoute goto MC1
54 if UsrSlct="EditMatch" do EditMatchFile goto MC1
55 if UsrSlct="FINDNEW" do FindUnmatched goto MC1
56 if UsrSlct="MATCH" do HandleLinks goto MC1
57 if UsrSlct="EDITVA" do EditVARoutes goto MC1
58
59
60 if UsrSlct="Prev" goto Menu^TMGNDF1E ;"quit can occur from there...
61 if UsrSlct="Next" goto Menu^TMGNDF2A ;"quit can occur from there...
62 goto MC1
63
64MCDone
65 quit
66
67 ;"=======================================================================
68
69
70ScrnAll
71 ;"Purpose: Fix missing or screen for Dose ROUTES from DRUG file
72 ;"Results -- none.
73
74 write "Scanning for records to display...",!
75 do SelEdRArray()
76 quit
77
78
79FixMissingRoute
80 ;"Purpose: Fix missing or screen for Dose ROUTES from DRUG file
81 ;"Results: none
82
83 new PreSelArray,JustSelected
84 set JustSelected=0
85
86 write "Scanning for entries with no DOSE ROUTE...",!
87 do GetFldVScreen^TMGSELED(22706.9,3,"$$ScrnTest^TMGNDF1F","PreSelArray")
88
89 write "Show just those preselected? (Faster)"
90 new % set %=1 do YN^DICN write !
91 if %=1 set JustSelected=1
92 else write "Now scanning for the rest of the entries...",!
93 do SelEdRArray(.PreSelArray,JustSelected)
94
95 do FindUnmatched
96 quit
97
98
99ScrnTest()
100 ;"Purpose: this is a callback function for GetFldVScreen^TMGSELED
101 ;" Screen out if value is null (i.e. LOOK FOR MISSING VALUES),
102 ;" or SKIP=true,
103 ;"Input: None. But following global-scope variables will be available for use
104 ;" File -- the File name or number
105 ;" FieldNum -- the field number
106 ;" IEN -- the IEN of the current record.
107 ;" RecValue -- the current value of the field
108 ;"Results: 1 if should be skipped, 0 if should be keps
109
110 new result set result=1;" default to SKIP
111 if RecValue'="" goto STDone ;"if not null, then skip
112 ;"Now see if 22706.9 is marked for SKIP
113 if $piece($get(^TMG(22706.9,IEN,1)),"^",4)=1 goto STDone ;"1;4=SKIP field, 1=SKIP
114 set result=0 ;"keep
115STDone
116 quit result
117
118
119Scrn2Test()
120 ;"Purpose: this is a callback function for GetFldVScreen^TMGSELED
121 ;" Screen out if record in 22706.9=SKIP,
122 ;"Input: None. But following global-scope variables will be available for use
123 ;" File -- the File name or number
124 ;" FieldNum -- the field number
125 ;" IEN -- the IEN of the current record.
126 ;" RecValue -- the current value of the field
127 ;"Results: 1 if should be skipped, 0 if should be keps
128
129 new result set result=1;" default to SKIP
130 ;"Now see if matching record in 22706.9 is marked for SKIP
131 if $piece($get(^TMG(22706.9,IEN,1)),"^",4)=1 goto ST2Done ;"1;4=SKIP field, 1=SKIP
132 if $data(^TMG(22706.9,IEN))=0 goto ST2Done ;"if null record (for some reason)
133 set result=0 ;"keep
134ST2Done
135 quit result
136
137
138
139SelEdRArray(SelArray,JustSelected)
140 ;"Purpose: Fix missing or screen for Dose ROUTES from DRUG file
141 ;"Input: SelList -- PASS BY REFERENCE. An OUT PARAMETER. Format
142 ;" List(IEN)=""
143 ;" List(IEN)="" <-- IEN in 50 that was selected.
144 ;" Mode -- 0 for missing routes, or "ALL" for screening all
145 ;"Results: none
146
147 new Options,IEN
148 set Options("FIELDS",1)=".05^TRADENAME^40"
149 set Options("FIELDS",1,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
150 set Options("FIELDS",2)="3.4^FDA DOSAGE FORM^15"
151 ;"set Options("FIELDS",2,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
152 set Options("FIELDS",3)="3^FDA ROUTE^15"
153 ;"set Options("FIELDS",4)="3.1^VA ROUTE^15"
154 set Options("FIELDS","MAX NUM")=3
155 set Options("FILE")="22706.9^TMG FDA IMPORT COMPILED"
156 ;"Get all records with SKIP THIS RECORD = 0 (KEEP)
157
158 if +$get(JustSelected)=0 do
159 . do GetFldVScreen^TMGSELED(22706.9,3,"$$Scrn2Test^TMGNDF1F",$name(Options("IEN LIST")))
160 else do
161 . merge Options("IEN LIST")=SelArray
162 . kill SelArray
163
164SE1 if $data(SelArray) do
165 . set IEN=""
166 . for set IEN=$order(SelArray(IEN)) quit:(IEN="") do
167 . . if $data(Options("IEN LIST",IEN))>0 do
168 . . . set Options("IEN LIST",IEN,"SEL")=""
169
170 if $$SELED^TMGSELED(.Options)'=2 goto SERDone
171 if $$GetIENs^TMGSELED(.Options)=0 goto SERDone
172 goto SE1
173
174SERDone quit
175
176
177
178 ;"=======================================================================
179
180
181FindUnmatched
182 ;"Purpose: Find new, unhandled, FDA dosage forms, and create a new record in
183 ;" TMG NDF FORMS VISTA EQUIVALENTS
184
185 new Array
186 write !,"Checking compiled FDA import records for new FDA drug ROUTES...",!
187 do GetFDARoute(.Array)
188 do TrimFoundRoutes(.Array)
189 if $data(Array) do
190 . write $$ListCt^TMGMISC("Array")," new drug ROUTES found. Adding now...",!
191 . do StubInNewRec(.Array)
192 . do HandleLinks
193 . write "Done.",!
194 else do
195 . write !,"No new FDA drug ROUTES found",!
196
197 do PressToCont^TMGUSRIF
198
199 quit
200
201
202GetFDARoute(Array)
203 ;"Purpose: to scan file 22706.9 (TMG FDA IMPORT COMPILED) and compile a list of all ROUTES
204 ;"Input: Array -- PASS BY REFERENCE. An OUT PARAMETER. Prior entries will be killed
205 ;"Results: Data passed back as follows:
206 ;" Array(Route)=""
207 ;" Array(Route)=""
208 ;"Result: none.
209
210 new Itr,IEN
211 set IEN=$$ItrInit^TMGITR(22706.9,.Itr)
212 do PrepProgress^TMGITR(.Itr,20,0,"IEN")
213 if IEN'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN)'>0)
214 . if $piece($get(^TMG(22706.9,IEN,1)),"^",4)=1 quit ;"1=SKIP
215 . new Route
216 . set Route=$piece($get(^TMG(22706.9,IEN,0)),"^",5)
217 . if Route="" quit
218 . set Array(Route)=IEN
219 do ProgressDone^TMGITR(.Itr)
220
221
222 quit
223
224
225TrimFoundRoutes(Array)
226 ;"Purpose: To remove entries from Array, for which mapping to a VistA equivilent
227 ;" has already ben created
228 ;"Input: Array -- PASS BY REFERENCE. Array as created by GetFDARoute
229 new Form set Form=""
230 for set Form=$order(Array(Form)) quit:(Form="") do
231 . new shortForm set shortForm=$extract(Form,1,30)
232 . if $order(^TMG(22706.82,"B",shortForm,""))'="" kill Array(Form)
233 quit
234
235
236StubInNewRec(Array)
237 ;"Purpose: To create new entries in 22706.8 for FDA forms not yet added.
238 ;"Input: Array -- PASS BY REFERENCE. An array of Forms to be added, as created
239 ;" by GetFDARoute.
240 ;"NOTE: ALL entries in Array will be added as new records. Thus, screening for
241 ;" prior entries must be performed, such as through TrimFoundRoutes()
242
243 new TMGFDA,TMGMSG,TMGIEN
244 new Form set Form=""
245 for set Form=$order(Array(Form)) quit:(Form="") do
246 . set TMGFDA(22706.82,"+1,",.01)=Form
247 . kill TMGMSG,TMGIEN
248 . do UPDATE^DIE("K","TMGFDA","TMGIEN","TMGMSG")
249 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
250 quit
251
252
253
254DisplayRoutes(Answers)
255 ;"Purpose: to display the list of Dosage forms that don't have a corresponding VA DOSE FORM
256 ;"Input: Answers -- PASS BY REFERENCE, and OUT PARAMETER. Old values killed.
257 ;"Output: Answers filled in as follows:
258 ;" Answers(n)=RxRoute^IEN in 22706.82
259 ;" Answers(n)=RxRoute^IEN in 22706.82
260 ;"Results: None
261
262 kill Answers
263 new count set count=0
264 new Itr,IEN
265 set IEN=$$ItrInit^TMGITR(22706.82,.Itr)
266 if IEN'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN)'>0)
267 . new VARouteIEN set VARouteIEN=+$piece($get(^TMG(22706.82,IEN,0)),"^",2)
268 . if VARouteIEN'=0 quit
269 . new FDARoute set FDARoute=$piece($get(^TMG(22706.82,IEN,0)),"^",1)
270 . set count=count+1
271 . write count,". ",FDARoute," --> ??",!
272 . set Answers(count)=FDARoute_"^"_IEN
273 if count=0 do
274 . write " -- List is Empty --",!
275
276 quit
277
278
279HandleLinks
280 ;"Purpose: To interact with user and find a link between FDA dosage forms, and VA dosage forms
281 ;"Input: none
282 ;"Output: results are stored in 22706.8
283 ;"Results: none
284
285 new Answers
286 new done set done=0
287 new input set input="R"
288 new LastNum
289 new VAPIndex
290
291 for do quit:(done=1)
292 . if input="R" do
293 . . write !!
294 . . write "-------------------------------------------------------------------",!
295 . . write "Specify which Dosage ROUTE to Look up",!
296 . . write "-------------------------------------------------------------------",!
297 . . do DisplayRoutes(.Answers)
298 . . set LastNum=$order(Answers(""),-1)
299 . . if LastNum="" set LastNum="^"
300 . . write "-------------------------------------------------------------------",!
301 . . write "Specify which Dosage ROUTE to Look up",!
302 . . write "-------------------------------------------------------------------",!
303 . write " R to refresh, E show Examples",!
304 . write " ^ to continue",!
305 . write "Enter number to Lookup (or codes listed above): ",LastNum,"//"
306 . read input
307 . if input="" set input=LastNum write LastNum
308 . write !
309 . ;"if input="" set input="^"
310 . if input="" set input=LastNum write LastNum
311 . set input=$$UP^XLFSTR(input)
312 . if input="^" set done=1
313 . if +input=input do
314 . . do DoLink(input,.Answers)
315 . . set input="R"
316 . if input="E" do
317 . . write "...Enter number to show examples for: "_LastNum_"//"
318 . . read input,!
319 . . if input="" set input=LastNum
320 . . do ShowExamples(+input,.Answers,.VAPIndex)
321 . . set input="R"
322
323 quit
324
325
326DoLink(InputNum,Answers)
327 ;"Purpose: To try to establish a link between 1 FDA ROUTE and a VA ROUTE
328 ;"Input: InputNum -- the number that the user chose to fix.
329 ;" Answers -- PASS BY REFERENCE. Array as put out by DisplayRoutes
330 ;"Output: if link is established then it will be store in 22706.8
331 ;"Results: none
332
333 new RxRoute,IEN
334 set RxRoute=$piece($get(Answers(InputNum)),"^",1)
335 set IEN=$piece($get(Answers(InputNum)),"^",2)
336 if RxRoute="" goto DLDone
337 new done set done=0
338
339 new VistaIEN set VistaIEN=0
340 new DIC,X,Y
341 set DIC=51.2
342 set X=RxRoute
343 set DIC(0)="M"
344 do ^DIC
345 if +Y>0 do
346 . write !,"Match automatically found...",!
347 . write "Use '",$piece(Y,"^",2),"' for '",RxRoute,"'"
348 . new % set %=1 do YN^DICN
349 . if %'=1 quit
350 . set VistaIEN=+Y
351 if VistaIEN'=0 goto DL2
352
353 set DIC(0)="AEQML"
354 set DIC("A")="Enter VA DOSE FORM name: // "
355 write !,"Enter name to match '"_RxRoute_"'"
356 do ^DIC write !
357 if +Y>0 do
358 . write "Use '",$piece(Y,"^",2),"' for '",RxRoute,"'"
359 . new % set %=1 do YN^DICN
360 . if %'=1 quit
361 . set VistaIEN=+Y
362
363DL2 if VistaIEN'=0 do
364 . new TMGFDA,TMGMSG
365 . set TMGFDA(22706.82,IEN_",",1)=VistaIEN
366 . do FILE^DIE("K","TMGFDA","TMGMSG")
367 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
368
369DLDone
370 quit
371
372
373ShowExamples(InputNum,Answers,Index)
374 ;"Purpose: To show all entries using dosage form specified
375 ;"Input: InputNum -- the input number from user to show
376 ;" Answers -- PASS BY REFERENCE, array as put out by DisplayForms
377 ;" Index -- OPTIONAL. An index of VAProduct
378
379 new RxRoute
380 set RxRoute=$piece($get(Answers(InputNum)),"^",1)
381 if RxRoute="" goto SEDone
382
383 new count set count=0
384 new IEN set IEN=0
385 new abort set abort=0
386 for set IEN=$order(^TMG(22706.9,"ROUTE",RxRoute,IEN)) quit:(+IEN'>0)!abort do
387 . write "#",IEN,": "
388 . do DumpRec2^TMGDEBUG(22706.9,IEN_",")
389 . set count=count+1
390 . write " -- Press ENTER to Continue (ESC to quit) --"
391 . new ch set ch=$$KeyPressed^TMGUSRIF(0,60)
392 . write !
393 . if ch=27 set abort=1 quit
394
395 if count=0 do
396 . write !,"Couldn't find any examples (error occurred).",!
397
398 do PressToCont^TMGUSRIF
399SEDone
400 quit
401
402
403 ;"========================================
404EditVARoutes
405 ;"Purpose: To edit Vista Routes file file 51.2
406
407 new Options,IEN
408 set Options("FIELDS",1)=".01^NAME^30"
409 set Options("FIELDS",1,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
410 set Options("FIELDS",2)="1^ABBREVIATION^15"
411 set Options("FIELDS",3)="3^PACKAGE USE^10"
412 set Options("FIELDS",4)="5^INACTIVATION DATE^10"
413 set Options("FIELDS",5)="6^IV FLAG^5"
414 set Options("FIELDS","MAX NUM")=5
415 set Options("FILE")="51.2^MEDICATION ROUTE"
416
417 do GetFldValue^TMGSELED(51.2,.01,"ALL",$name(Options("IEN LIST")))
418
419EF1
420 if $$SELED^TMGSELED(.Options)'=2 goto EFDone
421 if $$GetIENs^TMGSELED(.Options)=0 goto EFDone
422 goto EF1
423
424EFDone quit
425
426 ;"========================================
427
428FillVARoute
429 ;"Purpose: To ensure that there is a entry in the VA ROUTE field
430 ;" in all records in TMG FDA IMPORT COMPILED
431 ;" (that are not marked to be skipped)
432
433 new Itr,IEN,abort,count,missingRoute
434 set abort=0,count=0,missingRoute=0
435
436 write "Scanning through all imports and applying matches from ROUTE --> VA ROUTE...",!
437 set IEN=$$ItrInit^TMGITR(22706.9,.Itr)
438 do PrepProgress^TMGITR(.Itr,20,0,"IEN")
439 if IEN'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN)'>0)!abort
440 . if $piece($get(^TMG(22706.9,IEN,1)),"^",4)=1 quit ;"1=SKIP
441 . if $$UserAborted^TMGUSRIF set abort=1 quit
442 . new FDARoute set FDARoute=$piece($get(^TMG(22706.9,IEN,0)),"^",5)
443 . new VARouteIEN set VARouteIEN=+$piece($get(^TMG(22706.9,IEN,7)),"^",7)
444 . if FDARoute="" do quit
445 . . if VARouteIEN'=0 quit
446 . . ;"write !,"No FDA drug ROUTE found for drug in record #",IEN,!
447 . . set missingRoute=missingRoute+1
448 . new mapIEN set mapIEN=+$order(^TMG(22706.82,"B",$extract(FDARoute,1,30),""))
449 . new VistaIEN set VistaIEN=+$piece($get(^TMG(22706.82,mapIEN,0)),"^",2)
450 . if (VARouteIEN=VistaIEN)&(VistaIEN'=0) quit ;"already set properly
451 . if VistaIEN=0 do quit
452 . . write !,"Mapping to VA ROUTE incomplete: ",FDARoute," --> ??. Edit Match File.",!
453 . new TMGFDA,TMGMSG
454 . set TMGFDA(22706.9,IEN_",",3.1)=VistaIEN
455 . do FILE^DIE("K","TMGFDA","TMGMSG")
456 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
457 . ;"write !,IEN," field 3.1 set to `",VistaIEN,!
458 . set count=count+1
459
460 write !,count," records changed",!
461 if missingRoute>0 write missingRoute," imports are missing a specified ROUTE",!
462 do PressToCont^TMGUSRIF
463
464FRFDone
465 quit
466
467 ;"========================================
468
469EditMatchFile
470 ;"Purpose: use Selector to browse and edit TMG FDA ROUTE VISTA EQUIVALENTS (22706.82)
471
472 new Options,IEN
473 set Options("FIELDS",1)=".01^FDA ROUTE^25"
474 set Options("FIELDS",1,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
475 set Options("FIELDS",2)="1^VISTA ROUTE^25"
476 set Options("FIELDS","MAX NUM")=2
477 set Options("FILE")="22706.82^TMG FDA ROUTES VISTA EQUIVALENTS"
478
479 do GetFldValue^TMGSELED(22706.82,.01,"ALL",$name(Options("IEN LIST")))
480
481SFM1
482 if $$SELED^TMGSELED(.Options)'=2 goto SFMDone
483 if $$GetIENs^TMGSELED(.Options)=0 goto SFMDone
484 goto SFM1
485
486SFMDone quit
487
488
489
490
Note: See TracBrowser for help on using the repository browser.