Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions analysis/process_date_of_uk_entry_cohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ output_file <- "output/tables/demographics_date_of_uk_entry_cohort.csv"
args <- commandArgs(trailingOnly=TRUE)
print(commandArgs(trailingOnly=TRUE))


# Import data ----
cohort <- read_feather(cohort_file) %>%
mutate(
Expand All @@ -45,7 +44,6 @@ vars_to_summarise <- c(
"imd_quintile"
)


rounding <- function(vars) {
case_when(vars == 0 ~ 0,
vars > 7 ~ round(vars / 5) * 5)
Expand All @@ -54,7 +52,7 @@ rounding <- function(vars) {
table_freq_overall <- cohort %>%
group_by(any_migrant) %>%
summarise(
n = rounding(nrow(cohort)),
n = rounding(n()),
percentage = 100) %>%
mutate(
subgroup = "All",
Expand Down
31 changes: 26 additions & 5 deletions analysis/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,31 @@ def build_common_vars(INTERVAL):
# -------------------
was_alive_on_1Jan = patients.is_alive_on(INTERVAL.start_date)

was_registered_on1Jan = (
practice_registrations.for_patient_on(INTERVAL.start_date)
.exists_for_patient()
)
was_registered_at_any_point_during_interval = practice_registrations.where(
# registered for the entire interval
((practice_registrations.start_date.is_on_or_before(INTERVAL.start_date))
& (practice_registrations.end_date.is_on_or_after(INTERVAL.end_date))) |

# registered during the interval and end date is after the interval end date
((practice_registrations.start_date.is_after(INTERVAL.start_date))
& (practice_registrations.end_date.is_on_or_after(INTERVAL.end_date))) |

# registered before the interval and registration is ongoing
((practice_registrations.start_date.is_on_or_before(INTERVAL.start_date)) &
(practice_registrations.end_date.is_null())) |

# registered after interval start date and registration is ongoing
((practice_registrations.start_date.is_after(INTERVAL.start_date)) &
(practice_registrations.end_date.is_null())) |

# registered before the interval start date and end date is before the end date, but after the start date
((practice_registrations.start_date.is_before(INTERVAL.start_date)) &
(practice_registrations.end_date.is_between_but_not_on(INTERVAL.start_date, INTERVAL.end_date))) |

# registered for part of the interval only
((practice_registrations.start_date.is_between_but_not_on(INTERVAL.start_date, INTERVAL.end_date)) &
(practice_registrations.end_date.is_between_but_not_on(INTERVAL.start_date, INTERVAL.end_date)))
).exists_for_patient()

has_recorded_sex = patients.sex.is_in(["male", "female"])

Expand All @@ -28,7 +49,7 @@ def build_common_vars(INTERVAL):

denominator = (
was_alive_on_1Jan
& was_registered_on1Jan
& was_registered_at_any_point_during_interval
& has_recorded_sex
& has_possible_age
)
Expand Down