generated from opensafely/research-template
/
report.R
81 lines (56 loc) · 3.81 KB
/
report.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
library(tidyverse)
library(lubridate)
#Compliance ratios from Section 1 of NG188 guidance
cohort_any_acute_covid_recorded <- read_csv('output/input_any_acute_covid_pri_care.csv')
Rec_1_1_denom <- nrow(cohort_any_acute_covid_recorded)
Rec_1_1_num <- sum((cohort_any_acute_covid_recorded$advice_given - cohort_any_acute_covid_recorded$acute_diag_dat > 0), na.rm = TRUE)
Rec_1_1_ratio <- Rec_1_1_num / Rec_1_1_denom
Rec_1_8_denom <- cohort_any_acute_covid_recorded %>% filter(interpreter_needed > ymd("20190101")) %>% nrow()
Rec_1_8_num <- cohort_any_acute_covid_recorded %>% filter(interpreter_needed > ymd("20190101"),
interpreter_booked > ymd("20190101")) %>% nrow()
Rec_1_8_ratio <- Rec_1_8_num / Rec_1_8_denom
#Leaving Rec 1_10 until outpatient linkage is carried out
#Compliance ratios from Section 2 of NG188 guidance
cohort_ongoing_or_post_covid <- read_csv('output/input_ongoing_post_covid.csv')
Rec_2_4_denom <- nrow(cohort_ongoing_or_post_covid)
Rec_2_4_num <- cohort_ongoing_or_post_covid %>% filter(discussion_about_daily_living > ymd("20190101")) %>% nrow()
Rec_2_4_ratio <- Rec_2_4_num / Rec_2_4_denom
#Compliance ratios from Section 3 of NG188 guidance
#Rec_3_1 abandoned as not sure what 'relevant acute services' ought to be, vagueness as to what
#3 diagnostic tests
Rec_3_4_denom <- Rec_2_4_denom
Rec_3_4_num <- cohort_ongoing_or_post_covid %>% filter(diagnostic_bloods > ymd("20190101")) %>% nrow()
Rec_3_4_ratio <- Rec_3_4_num / Rec_3_4_denom
Rec_3_5_denom <- Rec_2_4_denom
Rec_3_5_num <- cohort_ongoing_or_post_covid %>% filter(diagnostic_sit_stand > ymd("20190101")) %>% nrow()
Rec_3_5_ratio <- Rec_3_5_num / Rec_3_5_denom
Rec_3_6_denom <- Rec_2_4_denom
Rec_3_6_num <- cohort_ongoing_or_post_covid %>% filter(diagnostic_bp_test > 0) %>% nrow()
Rec_3_6_ratio <- Rec_3_6_num / Rec_3_6_denom
Rec_3_7_denom <- Rec_2_4_denom
Rec_3_7_num <- cohort_ongoing_or_post_covid %>% filter(diagnostic_chest_xray > ymd("20190101")) %>% nrow()
Rec_3_7_ratio <- Rec_3_7_num / Rec_3_7_denom
Rec_3_8_denom <- cohort_ongoing_or_post_covid %>% filter(risk_of_self_harm > ymd("20190101")) %>% nrow()
Rec_3_8_num <- cohort_ongoing_or_post_covid %>% filter(risk_of_self_harm > ymd("20190101"),
referral_psych > ymd("20190101")) %>% nrow()
Rec_3_8_ratio <- Rec_3_8_num / Rec_3_8_denom
Rec_3_9_denom <- cohort_ongoing_or_post_covid %>% filter(mild_anxiety_or_depression > ymd("20190101")) %>% nrow()
Rec_3_9_num <- cohort_ongoing_or_post_covid %>% filter(mild_anxiety_or_depression > ymd("20190101"),
referral_psych_iapt > ymd("20190101")) %>% nrow()
Rec_3_9_ratio <- Rec_3_9_num / Rec_3_9_denom
Rec_3_10_denom <- Rec_2_4_denom
Rec_3_10_num <- cohort_ongoing_or_post_covid %>% filter(referral_pc_clinic > ymd("20190101")) %>% nrow()
Rec_3_10_ratio <- Rec_3_10_num / Rec_3_10_denom
#3 referral patterns, self-care, secondary care, treated in primary care
Rec_3_11_denom <- Rec_2_4_denom
Rec_3_11_num_self_management <- cohort_ongoing_or_post_covid %>% filter(self_care_advise_or_support > ymd("20190101")) %>% nrow()
Rec_3_11_num_community_referral <- cohort_ongoing_or_post_covid %>% filter(community_care > ymd("20190101")) %>% nrow()
Rec_3_11_prim_care <- cohort_ongoing_or_post_covid %>% filter(primary_care_managment > ymd("20190101")) %>% nrow()
#other referral destinations - would they go direct from primary care or be cross-referred from PC clinic (or both? - maybe needs thinking about)
#4 long covid rates by practice - need
#5 variation in long covid rates
#variables
#demographic - age, ethnicity, health worker?, socioeconomic deprivation
#comorbidities
rm(cohort_any_acute_covid_recorded, cohort_ongoing_or_post_covid)
mget(ls()) %>% bind_rows() %>% write_csv('output/ratios.csv')