source: ccr/trunk/p/C0CRXNRD.m@ 594

Last change on this file since 594 was 594, checked in by Sam Habiel, 15 years ago

Not quite working RxNorm updater--intermediate version

File size: 5.3 KB
RevLine 
[280]1C0CRXNRD ; WV/SMH - CCR/CCD PROJECT: Routine to Read RxNorm files;11/15/08
[594]2 ;;0.1;C0C;nopatch;noreleasedate
[280]3 W "No entry from top" Q
[594]4IMPORT(PATH)
5 I PATH="" QUIT
6 D READSRC(PATH),READCON(PATH),READNDC(PATH)
7 QUIT
[280]8 ;
[593]9DELFILED(FN) ; Delete file data; PEP procedure; only for RxNorm files
[582]10 ; FN is Filenumber passed by Value
[593]11 QUIT:$E(FN,1,3)'=176 ; Quit if not RxNorm files
[582]12 D CLEAN^DILF ; Clean FM variables
[593]13 N ROOT S ROOT=$$ROOT^DILFD(FN,"",1) ; global root
14 N ZERO S ZERO=@ROOT@(0) ; Save zero node
[582]15 S $P(ZERO,U,3,9999)="" ; Remove entry # and last edited
[593]16 K @ROOT ; Kill the file -- so sad!
17 S @ROOT@(0)=ZERO ; It riseth again!
[582]18 QUIT
19GETLINES(PATH,FILENAME) ; Get number of lines in a file
20 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
21 U IO
22 N I
23 F I=1:1 R LINE Q:$$STATUS^%ZISH
24 D CLOSE^%ZISH("FILE")
25 Q I-1
[594]26READCON(PATH,INCRES) ; Open and read concepts file: RXNCONSO.RRF; EP
27 ; PATH ByVal, path of RxNorm files
28 ; INCRES ByVal, include restricted sources. 1 for yes, 0 for no
[310]29 I PATH="" QUIT
[594]30 S INCRES=+$G(INCRES) ; if not passed, becomes zero.
[280]31 N FILENAME S FILENAME="RXNCONSO.RRF"
[593]32 D DELFILED(176.001) ; delete data
[582]33 N LINES S LINES=$$GETLINES(PATH,FILENAME)
[280]34 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
[582]35 IF POP D EN^DDIOL("Error reading file..., Please check...") G EX
36 N C0CCOUNT
37 F C0CCOUNT=1:1 D Q:$$STATUS^%ZISH
[280]38 . U IO
39 . N LINE R LINE
40 . IF $$STATUS^%ZISH QUIT
[582]41 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
[280]42 . N RXCUI,RXAUI,SAB,TTY,CODE,STR ; Fileman fields numbers below
43 . S RXCUI=$P(LINE,"|",1) ; .01
44 . S RXAUI=$P(LINE,"|",8) ; 1
45 . S SAB=$P(LINE,"|",12) ; 2
[594]46 . ; If the source is a restricted source, decide what to do based on what's asked.
47 . N SRCIEN S SRCIEN=$$FIND1^DIC(176.003,"","QX",SAB,"B") ; SrcIEN in RXNORM SOURCES file
48 . N RESTRIC S RESTRIC=$$GET1^DIQ(176.003,SRCIEN,14,"I") ; 14 is restriction field; values 0-4
49 . ; If RESTRIC is zero, then it's unrestricted. Everything else is restricted.
50 . ; If user didn't ask to include restricted sources, and the source is restricted, then quit
51 . I 'INCRES,RESTRIC QUIT
[280]52 . S TTY=$P(LINE,"|",13) ; 3
53 . S CODE=$P(LINE,"|",14) ; 4
54 . S STR=$P(LINE,"|",15) ; 5
55 . ; Remove embedded "^"
[283]56 . S STR=$TR(STR,"^")
[280]57 . ; Convert STR into an array of 80 characters on each line
58 . N STRLINE S STRLINE=$L(STR)\80+1
59 . ; In each line, chop 80 characters off, reset STR to be the rest
[582]60 . N J F J=1:1:STRLINE S STR(J)=$E(STR,1,80) S STR=$E(STR,81,$L(STR))
[280]61 . ; Now, construct the FDA array
62 . N RXNFDA
[582]63 . S RXNFDA(176.001,"+"_C0CCOUNT_",",.01)=RXCUI
64 . S RXNFDA(176.001,"+"_C0CCOUNT_",",1)=RXAUI
65 . S RXNFDA(176.001,"+"_C0CCOUNT_",",2)=SAB
66 . S RXNFDA(176.001,"+"_C0CCOUNT_",",3)=TTY
67 . S RXNFDA(176.001,"+"_C0CCOUNT_",",4)=CODE
[594]68 . N RXNIEN S RXNIEN(1)=C0CCOUNT
69 . D UPDATE^DIE("","RXNFDA","RXNIEN")
[582]70 . I $D(^TMP("DIERR",$J)) D EN^DDIOL("ERROR") G EX
[280]71 . ; Now, file WP field STR
[582]72 . D WP^DIE(176.001,C0CCOUNT_",",5,,$NA(STR))
73EX D CLOSE^%ZISH("FILE")
74 QUIT
[311]75READNDC(PATH) ; Open and read NDC/RxNorm/VANDF relationship file: RXNSAT.RRF
76 I PATH="" QUIT
77 N FILENAME S FILENAME="RXNSAT.RRF"
[593]78 D DELFILED(176.002) ; delete data
[582]79 N LINES S LINES=$$GETLINES(PATH,FILENAME)
[280]80 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
[582]81 IF POP W "Error reading file..., Please check...",! G EX2
82 F C0CCOUNT=1:1 Q:$$STATUS^%ZISH D
[311]83 . U IO
[280]84 . N LINE R LINE
85 . IF $$STATUS^%ZISH QUIT
[582]86 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
87 . IF LINE'["NDC|RXNORM" QUIT
[280]88 . ; Otherwise, we are good to go
[369]89 . N RXCUI,NDC ; Fileman fields below
[280]90 . S RXCUI=$P(LINE,"|",1) ; .01
91 . S NDC=$P(LINE,"|",11) ; 2
92 . ; Using classic call to update.
93 . N DIC,X,DA,DR
94 . K DO
[582]95 . S DIC="^C0CRXN(176.002,",DIC(0)="F",X=RXCUI,DIC("DR")="2////"_NDC
[280]96 . D FILE^DICN
[582]97 . I Y<1 U $P W !,"THERE IS TROUBLE IN RIVER CITY",! G EX2
98EX2 D CLOSE^%ZISH("FILE")
[369]99 QUIT
[581]100READSRC(PATH) ; Open the read RxNorm Sources file: RXNSAB.RRF
101 I PATH="" QUIT
102 N FILENAME S FILENAME="RXNSAB.RRF"
[593]103 D DELFILED(176.003) ; delete data
[581]104 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
[582]105 IF POP W "Error reading file..., Please check...",! G EX3
[581]106 F I=1:1 Q:$$STATUS^%ZISH D
107 . U IO
108 . N LINE R LINE
109 . IF $$STATUS^%ZISH QUIT
110 . U $P W I,! U IO ; Write I to the screen, then go back to reading the file
[594]111 . N VCUI,RCUI,VSAB,RSAB,SON,SF,SVER,SRL,SCIT ; Fileman fields numbers below
[581]112 . S VCUI=$P(LINE,"|",1) ; .01
113 . S RCUI=$P(LINE,"|",2) ; 2
114 . S VSAB=$P(LINE,"|",3) ; 3
115 . S RSAB=$P(LINE,"|",4) ; 4
116 . S SON=$P(LINE,"|",5) ; 5
117 . S SF=$P(LINE,"|",6) ; 6
118 . S SVER=$P(LINE,"|",7) ; 7
[594]119 . S SRL=$P(LINE,"|",14) ; 14
[581]120 . S SCIT=$P(LINE,"|",25) ; 25
121 . ; Remove embedded "^"
122 . S SCIT=$TR(SCIT,"^")
123 . ; Convert SCIT into an array of 80 characters on each line
124 . ; In each line, chop 80 characters off, reset SCIT to be the rest
125 . N SCITLINE S SCITLINE=$L(SCIT)\80+1
126 . F J=1:1:SCITLINE S SCIT(J)=$E(SCIT,1,80) S SCIT=$E(SCIT,81,$L(SCIT))
127 . ; Now, construct the FDA array
128 . N RXNFDA
129 . S RXNFDA(176.003,"+"_I_",",.01)=VCUI
130 . S RXNFDA(176.003,"+"_I_",",2)=RCUI
131 . S RXNFDA(176.003,"+"_I_",",3)=VSAB
132 . S RXNFDA(176.003,"+"_I_",",4)=RSAB
133 . S RXNFDA(176.003,"+"_I_",",5)=SON
134 . S RXNFDA(176.003,"+"_I_",",6)=SF
135 . S RXNFDA(176.003,"+"_I_",",7)=SVER
[594]136 . S RXNFDA(176.003,"+"_I_",",14)=SRL
[581]137 . D UPDATE^DIE("","RXNFDA")
[582]138 . I $D(^TMP("DIERR",$J)) U $P W "ERR" G EX
[581]139 . ; Now, file WP field SCIT
140 . D WP^DIE(176.003,I_",",25,,$NA(SCIT))
[582]141EX3 D CLOSE^%ZISH("FILE")
[581]142 Q
143
Note: See TracBrowser for help on using the repository browser.