source: ePrescribing/trunk/p/C0PRXNRD.m@ 1752

Last change on this file since 1752 was 1595, checked in by George Lilly, 12 years ago

initial release of ePrescribing

File size: 4.4 KB
Line 
1C0PRXNRD ; VEN/SMH - eRx: Routine to Read RxNorm files; 12/06/09 12:25am
2 ;;0.1;C0P;nopatch;noreleasedate;Build 1
3 W "No entry from top" Q
4 ;
5CONFN() Q 1130590011.001
6SRCFN() Q 1130590012.003
7 ;
8IMPORT(PATH)
9 I PATH="" QUIT
10 D READSRC(PATH),READCON(PATH,1)
11 QUIT
12 ;
13DELFILED(FN) ; Delete file data; PEP procedure; only for RxNorm files
14 ; FN is Filenumber passed by Value
15 D CLEAN^DILF ; Clean FM variables
16 N ROOT S ROOT=$$ROOT^DILFD(FN,"",1) ; global root
17 N ZERO S ZERO=@ROOT@(0) ; Save zero node
18 S $P(ZERO,U,3,9999)="" ; Remove entry # and last edited
19 K @ROOT ; Kill the file -- so sad!
20 S @ROOT@(0)=ZERO ; It riseth again!
21 QUIT
22GETLINES(PATH,FILENAME) ; Get number of lines in a file
23 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
24 U IO
25 N I
26 F I=1:1 R LINE Q:$$STATUS^%ZISH
27 D CLOSE^%ZISH("FILE")
28 Q I-1
29READCON(PATH,INCRES) ; Open and read concepts file: RXNCONSO.RRF; EP
30 ; PATH ByVal, path of RxNorm files
31 ; INCRES ByVal, include restricted sources. 1 for yes, 0 for no
32 I PATH="" QUIT
33 S INCRES=+$G(INCRES) ; if not passed, becomes zero.
34 N FILENAME S FILENAME="RXNCONSO.RRF"
35 D DELFILED($$CONFN) ; delete data
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 . ; If the source is a restricted source, decide what to do based on what's asked.
50 . N SRCIEN S SRCIEN=$$FIND1^DIC($$SRCFN,"","QX",SAB,"B") ; SrcIEN in RXNORM SOURCES file
51 . N RESTRIC S RESTRIC=$$GET1^DIQ($$SRCFN,SRCIEN,14,"I") ; 14 is restriction field; values 0-4
52 . ; If RESTRIC is zero, then it's unrestricted. Everything else is restricted.
53 . ; If user didn't ask to include restricted sources, and the source is restricted, then quit
54 . I 'INCRES,RESTRIC QUIT
55 . S TTY=$P(LINE,"|",13) ; 3
56 . S CODE=$P(LINE,"|",14) ; 4
57 . S STR=$P(LINE,"|",15) ; 5
58 . ; Remove embedded "^"
59 . S STR=$TR(STR,"^")
60 . ; Convert STR into an array of 80 characters on each line
61 . N STRLINE S STRLINE=$L(STR)\80+1
62 . ; In each line, chop 80 characters off, reset STR to be the rest
63 . N J F J=1:1:STRLINE S STR(J)=$E(STR,1,80) S STR=$E(STR,81,$L(STR))
64 . ; Now, construct the FDA array
65 . N RXNFDA
66 . S RXNFDA($$CONFN,"+1,",.01)=RXCUI
67 . S RXNFDA($$CONFN,"+1,",1)=RXAUI
68 . S RXNFDA($$CONFN,"+1,",2)=SAB
69 . S RXNFDA($$CONFN,"+1,",3)=TTY
70 . S RXNFDA($$CONFN,"+1,",4)=CODE
71 . N RXNIEN S RXNIEN(1)=C0CCOUNT
72 . D UPDATE^DIE("","RXNFDA","RXNIEN")
73 . I $D(^TMP("DIERR",$J)) D EN^DDIOL("ERROR") G EX
74 . ; Now, file WP field STR
75 . D WP^DIE($$CONFN,C0CCOUNT_",",5,,$NA(STR))
76EX D CLOSE^%ZISH("FILE")
77 QUIT
78READSRC(PATH) ; Open the read RxNorm Sources file: RXNSAB.RRF
79 I PATH="" QUIT
80 N FILENAME S FILENAME="RXNSAB.RRF"
81 D DELFILED($$SRCFN) ; delete data
82 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
83 IF POP W "Error reading file..., Please check...",! G EX3
84 F I=1:1 Q:$$STATUS^%ZISH D
85 . U IO
86 . N LINE R LINE
87 . IF $$STATUS^%ZISH QUIT
88 . U $P W I,! U IO ; Write I to the screen, then go back to reading the file
89 . N VCUI,RCUI,VSAB,RSAB,SON,SF,SVER,SRL,SCIT ; Fileman fields numbers below
90 . S VCUI=$P(LINE,"|",1) ; .01
91 . S RCUI=$P(LINE,"|",2) ; 2
92 . S VSAB=$P(LINE,"|",3) ; 3
93 . S RSAB=$P(LINE,"|",4) ; 4
94 . S SON=$P(LINE,"|",5) ; 5
95 . S SF=$P(LINE,"|",6) ; 6
96 . S SVER=$P(LINE,"|",7) ; 7
97 . S SRL=$P(LINE,"|",14) ; 14
98 . S SCIT=$P(LINE,"|",25) ; 25
99 . ; Remove embedded "^"
100 . S SCIT=$TR(SCIT,"^")
101 . ; Convert SCIT into an array of 80 characters on each line
102 . ; In each line, chop 80 characters off, reset SCIT to be the rest
103 . N SCITLINE S SCITLINE=$L(SCIT)\80+1
104 . F J=1:1:SCITLINE S SCIT(J)=$E(SCIT,1,80) S SCIT=$E(SCIT,81,$L(SCIT))
105 . ; Now, construct the FDA array
106 . N RXNFDA
107 . S RXNFDA($$SRCFN,"+"_I_",",.01)=VCUI
108 . S RXNFDA($$SRCFN,"+"_I_",",2)=RCUI
109 . S RXNFDA($$SRCFN,"+"_I_",",3)=VSAB
110 . S RXNFDA($$SRCFN,"+"_I_",",4)=RSAB
111 . S RXNFDA($$SRCFN,"+"_I_",",5)=SON
112 . S RXNFDA($$SRCFN,"+"_I_",",6)=SF
113 . S RXNFDA($$SRCFN,"+"_I_",",7)=SVER
114 . S RXNFDA($$SRCFN,"+"_I_",",14)=SRL
115 . D UPDATE^DIE("","RXNFDA")
116 . I $D(^TMP("DIERR",$J)) U $P W "ERR" G EX
117 . ; Now, file WP field SCIT
118 . D WP^DIE($$SRCFN,I_",",25,,$NA(SCIT))
119EX3 D CLOSE^%ZISH("FILE")
120 Q
121
Note: See TracBrowser for help on using the repository browser.