forked from HeatherARobinson/EHR-reshaping
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPERMIT SIR add prescription data
More file actions
44 lines (32 loc) · 1.54 KB
/
PERMIT SIR add prescription data
File metadata and controls
44 lines (32 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#2 files can be used but only 1 is needed.
#Required: patient ID, code, date, instruction text field
library(stringr)
library(lubridate)
load("sir.datahfonly.Rdata")
temp = list.files(pattern="*1.csv")
for (i in 1:length(temp)) assign(temp[i], read.csv(temp[i]))
dialysis<-sir.data[sir.data$ReadCode %in% Dialysis1.csv$ReadCode,]
levels(as.factor(dialysis$PatientID)) #48 dialysis patients will be removed
sir.data<-sir.data[!sir.data$PatientID %in% Dialysis1.csv$PatientID,]
codes<-read.csv("drug-codes-READv2.csv",header=TRUE)
codes2<-read.csv("drug-codes-EMIS.csv",header=TRUE)
codesfile<-sir.data[sir.data$ReadCode %in% codes$CODE|sir.data$ReadCode %in% codes2$CODE,c(1,2,3,4,5,6)]
#remove punctuation this is not helpful here,
#replace it with spaces so the regex
#recognises words still
x <-codesfile
str_replace_all(x,"[[:punct:]]", " ")
gsub("[[:punct:]]", "", codesfile, except(".", "-") )
head(codesfile)
#cut down to prescriptions in or after 2007
codesfile$event.date<-as.Date(as.character(codesfile$EntryDate),format="%Y%m%d")
codesfile<-codesfile[as.numeric(year(strptime(codesfile$event.date, format="%Y-%m-%d")))>=2007,]
na.omit(codesfile)
write.csv(codesfile[,c(1,2,4:6)],file="codesh.txt", row.names = FALSE)
#PERL COMMANDS
cd research-events-medication-htn
npm install
node index.js -a resources\codesh.txt && sort resources\codesh.txt.done > resources\codesh.txt.done.sorted
#CHECK THE REGEX FILE FOR ANY DESCRIPTIONS THAT DID NOT PARSE,
#YOU WILL MANUALLY NEED TO TEACH THESE TO THE REGEX
#ESPECIALLY IF YOUR MEDICATIONS ARE NOT ALL SOLID DOSE.