1 | C0CRXNRD ; 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 | ;
|
---|
5 | DELFILED(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
|
---|
23 | GETLINES(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
|
---|
30 | READCON(PATH) ; Open and read concepts file: RXNCONSO.RRF
|
---|
31 | I PATH="" QUIT
|
---|
32 | N FILENAME S FILENAME="RXNCONSO.RRF"
|
---|
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)
|
---|
37 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
---|
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
|
---|
41 | . U IO
|
---|
42 | . N LINE R LINE
|
---|
43 | . IF $$STATUS^%ZISH QUIT
|
---|
44 | . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
|
---|
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 "^"
|
---|
53 | . S STR=$TR(STR,"^")
|
---|
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
|
---|
57 | . N J F J=1:1:STRLINE S STR(J)=$E(STR,1,80) S STR=$E(STR,81,$L(STR))
|
---|
58 | . ; Now, construct the FDA array
|
---|
59 | . N RXNFDA
|
---|
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
|
---|
65 | . D UPDATE^DIE("","RXNFDA")
|
---|
66 | . I $D(^TMP("DIERR",$J)) D EN^DDIOL("ERROR") G EX
|
---|
67 | . ; Now, file WP field STR
|
---|
68 | . D WP^DIE(176.001,C0CCOUNT_",",5,,$NA(STR))
|
---|
69 | EX D CLOSE^%ZISH("FILE")
|
---|
70 | QUIT
|
---|
71 | READNDC(PATH) ; Open and read NDC/RxNorm/VANDF relationship file: RXNSAT.RRF
|
---|
72 | I PATH="" QUIT
|
---|
73 | N FILENAME S FILENAME="RXNSAT.RRF"
|
---|
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)
|
---|
78 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
---|
79 | IF POP W "Error reading file..., Please check...",! G EX2
|
---|
80 | F C0CCOUNT=1:1 Q:$$STATUS^%ZISH D
|
---|
81 | . U IO
|
---|
82 | . N LINE R LINE
|
---|
83 | . IF $$STATUS^%ZISH QUIT
|
---|
84 | . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
|
---|
85 | . IF LINE'["NDC|RXNORM" QUIT
|
---|
86 | . ; Otherwise, we are good to go
|
---|
87 | . N RXCUI,NDC ; Fileman fields below
|
---|
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
|
---|
93 | . S DIC="^C0CRXN(176.002,",DIC(0)="F",X=RXCUI,DIC("DR")="2////"_NDC
|
---|
94 | . D FILE^DICN
|
---|
95 | . I Y<1 U $P W !,"THERE IS TROUBLE IN RIVER CITY",! G EX2
|
---|
96 | EX2 D CLOSE^%ZISH("FILE")
|
---|
97 | QUIT
|
---|
98 | READSRC(PATH) ; Open the read RxNorm Sources file: RXNSAB.RRF
|
---|
99 | I PATH="" QUIT
|
---|
100 | N FILENAME S FILENAME="RXNSAB.RRF"
|
---|
101 | N ERR
|
---|
102 | D DELFILED(176.003,.ERR) ; delete data
|
---|
103 | IF $G(ERR) D EN^DDIOL("Couldn't delete file") G EX2
|
---|
104 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
---|
105 | IF POP W "Error reading file..., Please check...",! G EX3
|
---|
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")
|
---|
136 | . I $D(^TMP("DIERR",$J)) U $P W "ERR" G EX
|
---|
137 | . ; Now, file WP field SCIT
|
---|
138 | . D WP^DIE(176.003,I_",",25,,$NA(SCIT))
|
---|
139 | EX3 D CLOSE^%ZISH("FILE")
|
---|
140 | Q
|
---|
141 |
|
---|