source: cprs/branches/tmg-cprs/m_files/TMGNDF3E.m@ 1099

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

Initial upload

File size: 9.4 KB
Line 
1TMGNDF3E ;TMG/kst/FDA Import: Inactivate unwanted DRUGs ;03/25/06
2 ;;1.0;TMG-LIB;**1**;11/21/06
3
4 ;" FDA - NATIONAL DRUG FILES COMPILING FUNCTIONS
5 ;" Inactivate DRUG entries not linked to import.
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
16 ;"=======================================================================
17 ;" Private Functions.
18 ;"=======================================================================
19
20Menu
21 ;"Purpose: Provide menu to entry points of main routines
22
23 new Menu,UsrSlct
24 set Menu(0)="Pick Option for Inactivate unused DRUG file entries (3E)"
25 set Menu(1)="Inactivate DRUG entries not linked to import"_$char(9)_"InactivateUnused"
26 set Menu(2)="Kill DRUG entries not linked to import (CAUTION!)"_$char(9)_"KillUnused"
27 set Menu(3)="View DRUG entries that ARE linked to import"_$char(9)_"BrowseUsed"
28 set Menu(4)="Review DRUG entries for bad imports"_$char(9)_"CheckForBad"
29 set Menu("P")="Prev Stage"_$char(9)_"Prev"
30 set Menu("N")="Next Stage"_$char(9)_"Next"
31
32MC1 write #
33 set UsrSlct=$$Menu^TMGUSRIF(.Menu,"^")
34 if UsrSlct="^" goto MCDone
35 if UsrSlct=0 set UsrSlct=""
36
37 if UsrSlct="InactivateUnused" do InactivateUnused goto MC1
38 if UsrSlct="KillUnused" do KillUnused goto MC1
39 if UsrSlct="BrowseUsed" do BrowseUsed goto MC1
40 if UsrSlct="CheckForBad" do ReviewForBad goto MC1
41 if UsrSlct="Prev" goto Menu^TMGNDF3D ;"quit can occur from there...
42 if UsrSlct="Next" goto Menu^TMGNDF4A ;"quit can occur from there...
43 goto MC1
44
45MCDone
46 quit
47
48 ;"=======================================================================
49
50InactivateUnused
51 ;"Purpose: To cycle through all DRUG entries and inactivate those
52 ;" not linked to a non-skipped entry in 22706.9 (TMG FDA IMPORT COMPILED)
53 ;"Input: none
54 ;"Results: none.
55
56 new count set count=0
57 new OnlyTMG set OnlyTMG=1
58 new % set %=1
59 write !,!,"When scanning through records in the DRUG file,",!
60 write "should just entries that this FDA import process",!
61 write "has added (for example, on a previous run), or ",!
62 write "should ALL entries be considered for inactivation?",!
63 write "Inactivate ONLY former FDA imports" do YN^DICN write !
64 if %=-1 goto IUDone
65 if %=1 goto IU2
66 set %=1
67 write "Inactivate ALL DRUG entries" do YN^DICN write !
68 if %'=1 goto IUDone
69 set OnlyTMG=0
70
71IU2 new Itr,IEN
72 new abort set abort=0
73 set IEN=$$ItrInit^TMGITR(50,.Itr)
74 write !,"Scanning DRUG entries to find entries to inactivate...",!
75 do PrepProgress^TMGITR(.Itr,20,0,"IEN")
76 if IEN'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN)'>0)!abort
77 . if $$UserAborted^TMGUSRIF set abort=1 quit
78 . if (OnlyTMG=1),($$TMGAdded(IEN)=0) quit
79 . new fdaIEN set fdaIEN=+$$GetfdaIEN^TMGNDFUT(IEN)
80 . if (fdaIEN'>0)&(OnlyTMG=1) quit
81 . if (fdaIEN>0),($piece($get(^TMG(22706.9,fdaIEN,1)),"^",4)'=1) quit ;" 1=SKIP
82 . new InactiveDate set InactiveDate=$$GET1^DIQ(50,IEN_",",100)
83 . if InactiveDate'="" quit ;"already inactivated.
84 . ;"write "Inactivate-->",$$GET1^DIQ(50,IEN_",",.01),!
85 . do AddMsg^TMGNDF3C(IEN,"TMG INACTIV D/T NO FDA") ;"Add a message in the Activity log field
86 . new TMGFDA,TMGMSG
87 . set TMGFDA(50,IEN_",",100)="NOW"
88 . do FILE^DIE("KE","TMGFDA","TMGMSG")
89 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
90 . set count=count+1
91 do ProgressDone^TMGITR(.Itr)
92
93IUDone
94 write count," entries inactivated.",!
95 do PressToCont^TMGUSRIF
96 quit
97
98
99KillUnused
100 ;"Purpose: To cycle through all DRUG entries and kill those
101 ;" not linked to a non-skipped entry in 22706.9 (TMG FDA IMPORT COMPILED)
102 ;"Input: none
103 ;"Results: none.
104
105 new count set count=0
106
107 write !,!
108 write "**********************************************************",!
109 write "NOTICE: * IMPORTANT *",!
110 write "This process could delete drugs that are referenced",!
111 write "by an active medical record. As such that would be",!
112 write "an alteration of a record (i.e. illegal).",!,!
113 write "This process should only be used during initial",!
114 write "installation of the drug files (i.e. during debugging etc.)",!,!
115 write "**********************************************************",!
116 write "If you want to continue, type: 'I UNDERSTAND'",!
117 new temp
118 read "> ",temp:($get(DTIME,3600)),!
119 if temp'="I UNDERSTAND" goto KUDone
120
121 new Itr,IEN
122 new abort set abort=0
123 set IEN=$$ItrInit^TMGITR(50,.Itr)
124 write !,"Scanning DRUG entries to find unused entries to delete...",!
125 do PrepProgress^TMGITR(.Itr,20,0,"IEN")
126 if IEN'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN)'>0)!abort
127 . if $$UserAborted^TMGUSRIF set abort=1 quit
128 . new fdaIEN set fdaIEN=+$$GetfdaIEN^TMGNDFUT(IEN)
129 . if (fdaIEN>0),($piece($get(^TMG(22706.9,fdaIEN,1)),"^",4)'=1) quit ;" 1=SKIP
130 . new TMGFDA,TMGMSG
131 . set TMGFDA(50,IEN_",",.01)="@" ;"delete record
132 . do FILE^DIE("KE","TMGFDA","TMGMSG")
133 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
134 . set count=count+1
135 do ProgressDone^TMGITR(.Itr)
136
137KUDone
138 write count," unlinked entries deleted.",!
139 do PressToCont^TMGUSRIF
140 quit
141
142
143
144TMGAdded(IEN50)
145 ;"Purpose: to determine if the record in 50 is one that this TMG code added.
146 ;"Input: IEN50 -- IEN in file 50
147 ;"Results: 1 if TMG added, 0 otherwise.
148
149 new result set result=0
150 new idx set idx=0
151 for set idx=$order(^PSDRUG(IEN50,4,idx)) quit:(idx="")!(result=1) do
152 . new msg set msg=$piece($get(^PSDRUG(IEN50,4,idx,0)),"^",5)
153 . if $extract(msg,1,3)="TMG" set result=1
154 quit result
155
156 ;"========================
157GetUsed(pList,pSource)
158 ;"Purpose: to Get a list of DRUG entries that are linked to from an import that is not SKIPPED
159 ;"Input: pList -- PASS BY NAME. An OUT PARAMETER. Format:
160 ;" @pList@(IEN50)=""
161 ;" @pList@(IEN50)=""
162 ;" pSource -- OPTIONAL. PASS BY NAME. an OUT PARAMETER. Format:
163 ;" @pSource@(IEN50,IEN22706d9)=""
164 ;" @pSource@(IEN50,IEN22706d9)=""
165 ;"Results: None
166
167 new Itr,IEN
168 new temp
169 set pSource=$get(pSource,"temp")
170 new abort set abort=0
171 set IEN=$$ItrInit^TMGITR(22706.9,.Itr)
172 write !,"Scanning DRUG entries to Browse/View...",!
173 do PrepProgress^TMGITR(.Itr,20,0,"IEN")
174 if IEN'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN)'>0)!abort
175 . if $$UserAborted^TMGUSRIF set abort=1 quit
176 . if $piece($get(^TMG(22706.9,IEN,1)),"^",4)=1 quit ;" 1=SKIP
177 . new gIEN,tIEN
178 . set tIEN=+$piece($get(^TMG(22706.9,IEN,7)),"^",1)
179 . set gIEN=+$piece($get(^TMG(22706.9,IEN,7)),"^",1)
180 . if tIEN>0 set @pList@(tIEN)="",@pSource@(tIEN,IEN)=""
181 . if gIEN>0 set @pList@(gIEN)="",@pSource@(gIEN,IEN)=""
182
183 quit
184
185BrowseUsed
186 ;"Purpose: To Browse DRUG entries that are linked to a used import (not skipped)
187
188 new List
189 new Options,IEN
190
191 set Options("FIELDS",1)=".01^GENERIC NAME^41"
192 set Options("FIELDS",1,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
193 set Options("FIELDS",2)="31^NDC^16"
194 set Options("FIELDS",2,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
195 set Options("FIELDS","MAX NUM")=2
196 set Options("FILE")="50^DRUG"
197
198 do GetUsed($name(Options("IEN LIST")))
199
200 new temp
201 set temp=$$SELED^TMGSELED(.Options)
202
203BUDone quit
204
205
206 ;"=======================================
207ReviewForBad
208 ;"Purpose: To review DRUG entries for bad imports
209 ;"Input: none
210 ;"Output: ...
211
212 ;"Results: None
213
214 new List
215 new IEN50List,IEN50,IEN22706d9,SrcList
216 new IENTMGList
217 new resultList
218
219 do GetUsed("IEN50List","SrcList")
220
221 do IENSelector^TMGUSRIF("IEN50List","resultList",50,".01",40,"Select any bad names to investigate them. [ESC][ESC] to exit",".01")
222
223 new Options
224
225 set IEN50=""
226 for set IEN50=$order(resultList(IEN50)) quit:(IEN50="") do
227 . set IEN22706d9=$order(^TMG(22706.9,"DRUGT",IEN50,""))
228 . if IEN22706d9'="" set Options("IEN LIST",IEN22706d9)=""
229 . set IEN22706d9=$order(^TMG(22706.9,"DRUG",IEN50,""))
230 . if IEN22706d9'="" set Options("IEN LIST",IEN22706d9)=""
231
232 set Options("FIELDS",1)=".055^TRADE NAME & FORM - 40^35"
233 set Options("FIELDS",1,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
234 set Options("FIELDS",2)=".075^,@pSource@(tIEN,IEN)=""^35"
235 set Options("FIELDS",2,"NO EDIT")=1 ;"i.e. show for browsing, but don't allow edit
236 set Options("FIELDS",3)="6^SKIP THIS RECORD^5"
237 set Options("FIELDS","MAX NUM")=3
238 set Options("FILE")="22706.9^TMG FDA IMPORT COMPILED"
239
240 new temp
241 set temp=$$SELED^TMGSELED(.Options)
242
243 quit
Note: See TracBrowser for help on using the repository browser.