source: cprs/branches/tmg-cprs/m_files/TMGNDF3C.m@ 1531

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

Initial upload

File size: 25.4 KB
Line 
1TMGNDF3C ;TMG/kst/FDA Import: Create DRUG entries ;03/25/06
2 ;;1.0;TMG-LIB;**1**;11/21/06
3
4 ;" FDA - NATIONAL DRUG FILES COMPILING FUNCTIONS
5 ;" Creation of records in file 50 (DRUG 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 ;"Refresh1(IEN22706d9,Option) -- Refresh one drug from 22706.9
16 ;"RefreshBatch(IENArray,Option) -- Refres batch entries in 22706.9
17
18 ;"=======================================================================
19 ;" Private Functions.
20 ;"=======================================================================
21 ;"RefreshNonSkips -- Refresh all non-skipped records in 22706.9
22 ;"GetAddList(List): get list of entries in VA PRODUCT (50.68) not having corresponding entry in DRUG file (50)
23 ;"EnsureFromList(List) -- Add to DRUG file (50) from TMG FDA IMPORT COMPILED
24 ;"Update50(IEN50,DrugInfo,Option) -- refresh info in DRUG (50) file, or add if it doesn't exist (or delete if needed)
25 ;"GetTMGDrugInfo(fdaIEN,DrugInfo) -- Create a very abbreviated version of the DrugInfo array
26 ;"Stuff50(IEN50,DrugInfo,Option) -- synch record(s) in the DRUG file, based on entry from VA PRODUCT file
27 ;"SetupFDA(DrugInfo,IENS,TMGFDA) -- setup FDA for data for record in DRUG file
28 ;"AddMsg(IEN50,Msg) -- Add a message in the Activity log field
29
30 ;"=======================================================================
31 ;"=======================================================================
32 ;"NOTE: Data mapping:
33 ;" File 50, .01 field (name) is filled with data from file 22706.9, from on
34 ;" of two possible fields:
35 ;" If entry in 50 represents a GENERICNAME drug, then .01 <--- .076
36 ;" If entry in 50 represents a TRADENAME drug, then .01 <--- .056
37 ;"=======================================================================
38 ;"=======================================================================
39 ;"Q: Where is BatchTo50 (i.e. 50.68-->50)??
40 ;"A: There are many entries in 50.68 that I don't want put into 50, so I need
41 ;" to do this: 22706.9 --> 50.68
42 ;" 22706.9 --> 50
43 ;" instead of this: 22706.9 --> 50.68 --> 50
44 ;"=======================================================================
45Menu
46 ;"Purpose: Provide menu to entry points of main routines
47
48 new Menu,UsrSlct
49 set Menu(0)="Pick Option for Synchronizing Imports Data to file 50 (3C)"
50 set Menu(1)="Synchronize DRUG file with import data"_$char(9)_"RefreshNonSkips"
51 set Menu(2)="Verify Synchronization"_$char(9)_"VerifySync"
52 set Menu("P")="Prev Stage"_$char(9)_"Prev"
53 set Menu("N")="Next Stage"_$char(9)_"Next"
54
55MC1 write #
56 set UsrSlct=$$Menu^TMGUSRIF(.Menu,"^")
57 if UsrSlct="^" goto MCDone
58 if UsrSlct=0 set UsrSlct=""
59
60 if UsrSlct="RefreshNonSkips" do RefreshNonSkips goto MC1
61 if UsrSlct="VerifySync" do VerifySync goto MC1
62 if UsrSlct="Prev" goto Menu^TMGNDF3A ;"quit can occur from there...
63 if UsrSlct="Next" goto Menu^TMGNDF3D ;"quit can occur from there...
64 goto MC1
65
66MCDone
67 quit
68
69
70RefreshNonSkips
71 ;"Purpose: To work on ALL records in 22706.9 that are not marked to be
72 ;" skipped, and ensure that all is refreshed appropriately
73
74 new tempList
75
76 new AddCt,OKCt
77 set AddCt=0,OKCt=0
78 new Itr,IEN
79 new abort set abort=0
80 write !,"Gathering list of imports to use (those not marked to be skipped)...",!
81 set IEN22706d9=$$ItrInit^TMGITR(22706.9,.Itr)
82 do PrepProgress^TMGITR(.Itr,20,0,"IEN22706d9")
83 if IEN22706d9'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN22706d9)'>0)!abort
84 . if $$UserAborted^TMGUSRIF set abort=1 quit
85 . if +$piece($get(^TMG(22706.9,IEN22706d9,1)),"^",4)=1 quit ;"1=SKIP
86 . new tIEN50 set tIEN50=+$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",1)
87 . new gIEN50 set gIEN50=+$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",2)
88 . set tempList(IEN22706d9)=""
89 . if (tIEN50>0)&(gIEN50>0) set OKCt=OKCt+1
90 . else set AddCt=AddCt+1
91 do ProgressDone^TMGITR(.Itr)
92
93 write !,AddCt," items may be added to DRUG file (if appropriate).",!
94 write OKCt," items will be refreshed in DRUG file.",!
95
96 new % set %=1
97 write "Proceed" do YN^DICN write !
98 if %'=1 goto RNSDone
99
100 do EnsureFromList(.tempList)
101
102RNSDone
103 quit
104
105RefreshBatch(IENArray,Option)
106 ;"Purpose: To take entries in 22706.9 and refresh them
107 ;"Input: IENArray -- PASS BY REFERENCE. Array of IENs from 22706.9
108 ;" IENArray(IEN22706d9)=""
109 ;" IENArray(IEN22706d9)=""
110 ;" Option -- OPTIONAL. Format:
111 ;" Option("FIX CHAIN")=1 <--- changes will be propigate forward
112 ;" to file 50, POI, OI, OQV etc.
113 ;" Option("QUIET")=1
114
115 ;"Results: none
116
117 new IEN22706d9,Itr
118 new abort set abort=0
119 set IEN22706d9=$$ItrAInit^TMGITR("IENArray",.Itr)
120 do PrepProgress^TMGITR(.Itr,1,1,"IEN22706d9")
121 if IEN22706d9'="" for do quit:($$ItrANext^TMGITR(.Itr,.IEN22706d9)="")!abort
122 . ;"write !,"Refreshing compiled entry #",IEN227606d9,!
123 . do Refresh1(IEN22706d9,.Option)
124 quit
125
126
127Refresh1(IEN22706d9,Option)
128 ;"Purpose: To take one entry in 22706.9 and refresh it
129 ;"Input: IEN22706d9 -- IEN from 22706.9
130 ;" Option -- OPTIONAL. Format:
131 ;" Option("FIX CHAIN")=1 <--- changes will be propigate forward
132 ;" to file 50, POI, OI, OQV etc.
133 ;"Results: none
134
135 new gIEN50,tIEN50
136 new skip
137 set skip=($piece($get(^TMG(22706.9,IEN22706d9,1)),"^",4)=1)
138
139 if $get(Option("FIX CHAIN"))=1 do
140 . new temp
141 . set tIEN50=+$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",1)
142 . set Option("IEN50","TRADE")=tIEN50
143 . set gIEN50=+$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",2)
144 . set Option("IEN50","GENERIC")=gIEN50
145 . set Option("FIX CHAIN","IEN22706d9")=IEN22706d9
146
147 new List
148 if skip set List(IEN22706d9)="S"
149 else set List(IEN22706d9)=""
150
151 do EnsureFromList(.List,.Option)
152
153 if $get(Option("FIX CHAIN"))=1 do
154 . if tIEN50>0 set temp=$$Fix1Drug^TMGNDF3D(tIEN50,IEN22706d9)
155 . if gIEN50>0 set temp=$$Fix1Drug^TMGNDF3D(gIEN50,IEN22706d9)
156
157 quit
158
159
160EnsureFromList(List,Option)
161 ;"Purpose: to add entries to, or refresh fields in, DRUG file (50) based on
162 ;" data from TMG FDA IMPORT COMPILED (22706.9),
163 ;" OR to ensure that the linked records are properly refreshed.
164 ;" OR ensure that records liked from a skipped record are deleted
165 ;"Input: List -- PASS BY REFERENCE, format:
166 ;" List(IEN22706d9)=""
167 ;" List(IEN22706d9)=""
168 ;" List(IEN22706d9)="S" <-- record now skipped, so ensure linked records are removed
169 ;" Option -- OPTIONAL. Format:
170 ;" Option("FIX CHAIN")=1 <--- changes will be propigate forward
171 ;" to file 50, POI, OI, OQV etc.
172 ;" OPTION("FIX CHAIN","IEN22706d9")=Source IEN
173 ;" Option("QUIET")=1 <-- supress text output
174 ;"Results: none
175
176 new IEN22706d9,Itr
177 new error set error=0
178 new abort set abort=0
179 new ChangeCt set ChangeCt=0
180 new quiet set quiet=($get(Option("QUIET"))=1)
181 do Unlock50^TMGNDFUT
182
183 if 'quiet write "Scanning import file, to ensure all records in DRUG file are updated...",!
184 set IEN22706d9=$$ItrAInit^TMGITR("List",.Itr)
185 if 'quiet do PrepProgress^TMGITR(.Itr,20,0,"IEN22706d9")
186 if IEN22706d9>0 for do quit:($$ItrANext^TMGITR(.Itr,.IEN22706d9)'>0)!abort
187 . new DrugInfo,ndcIEN,tempS,error,temp,vapIEN,temp
188 . new skip set skip=($get(List(IEN22706d9))="S")
189 . set error=0,temp=0,tempS=""
190 . if $$UserAborted^TMGUSRIF set abort=1 quit
191 . set vapIEN=+$piece($get(^TMG(22706.9,IEN22706d9,6)),"^",2)
192 . if skip=0,vapIEN>0,$data(^PSNDF(50.68,vapIEN))=0 do
193 . . if 'quiet write "Pointer to VA PRODUCT from File 22709.9, IEN# ",IEN22706d9," is invalid. Will delete.",!
194 . . set vapIEN=0
195 . . new TMGMSG,TMGFDA
196 . . set TMGFDA(22706.9,fdaIEN_",",5.5)="@"
197 . . do FILE^DIE("K","TMGFDA","TMGMSG")
198 . . do ShowIfDIERR^TMGDEBUG(.TMGMSG) ;"show errors, even if quiet
199 . if skip=0,vapIEN'>0 set error=1 quit
200 . set temp=$$GetTMGDrugInfo(IEN22706d9,.DrugInfo)
201 . if skip=0,temp=0 set error=1 quit
202 . if skip=1 set Option("DELETING")=1
203 . ;"--- work on Trade Name link ---
204 . if ($get(DrugInfo("NAME","TRADE"))=$get(DrugInfo("NAME","GENERIC"))) set DrugInfo("NAME","TRADE")=""
205 . new tIEN50 set tIEN50=+$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",1) ;"DRUG TRADENAME LINK
206 . set Option("CUR MODE")="TRADE"
207 . set temp=$$Update50(tIEN50,.DrugInfo,.Option) ;"may chain forward
208 . if temp=1 set ChangeCt=ChangeCt+1
209 . else if temp=-1 set error=1 ;"quit
210 . ;"--- work on Generic Name link ---
211 . new gIEN50 set gIEN50=+$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",2) ;"DRUG GENERIC LINK
212 . if gIEN50=tIEN50 set gIEN50=0
213 . set Option("CUR MODE")="GENERIC"
214 . set temp=$$Update50(gIEN50,.DrugInfo,.Option) ;"may chain forward
215 . if temp=1 set ChangeCt=ChangeCt+1
216 . else if temp=-1 set error=1 ;"quit
217 if error write "Error with import : IEN22706d9=",IEN22706d9,!
218
219 if 'quiet do
220 . write ChangeCt," Records Modified.",!
221 . do PressToCont^TMGUSRIF
222
223 do Unlock50^TMGNDFUT
224 quit
225
226
227GetTMGDrugInfo(IEN22706d9,DrugInfo)
228 ;"Purpose: Create a very abbreviated version of the DrugInfo array
229 ;" This is because calling GetDrugInfo^TMGNDF1A is unneccesarily SLOW
230 ;" Also, it makes one dependant on FDA primary files.
231 ;"Input: IEN22706d9 -- IEN in file 22706.9
232 ;" DrugInfo -- PASS BY REFERENCE. Format:
233 ;" DrugInfo("NDC")
234 ;"Output: DrugInfo("NAME","TRADE")=.056 field
235 ;" DrugInfo("NAME","GENERIC")=.076 field
236 ;" DrugInfo("SOURCE IEN")=source IEN in 22706.9
237 ;" DrugInfo("IEN 50.68")=field 5.5, a pointer to 50.68 (VA PRODUCT)
238 ;"Results: 1=OK to continue, 0=error
239 ;"NOTE: 11/5/07 Modifying to make use of fields .055 and .075, where name is
240 ;" prepaired and stored in a previous step.
241 ;"NOTE: 11/10/07 Modifying to make use of fields .056 and .076, where name is
242 ;" prepaired and stored in a previous step.
243
244 kill DrugInfo
245 new result set result=1
246 set DrugInfo("NDC")=$piece($get(^TMG(22706.9,IEN22706d9,1)),"^",1)
247 if DrugInfo("NDC")="" set result=0
248
249 set DrugInfo("SOURCE IEN")=IEN22706d9
250 set DrugInfo("IEN 50.68")=+$piece($get(^TMG(22706.9,IEN22706d9,6)),"^",2)
251
252 new tempS set tempS=$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",1) ;".056 TRADENAME FORM DOSE UNIT - 40
253 if tempS'="" set DrugInfo("NAME","TRADE")=tempS
254
255 new tempS set tempS=$piece($get(^TMG(22706.9,IEN22706d9,8)),"^",2) ;".076 GENERICNAME FORM DOSE UNT - 40
256 if tempS'="" set DrugInfo("NAME","GENERIC")=tempS
257
258GDIDone
259 quit result
260
261
262Update50(IEN50,DrugInfo,Option)
263 ;"Purpose: to refresh info in DRUG file, or add if it doesn't exist (or delete if needed)
264 ;"Input: IEN50: Target IEN to refresh, or 0 if needs to be added
265 ;" DrugInfo -- PASS BY REFERENCE. Format:
266 ;" DrugInfo("NDC")
267 ;" DrugInfo("NAME","TRADE")=.056 field
268 ;" DrugInfo("NAME","GENERIC")=.076 field
269 ;" DrugInfo("SOURCE IEN")=source IEN in 22706.9
270 ;" DrugInfo("IEN 50.68")=field 5.5, a pointer to 50.68 (VA PRODUCT)
271 ;" Option -- NON-OPTIONAL part. Format:
272 ;" Option("CUR MODE")="TRADE"
273 ;" Option -- OPTIONAL part. Format:
274 ;" Option("FIX CHAIN")=1 <--- changes will be propigate forward
275 ;" to file 50, POI, OI, OQV etc.
276 ;" OPTION("FIX CHAIN","IEN22706d9")=Source IEN
277 ;" Option("QUIET")=1 <-- supress text output
278 ;" Option("DELETING")=1 <-- deleting chain (not IEN22706d9)
279 ;"Result: -1 = error, 0=info refreshed, 1=record added.
280
281 new result set result=0
282 new quiet set quiet=$get(Option("QUIET"))=1
283 new IEN22706d9 set IEN22706d9=+$get(DrugInfo("SOURCE IEN"))
284 new mode set mode=$get(Option("CUR MODE"))
285 if (mode'="TRADE")&(mode'="GENERIC") set result=-1 goto UDDone
286
287 new StoreField,node,pce
288 if mode="TRADE" set StoreField=5.6,node=7,pce=1
289 else set StoreField=5.7,node=7,pce=2
290
291 new drugName set drugName=$get(DrugInfo("NAME",mode))
292 set DrugInfo("NAME",mode)=drugName
293 if (drugName="")!(drugName="<DUPLICATE>")!($get(Option("DELETING"))=1) do goto UDDone
294 . do Kill50^TMGNDFUT(IEN50,IEN22706d9,mode,quiet) ;"is OK if IEN50=0
295 . set result=-1
296
297 if (IEN50>0),$data(^PSDRUG(IEN50))=0 do
298 . set IEN50=0 ;"I found case of dangling pointer
299
300 if IEN50=0 do ;"Create stub entry with drug name in .01 field
301 . new PSSZ set PSSZ=1 ;"allows code to add entries into DRUG file.
302 . new TMGFDA,TMGMSG,TMGIEN,IENS
303 . set TMGFDA(50,"+1,",.01)=drugName
304 . do UPDATE^DIE("S","TMGFDA","TMGIEN","TMGMSG")
305 . do ShowDIERR^TMGDEBUG(.TMGMSG)
306 . set IEN50=+$get(TMGIEN(1)) if IEN50=0 quit
307 . do AddMsg(IEN50,"TMG AUTOADDED FROM FDA")
308 . set Option("IEN50",mode)=IEN50
309 . set Option("IEN50",mode,"NAME")=drugName
310
311 set DrugInfo("CUR MODE")=mode
312 set temp=$$Stuff50(IEN50,.DrugInfo,.Option) ;"no chain forward
313 if temp=0 set result=-1
314 if temp=2 set result=1
315
316 ;"Ensure pointer to DRUG (50) is stored in 22706.9
317 if $piece($get(^TMG(22706.9,IEN22706d9,node)),"^",pce)'=IEN50 do
318 . new TMGFDA,TMGMSG
319 . set TMGFDA(22706.9,IEN22706d9_",",StoreField)=IEN50
320 . do FILE^DIE("K","TMGFDA","TMGMSG")
321 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
322 . set Option("IEN50",mode)=IEN50
323
324 if $get(Option("FIX CHAIN"))=1 do
325 . new temp set temp=$$POIFromTMG^TMGNDF4A(IEN22706d9,.Option) ;" --> more chain from here
326 . ;"if $get(Option("DELETING"))=1 do
327 . ;". do Kill50^TMGNDFUT(IEN50,IEN22706d9,mode,quiet) ;"is OK if IEN50=0
328
329UDDone
330 quit result
331
332
333Stuff50(IEN50,DrugInfo,Option)
334 ;"Purpose: To synch record(s) in the DRUG file
335 ;"Input: IEN50 -- IEN of record in file 50 to update
336 ;" DrugInfo -- PASS BY REFERENCE -- Drug info array. Format:
337 ;" DrugInfo("NAME","GENERIC")=e.g. NAME: DILTIAZEM 240MG
338 ;" DrugInfo("NAME","TRADE")=e.g. NAME: CARDIZEM CD 240MG
339 ;" DrugInfo("NDC")
340 ;" DrugInfo("SOURCE IEN")=source IEN in 22706.9
341 ;" DrugInfo("IEN 50.68")=field 5.5, a pointer to 50.68 (VA PRODUCT)
342 ;" Option -- NON-OPTIONAL part. Format:
343 ;" Option("CUR MODE")="TRADE"
344 ;" Option -- OPTIONAL. Format:
345 ;" Option("FIX CHAIN")=1 <--- changes will be propigate forward
346 ;" to file 50, POI, OI, OQV etc.
347 ;" OPTION("FIX CHAIN","IEN22706d9")=Source IEN
348 ;" Option("QUIET")=1 <-- supress text output
349 ;"Output: A record will be added to file DRUG (50)
350 ;"Result: 1=OK to continue, 2=change made, 0 if error
351
352 ;"Note: must set PSSZ=1 to be allowed to enter entries into DRUG file.
353
354 new result set result=1 ;"default to success -- don't change.
355 new PSSZ set PSSZ=1 ;"allows code to add entries into DRUG file.
356
357 ;"Remove any synonyms
358RF1 new numSyns
359 for do quit:(numSyns'>0)
360 . set numSyns=+$piece($get(^PSDRUG(IEN50,1,0)),"^",4) ;"number of records
361 . if numSyns=0 quit
362RF2 . set subIEN=$order(^PSDRUG(IEN50,1,0))
363 . if (subIEN'>0) set numSyns=0 quit
364 . new TMGFDA,TMGMSG
365 . set TMGFDA(50.1,subIEN_","_IEN50_",",.01)="@"
366 . do FILE^DIE("K","TMGFDA","TMGMSG")
367 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
368 . set result=2
369
370 new TMGFDA,TMGMSG,TMGIEN
371
372 set result=$$SetupFDA(.DrugInfo,IEN50_",",.TMGFDA)
373 if result=0 goto RFDone
374 new temp set temp=$$TrimFDA^TMGDBAPI(.TMGFDA)
375 if $data(TMGFDA)=0 goto RFDone
376
377 do FILE^DIE("KS","TMGFDA","TMGMSG")
378 if $data(TMGMSG("DIERR")) do goto RFDone
379 . set result=0
380 . if $get(Quiet)=1 quit
381 . write !,"Error editing record in file 50",!
382 . new PriorErrorFound
383 . do ShowDIERR^TMGDEBUG(.TMGMSG,.PriorErrorFound)
384
385 do AddMsg(IEN50,"TMG AUTO UPDATED FROM FDA")
386 set result=2 ;"update made.
387
388RFDone quit result
389
390
391AddMsg(IEN50,Msg)
392 ;"Purpose: to Add a message in the Activity log field
393 ;"Input: IEN50 -- the IEN in DRUG file
394 ;" Msg -- the Message to add (a string)
395 ;"results: none.
396
397 ;"Check that record was added, then then add subfile entries:
398 set IENS="+1,"_IEN50_","
399 kill TMGFDA,TMGMSG,TMGIEN
400 ;" 214 ACTIVITY LOG <-Mult [50.0214DA]
401 ;" .01 -ACTIVITY LOG [D]
402 ;" 1 -REASON [S]
403 ;" 2 -INITIATOR OF ACTIVITY <-Pntr [P200']
404 ;" 3 -FIELD EDITED [F]
405 ;" 4 -NEW VALUE [F]
406 ;" 5 -NDF UPDATE [F]
407 set TMGFDA(50.0214,IENS,.01)="NOW"
408 set TMGFDA(50.0214,IENS,1)="E"
409 set TMGFDA(50.0214,IENS,2)="`"_DUZ
410 set TMGFDA(50.0214,IENS,3)="ALL FIELDS"
411 set TMGFDA(50.0214,IENS,4)=Msg
412
413 do UPDATE^DIE("ES","TMGFDA","TMGIEN","TMGMSG")
414 if $get(Quiet)'=1 do ShowIfDIERR^TMGDEBUG(.TMGMSG)
415
416 quit
417
418
419SetupFDA(DrugInfo,IENS,TMGFDA)
420 ;"Purpose: To set up the FDA (Filman data array) for the data that will go into
421 ;" a record to the DRUG file, based on entry from VA PRODUCT file
422 ;"Input: DrugInfo -- PASS BY REFERENCE -- Drug info from array GetTMGDrugInfo, and
423 ;" as modified by Add2VAProd^TMGNDF3A
424 ;" Fields used are:
425 ;" DrugInfo("CUR MODE")="GENERIC" or "TRADE"
426 ;" DrugInfo("NAME","GENERIC")=e.g. NAME: DILTIAZEM 240MG
427 ;" DrugInfo("NAME","TRADE")=e.g. NAME: CARDIZEM CD 240MG
428 ;" DrugInfo("NDC")
429 ;" DrugInfo("SOURCE IEN")=source IEN in 22706.9
430 ;" DrugInfo("IEN 50.68")=field 5.5, a pointer to 50.68 (VA PRODUCT)
431 ;" IENS -- a standard fileman IENS for this FDA to be created with
432 ;" TMGFDA -- PASS BY REFERENCE -- an OUT PARAMETER. This will be a standard
433 ;" fileman FDA
434 ;"Output: TMGFDA will be filled
435 ;"Result: 1=OK to continue, 0 if error
436
437 ;"NOTE: The FDA that this function contains will contain INTERNAL values
438
439 new result set result=1 ;"default to success -- don't change.
440 new mode set mode=$get(DrugInfo("CUR MODE"))
441 if (mode'="TRADE")&(mode'="GENERIC") set result=0 goto SUFDone
442
443 new TMGMSG,TMGIEN
444 new tempS,tempIEN
445 new IEN22706d9 set IEN22706d9=+$get(DrugInfo("SOURCE IEN"))
446
447 ;"Example Entry. (Edited for fields I care about)
448 ;"#50 .01 GENERIC NAME: DILTIAZEM CD 120MG CAP
449 ;"#50.68 .01 NAME [RFa]
450 ;"#50.68 e.g. NAME: DILTIAZEM (CARDIZEM CD) 240MG SA CAP
451 set tempS=$get(DrugInfo("NAME",mode))
452 set tempS=$translate(tempS,";",":") ;" for some reason ';' is not allowed in .01 field
453 if $length(tempS)>40 set tempS=$extract(tempS,1,37)_"..."
454 set TMGFDA(50,IENS,.01)=tempS
455
456 ;"#50 22 PSNDF VA PRODUCT NAME ENTRY: DILTIAZEM (CARDIZEM CD) 120MG SA CAP
457 ;"#50.68 .01 NAME [RFa]
458 ;"#50.68 e.g. NAME: DILTIAZEM (CARDIZEM CD) 240MG SA CAP
459 new vapIEN set vapIEN=+$get(DrugInfo("IEN 50.68"))
460 if +vapIEN>0 DO
461 . set TMGFDA(50,IENS,22)=vapIEN
462 . new vapName
463 . set vapName=$$GET1^DIQ(50.68,vapIEN,.01)
464 . ;"#50 21 VA PRODUCT NAME: DILTIAZEM (CARDIZEM CD) 120MG SA CAP
465 . ;"#50.68 .01 NAME [RFa]
466 . ;"#50.68 e.g. NAME: DILTIAZEM (CARDIZEM CD) 240MG SA CAP
467 . set TMGFDA(50,IENS,21)=vapName
468 . ;"set TMGFDA(50,IENS,21)=tempS
469
470 ;"#50 5 STANDARD SIG: T1 CAP QD
471 ;" plan "USE AS DIRECTED"
472 set TMGFDA(50,IENS,5)="USE AS DIRECTED"
473
474 ;"#50 20 NATIONAL DRUG FILE ENTRY: DILTIAZEM <-Pntr [P50.6, VA GENERIC]
475 set tempIEN=+$piece($get(^TMG(22706.9,IEN22706d9,1)),"^",3) ;"1;3 = field .08 VA GENERIC
476 if tempIEN>0 set TMGFDA(50,IENS,20)=tempIEN
477
478 ;"#50 25 NATIONAL DRUG CLASS <-Pntr [P50.605']
479 ;"#50 2 VA CLASSIFICATION [FX]
480 set tempIEN=+$piece($get(^TMG(22706.9,IEN22706d9,1)),"^",5) ;"1;5 = field .09 VA DRUG CLASS
481 set TMGFDA(50,IENS,25)=tempIEN
482 set tempClass=$$GET1^DIQ(50.605,tempIEN_",",.01)
483 if tempClass'="" set TMGFDA(50,IENS,2)=tempClass
484
485 ;"#50 29 NATIONAL FORMULARY INDICATOR: NO
486 set TMGFDA(50,IENS,29)=0 ;"0=NO, 1=YES
487
488 ;"#50 31 NDC: 0088-1795-30
489 new NDC set NDC=$piece($get(^TMG(22706.9,IEN22706d9,1)),"^",1)
490 set NDC=$extract(NDC,2,20) ;"should be in 5-4-2 format, but must be 11 digits, 1st is not significant
491 if NDC'="" set TMGFDA(50,IENS,31)=NDC
492
493 ;"#50 901 STRENGTH: 120
494 new tempStr set tempStr=$piece($get(^TMG(22706.9,IEN22706d9,0)),"^",2) ;"0;2=field 1 STRENGTH
495 if tempStr'="" set TMGFDA(50,IENS,901)=tempStr
496
497 ;"#50 902 UNIT: MG
498 ;"#50.68 3 UNITS <-Pntr [P50.607'a]
499 ;"#50.68 e.g. UNITS: MG
500 new tempUnit set tempUnit=$$GET1^DIQ(50.68,vapIEN,3,"I")
501 if tempUnit'="" set TMGFDA(50,IENS,902)=tempUnit
502
503 ;"#50 62.02 UNIT DOSE MED ROUTE <-Pntr [*P51.2']
504 ;"#22706.9 3.1 VA ROUTE <-Pntr [P51.2']
505 set tempIEN=+$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",7) ;"7;7 3.1 VA ROUTE
506 if tempIEN>0 set TMGFDA(50,IENS,62.02)=tempIEN
507
508SUFDone
509 quit result
510
511
512VerifySync
513 ;"To verify the synchronization, i.e. looking for dangling pointers etc.
514
515 new ChangeCt set ChangeCt=0
516 new Itr,IEN22706d9
517 new abort set abort=0
518 write !,"Checking Synchronization",!
519 set IEN22706d9=$$ItrInit^TMGITR(22706.9,.Itr)
520 do PrepProgress^TMGITR(.Itr,20,0,"IEN22706d9")
521 if IEN22706d9'="" for do quit:($$ItrNext^TMGITR(.Itr,.IEN22706d9)'>0)!abort
522 . if $$UserAborted^TMGUSRIF set abort=1 quit
523 . ;"if +$piece($get(^TMG(22706.9,IEN22706d9,1)),"^",4)=1 quit ;"1=SKIP
524 . new tIEN50 set tIEN50=$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",1)
525 . set ChangeCt=ChangeCt+$$Verify1(IEN22706d9,tIEN50,"TRADE")
526 . new gIEN50 set gIEN50=$piece($get(^TMG(22706.9,IEN22706d9,7)),"^",2)
527 . set ChangeCt=ChangeCt+$$Verify1(IEN22706d9,gIEN50,"GENERIC")
528 do ProgressDone^TMGITR(.Itr)
529
530 do PressToCont^TMGUSRIF
531
532 quit
533
534Verify1(IEN22706d9,IEN50,mode)
535 ;"To Verify one
536 ;"Input: IEN22706d9
537 ;" IEN50 -- link to DRUG file (either for Generic Drug, or Trade Drug)
538 ;" mode - "GENERIC" or "TRADE"
539 ;"Result: 0 -- no change, 1= change made
540
541 new result set result=0
542 new field50 set field50=""
543 new fieldName set fieldName=""
544 new node,pce set (node,pce)=""
545 if mode="GENERIC" do
546 . set field50=5.7
547 . set fieldName=.076
548 . set node=8,pce=2
549 else if mode="TRADE" do
550 . set field50=5.6
551 . set fieldName=.056
552 . set node=8,pce=1
553 if (field50="") goto V1Done
554 if (IEN50="") goto V1Done
555
556 new drugName set drugName=$piece($get(^PSDRUG(IEN50,0)),"^",1)
557 new TMGName set TMGName=$piece($get(^TMG(22706.9,IEN22706d9,node)),"^",pce)
558 set TMGName=$translate(TMGName,";",":")
559
560 if $data(^PSDRUG(+$get(IEN50)))=0 do
561 . write "Bad pointer: ",IEN50
562 . set IEN50=0
563
564 if drugName'=TMGName do
565 . write IEN22706d9," (",$extract(mode,1),"): Name mismatch: ",drugName," vs ",TMGName,!
566 . if TMGName="" set IEN50=0
567
568 if $get(IEN50)=0 do goto V1Done
569 . new TMGFDA,TMGMSG
570 . set TMGFDA(22706.9,IEN22706d9_",",field50)="@"
571 . do UPDATE^DIE("","TMGFDA","TMGMSG")
572 . do ShowIfDIERR^TMGDEBUG(.TMGMSG)
573 . write " ... fixed.",!
574 . set result=1
575
576
577V1Done
578 quit result
Note: See TracBrowser for help on using the repository browser.