Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: C0CRXNRD

C0CRXNRD.m

Go to the documentation of this file.
  1. C0CRXNRD ; WV/SMH - CCR/CCD PROJECT: Routine to Read RxNorm files;11/15/08
  1. ;;0.1;C0C;nopatch;noreleasedate;Build 6
  1. W "No entry from top" Q
  1. IMPORT(PATH)
  1. I PATH="" QUIT
  1. D READSRC(PATH),READCON(PATH),READNDC(PATH)
  1. QUIT
  1. ;
  1. DELFILED(FN) ; Delete file data; PEP procedure; only for RxNorm files
  1. ; FN is Filenumber passed by Value
  1. QUIT:$E(FN,1,3)'=176 ; Quit if not RxNorm files
  1. D CLEAN^DILF ; Clean FM variables
  1. N ROOT S ROOT=$$ROOT^DILFD(FN,"",1) ; global root
  1. N ZERO S ZERO=@ROOT@(0) ; Save zero node
  1. S $P(ZERO,U,3,9999)="" ; Remove entry # and last edited
  1. K @ROOT ; Kill the file -- so sad!
  1. S @ROOT@(0)=ZERO ; It riseth again!
  1. QUIT
  1. GETLINES(PATH,FILENAME) ; Get number of lines in a file
  1. D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
  1. U IO
  1. N I
  1. F I=1:1 R LINE Q:$$STATUS^%ZISH
  1. D CLOSE^%ZISH("FILE")
  1. Q I-1
  1. READCON(PATH,INCRES) ; Open and read concepts file: RXNCONSO.RRF; EP
  1. ; PATH ByVal, path of RxNorm files
  1. ; INCRES ByVal, include restricted sources. 1 for yes, 0 for no
  1. I PATH="" QUIT
  1. S INCRES=+$G(INCRES) ; if not passed, becomes zero.
  1. N FILENAME S FILENAME="RXNCONSO.RRF"
  1. D DELFILED(176.001) ; delete data
  1. N LINES S LINES=$$GETLINES(PATH,FILENAME)
  1. D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
  1. IF POP D EN^DDIOL("Error reading file..., Please check...") G EX
  1. N C0CCOUNT
  1. F C0CCOUNT=1:1 D Q:$$STATUS^%ZISH
  1. . U IO
  1. . N LINE R LINE
  1. . IF $$STATUS^%ZISH QUIT
  1. . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
  1. . N RXCUI,RXAUI,SAB,TTY,CODE,STR ; Fileman fields numbers below
  1. . S RXCUI=$P(LINE,"|",1) ; .01
  1. . S RXAUI=$P(LINE,"|",8) ; 1
  1. . S SAB=$P(LINE,"|",12) ; 2
  1. . ; If the source is a restricted source, decide what to do based on what's asked.
  1. . N SRCIEN S SRCIEN=$$FIND1^DIC(176.003,"","QX",SAB,"B") ; SrcIEN in RXNORM SOURCES file
  1. . N RESTRIC S RESTRIC=$$GET1^DIQ(176.003,SRCIEN,14,"I") ; 14 is restriction field; values 0-4
  1. . ; If RESTRIC is zero, then it's unrestricted. Everything else is restricted.
  1. . ; If user didn't ask to include restricted sources, and the source is restricted, then quit
  1. . I 'INCRES,RESTRIC QUIT
  1. . S TTY=$P(LINE,"|",13) ; 3
  1. . S CODE=$P(LINE,"|",14) ; 4
  1. . S STR=$P(LINE,"|",15) ; 5
  1. . ; Remove embedded "^"
  1. . S STR=$TR(STR,"^")
  1. . ; Convert STR into an array of 80 characters on each line
  1. . N STRLINE S STRLINE=$L(STR)\80+1
  1. . ; In each line, chop 80 characters off, reset STR to be the rest
  1. . N J F J=1:1:STRLINE S STR(J)=$E(STR,1,80) S STR=$E(STR,81,$L(STR))
  1. . ; Now, construct the FDA array
  1. . N RXNFDA
  1. . S RXNFDA(176.001,"+1,",.01)=RXCUI
  1. . S RXNFDA(176.001,"+1,",1)=RXAUI
  1. . S RXNFDA(176.001,"+1,",2)=SAB
  1. . S RXNFDA(176.001,"+1,",3)=TTY
  1. . S RXNFDA(176.001,"+1,",4)=CODE
  1. . N RXNIEN S RXNIEN(1)=C0CCOUNT
  1. . D UPDATE^DIE("","RXNFDA","RXNIEN")
  1. . I $D(^TMP("DIERR",$J)) D EN^DDIOL("ERROR") G EX
  1. . ; Now, file WP field STR
  1. . D WP^DIE(176.001,C0CCOUNT_",",5,,$NA(STR))
  1. EX D CLOSE^%ZISH("FILE")
  1. QUIT
  1. READNDC(PATH) ; Open and read NDC/RxNorm/VANDF relationship file: RXNSAT.RRF
  1. I PATH="" QUIT
  1. N FILENAME S FILENAME="RXNSAT.RRF"
  1. D DELFILED(176.002) ; delete data
  1. N LINES S LINES=$$GETLINES(PATH,FILENAME)
  1. D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
  1. IF POP W "Error reading file..., Please check...",! G EX2
  1. F C0CCOUNT=1:1 Q:$$STATUS^%ZISH D
  1. . U IO
  1. . N LINE R LINE
  1. . IF $$STATUS^%ZISH QUIT
  1. . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
  1. . IF LINE'["NDC|RXNORM" QUIT
  1. . ; Otherwise, we are good to go
  1. . N RXCUI,NDC ; Fileman fields below
  1. . S RXCUI=$P(LINE,"|",1) ; .01
  1. . S NDC=$P(LINE,"|",11) ; 2
  1. . ; Using classic call to update.
  1. . N DIC,X,DA,DR
  1. . K DO
  1. . S DIC="^C0CRXN(176.002,",DIC(0)="F",X=RXCUI,DIC("DR")="2////"_NDC
  1. . D FILE^DICN
  1. . I Y<1 U $P W !,"THERE IS TROUBLE IN RIVER CITY",! G EX2
  1. EX2 D CLOSE^%ZISH("FILE")
  1. QUIT
  1. READSRC(PATH) ; Open the read RxNorm Sources file: RXNSAB.RRF
  1. I PATH="" QUIT
  1. N FILENAME S FILENAME="RXNSAB.RRF"
  1. D DELFILED(176.003) ; delete data
  1. D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
  1. IF POP W "Error reading file..., Please check...",! G EX3
  1. F I=1:1 Q:$$STATUS^%ZISH D
  1. . U IO
  1. . N LINE R LINE
  1. . IF $$STATUS^%ZISH QUIT
  1. . U $P W I,! U IO ; Write I to the screen, then go back to reading the file
  1. . N VCUI,RCUI,VSAB,RSAB,SON,SF,SVER,SRL,SCIT ; Fileman fields numbers below
  1. . S VCUI=$P(LINE,"|",1) ; .01
  1. . S RCUI=$P(LINE,"|",2) ; 2
  1. . S VSAB=$P(LINE,"|",3) ; 3
  1. . S RSAB=$P(LINE,"|",4) ; 4
  1. . S SON=$P(LINE,"|",5) ; 5
  1. . S SF=$P(LINE,"|",6) ; 6
  1. . S SVER=$P(LINE,"|",7) ; 7
  1. . S SRL=$P(LINE,"|",14) ; 14
  1. . S SCIT=$P(LINE,"|",25) ; 25
  1. . ; Remove embedded "^"
  1. . S SCIT=$TR(SCIT,"^")
  1. . ; Convert SCIT into an array of 80 characters on each line
  1. . ; In each line, chop 80 characters off, reset SCIT to be the rest
  1. . N SCITLINE S SCITLINE=$L(SCIT)\80+1
  1. . F J=1:1:SCITLINE S SCIT(J)=$E(SCIT,1,80) S SCIT=$E(SCIT,81,$L(SCIT))
  1. . ; Now, construct the FDA array
  1. . N RXNFDA
  1. . S RXNFDA(176.003,"+"_I_",",.01)=VCUI
  1. . S RXNFDA(176.003,"+"_I_",",2)=RCUI
  1. . S RXNFDA(176.003,"+"_I_",",3)=VSAB
  1. . S RXNFDA(176.003,"+"_I_",",4)=RSAB
  1. . S RXNFDA(176.003,"+"_I_",",5)=SON
  1. . S RXNFDA(176.003,"+"_I_",",6)=SF
  1. . S RXNFDA(176.003,"+"_I_",",7)=SVER
  1. . S RXNFDA(176.003,"+"_I_",",14)=SRL
  1. . D UPDATE^DIE("","RXNFDA")
  1. . I $D(^TMP("DIERR",$J)) U $P W "ERR" G EX
  1. . ; Now, file WP field SCIT
  1. . D WP^DIE(176.003,I_",",25,,$NA(SCIT))
  1. EX3 D CLOSE^%ZISH("FILE")
  1. Q