Skip to content

Commit 2e7a9fa

Browse files
authored
Merge branch 'development' into refactor-delayed-discharges
2 parents a0e965c + fa6b0ba commit 2e7a9fa

File tree

10 files changed

+261
-313
lines changed

10 files changed

+261
-313
lines changed

R/process_extract_homelessness.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ process_extract_homelessness <- function(
163163
dplyr::mutate(hl1_completeness = round(.data$hl1_completeness, 2))
164164

165165
final_data <- hl1_data %>%
166-
mutate(
166+
dplyr::mutate(
167167
run_id = run_id,
168168
run_date_time = run_date_time
169169
) %>%

R/process_extract_mental_health.R

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
#' @return the final data as a [tibble][tibble::tibble-package].
1313
#' @export
1414
#' @family process extracts
15-
process_extract_mental_health <- function(data, year, write_to_disk = TRUE) {
15+
process_extract_mental_health <- function(data,
16+
year,
17+
write_to_disk = TRUE,
18+
BYOC_MODE = FALSE,
19+
run_id = NA,
20+
run_date_time = NA) {
1621
log_slf_event(stage = "process", status = "start", type = "mh", year = year)
1722

1823
# Only run for a single year
@@ -39,7 +44,7 @@ process_extract_mental_health <- function(data, year, write_to_disk = TRUE) {
3944
"NA"
4045
)
4146
) %>%
42-
dplyr::select(-.data$cij_inpatient) %>%
47+
dplyr::select(-"cij_inpatient") %>%
4348
# cij_admtype recode unknown to 99
4449
dplyr::mutate(
4550
cij_admtype = dplyr::if_else(
@@ -50,9 +55,9 @@ process_extract_mental_health <- function(data, year, write_to_disk = TRUE) {
5055
) %>%
5156
# monthly beddays and costs
5257
convert_monthly_rows_to_vars(
53-
.data$costmonthnum,
54-
.data$cost_total_net,
55-
.data$yearstay
58+
costmonthnum,
59+
cost_total_net,
60+
yearstay
5661
) %>%
5762
dplyr::mutate(
5863
# yearstay
@@ -76,7 +81,13 @@ process_extract_mental_health <- function(data, year, write_to_disk = TRUE) {
7681

7782
mh_processed <- mh_clean %>%
7883
dplyr::arrange(.data$anon_chi, .data$record_keydate1) %>%
84+
dplyr::mutate(
85+
run_id = run_id,
86+
run_date_time = run_date_time
87+
) %>%
7988
dplyr::select(
89+
"run_id",
90+
"run_date_time",
8091
"year",
8192
"recid",
8293
"smrtype",
@@ -123,7 +134,8 @@ process_extract_mental_health <- function(data, year, write_to_disk = TRUE) {
123134
if (write_to_disk) {
124135
write_file(
125136
mh_processed,
126-
get_source_extract_path(year, "mh", check_mode = "write"),
137+
get_source_extract_path(year, "mh", check_mode = "write", BYOC_MODE = BYOC_MODE),
138+
BYOC_MODE = BYOC_MODE,
127139
group_id = 3356 # sourcedev owner
128140
)
129141
}

R/read_extract_maternity.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ read_extract_maternity <- function(
6363
hbpraccode = "practice_nhs_health_board_curr",
6464
hbrescode = "nhs_board_of_residence_code_curr",
6565
hbtreatcode = "treatment_nhs_board_code_curr",
66-
hscp = "hspc_of_residence_code_curr",
66+
hscp = "hscp_of_residence_code_curr",
6767
lca = "geo_council_area_code",
6868
location = "treatment_location_code",
6969
mpat = "management_of_patient_code",

R/read_extract_mental_health.R

Lines changed: 80 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -5,133 +5,96 @@
55
#' @export
66
read_extract_mental_health <- function(
77
year,
8-
file_path = get_boxi_extract_path(year = year, type = "mh")
8+
denodo_connect = get_denodo_connection(BYOC_MODE = BYOC_MODE),
9+
file_path = get_boxi_extract_path(year = year, type = "mh", BYOC_MODE = BYOC_MODE),
10+
BYOC_MODE
911
) {
1012
log_slf_event(stage = "read", status = "start", type = "mh", year = year)
1113

14+
year <- check_year_format(year, format = "fyyear")
15+
c_year <- convert_fyyear_to_year(year)
16+
17+
on.exit(try(DBI::dbDisconnect(denodo_connect), silent = TRUE), add = TRUE)
18+
1219
# Read BOXI extract
13-
extract_mental_health <- read_file(file_path,
14-
col_types = readr::cols_only(
15-
"Costs Financial Year (04)" = readr::col_double(),
16-
"Costs Financial Month Number (04)" = readr::col_double(),
17-
"Date of Admission(04)" = readr::col_date(format = "%Y/%m/%d %T"),
18-
"Date of Discharge(04)" = readr::col_date(format = "%Y/%m/%d %T"),
19-
"anon_chi" = readr::col_character(),
20-
"Pat Gender Code" = readr::col_integer(),
21-
"Pat Date Of Birth [C]" = readr::col_date(format = "%Y/%m/%d %T"),
22-
"Practice Location Code" = readr::col_character(),
23-
"Practice NHS Board Code - current" = readr::col_character(),
24-
"Geo Postcode [C]" = readr::col_character(),
25-
"NHS Board of Residence Code - current" = readr::col_character(),
26-
"Geo Council Area Code" = readr::col_character(),
27-
"Geo HSCP of Residence Code - current" = readr::col_character(),
28-
"Treatment Location Code" = readr::col_character(),
29-
"Treatment NHS Board Code - current" = readr::col_character(),
30-
"Occupied Bed Days (04)" = readr::col_double(),
31-
"Specialty Classificat. 1/4/97 Code" = readr::col_character(),
32-
"Significant Facility Code" = readr::col_character(),
33-
"Lead Consultant/HCP Code" = readr::col_character(),
34-
"Management of Patient Code" = readr::col_character(),
35-
"Patient Category Code" = readr::col_character(),
36-
"Admission Type Code" = readr::col_character(),
37-
"Admitted Trans From Code" = readr::col_character(),
38-
"Location Admitted Trans From Code" = readr::col_character(),
39-
"Discharge Type Code" = readr::col_character(),
40-
"Discharge Trans To Code" = readr::col_character(),
41-
"Location Discharged Trans To Code" = readr::col_character(),
42-
"Diagnosis 1 Code (6 char)" = readr::col_character(),
43-
"Diagnosis 2 Code (6 char)" = readr::col_character(),
44-
"Diagnosis 3 Code (6 char)" = readr::col_character(),
45-
"Diagnosis 4 Code (6 char)" = readr::col_character(),
46-
"Diagnosis 5 Code (6 char)" = readr::col_character(),
47-
"Diagnosis 6 Code (6 char)" = readr::col_character(),
48-
"Status on Admission Code" = readr::col_integer(),
49-
"Admission Diagnosis 1 Code (6 char)" = readr::col_character(),
50-
"Admission Diagnosis 2 Code (6 char)" = readr::col_character(),
51-
"Admission Diagnosis 3 Code (6 char)" = readr::col_character(),
52-
"Admission Diagnosis 4 Code (6 char)" = readr::col_character(),
53-
"Age at Midpoint of Financial Year (04)" = readr::col_integer(),
54-
"Continuous Inpatient Journey Marker (04)" = readr::col_integer(),
55-
"CIJ Planned Admission Code (04)" = readr::col_integer(),
56-
"CIJ Inpatient Day Case Identifier Code (04)" = readr::col_character(),
57-
"CIJ Type of Admission Code (04)" = readr::col_character(),
58-
"CIJ Admission Specialty Code (04)" = readr::col_character(),
59-
"CIJ Discharge Specialty Code (04)" = readr::col_character(),
60-
"CIJ Start Date (04)" = readr::col_date(format = "%Y/%m/%d %T"),
61-
"CIJ End Date (04)" = readr::col_date(format = "%Y/%m/%d %T"),
62-
"Total Net Costs (04)" = readr::col_double(),
63-
"Alcohol Related Admission (04)" = readr::col_factor(levels = c("Y", "N")),
64-
"Substance Misuse Related Admission (04)" = readr::col_factor(levels = c("Y", "N")),
65-
"Falls Related Admission (04)" = readr::col_factor(levels = c("Y", "N")),
66-
"Self Harm Related Admission (04)" = readr::col_factor(levels = c("Y", "N")),
67-
"Duplicate Record Flag (04)" = readr::col_factor(levels = c("Y", "N")),
68-
"NHS Hospital Flag (04)" = readr::col_factor(levels = c("Y", "N")),
69-
"Community Hospital Flag (04)" = readr::col_factor(levels = c("Y", "N")),
70-
"Unique Record Identifier" = readr::col_character()
71-
)
20+
extract_mental_health <- dplyr::tbl(
21+
denodo_connect,
22+
dbplyr::in_schema("sdl", "sdl_mental_health_episode_source")
7223
) %>%
24+
dplyr::filter(
25+
.data$costs_financial_year == c_year,
26+
.data$duplicate_record_flag != "Y"
27+
) %>%
7328
# rename variables
74-
dplyr::rename(
75-
costsfy = "Costs Financial Year (04)",
76-
costmonthnum = "Costs Financial Month Number (04)",
77-
record_keydate1 = "Date of Admission(04)",
78-
record_keydate2 = "Date of Discharge(04)",
79-
anon_chi = "anon_chi",
80-
gender = "Pat Gender Code",
81-
dob = "Pat Date Of Birth [C]",
82-
gpprac = "Practice Location Code",
83-
hbpraccode = "Practice NHS Board Code - current",
84-
postcode = "Geo Postcode [C]",
85-
hbrescode = "NHS Board of Residence Code - current",
86-
lca = "Geo Council Area Code",
87-
hscp = "Geo HSCP of Residence Code - current",
88-
location = "Treatment Location Code",
89-
hbtreatcode = "Treatment NHS Board Code - current",
90-
yearstay = "Occupied Bed Days (04)",
91-
spec = "Specialty Classificat. 1/4/97 Code",
92-
sigfac = "Significant Facility Code",
93-
conc = "Lead Consultant/HCP Code",
94-
mpat = "Management of Patient Code",
95-
cat = "Patient Category Code",
96-
tadm = "Admission Type Code",
97-
adtf = "Admitted Trans From Code",
98-
admloc = "Location Admitted Trans From Code",
99-
disch = "Discharge Type Code",
100-
dischto = "Discharge Trans To Code",
101-
dischloc = "Location Discharged Trans To Code",
102-
diag1 = "Diagnosis 1 Code (6 char)",
103-
diag2 = "Diagnosis 2 Code (6 char)",
104-
diag3 = "Diagnosis 3 Code (6 char)",
105-
diag4 = "Diagnosis 4 Code (6 char)",
106-
diag5 = "Diagnosis 5 Code (6 char)",
107-
diag6 = "Diagnosis 6 Code (6 char)",
108-
stadm = "Status on Admission Code",
109-
adcon1 = "Admission Diagnosis 1 Code (6 char)",
110-
adcon2 = "Admission Diagnosis 2 Code (6 char)",
111-
adcon3 = "Admission Diagnosis 3 Code (6 char)",
112-
adcon4 = "Admission Diagnosis 4 Code (6 char)",
113-
age = "Age at Midpoint of Financial Year (04)",
114-
cij_marker = "Continuous Inpatient Journey Marker (04)",
115-
cij_pattype_code = "CIJ Planned Admission Code (04)",
116-
cij_inpatient = "CIJ Inpatient Day Case Identifier Code (04)",
117-
cij_admtype = "CIJ Type of Admission Code (04)",
118-
cij_adm_spec = "CIJ Admission Specialty Code (04)",
119-
cij_dis_spec = "CIJ Discharge Specialty Code (04)",
120-
cij_start_date = "CIJ Start Date (04)",
121-
cij_end_date = "CIJ End Date (04)",
122-
cost_total_net = "Total Net Costs (04)",
123-
alcohol_adm = "Alcohol Related Admission (04)",
124-
submis_adm = "Substance Misuse Related Admission (04)",
125-
falls_adm = "Falls Related Admission (04)",
126-
selfharm_adm = "Self Harm Related Admission (04)",
127-
duplicate = "Duplicate Record Flag (04)",
128-
nhshosp = "NHS Hospital Flag (04)",
129-
commhosp = "Community Hospital Flag (04)",
130-
uri = "Unique Record Identifier"
29+
dplyr::select(
30+
costsfy = "costs_financial_year",
31+
costmonthnum = "costs_financial_month_number",
32+
record_keydate1 = "date_of_admission",
33+
record_keydate2 = "date_of_discharge",
34+
chi = "patient_chi",
35+
gender = "gender",
36+
dob = "patient_dob",
37+
gpprac = "practice_location_code",
38+
hbpraccode = "practice_nhs_board_code_curr",
39+
postcode = "geo_postcode",
40+
hbrescode = "nhs_board_of_residence_code_curr",
41+
lca = "geo_council_area_code",
42+
hscp = "geo_hscp_of_residence_code_curr",
43+
location = "treatment_location_code",
44+
hbtreatcode = "treatment_nhs_board_code_curr",
45+
yearstay = "occupied_bed_days",
46+
spec = "specialty_classification_code",
47+
sigfac = "significant_facility_code",
48+
conc = "lead_consultant_hcp_code",
49+
mpat = "management_of_patient_code",
50+
cat = "patient_category_code",
51+
tadm = "admission_type_code",
52+
adtf = "admitted_trans_from_code",
53+
admloc = "location_admitted_trans_from_code",
54+
disch = "discharge_type_code",
55+
dischto = "discharge_trans_to_code",
56+
dischloc = "location_discharge_trans_to_code",
57+
diag1 = "diagnosis_1_code",
58+
diag2 = "diagnosis_2_code",
59+
diag3 = "diagnosis_3_code",
60+
diag4 = "diagnosis_4_code",
61+
diag5 = "diagnosis_5_code",
62+
diag6 = "diagnosis_6_code",
63+
stadm = "status_on_admission_code",
64+
adcon1 = "admission_diagnosis_1_code",
65+
adcon2 = "admission_diagnosis_2_code",
66+
adcon3 = "admission_diagnosis_3_code",
67+
adcon4 = "admission_diagnosis_4_code",
68+
age = "age_at_midpoint_of_financial_year",
69+
cij_marker = "continuous_inpatient_journey_marker",
70+
cij_pattype_code = "cij_planned_admission_code",
71+
cij_inpatient = "cij_inpatient_day_case_identifier_code",
72+
cij_admtype = "cij_type_of_admission_code",
73+
cij_adm_spec = "cij_admission_specialty_code",
74+
cij_dis_spec = "cij_discharge_specialty_code",
75+
cij_start_date = "cij_start_date",
76+
cij_end_date = "cij_end_date",
77+
cost_total_net = "total_net_cost",
78+
alcohol_adm = "alcohol_related_admission",
79+
submis_adm = "substance_misuse_related_admission",
80+
falls_adm = "falls_related_admission",
81+
selfharm_adm = "self_harm_related_admission",
82+
duplicate = "duplicate_record_flag",
83+
nhshosp = "nhs_hospital_flag",
84+
commhosp = "community_hospital_flag",
85+
uri = "unique_record_id"
13186
) %>%
87+
dplyr::collect() %>%
13288
# replace NA in cost_total_net by 0
13389
dplyr::mutate(
13490
cost_total_net = tidyr::replace_na(.data[["cost_total_net"]], 0.0)
91+
) %>%
92+
slfhelper::get_anon_chi("chi") %>%
93+
# data type modification
94+
dplyr::mutate(
95+
costsfy = as.double(.data$costsfy),
96+
costmonthnum = as.double(.data$costmonthnum),
97+
uri = as.character(.data$uri)
13598
)
13699

137100
log_slf_event(stage = "read", status = "complete", type = "mh", year = year)

Run_SLF_Files_targets/run_all_targets.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ write_console_output(
4949
log_tar_message("start")
5050

5151
# tar_make() will run the pipeline and use crew() for parallel processing.
52-
tar_make()
52+
tar_make(store = "/conf/sourcedev/Source_Linkage_File_Updates/_targets")
5353

5454
# Run combine_tests() for outputting the test workbooks.
5555
log_tar_message("combining_tests")

0 commit comments

Comments
 (0)