source: cprs/branches/tmg-cprs/m_files/TMGNDF4C.m@ 1381

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

Initial upload

File size: 29.4 KB
RevLine 
[796]1TMGNDF4C ;TMG/kst/FDA Import: Move drugs from 50.7 --> 101.43 ;03/25/06
2 ;;1.0;TMG-LIB;**1**;11/21/06
3
4 ;" FDA - NATIONAL DRUG FILES COMPILING FUNCTIONS
5 ;" Move drugs from 50.7 --> 101.43
6 ;"Kevin Toppenberg MD
7 ;"GNU General Public License (GPL) applies
8 ;"11-21-2006
9
10 ;"Note: The database itself tries to create entries in 101.43 when a drug
11 ;" is added to file 50.7. But I am not happy with the job it does.
12 ;" There are missing records, and it combines various IR, SR, XR
13 ;" into one entry. So I am going to delete the auto-created records
14 ;" and create my own.
15
16 ;"=======================================================================
17 ;" API -- Public Functions.
18 ;"=======================================================================
19 ;"Menu
20 ;"=======================================================================
21 ;"AddAllTMG -- Add/Refresh all relevent TMG entries into OI
22 ;"OIFromTMG(IEN,Option) -- Add/Update ONE entry in ORDERABLE ITEM (101.43) file
23
24 ;"=======================================================================
25 ;" Private Functions.
26 ;"=======================================================================
27 ;"VerifySync -- verify correct links PHARMACY ORDERABLE ITEM --> ORDERABLE ITEM
28 ;"OIFromTMG(IEN22706d9,Option)
29 ;"EnsureOI(IEN50d7,Name,Synonyms,Option) -- make sure that there is a corresponding entry
30 ;" in 101.43. If one doesn't already exist, then it will be added.
31 ;"InactivateOI -- cycle through 101.43 and ensure needed records are inactivated.
32 ;"NewOI(Name) -- add one record to file 101.43--stub in an empty record for later stuffing
33 ;"StuffOI(IEN101d43,Name,Synonyms,IEN50d7) -- fill one record to file 101.43 with data
34
35
36 ;"ResetFiles -- For debugging purposes, this will reset two files: 101.44, 101.43
37
38
39 ;"=======================================================================
40
41Menu
42
43 new Menu,UsrSlct
44 set Menu(0)="Pick Option to Sync ORDERABLE ITEMS (4C)"
45 set Menu(1)="Sync imports to ORDERABLE ITEMS."_$char(9)_"Sync2OI"
46 ;"set Menu(2)="Inactivate non-FDA-drug-OI's"_$char(9)_"InactivateOI"
47 set Menu(2)="Ensure Activation Status of Import OI's"_$char(9)_"SyncActivOI"
48 set Menu(3)="Verify Sync of PHARMACY ORDERABLE ITEMS --> OI's"_$char(9)_"VerifySync"
49 ;"set Menu(4)="Check for duplicate ORDABLE ITEMS records"_$char(9)_"Check4Dups"
50 set Menu(4)="Check for dangling ORDERABLE ITEMS records"_$char(9)_"CheckDangle"
51 set Menu("P")="Prev Stage"_$char(9)_"Prev"
52 set Menu("N")="Next Stage"_$char(9)_"Next"
53
54M1 write #
55 set UsrSlct=$$Menu^TMGUSRIF(.Menu,"^")
56
57 if UsrSlct="Sync2OI" do AddAllTMG goto M1
58 ;"if UsrSlct="Sync2OI" do Sync2OI goto M1
59 ;"if UsrSlct="InactivateOI" do InactivateOI goto M1
60 if UsrSlct="SyncActivOI" do SyncActivOI goto M1
61 if UsrSlct="VerifySync" do VerifySync goto M1
62 ;"if UsrSlct="Check4Dups" do Check4Dups goto M1
63 if UsrSlct="CheckDangle" do CheckDangle goto M1
64
65 if UsrSlct="Prev" goto Menu^TMGNDF4B ;"quit can occur from there...
66 if UsrSlct="Next" goto Menu^TMGNDF4E ;"quit can occur from there...
67
68 if UsrSlct="^" goto MenuDone
69 goto M1
70
71MenuDone
72 quit
73
74 ;"=============================================================================
75
76AddAllTMG
77 ;"Purpose: Add/Refresh all relevent TMG entries into OI
78 ;"Input:none
79 ;"results: none
80
81 new IEN,Itr
82 new abort set abort=0
83 new result set result=0
84 write "Scanning all imports to ensure ORDERABLE ITEMS are set up.",!
85 set IEN=$$ItrInit^TMGITR(22706.9,.Itr)
86 do PrepProgress^TMGITR(.Itr,20,0,"IEN")
87 if IEN'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN)'>0)!(abort=1)
88 . if $$UserAborted^TMGUSRIF set abort=1 quit
89 . new Option
90 . set Option("CUR MODE")="TRADE"
91 . set result=$$OIFromTMG(IEN,.Option) ;"screen for skip will occur in function
92 . set Option("CUR MODE")="GENERIC"
93 . set result=$$OIFromTMG(IEN,.Option) ;"screen for skip will occur in function
94 quit
95
96
97OIFromTMG(IEN22706d9,Option,Synonyms)
98 ;"Purpose: to Add/Update ONE entry in ORDERABLE ITEM (101.43) file
99 ;"Input: IEN22706d9 -- IEN in 22706.9
100 ;" Option -- NON-OPTIONAL part. Format:
101 ;" Option("CUR MODE")="TRADE"
102 ;" Option -- OPTIONAL. Format:
103 ;" Option("IEN50.7","TRADE")=IEN50d7
104 ;" Option("IEN50.7","GENERIC")=IEN50d7
105 ;" Option("IEN101.43","TRADE")=IEN101.43 for Trade Name. May be 0
106 ;" Option("IEN101.43","GENERIC")=IEN101.43 for Generic Name. May be 0
107 ;" Option("FIX CHAIN")=1 <--- changes will be propigate forward
108 ;" to file POI, OI, OQV etc.
109 ;" OPTION("FIX CHAIN","IEN22706d9")=Source IEN
110 ;" Option("QUIET")=1 <-- supress text output
111 ;" Option("IEN50","TRADE")=IEN50 for Trade Name
112 ;" Option("IEN50","GENERIC")=IEN50 for Generic Name
113 ;" Option("DRUG NAME AND FORM","TRADE")=Trade Name and Form
114 ;" Option("DRUG NAME AND FORM","GENERIC")=Generic Name and Form
115 ;" Option("CUR MODE")="TRADE" or "GENERIC"
116 ;" Option("DELETING")=1 <-- deleting chain (not IEN22706d9)
117 ;" Synonyms --OPTIONAL. PASS BY REFERENCE. Expected format:
118 ;" Synonyms(Name)=""
119 ;" Synonyms(Name)=""
120 ;"NOTE: This function DOES screen for skipped entries, and skips
121 ;" proccessing. BUT, if Deleting, then it is NOT skipped
122 ;"Output: OI records will be added or refreshed, or deleted.
123 ;"Result: 1=Modified, 0=not modified
124
125 new result set result=0
126 if $get(Option("DELETING"))'=1,$piece($get(^TMG(22706.9,IEN22706d9,1)),"^",4)=1 goto EOIDone ;"1=SKIP
127 if +$get(IEN22706d9)=0 goto EOIDone
128 new quiet set quiet=+$get(Option("QUIET"))
129 do LoadOption(IEN22706d9,.Option)
130
131 new mode set mode=$get(Option("CUR MODE")) if mode="" goto EOIDone
132 new IEN50d7 set IEN50d7=+$get(Option("IEN50.7",mode)) if IEN50d7=0 goto EOIDone
133 new DrugNAF set DrugNAF=$get(Option("DRUG NAME AND FORM",mode)) if DrugNAF="" goto EOIDone
134
135 new IEN101d43 set IEN101d43=+$get(Option("IEN101.43",mode))
136
137 if $get(Option("DELETING"))=1 do goto EOIDone
138 . do KillOI^TMGNDFUT(IEN101d43)
139 . set Option("IEN101.43",mode)=""
140
141 if (IEN101d43>0),$data(^ORD(101.43,IEN101d43))=0 do
142 . set IEN101d43=0 ;"I found a dangling pointer
143 ;"I am taking line below out because there is supposed to be a 1:1
144 ;" connection between POI<-->OI. Below might cause cross link of chains
145 ;"if IEN101d43=0 set IEN101d43=$$FindOI^TMGNDFUT(DrugNAF)
146 if IEN101d43=0 do
147 . set IEN101d43=$$NewOI(DrugNAF)
148 . set Option("IEN101.43",mode)=IEN101d43
149 . set result=1
150 if IEN101d43=0 set result=0 goto EOIDone
151
152 set result=$$StuffOI(IEN101d43,DrugNAF,.Synonyms,IEN50d7) ;"result 1=modified
153
154 ;"Ensure pointer to 101.43 stored in TMG IMPORT COMPILED records
155 if mode="TRADE" do
156 . new IEN22706d9 set IEN22706d9=""
157 . for set IEN22706d9=$order(^TMG(22706.9,"POIT",IEN50d7,IEN22706d9)) quit:(IEN22706d9="") do
158 . . if +$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",5)=IEN101d43 quit
159 . . new TMGFDA,TMGMSG
160 . . set TMGFDA(22706.9,IEN22706d9_",",5.611)=IEN101d43
161 . . do FILE^DIE("","TMGFDA","TMGMSG")
162 . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
163 if mode="GENERIC" do
164 . new IEN22706d9 set IEN22706d9=""
165 . for set IEN22706d9=$order(^TMG(22706.9,"POIG",IEN50d7,IEN22706d9)) quit:(IEN22706d9="") do
166 . . if +$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",6)=IEN101d43 quit
167 . . new TMGFDA,TMGMSG
168 . . set TMGFDA(22706.9,IEN22706d9_",",5.711)=IEN101d43
169 . . do FILE^DIE("","TMGFDA","TMGMSG")
170 . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
171
172 ;"Ensure just 1 link 50.7 --> 101.43 (actually pointer is the other way: 101.43-->50.7)
173 new all,temp
174 set temp=$$GetOI^TMGNDFUT(IEN50d7,.all)
175OI1 if $$ListCt^TMGMISC("all")>0 do
176 . new IEN set IEN=""
177 . for set IEN=$order(all(IEN)) quit:(IEN="") do
178 . . if IEN=IEN101d43 quit
179 . . if 'quiet write "?? Mult pointers 101.43 --> 50.7 ??. Deleting 101.43 #",IEN,!
180 . . do KillOI^TMGNDFUT(IEN)
181
182 if $get(Option("FIX CHAIN"))=1 do
183 . ;"pass message forward for fix
184 . if result=1 do
185 . . new temp set temp=$$Fix1OQV^TMGNDF4E(IEN101d43,.Option)
186 . ;"Delete AFTER above so chain is deleted 101.44-->101.43-->50.7-->50
187 . ;"if $get(Option("DELETING"))=1 do
188 . ;". do KillOI^TMGNDFUT(IEN101d43)
189EOIDone
190 quit result
191
192
193LoadOption(IEN22706d9,Option)
194 ;"Purpose: To load up Option array with info
195 ;"Input: IEN22706d9 -- IEN in 22706.9
196 ;" Option -- PASS BY REFERENCE. An OUT PARAMETER. Format:
197 ;" Option("IEN50.7","TRADE")=IEN50.7 for Trade Name
198 ;" Option("IEN50.7","GENERIC")=IEN50.7 for Generic Name
199 ;" Option("DRUG NAME AND FORM","TRADE")=Trade Name and Form
200 ;" Option("DRUG NAME AND FORM","GENERIC")=Generic Name and Form
201 ;" Option("IEN50","TRADE")=IEN50 for Trade Name
202 ;" Option("IEN50","GENERIC")=IEN50 for Generic Name
203 ;" Option("IEN101.43","TRADE")=IEN50 for Trade Name
204 ;" Option("IEN101.43","GENERIC")=IEN50 for Generic Name
205 ;"Note: May sync pointers in various records
206 ;"Results: none
207
208 new node7 set node7=$get(^TMG(22706.9,IEN22706d9,7))
209 set Option("DRUG NAME AND FORM","TRADE")=$piece(node7,"^",3)
210 set Option("DRUG NAME AND FORM","GENERIC")=$piece(node7,"^",4)
211
212 new tIEN50 set tIEN50=+$get(Option("IEN50","TRADE"))
213 if tIEN50=0 do
214 . new tIEN50 set tIEN50=+$piece(node7,"^",1)
215 . set Option("IEN50","TRADE")=tIEN50
216 if tIEN50>0 set Option("IEN50","TRADE","NAME")=$piece($get(^PSDRUG(tIEN50,0)),"^",1)
217
218 new gIEN50 set gIEN50=+$get(Option("IEN50","GENERIC"))
219 if gIEN50=0 do
220 . set gIEN50=+$piece(node7,"^",2)
221 . set Option("IEN50","GENERIC")=gIEN50
222 if gIEN50>0 set Option("IEN50","GENERIC","NAME")=$piece($get(^PSDRUG(gIEN50,0)),"^",1)
223
224 new tIEN50d7 set tIEN50d7=+$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",3)
225 if tIEN50'=0 do
226 . if tIEN50d7=0 do
227 . . set tIEN50d7=+$piece($get(^PSDRUG(tIEN50,2)),"^",1)
228 . . new TMGFDA,TMGIEN,TMGMSG
229 . . set TMGFDA(22706.9,IEN22706d9_",",5.61)=tIEN50d7
230 . . do FILE^DIE("S","TMGFDA","TMGMSG")
231 . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
232 . else do ;"sync 50 to match TMG COMPILED
233 . . if tIEN50d7=+$piece($get(^PSDRUG(tIEN50,2)),"^",1) quit
234 . . new TMGFDA,TMGIEN,TMGMSG
235 . . set TMGFDA(50,tIEN50_",",2.1)=tIEN50d7
236 . . do FILE^DIE("S","TMGFDA","TMGMSG")
237 . . if $data(TMGMSG("DIERR")) do
238 . . . if $data(TMGMSG("DIERR","E",120))>0 quit ;"ignore error if #120 (hook) present.
239 . . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
240 set Option("IEN50.7","TRADE")=tIEN50d7 ;"may be 0 at this point
241 if tIEN50d7>0 set Option("IEN50.7","TRADE","NAME")=$piece($get(^PS(50.7,tIEN50d7,0)),"^",1)
242
243 new gIEN50d7 set gIEN50d7=+$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",4)
244 if gIEN50'=0 do
245 . if gIEN50d7=0 do
246 . . set gIEN50d7=+$piece($get(^PSDRUG(gIEN50,2)),"^",1)
247 . . new TMGFDA,TMGIEN,TMGMSG
248 . . set TMGFDA(22706.9,IEN22706d9_",",5.71)=gIEN50d7
249 . . do FILE^DIE("S","TMGFDA","TMGMSG")
250 . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
251 . else do ;"sync 50 to match TMG COMPILED
252 . . if gIEN50d7=+$piece($get(^PSDRUG(gIEN50,2)),"^",1) quit
253 . . new TMGFDA,TMGIEN,TMGMSG
254 . . set TMGFDA(50,gIEN50_",",2.1)=gIEN50d7
255 . . do FILE^DIE("S","TMGFDA","TMGMSG")
256 . . if $data(TMGMSG("DIERR")) do
257 . . . if $data(TMGMSG("DIERR","E",120))>0 quit ;"ignore error if #120 (hook) present.
258 . . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
259 set Option("IEN50.7","GENERIC")=gIEN50d7 ;"may be 0 at this point
260 if gIEN50d7>0 set Option("IEN50.7","GENERIC","NAME")=$piece($get(^PS(50.7,gIEN50d7,0)),"^",1)
261
262 new tradeNameAF set tradeNameAF=$get(Option("DRUG NAME AND FORM","TRADE"))
263 if tradeNameAF="" do
264 . set tradeNameAF=$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",3)
265 . set Option("DRUG NAME AND FORM","TRADE")=tradeNameAF
266
267 new genericNameAF set genericNameAF=$get(Option("DRUG NAME AND FORM","GENERIC"))
268 if genericNameAF="" do
269 . set genericNameAF=$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",4)
270 . set Option("DRUG NAME AND FORM","GENERIC")=genericNameAF
271
272 new tIEN101d43 set tIEN101d43=+$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",5)
273 if (tIEN101d43=0)&(tIEN50d7'=0) do
274 . set tIEN101d43=$$GetOI^TMGNDFUT(tIEN50d7)
275 . if tIEN101d43'>0 quit
276 . new TMGFDA,TMGMSG
277 . set TMGFDA(22706.9,IEN22706d9_",",5.611)=tIEN101d43
278 . do FILE^DIE("S","TMGFDA","TMGMSG")
279 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
280 set Option("IEN101.43","TRADE")=tIEN101d43 ;"could be 0 at this point
281 if tIEN101d43>0 set Option("IEN101.43","TRADE","NAME")=$piece($get(^ORD(101.43,tIEN101d43,0)),"^",1)
282
283 new gIEN101d43 set gIEN101d43=+$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",6)
284 if (gIEN101d43=0)&(gIEN50d7'=0) do
285 . set gIEN101d43=$$GetOI^TMGNDFUT(gIEN50d7)
286 . if gIEN101d43=0 quit
287 . new TMGFDA,TMGMSG
288 . set TMGFDA(22706.9,IEN22706d9_",",5.711)=gIEN101d43
289 . do FILE^DIE("S","TMGFDA","TMGMSG")
290 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
291 set Option("IEN101.43","GENERIC")=gIEN101d43 ;"could be 0 at this point
292 if gIEN101d43>0 set Option("IEN101.43","GENERIC","NAME")=$piece($get(^ORD(101.43,gIEN101d43,0)),"^",1)
293
294 quit
295
296
297NewOI(Name)
298 ;"Purpose: to add one record to file 101.43--stub in an empty record for later stuffing
299 ;"Input: Name -- the text of the ORDERABLE ITEM (i.e. drug name) to add
300 ;"Results: returns new IEN of added record
301
302 new newIEN set newIEN=0
303 new TMGFDA,TMGMSG,TMGIEN
304 set TMGFDA(101.43,"+1,",.01)=Name
305 do UPDATE^DIE("K","TMGFDA","TMGIEN","TMGMSG") ;"ADD RECORD
306 if $$ShowIfError^TMGDBAPI(.TMGMSG) goto NOIDone
307 set newIEN=+$get(TMGIEN(1)) ;"GET BACK ADDED RECORD NUMBER
308NOIDone
309 quit newIEN
310
311
312StuffOI(IEN101d43,Name,Synonyms,IEN50d7)
313 ;"Purpose: to fill one record to file 101.43 with data
314 ;"Input: IEN110d43 -- IEN in 101.43 to stuff
315 ;" Name -- the text of the drug name to add
316 ;" Synonyms -- PASS BY REFERENCE. Expected format:
317 ;" Synonyms(Name)=""
318 ;" Synonyms(Name)=""
319 ;" IEN50d7 -- IEN in 50.7 -- the record in PHARMACY ORDERABLE ITEM (50.7) to link to
320 ;"Results: 1 if modified, 0 if not modified
321
322 ;"Here is an example of a drug that was stuff
323 ;" .01-NAME : BUPROPION TAB
324 ;" 1-SYNONYMS :
325 ;" Multiple Entry #1 .01-SYNONYM : BUDEPRION SR EXT REL TABS
326 ;" Multiple Entry #2 .01-SYNONYM : BUDEPRION SR TABS
327 ;" Multiple Entry #3 .01-SYNONYM : BUPROPION HCL EXT REL TABS
328 ;" Multiple Entry #4 .01-SYNONYM : BUPROPION HCL SR TABS
329 ;" 1.1-PACKAGE NAME : BUPROPION TAB
330 ;" 2-ID : 3267;99PSP <--- 3267 is IEN in 50.7 to link to
331 ;" 5-DISPLAY GROUP : PHARMACY
332 ;" 9-SET MEMBERSHIP :
333 ;" Multiple Entry #1 .01-SET : RX
334 ;" 50.1-INPATIENT MED : NO
335 ;" 50.2-OUTPATIENT MED : NO
336 ;" 50.3-IV BASE : NO
337 ;" 50.4-IV ADDITIVE : NO
338 ;" 50.5-SUPPLY : NO
339 ;" 50.6-NON-FORMULARY : NO
340 ;" 50.7-NON-VA MEDS : NO
341
342 new result set result=0
343 new TMGFDA,TMGMSG,TMGIEN
344 new IENS set IENS=IEN101d43_","
345 set TMGFDA(101.43,IEN101d43_",",.01)=Name
346 if $piece($get(^ORD(101.43,IEN101d43,.1)),"^",1)'="" do
347 . set TMGFDA(101.43,IENS,.1)="@" ;"delete any inactivation date.
348 set TMGFDA(101.43,IENS,1.1)=Name
349 set TMGFDA(101.43,IENS,2)=IEN50d7_";99PSP"
350 set TMGFDA(101.43,IENS,5)="PHARMACY"
351 set TMGFDA(101.43,IENS,50.1)="NO"
352 set TMGFDA(101.43,IENS,50.2)="YES"
353 set TMGFDA(101.43,IENS,50.3)="NO"
354 set TMGFDA(101.43,IENS,50.4)="NO"
355 set TMGFDA(101.43,IENS,50.5)="NO"
356 set TMGFDA(101.43,IENS,50.6)="NO"
357 set TMGFDA(101.43,IENS,50.7)="NO"
358
359 new temp set temp=$$TrimFDA^TMGDBAPI(.TMGFDA)
360 if $data(TMGFDA)=0 goto SOI2
361
362 ;"UPDATE RECORD
363 do FILE^DIE("EK","TMGFDA","TMGMSG")
364 new PriorErrorFound,newIEN
365 if $$ShowIfError^TMGDBAPI(.TMGMSG,.PriorErrorFound) goto SOIDone
366 set result=1
367
368 ;"ADD SET MEMBERSHIP ENTRIES
369 ;"NOTE: It seems that the database adds these automatically
370 ;"kill TMGFDA,TMGMSG,TMGIEN
371 ;"set TMGFDA(101.439,"+1,"_newIEN_",",.01)="RX"
372 ;"set TMGFDA(101.439,"+2,"_newIEN_",",.01)="O RX"
373 ;"do UPDATE^DIE("ES","TMGFDA","TMGIEN","TMGMSG")
374 ;"if $$ShowIfError^TMGDBAPI(.TMGMSG,.PriorErrorFound) quit
375SOI2
376 new subIEN set subIEN=0
377 for set subIEN=$order(^ORD(101.43,IEN101d43,2,subIEN)) quit:(+subIEN'>0) do
378 . new syn set syn=$piece($get(^ORD(101.43,IEN101d43,2,subIEN,0)),"^",1)
379 . if $data(Synonyms(syn))'=0 kill Synonyms(syn) quit ;"no need to add, already present
380 . new TMGFDA,TMGMSG
381 . set TMGFDA(101.432,subIEN_","_IEN101d43_",",.01)="@" ;"kill unwanted synonyms
382 . do FILE^DIE("KE","TMGFDA","TMGMSG")
383 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
384
385 ;"ADD ANY MISSING SYONYMS
386 new SynName set SynName=""
387 for set SynName=$order(Synonyms(SynName)) quit:(SynName="") do
388 . kill TMGIEN,TMGFDA,TMGMSG
389 . set TMGFDA(101.432,"+1,"_IEN101d43_",",.01)=SynName ;"was newIEN, change --> IEN101d43
390 . do UPDATE^DIE("EKS","TMGFDA","TMGIEN","TMGMSG")
391 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
392 . set result=1
393SOIDone
394 quit result
395
396
397InactivateOI
398 ;"Purpose: To cycle through records in 101.43 and ensure needed records are
399 ;" inactivated.
400
401 write "Scanning entries to ensure inactivation status is synchronized...",!
402 new Itr,IEN50d7
403 new count set count=0
404 new abort set abort=0
405 set IEN101d43=$$ItrInit^TMGITR(101.43,.Itr)
406 do PrepProgress^TMGITR(.Itr,20,0,"IEN101d43")
407 if IEN101d43'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN101d43)'>0)!abort
408 . if $$UserAborted^TMGUSRIF set abort=1 quit
409 . new IEN50d7 set IEN50d7=$$GetPOI^TMGNDFUT(IEN101d43) ;"(will fix bad records)
410 . if IEN50d7'>0 quit ;"was bad record, non pharmacy item
411 . new date set date=$piece($get(^ORD(101.43,IEN101d43,.1)),"^",1) quit:(date'="") ;"already inactivated
412 . if $$IsImport^TMGNDFUT(IEN50d7)=1 quit ;"is active import --> don't inactivate
413 . new TMGFDA,TMGMSG,X,Y
414 . set X="NOW" do ^%DT ;"results return in Y
415 . set TMGFDA(101.43,IEN101d43_",",.1)=Y
416 . do FILE^DIE("K","TMGFDA","TMGMSG")
417 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
418 . set count=count+1
419 do ProgressDone^TMGITR(.Itr)
420
421 write count," entries modified.",!
422 do PressToCont^TMGUSRIF
423 quit
424
425
426SyncActivOI
427 ;"Purpose: To cycle through records in 101.43 and ensure needed records are
428 ;" Activated or Inactivation.
429
430 write "Scanning entries to ensure activation/inactivation status is synchronized...",!
431 new Itr,IEN50d7
432 new count set count=0
433 new abort set abort=0
434 set IEN101d43=$$ItrInit^TMGITR(101.43,.Itr)
435 do PrepProgress^TMGITR(.Itr,20,0,"IEN101d43")
436 if IEN101d43'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN101d43)'>0)!abort
437 . if $$UserAborted^TMGUSRIF set abort=1 quit
438 . new IEN50d7 set IEN50d7=$$GetPOI^TMGNDFUT(IEN101d43) ;"(will fix bad records)
439 . if IEN50d7'>0 quit ;"was bad record, non pharmacy item
440 . new date set date=$piece($get(^ORD(101.43,IEN101d43,.1)),"^",1)
441 . new pastInactiveDate set pastInactiveDate=0
442 . if date'="" do
443 . . new X,Y set X="NOW" do ^%DT ;"results in Y
444 . . new X1,X2
445 . . set X1=Y,X2=date
446 . . do ^%DTC ;"result is X=X1-X2 (X=NOW-InactiveDate) X>-1 means past inactive date
447 . . set pastInactiveDate=(X>-1)
448 . if $$IsImport^TMGNDFUT(IEN50d7)=1 do
449 . . if date="" quit
450 . . if 'pastInactiveDate quit
451 . . new TMGFDA,TMGMSG,X,Y
452 . . set TMGFDA(101.43,IEN101d43_",",.1)="@"
453 . . do FILE^DIE("K","TMGFDA","TMGMSG")
454 . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
455 . . set count=count+1
456 . else do ;"is NOT an active import, so ensure inactivated
457 . . if pastInactiveDate quit
458 . . new TMGFDA,TMGMSG,X,Y
459 . . set X="NOW" do ^%DT ;"results return in Y
460 . . set TMGFDA(101.43,IEN101d43_",",.1)=Y
461 . . do FILE^DIE("K","TMGFDA","TMGMSG")
462 . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
463 . . set count=count+1
464 do ProgressDone^TMGITR(.Itr)
465
466 write count," entries modified.",!
467 do PressToCont^TMGUSRIF
468 quit
469
470
471ResetFiles
472 ;"Purpose: For debugging purposes, this will reset two files:
473 ;" 101.44, 101.43
474
475 ;"CAUTION: make sure you have saved data in the locations below FIRST...
476 ;"ALSO: There are many pointers IN to file 101.43. So if this function is run
477 ;" in a production system (containing valid patient data), then corruption
478 ;" will be introduced.
479
480 kill ^TMG("TMP","TEMP BACKUP","^ORD(101.43, 10-16-06")
481 merge ^TMG("TMP","TEMP BACKUP","^ORD(101.43, 10-16-06")=^ORD(101.43)
482 kill ^ORD(101.43)
483 merge ^ORD(101.43)=^TMG("TMP","^ORD(101.43, 10-16-06")
484
485 kill ^TMG("TMP","TEMP BACKUP","^ORD(101.44, 10-16-06")
486 merge ^TMG("TMP","TEMP BACKUP","^ORD(101.44, 10-16-06")=^ORD(101.44)
487 kill ^ORD(101.44)
488 merge ^ORD(101.44)=^TMG("TMP","^ORD(101.44, 10-16-06")
489
490 quit
491
492 ;"-----------------------------------
493VerifySync
494 ;"Purpose: to verify that links PHARMACY ORDERABLE ITEM --> ORDERABLE ITEM
495 ;" are correct. Link is based on a text pointer (and I think less likely
496 ;" to have been fixed with multiple runs...)
497
498 new fixArray
499
500 write "Scanning entries to ensure link is correctly synchronized...",!
501 new Itr,IEN50d7
502 new abort set abort=0
503 set IEN101d43=$$ItrInit^TMGITR(101.43,.Itr)
504 do PrepProgress^TMGITR(.Itr,20,0,"IEN101d43")
505 if IEN101d43'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN101d43)'>0)!abort
506 . if $$UserAborted^TMGUSRIF set abort=1 quit
507 . new date set date=$piece($get(^ORD(101.43,IEN101d43,.1)),"^",1)
508 . if $$OIInactive^TMGNDFUT(IEN101d43) quit ;"ignore inactivate entries
509 . set IEN50d7=$$GetPOI^TMGNDFUT(IEN101d43) ;"(will fix bad records)
510 . if IEN50d7'>0 quit ;"was bad record, non pharmacy item
511 . new OIName set OIName=$piece($get(^ORD(101.43,IEN101d43,0)),"^",1)
512 . new POIName set POIName=$piece($get(^PS(50.7,IEN50d7,0)),"^",1)
513 . if (OIName'=POIName) do
514 . . write !,OIName," (OI #",IEN101d43,") <-- ",POIName," (POI #",IEN50d7,") ??",!
515 . . set fixArray(IEN50d7,IEN101d43)=""
516 . if (OIName="") do
517 . . write !,"NULL NAME. (OI #",IEN101d43,") <-- ",POIName," (POI #",IEN50d7,") ??",!
518 . . set fixArray(IEN50d7,IEN101d43)=""
519 . if $$IsImport^TMGNDFUT(IEN50d7)=0 do
520 . . write " 50.7 #",IEN50d7," ",POIName," is not an active import!",!
521 . . set fixArray(IEN50d7,IEN101d43)="@"
522 do ProgressDone^TMGITR(.Itr)
523
524 new IEN50d7 set IEN50d7=""
525 for set IEN50d7=$order(fixArray(IEN50d7)) quit:(IEN50d7="") do
526 . new POIName set POIName=$piece($get(^PS(50.7,IEN50d7,0)),"^",1)
527 . new IEN50Array
528 . do GetDRUGs^TMGNDFUT(IEN50d7,.IEN50Array,1)
529 . new Name50 set Name50=""
530 . for set Name50=$order(IEN50Array(Name50)) quit:(Name50="") do
531 . . new IEN50 set IEN50=""
532 . . for set IEN50=$order(IEN50Array(Name50,IEN50)) quit:(IEN50="") do
533 . . . write "File 50, #",IEN50,": ",Name50," ",$piece($get(^PSDRUG(IEN50,0)),"^",1)," -->",!
534 . write " POI Name=",POIName," --> ",!
535 . new IEN101d43 set IEN101d43=""
536 . for set IEN101d43=$order(fixArray(IEN50d7,IEN101d43)) quit:(IEN101d43="") do
537 . . if $get(fixArray(IEN50d7,IEN101d43))="@" do quit
538 . . . new TMGFDA,TMGMSG,PSEDITNM
539 . . . set PSEDITNM=1
540 . . . set TMGFDA(50.7,IEN50d7_",",.01)="@"
541 . . . do FILE^DIE("","TMGFDA","TMGMSG")
542 . . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
543 . . . kill TMGFDA,TMGMSG
544 . . . set TMGFDA(101.43,IEN101d43_",",.01)="@"
545 . . . do FILE^DIE("","TMGFDA","TMGMSG")
546 . . . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
547 . . new OIName set OIName=$piece($get(^ORD(101.43,IEN101d43,0)),"^",1)
548 . . write " OI Name=",OIName,!
549 . . new result
550 . . set result=$$StuffOI(IEN101d43,POIName,,IEN50d7) ;"result 1=modified
551
552 ;"Now verify ID cross reference
553
554
555 do PressToCont^TMGUSRIF
556 quit
557
558
559Check4Dups ;"DON'T USE. There are times when the "TRADE" name will actually be a generic
560 ;"name, and then the chains between generic and trade name drugs get crossed.
561 ;"An OI can only point to 1 POI, so one could cause a situation whereby
562 ;"Trade POI --> OI, but OI --> Generic POI (and Trade POI gets lost)
563
564 ;"Purpose: to ensure that there are not two entries in the ORDERABLE ITEM
565 ;" file with the same name.
566
567 new array,dupArray
568
569 new Itr,IEN
570 new abort set abort=0
571 new count set count=0
572 set IEN=$$ItrInit^TMGITR(101.43,.Itr)
573 do PrepProgress^TMGITR(.Itr,20,0,"IEN")
574 if IEN'="" for do quit:(+$$ItrNext^TMGITR(.Itr,.IEN)'>0)!abort
575 . if $$UserAborted^TMGUSRIF set abort=1 quit
576 . new name set name=$piece($get(^ORD(101.43,IEN,0)),"^",1)
577 . new priorIEN set priorIEN=+$order(array(name,""))
578 . if priorIEN'=0 do
579 . . write !,name," previously found...",!
580 . . set dupArray(name,priorIEN)=""
581 . . set dupArray(name,IEN)=""
582 . set array(name,IEN)=""
583 do ProgressDone^TMGITR(.Itr)
584 if abort=1 goto C4DDone
585
586 new Itr,fixName
587 set fixName=$$ItrAInit^TMGITR("dupArray",.Itr)
588 do PrepProgress^TMGITR(.Itr,1,1,"fixName")
589 if fixName'="" for do quit:($$ItrANext^TMGITR(.Itr,.fixName)="")!abort
590 . new IEN101d43 set IEN101d43=""
591 . new keepIEN set keepIEN=""
592 . for set IEN101d43=$order(dupArray(fixName,IEN101d43)) quit:(IEN101d43="") do
593 . . if keepIEN="" set keepIEN=IEN101d43 quit ;"use first record as one to keep.
594 . . do RedirOI^TMGNDFUT(IEN101d43,keepIEN)
595 . . do KillOI^TMGNDFUT(IEN101d43)
596 . . set count=count+1
597 do ProgressDone^TMGITR(.Itr)
598
599C4DDone
600 write !,count," Modifications Made.",!
601 do PressToCont^TMGUSRIF
602 quit
603
604
605
606
607CheckDangle
608 ;"Purpose: to verify that ORDERABLE ITEM records are not dangling records
609
610 new delArray
611
612 write "Scanning entries checking for dangling records...",!
613 new Itr,IEN50d7,TMGArray,ID,Info
614 new abort set abort=0
615 set IEN101d43=$$ItrInit^TMGITR(101.43,.Itr)
616 do PrepProgress^TMGITR(.Itr,20,0,"IEN101d43")
617 if IEN101d43'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN101d43)'>0)!abort
618 . if $$UserAborted^TMGUSRIF set abort=1 quit
619 . new OIArray
620 . do GetOIInfo^TMGNDFUT(IEN101d43,.OIArray)
621 . if $get(OIArray("IEN 101.43","INACTIVE"))=1 quit ;"ignore inactivated records
622 . new pkg set pkg=$get(OIArray("IEN 101.43","PACKAGE"))
623 . if (pkg'="")&(pkg'["PSP") quit ;" -- not a pharmacy item, so ignore
624 . set IEN50d7=+$get(OIArray("IEN 50.7 from 101.43"))
625 . new OIName set OIName=$get(OIArray("IEN 101.43","NAME"))
626 . ;"if OIName'="<DUPLICATE>" quit ;"temporary....
627 . new POIName set POIName=$get(OIArray("IEN 50.7 from 101.43","NAME"))
628 . if IEN50d7=0 do
629 . . write !,"Record 101.43 #",IEN101d43," (",OIName,") doesn't point to any PHARMACY ORDERABLE ITEM",!
630 . . set delArray(IEN101d43)=""
631 . else if $$IsImport^TMGNDFUT(IEN50d7)=0 do
632 . . write !,"Record 101.43 #",IEN101d43," (",OIName,") points to PHARMACY ORDERABLE ITEM (50.7)#",IEN50d7,!
633 . . write " But 50.7 #",IEN50d7," (",POIName,") is not an active import!",!
634 do ProgressDone^TMGITR(.Itr)
635
636 new count set count=$$ListCt^TMGMISC("delArray")
637 write count," records to be deleted.",!
638
639 if count>0 do
640 . new % set %=1
641 . write "Delete records now" do YN^DICN write !
642 . if %'=1 quit
643 . set IEN101d43=""
644 . for set IEN101d43=$order(delArray(IEN101d43)) quit:(IEN101d43="") do
645 . . do KillOI^TMGNDFUT(IEN101d43)
646 . write "Done.",!
647 . do PressToCont^TMGUSRIF
648 else do PressToCont^TMGUSRIF
649
650 quit
651
652
653
Note: See TracBrowser for help on using the repository browser.