source: cprs/branches/tmg-cprs/m_files/TMGNDF1E.m@ 1548

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

Initial upload

File size: 16.6 KB
Line 
1TMGNDF1E ;TMG/kst/FDA Import: Pick imports to skip ;03/25/06
2 ;;1.0;TMG-LIB;**1**;01/23/07
3
4 ;"FDA - NATIONAL DRUG FILES COMPILING FUNCTIONS
5 ;"More code for determining files to skip.
6 ;"Kevin Toppenberg MD
7 ;"GNU General Public License (GPL) applies
8 ;"1-23-07
9
10 ;"=======================================================================
11 ;" API -- Public Functions.
12 ;"=======================================================================
13 ;"Menu
14
15 ;"=======================================================================
16 ;" Private Functions.
17 ;"=======================================================================
18 ;"=======================================================================
19
20Menu
21 ;"Purpose: To give an interactive menu of tools to clean up data.
22
23 new Menu,UsrSlct
24 new i set i=0
25 set Menu(i)="Pick Option for Picking Imports to SKIP (1E)",i=i+1
26 set Menu(i)="Flag DUPLICATE entries to be skipped"_$char(9)_"DUPS",i=i+1
27 set Menu(i)="Flag entries with MISSING STRENGTH to be skipped"_$char(9)_"RemoveStrMissing",i=i+1
28 set Menu(i)="Flag entries with MISSING UNITS to be skipped"_$char(9)_"RemoveUnitMissing",i=i+1
29 set Menu(i)="Flag entries with MISSING INGREDIENTS to be skipped"_$char(9)_"RemoveIngredMissing",i=i+1
30 set Menu(i)="Flag entries with MISSING TRADE NAME to be skipped"_$char(9)_"RemoveTNameMissing",i=i+1
31 set Menu(i)="Flag entries with MISSING GENERIC NAME to be skipped"_$char(9)_"RemoveGNameMissing",i=i+1
32 set Menu(i)="Flag entries with MISSING NDC to be skipped"_$char(9)_"RemoveNDCMissing",i=i+1
33 set Menu(i)="Manually PICK drugs to be skipped: Trade Name, Units, Strength"_$char(9)_"PICK",i=i+1
34 set Menu(i)="Manually PICK drugs to be skipped: Trade Name, Generic Name, Strength"_$char(9)_"PICK2",i=i+1
35 set Menu(i)="Manually PICK drugs to be skipped: Long Name, Trade&Form, Generic&Form"_$char(9)_"PICK3",i=i+1
36 set Menu(i)="Manually PICK drugs to be UNSKIPPED: Trade Name, Units, Strength"_$char(9)_"UNPICK",i=i+1
37 set Menu("P")="Prev Stage"_$char(9)_"Prev"
38 set Menu("N")="Next Stage"_$char(9)_"Next"
39
40CD1
41 write #
42 set UsrSlct=$$Menu^TMGUSRIF(.Menu,"^")
43 if UsrSlct="^" goto CDDone
44 if UsrSlct=0 set UsrSlct=""
45
46 if UsrSlct="Prev" goto Menu^TMGNDF1D ;"quit can occur from there...
47 if UsrSlct="Next" goto Menu^TMGNDF1F ;"quit can occur from there...
48
49 if UsrSlct="DUPS" do RemoveDups goto CD1
50 if UsrSlct="RemoveStrMissing" do RemoveStrMissing goto CD1
51 if UsrSlct="RemoveUnitMissing" do RemoveUnitMissing goto CD1
52 if UsrSlct="RemoveTNameMissing" do RemoveTNameMissing goto CD1
53 if UsrSlct="RemoveGNameMissing" do RemoveGNameMissing goto CD1
54 if UsrSlct="RemoveNDCMissing" do RemoveNDCMissing goto CD1
55 if UsrSlct="RemoveIngredMissing" do RemoveIngredMissing goto CD1
56 if UsrSlct="PICK" do PickSkips(,,1,1) goto CD1
57 if UsrSlct="PICK2" do PickSkp2(,) goto CD1
58 if UsrSlct="PICK3" do PickSkp3(,) goto CD1
59 if UsrSlct="UNPICK" do PickSkips(,,,,"ALL") goto CD1
60 goto CDDone
61CDDone
62 quit
63
64
65
66
67SelectScan(ScrnCode,editStr,edtUnit)
68 ;"Purpose: Set chosen records to be skipped
69 ;" This will scan for records passing screen and pre-select
70 ;" them. Then display them to the user to allow
71 ;" the individual drugs to be de-selected if wanted.
72 ;" After finishing the review, then all the selected
73 ;" records may be set to SKIP
74 ;"Input: ScrnCode -- OPTIONAL. M Code to execute in the following format:
75 ;" set flagToSkip=$$SomeTest(IEN)
76 ;" Code may use variable IEN, which is record in 22706.9
77 ;" editStr: Optional. Default=0. 1 if Can edit Strength field
78 ;" editUnit: Optional. Default=0. 1 if Can edit Unit field
79 ;"Output: Records may be set to be skipped if user chooses to do this.
80 ;"Results: none
81
82 new SelArray,flagToSkip
83 set ScrnCode=$get(ScrnCode)
84
85 new Itr,IEN,abort,name
86 set abort=0
87 write "Scanning drugs for entries to be preselected for skipping...",!
88 set IEN=$$ItrInit^TMGITR(22706.9,.Itr)
89 do PrepProgress^TMGITR(.Itr,20,0,"IEN")
90 if IEN'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN)'>0)!abort
91 . if $piece($get(^TMG(22706.9,IEN,1)),"^",4)'=0 quit ;"0=KEEP; 1=SKIP
92 . if $$KeyPressed^TMGUSRIF=27 set abort=27 quit
93 . set flagToSkip=0
94 . new $etrap set $etrap="write !,""Error trapped."",!"
95 . if ScrnCode'="" xecute ScrnCode
96 . if flagToSkip=1 set SelArray(IEN)=""
97
98 new %
99 if $data(SelArray)=0 do goto:(%'=2) SScDone
100 . set %=1
101 . write !,"No entries found. Done" do YN^DICN
102 else do goto:(%=-1) SScDone
103 . set %=1
104 . write !,"Show ONLY preselected drugs (faster)"
105 . do YN^DICN write !
106 . if %=2 write !,"Now will show entries PRESELECTED in list of all drugs.",!
107 do PickSkips(.SelArray,(%=1),.editStr,.editUnit)
108
109SScDone
110 quit
111
112
113
114PickSkips(SelArray,JustSelected,editStr,edtUnit,SkipValue)
115 ;"Purpose: to select records to mark as to be skipped.
116 ;"Input: SelArray: Optional. PASS BY REFERENCE. An array of preselected IEN's
117 ;" Format: SelArray(IEN in 22706.9)="" <-- IEN preselected
118 ;" JustSelected: Optional. if 1, then ONLY IENs from SelArray shown.
119 ;" editStr: Optional. Default=0. 1 if Can edit Strength field
120 ;" editUnit: Optional. Default=0. 1 if Can edit Unit field
121 ;" SkipValue: OPTIONAL. Default=0.
122 ;" 0=show only values NOT marked to be skipped
123 ;" 1=show only values MARKED to be skipped
124 ;" ALL=show BOTH skip and non-skipped fields.
125 ;"Output: User may alter the value of SKIP THIS RECORD field for all records
126 ;"Results: none
127
128 new Options,IEN
129 set Options("FIELDS",1)=".05^TRADENAME^50"
130 set Options("FIELDS",1,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
131 set Options("FIELDS",2)="1^STRENGTH^9"
132 if +$get(editStr)=0 set Options("FIELDS",2,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
133 set Options("FIELDS",3)="2^UNIT^9"
134 if +$get(editUnit)=0 set Options("FIELDS",3,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
135 set Options("FIELDS",4)="6^SKIP THIS RECORD^4"
136 set Options("FIELDS","MAX NUM")=4
137 set Options("FILE")="22706.9^TMG FDA IMPORT COMPILED"
138
139 set SkipValue=$get(SkipValue,0)
140 if +$get(JustSelected)=0 do
141 . ;"Get all records with chosed SKIP THIS RECORD value
142 . if SkipValue=0 do
143 . . new ScrnCode set ScrnCode="($get(RecValue)=1)" ;"Field has THREE possible values: 0,1,NULL
144 . . do GetFldVScreen^TMGSELED(22706.9,6,ScrnCode,$name(Options("IEN LIST")))
145 . else do
146 . . do GetFldValue^TMGSELED(22706.9,6,SkipValue,$name(Options("IEN LIST")))
147 else do
148 . merge Options("IEN LIST")=SelArray
149
150PSK1 if $data(SelArray) do
151 . set IEN=""
152 . for set IEN=$order(SelArray(IEN)) quit:(IEN="") do
153 . . if $data(Options("IEN LIST",IEN))>0 do
154 . . . set Options("IEN LIST",IEN,"SEL")=""
155
156 if $$SELED^TMGSELED(.Options)'=2 goto PSKDone
157 if $$GetIENs^TMGSELED(.Options)=0 goto PSKDone
158 goto PSK1
159
160PSKDone quit
161
162
163PickSkp2(SelArray,JustSelected,SkipValue)
164 ;"Purpose: to select records to mark as to be skipped.
165 ;" Showing Tradename and Generic name
166 ;"Input: SelArray: Optional. PASS BY REFERENCE. An array of preselected IEN's
167 ;" Format: SelArray(IEN in 22706.9)="" <-- IEN preselected
168 ;" JustSelected: Optional. if 1, then ONLY IENs from SelArray shown.
169 ;" SkipValue: OPTIONAL. Default=0.
170 ;" 0=show only values NOT marked to be skipped
171 ;" 1=show only values MARKED to be skipped
172 ;" ALL=show BOTH skip and non-skipped fields.
173 ;"Output: User may alter the value of SKIP THIS RECORD field for all records
174 ;"Results: none
175
176 new Options,IEN
177 set Options("FIELDS",1)=".05^TRADENAME^30"
178 set Options("FIELDS",1,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
179 set Options("FIELDS",2)=".07^GENERIC NAME^30"
180 set Options("FIELDS",2,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
181 set Options("FIELDS",3)="1^STRENGTH^9"
182 set Options("FIELDS",3,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
183 set Options("FIELDS",4)="6^SKIP THIS RECORD^4"
184 set Options("FIELDS","MAX NUM")=4
185 set Options("FILE")="22706.9^TMG FDA IMPORT COMPILED"
186
187 set SkipValue=$get(SkipValue,0)
188 if +$get(JustSelected)=0 do
189 . ;"Get all records with chosed SKIP THIS RECORD value
190 . if SkipValue=0 do
191 . . new ScrnCode set ScrnCode="($get(RecValue)=1)" ;"Field has THREE possible values: 0,1,NULL
192 . . do GetFldVScreen^TMGSELED(22706.9,6,ScrnCode,$name(Options("IEN LIST")))
193 . else do
194 . . do GetFldValue^TMGSELED(22706.9,6,SkipValue,$name(Options("IEN LIST")))
195 else do
196 . merge Options("IEN LIST")=SelArray
197
198PSK21 if $data(SelArray) do
199 . set IEN=""
200 . for set IEN=$order(SelArray(IEN)) quit:(IEN="") do
201 . . if $data(Options("IEN LIST",IEN))>0 do
202 . . . set Options("IEN LIST",IEN,"SEL")=""
203
204 if $$SELED^TMGSELED(.Options)'=2 goto PSK2Done
205 if $$GetIENs^TMGSELED(.Options)=0 goto PSK2Done
206 goto PSK21
207
208PSK2Done quit
209
210
211
212PickSkp3(SelArray,JustSelected,SkipValue)
213 ;"Purpose: to select records to mark as to be skipped.
214 ;" Showing Tradename and Generic name
215 ;"Input: SelArray: Optional. PASS BY REFERENCE. An array of preselected IEN's
216 ;" Format: SelArray(IEN in 22706.9)="" <-- IEN preselected
217 ;" JustSelected: Optional. if 1, then ONLY IENs from SelArray shown.
218 ;" SkipValue: OPTIONAL. Default=0.
219 ;" 0=show only values NOT marked to be skipped
220 ;" 1=show only values MARKED to be skipped
221 ;" ALL=show BOTH skip and non-skipped fields.
222 ;"Output: User may alter the value of SKIP THIS RECORD field for all records
223 ;"Results: none
224
225 new Options,IEN
226 set Options("FIELDS",1)=".04^LONG NAME^30"
227 set Options("FIELDS",1,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
228 set Options("FIELDS",2)=".055^TRADE NAME & FORM - 40^20"
229 set Options("FIELDS",2,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
230 set Options("FIELDS",3)=".075^GENERIC NAME & FORM - 40^20"
231 set Options("FIELDS",3,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
232 set Options("FIELDS",4)="6^SKIP THIS RECORD^4"
233 set Options("FIELDS","MAX NUM")=4
234 set Options("FILE")="22706.9^TMG FDA IMPORT COMPILED"
235
236 set SkipValue=$get(SkipValue,0)
237 if +$get(JustSelected)=0 do
238 . ;"Get all records with chosed SKIP THIS RECORD value
239 . if SkipValue=0 do
240 . . new ScrnCode set ScrnCode="($get(RecValue)=1)" ;"Field has THREE possible values: 0:keep,1:skip,NULL
241 . . do GetFldVScreen^TMGSELED(22706.9,6,ScrnCode,$name(Options("IEN LIST")))
242 . else do
243 . . do GetFldValue^TMGSELED(22706.9,6,SkipValue,$name(Options("IEN LIST")))
244 else do
245 . merge Options("IEN LIST")=SelArray
246
247PSK31 if $data(SelArray) do
248 . set IEN=""
249 . for set IEN=$order(SelArray(IEN)) quit:(IEN="") do
250 . . if $data(Options("IEN LIST",IEN))>0 do
251 . . . set Options("IEN LIST",IEN,"SEL")=""
252
253 if $$SELED^TMGSELED(.Options)'=2 goto PSK3Done
254 if $$GetIENs^TMGSELED(.Options)=0 goto PSK3Done
255 goto PSK31
256
257PSK3Done quit
258
259
260
261RemoveDups
262 ;"Purpose: Set duplicate records to be skipped
263 ;" Then allow selected records to be set to SKIP
264
265 new ref set ref=$name(^TMG("TMP","SEL SCAN"))
266 kill @ref
267 do SelectScan("set flagToSkip=$$DupTest(IEN)",0,0)
268 kill @ref
269 quit
270
271
272DupTest(IEN)
273 ;"Purpose: to determine if record should be selected
274 ;"Returns 1 if should be flagged for skip, otherwise 0
275
276 new result set result=0
277 if $get(IEN)'="" do
278 . new ref set ref=$name(^TMG("TMP","SEL SCAN"))
279 . ;"if $piece($get(^TMG(22706.9,IEN,1)),"^",4)=1 set result=1 goto DTDone
280 . new name set name=$$MakeName^TMGNDF2G(IEN)
281 . if $data(@ref@(name))>0 set result=1
282 . else set @ref@(name)=""
283
284DTDone quit result
285
286
287RemoveStrMissing
288 ;"Purpose: Set incomplete records to be skipped
289 ;" Then allow selected records to be set to SKIP
290 write "Preselect items with Strength missing...",!
291 do SelectScan("set flagToSkip=$$MissStrTest(IEN)",1,1)
292 quit
293
294MissStrTest(IEN)
295 ;"Purpose: to determine if record should be selected
296 ;" Will flag for skipping if missing STRENGTH
297 ;"Returns 1 if should be flagged for skip, otherwise 0
298
299 new result set result=0
300 new s set s=$get(^TMG(22706.9,IEN,0))
301 ;"0;2=STENGTH field
302 if ($piece(s,"^",2)="") set result=1
303 quit result
304
305
306RemoveUnitMissing
307 ;"Purpose: Set incomplete records to be skipped
308 ;" Then allow selected records to be set to SKIP
309 write "Preselect items with Units missing...",!
310 do SelectScan("set flagToSkip=$$MissUnitTest(IEN)",1,1)
311 quit
312
313
314MissUnitTest(IEN)
315 ;"Purpose: to determine if record should be selected
316 ;" Will flag for skipping if missing UNITS
317 ;"Returns 1 if should be flagged for skip, otherwise 0
318
319 new result set result=0
320 new s set s=$get(^TMG(22706.9,IEN,0))
321 ;"0;3=UNIT field
322 if ($piece(s,"^",3)="") set result=1
323 quit result
324
325RemoveTNameMissing
326 ;"Purpose: Set incomplete records to be skipped
327 ;" Then allow selected records to be set to SKIP
328 write "Preselect items with Tradename missing...",!
329 do SelectScan("set flagToSkip=$$MissTNameTest(IEN)",1,1)
330 quit
331
332
333MissTNameTest(IEN)
334 ;"Purpose: to determine if record should be selected
335 ;" Will flag for skipping if missing TRADENAME
336 ;"Returns 1 if should be flagged for skip, otherwise 0
337
338 new result set result=0
339 new s set s=$get(^TMG(22706.9,IEN,0))
340 ;"0;4=TRADENAME
341 if ($piece(s,"^",4)="") set result=1
342 quit result
343
344RemoveGNameMissing
345 ;"Purpose: Set incomplete records to be skipped
346 ;" Then allow selected records to be set to SKIP
347 write "Preselect items with Generic Name missing...",!
348 do SelectScan("set flagToSkip=$$MissGNameTest(IEN)",1,1)
349 quit
350
351
352MissGNameTest(IEN)
353 ;"Purpose: to determine if record should be selected
354 ;" Will flag for skipping if missing GENERIC NAME
355 ;"Returns 1 if should be flagged for skip, otherwise 0
356
357 new result set result=0
358 new s set s=$get(^TMG(22706.9,IEN,0))
359 ;"0;6=GENERIC NAME
360 if ($piece(s,"^",6)="") set result=1
361 quit result
362
363RemoveNDCMissing
364 ;"Purpose: Set incomplete records to be skipped
365 ;" Then allow selected records to be set to SKIP
366 write "Preselect items with NDC missing...",!
367 do SelectScan("set flagToSkip=$$MissNDCTest(IEN)",1,1)
368 quit
369
370
371MissNDCTest(IEN)
372 ;"Purpose: to determine if record should be selected
373 ;" Will flag for skipping if missing NDC
374 ;"Returns 1 if should be flagged for skip, otherwise 0
375
376 new result set result=0
377 set s=$get(^TMG(22706.9,IEN,1))
378 ;"1;2=NDC 12 DIGIT
379 if ($piece(s,"^",2)="") set result=1
380 quit result
381
382RemoveIngredMissing
383 ;"Purpose: Set incomplete records to be skipped
384 ;" Then allow selected records to be set to SKIP
385 write "Preselect items with Ingredients missing...",!
386 do SelectScan("set flagToSkip=$$MissIngredTest(IEN)",1,1)
387 quit
388
389
390MissIngredTest(IEN)
391 ;"Purpose: to determine if record should be selected
392 ;" Will flag for skipping if missing NDC
393 ;"Returns 1 if should be flagged for skip, otherwise 0
394
395 new result set result=0
396 ;"4th piece of 0 node is total number of records
397 new numRecs
398 set numRecs=+$piece($get(^TMG(22706.9,IEN,4,0)),"^",4)
399 if numRecs=0 set result=1
400 if numRecs=1 do
401 . if +$piece($get(^TMG(22706.9,IEN,4,1,0)),"^",3)=0 set result=1
402 quit result
403
Note: See TracBrowser for help on using the repository browser.