generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfn-qa.R
55 lines (39 loc) · 2.78 KB
/
fn-qa.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
# Function to apply quality assurance
qa <- function(input, study_dates) {
# Specify consort table --------------------------------------------------------
print('Specify consort table')
consort <- data.frame(Description = "Input",
N = nrow(input),
stringsAsFactors = FALSE)
print('Quality assurance: Year of birth is after year of death or patient only has year of death')
input <- input[!((input$qa_num_birth_year > (format(input$cens_date_death, format="%Y")) &
is.na(input$qa_num_birth_year)== FALSE & is.na(input$cens_date_death) == FALSE) |
(is.na(input$qa_num_birth_year)== TRUE & is.na(input$cens_date_death) == FALSE)),]
consort[nrow(consort)+1,] <- c("Quality assurance: Year of birth is after year of death or patient only has year of death",
nrow(input))
print('Quality assurance: Year of birth is before 1793 or year of birth exceeds current date')
input <- input[!((input$qa_num_birth_year < 1793 |
(input$qa_num_birth_year >format(Sys.Date(),"%Y"))) &
is.na(input$qa_num_birth_year) == FALSE),]
consort[nrow(consort)+1,] <- c("Quality assurance: Year of birth is before 1793 or year of birth exceeds current date",
nrow(input))
print('Quality assurance: Date of death is invalid (on or before 1/1/1900 or after current date)')
input <- input[!((input$cens_date_death <= as.Date(study_dates$earliest_expec) |
input$cens_date_death > format(Sys.Date(),"%Y-%m-%d")) & is.na(input$cens_date_death) == FALSE),]
consort[nrow(consort)+1,] <- c("Quality assurance: Date of death is invalid (on or before 1/1/1900 or after current date)",
nrow(input))
print('Quality assurance: Pregnancy/birth codes for men')
input <- input[!(input$qa_bin_pregnancy == TRUE & input$cov_cat_sex=="Male") | is.na(input$cov_cat_sex),]
consort[nrow(consort)+1,] <- c("Quality assurance: Pregnancy/birth codes for men",
nrow(input))
print('Quality assurance: HRT or COCP meds for men')
input <- input[!(input$cov_cat_sex=="Male" & input$qa_bin_hrtcocp==TRUE) | is.na(input$cov_cat_sex),]
consort[nrow(consort)+1,] <- c("Quality assurance: HRT or COCP meds for men",
nrow(input))
print('Quality assurance: Prostate cancer codes for women')
input <- input[!(input$qa_bin_prostate_cancer == TRUE &
input$cov_cat_sex=="Female") | is.na(input$cov_cat_sex),]
consort[nrow(consort)+1,] <- c("Quality assurance: Prostate cancer codes for women",
nrow(input))
return(list(input = input, consort = consort))
}