| 1 | C0CRXNRD ; VEN/SMH - RxNorm Utilities: Routine to Read RxNorm files;2013-11-14 1:23 PM
|
|---|
| 2 | ;;2.3;RXNORM FOR VISTA;;Jul 22, 2014;Build 10
|
|---|
| 3 | ; (C) Sam Habiel 2013
|
|---|
| 4 | ; See license for terms of use.
|
|---|
| 5 | ;
|
|---|
| 6 | W "No entry from top" Q
|
|---|
| 7 | IMPORT(PATH,RESTRICTED) ; PUBLIC ENTRY POINT. Rest are private
|
|---|
| 8 | I PATH="" QUIT
|
|---|
| 9 | S RESTRICTED=$G(RESTRICTED,0)
|
|---|
| 10 | S U="^"
|
|---|
| 11 | N STARTTIME S STARTTIME=$P($H,",")*24*60*60+$P($H,",",2)
|
|---|
| 12 | N SABS
|
|---|
| 13 | D SAB(PATH,.SABS) ; Load restriction values into SAB. ; 176.006
|
|---|
| 14 | D CONSO(PATH,.SABS,RESTRICTED),SAT(PATH,.SABS,RESTRICTED) ; 176.001,176.002
|
|---|
| 15 | D STY(PATH),REL(PATH),DOC(PATH) ; 176.003-5
|
|---|
| 16 | N ENDTIME S ENDTIME=$P($H,",")*24*60*60+$P($H,",",2)
|
|---|
| 17 | W !,(ENDTIME-STARTTIME)/60_" minutes elapsed"
|
|---|
| 18 | QUIT
|
|---|
| 19 | ;
|
|---|
| 20 | ; Everything is private from down on...
|
|---|
| 21 | DELFILED(FN) ; Delete file data; PEP procedure; only for RxNorm files
|
|---|
| 22 | ; FN is Filenumber passed by Value
|
|---|
| 23 | QUIT:$E(FN,1,3)'=176 ; Quit if not RxNorm files
|
|---|
| 24 | N ROOT S ROOT=$$ROOT^DILFD(FN,"",1) ; global root
|
|---|
| 25 | N ZERO S ZERO=@ROOT@(0) ; Save zero node
|
|---|
| 26 | S $P(ZERO,U,3,9999)="" ; Remove entry # and last edited
|
|---|
| 27 | K @ROOT ; Kill the file -- so sad!
|
|---|
| 28 | S @ROOT@(0)=ZERO ; It riseth again!
|
|---|
| 29 | QUIT
|
|---|
| 30 | GETLINES(PATH,FILENAME) ; Get number of lines in a file
|
|---|
| 31 | N POP
|
|---|
| 32 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
|---|
| 33 | Q:POP
|
|---|
| 34 | U IO
|
|---|
| 35 | N I,LINE
|
|---|
| 36 | F I=1:1 R LINE:0 Q:$$STATUS^%ZISH
|
|---|
| 37 | D CLOSE^%ZISH("FILE")
|
|---|
| 38 | Q I-1
|
|---|
| 39 | CONSO(PATH,SABS,RESTRICTED) ; Open and read concepts file: RXNCONSO.RRF
|
|---|
| 40 | ; PATH ByVal, path of RxNorm files
|
|---|
| 41 | ; SABS ByRef, arrays of SABS(SAB)=restriction level
|
|---|
| 42 | ; RESTRICTED ByVal, include restricted sources. 1 for yes, 0 for no
|
|---|
| 43 | I PATH="" QUIT
|
|---|
| 44 | N FILENAME S FILENAME="RXNCONSO.RRF"
|
|---|
| 45 | D DELFILED(176.001) ; delete data
|
|---|
| 46 | N LINES S LINES=$$GETLINES(PATH,FILENAME)
|
|---|
| 47 | N POP
|
|---|
| 48 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
|---|
| 49 | IF POP D EN^DDIOL("Error reading file..., Please check...") G EX
|
|---|
| 50 | N C0CCOUNT
|
|---|
| 51 | F C0CCOUNT=1:1 D Q:$$STATUS^%ZISH
|
|---|
| 52 | . U IO
|
|---|
| 53 | . N LINE R LINE:0
|
|---|
| 54 | . IF $$STATUS^%ZISH QUIT
|
|---|
| 55 | . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
|
|---|
| 56 | . ;
|
|---|
| 57 | . ; Deal with restriction level
|
|---|
| 58 | . N SAB S SAB=$P(LINE,"|",12)
|
|---|
| 59 | . I 'RESTRICTED,SABS(SAB) QUIT ; If not include restricted, and SABS(SAB) is not zero, quit
|
|---|
| 60 | . ;
|
|---|
| 61 | . ; Save data
|
|---|
| 62 | . S ^C0CRXN(176.001,C0CCOUNT,0)=$TR(LINE,"|^","^|")
|
|---|
| 63 | EX D CLOSE^%ZISH("FILE")
|
|---|
| 64 | N DIK S DIK="^C0CRXN(176.001," D IXALL^DIK
|
|---|
| 65 | QUIT
|
|---|
| 66 | ;
|
|---|
| 67 | ;
|
|---|
| 68 | SAT(PATH,SABS,RESTRICTED) ; Open and read Concept and Atom attributes: RXNSAT.RRF
|
|---|
| 69 | ; PATH ByVal, path of RxNorm files
|
|---|
| 70 | ; SABS ByRef, arrays of SABS(SAB)=restriction level
|
|---|
| 71 | ; RESTRICTED ByVal, include restricted sources. 1 for yes, 0 for no
|
|---|
| 72 | I PATH="" QUIT
|
|---|
| 73 | N FILENAME S FILENAME="RXNSAT.RRF"
|
|---|
| 74 | D DELFILED(176.002) ; delete data
|
|---|
| 75 | N LINES S LINES=$$GETLINES(PATH,FILENAME)
|
|---|
| 76 | N POP
|
|---|
| 77 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
|---|
| 78 | IF POP W "Error reading file..., Please check...",! G EX2
|
|---|
| 79 | N C0CCOUNT F C0CCOUNT=1:1 Q:$$STATUS^%ZISH D
|
|---|
| 80 | . U IO
|
|---|
| 81 | . N LINE R LINE:0
|
|---|
| 82 | . IF $$STATUS^%ZISH QUIT
|
|---|
| 83 | . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
|
|---|
| 84 | . ;
|
|---|
| 85 | . ; We switch around the fields .01 and .09 because the .01 isn't always present; where as .09 is required
|
|---|
| 86 | . N RXCUI1,ATN9
|
|---|
| 87 | . S RXCUI1=$P(LINE,"|",1)
|
|---|
| 88 | . S ATN9=$P(LINE,"|",9)
|
|---|
| 89 | . S $P(LINE,"|",1)=ATN9
|
|---|
| 90 | . S $P(LINE,"|",9)=RXCUI1
|
|---|
| 91 | . ;
|
|---|
| 92 | . ; Deal with restricted sources
|
|---|
| 93 | . N SAB S SAB=$P(LINE,"|",10)
|
|---|
| 94 | . I 'RESTRICTED,SABS(SAB) QUIT ; If not include restricted, and SABS(SAB) is not zero, quit
|
|---|
| 95 | . ;
|
|---|
| 96 | . ; Save off
|
|---|
| 97 | . S ^C0CRXN(176.002,C0CCOUNT,0)=$TR(LINE,"|^","^|")
|
|---|
| 98 | EX2 D CLOSE^%ZISH("FILE")
|
|---|
| 99 | N DIK S DIK="^C0CRXN(176.002," D IXALL^DIK
|
|---|
| 100 | QUIT
|
|---|
| 101 | ;
|
|---|
| 102 | ;
|
|---|
| 103 | SAB(PATH,SABS) ; Open the read RxNorm Sources file: RXNSAB.RRF
|
|---|
| 104 | I PATH="" QUIT
|
|---|
| 105 | N FILENAME S FILENAME="RXNSAB.RRF"
|
|---|
| 106 | D DELFILED(176.003) ; delete data
|
|---|
| 107 | N POP
|
|---|
| 108 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
|---|
| 109 | IF POP W "Error reading file..., Please check...",! G EX3
|
|---|
| 110 | N I F I=1:1 Q:$$STATUS^%ZISH D
|
|---|
| 111 | . U IO
|
|---|
| 112 | . N LINE R LINE:0
|
|---|
| 113 | . IF $$STATUS^%ZISH QUIT
|
|---|
| 114 | . U $P W I,! U IO ; Write I to the screen, then go back to reading the file
|
|---|
| 115 | . ; Switch pieces 1 and 4 because 4 is always defined. Goes into .01 field.
|
|---|
| 116 | . N VCUI S VCUI=$P(LINE,"|",1)
|
|---|
| 117 | . N RSAB S RSAB=$P(LINE,"|",4)
|
|---|
| 118 | . S $P(LINE,"|",1)=RSAB
|
|---|
| 119 | . S $P(LINE,"|",4)=VCUI
|
|---|
| 120 | . S ^C0CRXN(176.003,I,0)=$TR(LINE,"^|","|^")
|
|---|
| 121 | EX3 D CLOSE^%ZISH("FILE")
|
|---|
| 122 | N DIK S DIK="^C0CRXN(176.003," D IXALL^DIK
|
|---|
| 123 | N C0CI F C0CI=0:0 S C0CI=$O(^C0CRXN(176.003,C0CI)) Q:'C0CI D
|
|---|
| 124 | . S SABS($$GET1^DIQ(176.003,C0CI,.01))=$$GET1^DIQ(176.003,C0CI,"SRL")
|
|---|
| 125 | QUIT
|
|---|
| 126 | STY(PATH) ; Open and read RxNorm Semantic types file: RXNSTY.RRF
|
|---|
| 127 | I PATH="" QUIT
|
|---|
| 128 | N FILENAME S FILENAME="RXNSTY.RRF"
|
|---|
| 129 | D DELFILED(176.004) ; delete data
|
|---|
| 130 | N LINES S LINES=$$GETLINES(PATH,FILENAME) ; Get # of lines
|
|---|
| 131 | N POP
|
|---|
| 132 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
|---|
| 133 | IF POP W "Error reading file..., Please check...",! G EX4
|
|---|
| 134 | N I F I=1:1 Q:$$STATUS^%ZISH D
|
|---|
| 135 | . U IO
|
|---|
| 136 | . N LINE R LINE:0
|
|---|
| 137 | . IF $$STATUS^%ZISH QUIT
|
|---|
| 138 | . I '(I#1000) U $P W I," of ",LINES," read ",! U IO ; update every 1000
|
|---|
| 139 | . S ^C0CRXN(176.004,I,0)=$TR(LINE,"^|","|^")
|
|---|
| 140 | EX4 D CLOSE^%ZISH("FILE")
|
|---|
| 141 | N DIK S DIK="^C0CRXN(176.004," D IXALL^DIK
|
|---|
| 142 | QUIT
|
|---|
| 143 | ;
|
|---|
| 144 | REL(PATH) ; Open and read RxNorm Relationships file: RXNREL.RRF
|
|---|
| 145 | I PATH="" QUIT
|
|---|
| 146 | N FILENAME S FILENAME="RXNREL.RRF"
|
|---|
| 147 | D DELFILED(176.005) ; delete data
|
|---|
| 148 | N LINES S LINES=$$GETLINES(PATH,FILENAME) ; Get # of lines
|
|---|
| 149 | N POP
|
|---|
| 150 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
|---|
| 151 | IF POP W "Error reading file..., Please check...",! G EX5
|
|---|
| 152 | N I F I=1:1 Q:$$STATUS^%ZISH D
|
|---|
| 153 | . U IO
|
|---|
| 154 | . N LINE R LINE:0
|
|---|
| 155 | . IF $$STATUS^%ZISH QUIT
|
|---|
| 156 | . I '(I#1000) U $P W I," of ",LINES," read ",! U IO ; update every 1000
|
|---|
| 157 | . ; swap RXCUI1 location with SAB b/c SAB is required so can be .01 field
|
|---|
| 158 | . N RXCUI1 S RXCUI1=$P(LINE,"|",1)
|
|---|
| 159 | . N SAB S SAB=$P(LINE,"|",11)
|
|---|
| 160 | . S $P(LINE,"|",1)=SAB
|
|---|
| 161 | . S $P(LINE,"|",11)=RXCUI1
|
|---|
| 162 | . S ^C0CRXN(176.005,I,0)=$TR(LINE,"^|","|^")
|
|---|
| 163 | EX5 D CLOSE^%ZISH("FILE")
|
|---|
| 164 | N DIK S DIK="^C0CRXN(176.005," D IXALL^DIK
|
|---|
| 165 | QUIT
|
|---|
| 166 | DOC(PATH) ; Open the read RxNorm Abbreviation Documentation file: RXNDOC.RRF
|
|---|
| 167 | I PATH="" QUIT
|
|---|
| 168 | N FILENAME S FILENAME="RXNDOC.RRF"
|
|---|
| 169 | D DELFILED(176.006) ; delete data
|
|---|
| 170 | N LINES S LINES=$$GETLINES(PATH,FILENAME) ; Get # of lines
|
|---|
| 171 | N POP
|
|---|
| 172 | D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
|
|---|
| 173 | IF POP W "Error reading file..., Please check...",! G EX6
|
|---|
| 174 | N I F I=1:1 Q:$$STATUS^%ZISH D
|
|---|
| 175 | . U IO
|
|---|
| 176 | . N LINE R LINE:0
|
|---|
| 177 | . IF $$STATUS^%ZISH QUIT
|
|---|
| 178 | . I '(I#1000) U $P W I," of ",LINES," read ",! U IO ; update every 1000
|
|---|
| 179 | . S ^C0CRXN(176.006,I,0)=$TR(LINE,"^|","|^")
|
|---|
| 180 | EX6 D CLOSE^%ZISH("FILE")
|
|---|
| 181 | N DIK S DIK="^C0CRXN(176.006," D IXALL^DIK
|
|---|
| 182 | QUIT
|
|---|