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

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

More updated to C0CRXNRD. Now it deletes the RxNorm files priors to building them again

File size: 5.0 KB
RevLine 
[280]1C0CRXNRD ; WV/SMH - CCR/CCD PROJECT: Routine to Read RxNorm files;11/15/08
2 ;;0.1;CCDCCR;nopatch;noreleasedate
3 W "No entry from top" Q
4 ;
[582]5DELFILED(FN,ERR) ; Delete file data; PEP procedure; READ WARNING
6 ; FN is Filenumber passed by Value
7 ; ERR is error info, passed by reference
8 ; If ERR is 1, then the operation failed.
9 ; WARNING: THIS IS VERY DANGEROUS OPERATION
10 ; I DON'T EVEN CHECK THE DEL NODE ON THE FILE!!!!
11 ;
12 D CLEAN^DILF ; Clean FM variables
13 N C0CFINFO ; File info
14 D FILE^DID(FN,"","GLOBAL NAME","C0CROOT") ; Get file info
15 I $D(DIERR) D EN^DDIOL("Error...") S ERR=1 QUIT
16 N ROOT2 S ROOT2=C0CROOT("GLOBAL NAME") ; Open global root
17 N CLROOT S CLROOT=$$CREF^DILF(ROOT2) ; Closed Root
18 N ZERO S ZERO=@CLROOT@(0) ; Save zero node
19 S $P(ZERO,U,3,9999)="" ; Remove entry # and last edited
20 K @CLROOT ; Kill the file -- so sad!
21 S @CLROOT@(0)=ZERO ; It riseth again!
22 QUIT
23GETLINES(PATH,FILENAME) ; Get number of lines in a file
24 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
25 U IO
26 N I
27 F I=1:1 R LINE Q:$$STATUS^%ZISH
28 D CLOSE^%ZISH("FILE")
29 Q I-1
[310]30READCON(PATH) ; Open and read concepts file: RXNCONSO.RRF
31 I PATH="" QUIT
[280]32 N FILENAME S FILENAME="RXNCONSO.RRF"
[582]33 N ERR
34 D DELFILED(176.001,.ERR) ; delete data
35 IF $G(ERR) D EN^DDIOL("Couldn't delete file") G EX
36 N LINES S LINES=$$GETLINES(PATH,FILENAME)
[280]37 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
[582]38 IF POP D EN^DDIOL("Error reading file..., Please check...") G EX
39 N C0CCOUNT
40 F C0CCOUNT=1:1 D Q:$$STATUS^%ZISH
[280]41 . U IO
42 . N LINE R LINE
43 . IF $$STATUS^%ZISH QUIT
[582]44 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
[280]45 . N RXCUI,RXAUI,SAB,TTY,CODE,STR ; Fileman fields numbers below
46 . S RXCUI=$P(LINE,"|",1) ; .01
47 . S RXAUI=$P(LINE,"|",8) ; 1
48 . S SAB=$P(LINE,"|",12) ; 2
49 . S TTY=$P(LINE,"|",13) ; 3
50 . S CODE=$P(LINE,"|",14) ; 4
51 . S STR=$P(LINE,"|",15) ; 5
52 . ; Remove embedded "^"
[283]53 . S STR=$TR(STR,"^")
[280]54 . ; Convert STR into an array of 80 characters on each line
55 . N STRLINE S STRLINE=$L(STR)\80+1
56 . ; In each line, chop 80 characters off, reset STR to be the rest
[582]57 . N J F J=1:1:STRLINE S STR(J)=$E(STR,1,80) S STR=$E(STR,81,$L(STR))
[280]58 . ; Now, construct the FDA array
59 . N RXNFDA
[582]60 . S RXNFDA(176.001,"+"_C0CCOUNT_",",.01)=RXCUI
61 . S RXNFDA(176.001,"+"_C0CCOUNT_",",1)=RXAUI
62 . S RXNFDA(176.001,"+"_C0CCOUNT_",",2)=SAB
63 . S RXNFDA(176.001,"+"_C0CCOUNT_",",3)=TTY
64 . S RXNFDA(176.001,"+"_C0CCOUNT_",",4)=CODE
[280]65 . D UPDATE^DIE("","RXNFDA")
[582]66 . I $D(^TMP("DIERR",$J)) D EN^DDIOL("ERROR") G EX
[280]67 . ; Now, file WP field STR
[582]68 . D WP^DIE(176.001,C0CCOUNT_",",5,,$NA(STR))
69EX D CLOSE^%ZISH("FILE")
70 QUIT
[311]71READNDC(PATH) ; Open and read NDC/RxNorm/VANDF relationship file: RXNSAT.RRF
72 I PATH="" QUIT
73 N FILENAME S FILENAME="RXNSAT.RRF"
[582]74 N ERR
75 D DELFILED(176.002,.ERR) ; delete data
76 IF $G(ERR) D EN^DDIOL("Couldn't delete file") G EX2
77 N LINES S LINES=$$GETLINES(PATH,FILENAME)
[280]78 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
[582]79 IF POP W "Error reading file..., Please check...",! G EX2
80 F C0CCOUNT=1:1 Q:$$STATUS^%ZISH D
[311]81 . U IO
[280]82 . N LINE R LINE
83 . IF $$STATUS^%ZISH QUIT
[582]84 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
85 . IF LINE'["NDC|RXNORM" QUIT
[280]86 . ; Otherwise, we are good to go
[369]87 . N RXCUI,NDC ; Fileman fields below
[280]88 . S RXCUI=$P(LINE,"|",1) ; .01
89 . S NDC=$P(LINE,"|",11) ; 2
90 . ; Using classic call to update.
91 . N DIC,X,DA,DR
92 . K DO
[582]93 . S DIC="^C0CRXN(176.002,",DIC(0)="F",X=RXCUI,DIC("DR")="2////"_NDC
[280]94 . D FILE^DICN
[582]95 . I Y<1 U $P W !,"THERE IS TROUBLE IN RIVER CITY",! G EX2
96EX2 D CLOSE^%ZISH("FILE")
[369]97 QUIT
[581]98READSRC(PATH) ; Open the read RxNorm Sources file: RXNSAB.RRF
99 I PATH="" QUIT
100 N FILENAME S FILENAME="RXNSAB.RRF"
[582]101 N ERR
102 D DELFILED(176.003,.ERR) ; delete data
103 IF $G(ERR) D EN^DDIOL("Couldn't delete file") G EX2
[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
111 . N VCUI,RCUI,VSAB,RSAB,SON,SF,SVER,SCIT ; Fileman fields numbers below
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
119 . S SCIT=$P(LINE,"|",25) ; 25
120 . ; Remove embedded "^"
121 . S SCIT=$TR(SCIT,"^")
122 . ; Convert SCIT into an array of 80 characters on each line
123 . ; In each line, chop 80 characters off, reset SCIT to be the rest
124 . N SCITLINE S SCITLINE=$L(SCIT)\80+1
125 . F J=1:1:SCITLINE S SCIT(J)=$E(SCIT,1,80) S SCIT=$E(SCIT,81,$L(SCIT))
126 . ; Now, construct the FDA array
127 . N RXNFDA
128 . S RXNFDA(176.003,"+"_I_",",.01)=VCUI
129 . S RXNFDA(176.003,"+"_I_",",2)=RCUI
130 . S RXNFDA(176.003,"+"_I_",",3)=VSAB
131 . S RXNFDA(176.003,"+"_I_",",4)=RSAB
132 . S RXNFDA(176.003,"+"_I_",",5)=SON
133 . S RXNFDA(176.003,"+"_I_",",6)=SF
134 . S RXNFDA(176.003,"+"_I_",",7)=SVER
135 . D UPDATE^DIE("","RXNFDA")
[582]136 . I $D(^TMP("DIERR",$J)) U $P W "ERR" G EX
[581]137 . ; Now, file WP field SCIT
138 . D WP^DIE(176.003,I_",",25,,$NA(SCIT))
[582]139EX3 D CLOSE^%ZISH("FILE")
[581]140 Q
141
Note: See TracBrowser for help on using the repository browser.