-
Notifications
You must be signed in to change notification settings - Fork 1
/
comorbidity_prescriptions.R
221 lines (189 loc) · 10.6 KB
/
comorbidity_prescriptions.R
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# comorbidity prescriptions
source('setup.R')
# proton pump inhibitiros (PPIs), h2-antagonists, anti-depressants etc
# use the pseudo-BNF list from OpenSafely to get a list of PPI drug names
ppi_bnf <- read_csv("lists_in/OpenSafely/opensafely-proton-pump-inhibitors-ppi-oral-2020-04-20.csv")
drugname <- sort(unique(unname(sapply(ppi_bnf$nm, function(x) str_split(x, '\\s', n=2)[[1]][1]))))
# search all drugname in NHS browser (v2) and open safely browser tool (v3)
drugs <- sort(unique(unname(sapply(ppi_bnf$nm, function(x) str_split(x, '\\s\\(', n=2)[[1]][1]))))
drugs[str_detect(drugs, regex('ventra', ignore_case = T))]
# no OpenSafely results for guardium or ventra
ppi_v2 <- read_delim("lists_in/Elsie/PPI_v2",
"\t", escape_double = FALSE,
trim_ws = TRUE, col_names = FALSE) %>%
select(read_code = X1, read_term = X3) %>%
mutate_at('read_term', list(~ str_remove(tolower(.), '^\\*')))
ppi_v3 <- read_csv("lists_in/Elsie/elsie-horne-proton-pump-inhibitors-63cc5591.csv") %>%
rename_all(~ str_c('read_', .)) %>%
mutate_at('read_term', list(~ str_remove(tolower(.), '^\\*')))
ppi <- bind_rows(ppi_v2, ppi_v3) %>%
filter(!str_detect(read_term, 'injection|intravenous')) %>%
# so that QOF = yes comes first and are kept with distinct
distinct(read_code, .keep_all = TRUE) %>%
mutate(cat2 = 'proton pump inhibitor')
# all H2-antagonists in the a6... branch of the v2 NHS Read code browser
h2antagonist_v2 <- read_delim("lists_in/Elsie/h2antagonist_v2",
"\t", escape_double = FALSE,
trim_ws = TRUE, col_names = FALSE) %>%
select(read_code = X1, read_term = X3) %>%
mutate_at('read_term', list(~ str_remove(tolower(.), '^\\*')))
h2names <- h2antagonist_v2 %>%
filter(!str_detect(read_term, 'injection')) %>%
select(read_term) %>%
unlist() %>% unname()
h2names <- sort(unique(unname(sapply(h2names, function(x) str_split(x, '\\s', n=2)[[1]][1]))))
# search these in the OpenSafely browser
# no results for raciran or ranzac
h2antagonist_v3 <- read_csv("lists_in/Elsie/elsie-horne-h2antagonist-50226248.csv") %>%
rename_all(~ str_c('read_', .)) %>%
mutate_at('read_term', list(~ str_remove(tolower(.), '^\\*'))) %>%
filter(! str_detect(read_code, '^a2'))
h2antagonist <- bind_rows(h2antagonist_v2, h2antagonist_v3) %>%
filter(!str_detect(read_term, 'injection|intravenous')) %>%
# so that QOF = yes comes first and are kept with distinct
distinct(read_code, .keep_all = TRUE) %>%
mutate(cat2 = 'h2-antagonist')
#### anxiety ####
anx_tx <- read_csv("lists_in/CPRD_Cambridge/CPRDCAM_ANX141_PC_V1-1_Oct2018.csv") %>%
select(read_term = productname)
anx_tx_os <- read_csv("lists_in/CPRD_Cambridge/elsie-horne-anxiety_drug-2368fbca.csv")
anxiety_prescriptions <- anx_tx %>%
mutate_at('read_term', list(~ str_remove(., '\\s+\\(.+\\)'))) %>%
mutate_at('read_term', list(~ str_to_lower(.))) %>%
mutate_at('read_term', list(~ str_replace(., 'microgram', 'mcg'))) %>%
mutate_at('read_term', list(~ str_replace(., 'micrograms', 'mcg'))) %>%
mutate_at('read_term', list(~ str_replace(., 'mcgs', 'mcg'))) %>%
mutate_at('read_term', list(~ str_replace(., 'tablets', 'tablet'))) %>%
mutate_at('read_term', list(~ str_replace(., 'capsules', 'capsule'))) %>%
mutate_at('read_term', list(~ str_replace(., 'modified-release', 'm/r'))) %>%
mutate_at('read_term', list(~ str_replace(., 'gel-fill', 'thick gel'))) %>% # checked and these seem to be equivalent
mutate_at('read_term', list(~ str_replace(., '0\\.5mg', '500mcg'))) %>%
# mutate_at('read_term', list(~ str_replace(., 'oral s.+', 'liquid'))) %>%
mutate(gemscript = TRUE) %>%
full_join(anx_tx_os %>%
mutate_at('term', list(~ str_to_lower(.))) %>%
mutate_at('term', list(~ str_replace(., 'microgram', 'mcg'))) %>%
mutate_at('term', list(~ str_replace(., 'micrograms', 'mcg'))) %>%
mutate_at('term', list(~ str_replace(., 'mcgs', 'mcg'))) %>%
mutate_at('term', list(~ str_replace(., 'tablets', 'tablet'))) %>%
mutate_at('term', list(~ str_replace(., 'capsules', 'capsule'))) %>%
mutate_at('term', list(~ str_replace(., 'trazodone hydrochloride', 'trazodone'))) %>%
mutate_at('term', list(~ str_replace(., 'buspirone hydrochloride', 'buspirone'))),
by = c('read_term' = 'term')) %>%
mutate(notes = NA_character_) %>%
distinct() %>%
arrange(read_term) %>%
mutate_at('notes', list(~ case_when(# remove if drug not in cambridge list
str_detect(read_term, 'unisomnia') ~ 'remove',
str_detect(read_term, 'tensium') ~ 'remove',
str_detect(read_term, 'rimapam') ~ 'remove',
str_detect(read_term, 'noctesed') ~ 'remove',
str_detect(read_term, 'meprate') ~ 'remove',
str_detect(read_term, 'alupram') ~ 'remove',
str_detect(read_term, 'almazine') ~ 'remove',
str_detect(read_term, 'zolpidem tartrate') ~ 'remove',
str_detect(read_term, 'remnos') & is.na(gemscript) ~ 'remove',
str_detect(read_term, 'oxanid') & is.na(gemscript) ~ 'remove',
str_detect(read_term, 'heminevrin') & is.na(gemscript) ~ 'remove',
str_detect(read_term, 'evacalm') & is.na(gemscript) ~ 'remove',
str_detect(read_term, 'equanil') & is.na(gemscript) ~ 'remove',
TRUE ~ .))) %>%
filter(is.na(notes)) %>%
select(read_term, read_code = code) %>%
filter(!is.na(read_code)) %>%
distinct() %>%
mutate(cat2 = 'anti-anxiety')
#### depression ####
dep_tx <- read_csv("lists_in/CPRD_Cambridge/CPRDCAM_DEP153_PC_V1-1_Oct2018.csv") %>%
select(read_term = productname)
dep_tx_os <- read_csv("lists_in/CPRD_Cambridge/elsie-horne-depression_drug-261bbbc0.csv")
depression_prescriptions <- dep_tx %>%
mutate_at('read_term', list(~ str_remove(., '\\s+\\(.+\\)'))) %>%
mutate_at('read_term', list(~ str_to_lower(.))) %>%
mutate_at('read_term', list(~ str_replace(., 'microgram', 'mcg'))) %>%
mutate_at('read_term', list(~ str_replace(., 'micrograms', 'mcg'))) %>%
mutate_at('read_term', list(~ str_replace(., 'mcgs', 'mcg'))) %>%
mutate_at('read_term', list(~ str_replace(., 'tablets', 'tablet'))) %>%
mutate_at('read_term', list(~ str_replace(., 'capsules', 'capsule'))) %>%
mutate_at('read_term', list(~ str_replace(., 'modified-release', 'm/r'))) %>%
mutate_at('read_term', list(~ str_replace(., 'gel-fill', 'thick gel'))) %>% # checked and these seem to be equivalent
mutate_at('read_term', list(~ str_replace(., '0\\.5mg', '500mcg'))) %>%
# mutate_at('read_term', list(~ str_replace(., 'oral s.+', 'liquid'))) %>%
mutate(gemscript = TRUE) %>%
full_join(dep_tx_os %>%
mutate_at('term', list(~ str_to_lower(.))) %>%
mutate_at('term', list(~ str_replace(., 'microgram', 'mcg'))) %>%
mutate_at('term', list(~ str_replace(., 'micrograms', 'mcg'))) %>%
mutate_at('term', list(~ str_replace(., 'mcgs', 'mcg'))) %>%
mutate_at('term', list(~ str_replace(., 'tablets', 'tablet'))) %>%
mutate_at('term', list(~ str_replace(., 'capsules', 'capsule'))),
by = c('read_term' = 'term')) %>%
mutate(notes = NA_character_) %>%
distinct() %>%
arrange(read_term) %>% mutate_at('notes',
list(~ case_when(# remove if drug not in cambridge list
str_detect(read_term, 'winfex') ~ 'remove',
str_detect(read_term, 'venladex') ~ 'remove',
str_detect(read_term, 'vaxalin') ~ 'remove',
str_detect(read_term, 'trixat') ~ 'remove',
str_detect(read_term, 'tranquax') ~ 'remove',
str_detect(read_term, 'sunveniz') ~ 'remove',
str_detect(read_term, 'olena') ~ 'remove',
str_detect(read_term, 'motival') ~ 'remove',
str_detect(read_term, 'lentizol') ~ 'remove',
str_detect(read_term, 'no drugs here') ~ 'remove',
str_detect(read_term, 'foraven xl 150mg m/r capsule') ~ 'remove',
str_detect(read_term, 'feprapax') ~ 'remove',
str_detect(read_term, 'dothiepin') ~ 'remove',
str_detect(read_term, 'cymbalta') ~ 'remove',
str_detect(read_term, 'bonilux') ~ 'remove',
str_detect(read_term, 'aventyl') ~ 'remove',
str_detect(read_term, 'elavil') & is.na(gemscript) ~ 'remove',
str_detect(read_term, 'praminil') & is.na(gemscript) ~ 'remove',
TRUE ~ .))) %>%
filter(is.na(notes)) %>%
select(read_term, read_code = code) %>%
filter(!is.na(read_code)) %>%
distinct() %>%
mutate(cat2 = 'anti-depressant')
# bind all
comorbidity_prescriptions <- bind_rows(h2antagonist,
ppi,
depression_prescriptions,
anxiety_prescriptions) %>%
mutate(cat1 = 'comorbidity prescription')
# make sure all Read codes are 5 characters and fix if not
comorbidity_prescriptions %>%
filter(str_length(read_code)<5)
comorbidity_prescriptions <- comorbidity_prescriptions %>%
mutate_at('read_code', list(~ str_pad(., width=5, side='right', pad='.')))
# save list
write_csv(comorbidity_prescriptions,
path = file.path(opcrd_analysis_path, 'comorbidity_prescriptions.csv'))
write_csv(comorbidity_prescriptions %>%
arrange(cat2, read_code, read_term) %>%
select(Comedication = cat2,
`Read code` = read_code,
Term = read_term),
path = 'lists_out/comorbidity_prescriptions.csv')
# latex tables for thesis
drug_list <- comorbidity_prescriptions %>%
group_split(cat2)
drug_latex_table <- function(.data) {
category <- .data %>%
distinct(cat2) %>%
unlist() %>%
unname()
category_ <- str_to_lower(str_replace_all(category, ' ', '_'))
caption <- str_c('Read codes for \\emph{\'', category, '\'} prescription group (return to \\nameref{cha:ehr:methods:pre:comorbidities} methods)')
label <- str_c('tab:app:rc_', category_)
table <- .data %>%
arrange(read_term) %>%
select(`Read code` = read_code,
`Term` = read_term) %>%
xtable(caption = caption,
label = label,
align=c('l',"p{2cm}","p{10cm}")) %>%
print_xtable_multi(filename = category_)
}
lapply(drug_list, drug_latex_table)