From f45b8a1e1fb8d5cbbfc4f4f29306486e5dbb9b50 Mon Sep 17 00:00:00 2001 From: abramm01 Date: Tue, 18 Jun 2024 08:41:13 +0100 Subject: [PATCH 1/2] Added code to deal with referrals where date of first contact is before date of diagnosis. Basic logic of the code is that if this is the case, then diagnosis date is treated as if it is the date of first contact. --- code/02_calculate-measures.R | 46 ++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/code/02_calculate-measures.R b/code/02_calculate-measures.R index ab45b41..e691cba 100644 --- a/code/02_calculate-measures.R +++ b/code/02_calculate-measures.R @@ -39,6 +39,11 @@ pds %<>% mutate( + # Date 11 months after diagnosis date + diag_11 = add_with_rollback(dementia_diagnosis_confirmed_date, + months(11), + roll_to_first = TRUE), + # Date 12 months after diagnosis date diag_12 = add_with_rollback(dementia_diagnosis_confirmed_date, months(12), @@ -66,16 +71,27 @@ pds %<>% #### COMPLETE #### # Started PDS within 12m of diagnosis AND PDS still ongoing after 12m - date_of_initial_first_contact < diag_12 & + date_of_initial_first_contact >= dementia_diagnosis_confirmed_date & + date_of_initial_first_contact < diag_12 & end_date >= pds_12 & - is.na(termination_or_transition_date) + is.na(termination_or_transition_date) + ~ "complete - still receiving", + + date_of_initial_first_contact < dementia_diagnosis_confirmed_date & + end_date >= diag_12 & + is.na(termination_or_transition_date) ~ "complete - still receiving", # Started PDS within 12m of diagnosis AND PDS ended after 11m - date_of_initial_first_contact < diag_12 & + date_of_initial_first_contact >= dementia_diagnosis_confirmed_date & + date_of_initial_first_contact < diag_12 & termination_or_transition_date >= pds_11 ~ "complete - ended", + date_of_initial_first_contact < dementia_diagnosis_confirmed_date & + termination_or_transition_date >= diag_11 + ~ "complete - ended", + #### FAIL #### # PDS started more than 12m after diagnosis @@ -89,7 +105,13 @@ pds %<>% ~ "fail - not started and >12m since diagnosis", # PDS terminated before 11 months from start date - termination_or_transition_date < pds_11 & + date_of_initial_first_contact >= dementia_diagnosis_confirmed_date & + termination_or_transition_date < pds_11 & + !(substr(termination_or_transition_reason, 1, 2) %in% exempt_reasons) + ~ "fail - term <11m from first contact", + + date_of_initial_first_contact < dementia_diagnosis_confirmed_date & + termination_or_transition_date < diag_11 & !(substr(termination_or_transition_reason, 1, 2) %in% exempt_reasons) ~ "fail - term <11m from first contact", @@ -114,13 +136,27 @@ pds %<>% ~ "ongoing - not started", # PDS started within 12m of diagnosis but not yet ended - date_of_initial_first_contact < diag_12 & + date_of_initial_first_contact >= dementia_diagnosis_confirmed_date & + date_of_initial_first_contact < diag_12 & end_date < pds_12 & is.na(termination_or_transition_date) + ~ "ongoing - still receiving", + + date_of_initial_first_contact < dementia_diagnosis_confirmed_date & + end_date < diag_12 & + is.na(termination_or_transition_date) ~ "ongoing - still receiving" )) +#add flag for initial contact before diagnosis date for checking purposes +pds %<>% + + mutate(contact_before_diag = if_else( + date_of_initial_first_contact < dementia_diagnosis_confirmed_date, 1, 0) + ) + + ### 6 - Add Age Group and Deprivation ---- From d32d62e62a4fc9c2fdd05556272bead17a5a5a18 Mon Sep 17 00:00:00 2001 From: abramm01 Date: Thu, 25 Jul 2024 12:48:38 +0100 Subject: [PATCH 2/2] new methodology is now only applied to non-finalised years --- code/02_calculate-measures.R | 102 +++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 17 deletions(-) diff --git a/code/02_calculate-measures.R b/code/02_calculate-measures.R index e691cba..0721617 100644 --- a/code/02_calculate-measures.R +++ b/code/02_calculate-measures.R @@ -61,10 +61,83 @@ pds %<>% ) +#add flag for initial contact before diagnosis date for checking purposes +pds %<>% + + mutate(contact_before_diag = if_else( + date_of_initial_first_contact < dementia_diagnosis_confirmed_date, 1, 0) + ) -### 5 - Add LDP standard classification ---- -pds %<>% +### 5a - Add LDP standard classification for finalised years ---- + +pds_finalised <- pds %>% filter(fy %in% finalised_years) %>% + + mutate(ldp = case_when( + + #### COMPLETE #### + + # Started PDS within 12m of diagnosis AND PDS still ongoing after 12m + date_of_initial_first_contact < diag_12 & + end_date >= pds_12 & + is.na(termination_or_transition_date) + ~ "complete - still receiving", + + # Started PDS within 12m of diagnosis AND PDS ended after 11m + date_of_initial_first_contact < diag_12 & + termination_or_transition_date >= pds_11 + ~ "complete - ended", + + #### FAIL #### + + # PDS started more than 12m after diagnosis + date_of_initial_first_contact >= diag_12 + ~ "fail - started >12m after diag", + + # More than 12m since diagnosis and PDS not started + end_date >= diag_12 & + is.na(date_of_initial_first_contact) & + is.na(termination_or_transition_date) + ~ "fail - not started and >12m since diagnosis", + + # PDS terminated before 11 months from start date + termination_or_transition_date < pds_11 & + !(substr(termination_or_transition_reason, 1, 2) %in% exempt_reasons) + ~ "fail - term <11m from first contact", + + # PDS terminated before first contact made + is.na(date_of_initial_first_contact) & + !is.na(termination_or_transition_date) & + !(substr(termination_or_transition_reason, 1, 2) %in% exempt_reasons) + ~ "fail - term before first contact", + + #### EXEMPT #### + + # Exempt termination reason; died/moved to other HB/refused/can't engage + substr(termination_or_transition_reason, 1, 2) %in% exempt_reasons + ~ "exempt", + + #### ONGOING #### + + # Less than 12m since diagnosis and PDS not started + end_date < diag_12 & + is.na(date_of_initial_first_contact) & + is.na(termination_or_transition_date) + ~ "ongoing - not started", + + # PDS started within 12m of diagnosis but not yet ended + date_of_initial_first_contact < diag_12 & + end_date < pds_12 & + is.na(termination_or_transition_date) + ~ "ongoing - still receiving" + + )) + + + +### 5b - Add LDP standard classification with new methodology to non-finalised years---- + +pds_new_method <- pds %>% filter(!fy %in% finalised_years) %>% mutate(ldp = case_when( @@ -149,14 +222,9 @@ pds %<>% )) -#add flag for initial contact before diagnosis date for checking purposes -pds %<>% +#bind rows - mutate(contact_before_diag = if_else( - date_of_initial_first_contact < dementia_diagnosis_confirmed_date, 1, 0) - ) - - +pds<- bind_rows(pds_finalised,pds_new_method) ### 6 - Add Age Group and Deprivation ---- @@ -187,13 +255,13 @@ pds %<>% ### 7 - Save individual level file for checking ---- -pds %>% +pds %>% write_file(path = data_path(directory = "mi", - type = "ldp_data", + type = "ldp_data", ext = "rds")) -pds %>% -write_file(path = data_path(directory = "mi", +pds %>% +write_file(path = data_path(directory = "mi", type = "ldp_data", ext = "csv")) @@ -230,10 +298,10 @@ pds %<>% filter(substr(fy, 1, 4) < year(end_date) | (substr(fy, 1, 4) == year(end_date) & month %in% inc_months)) - -# write final data -pds %>% -write_file(path = data_path(directory = "mi", + +#write final data +pds %>% +write_file(path = data_path(directory = "mi", type = "final_data", ext = "rds"))