Skip to content

Commit

Permalink
reorganise publications folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bex-0-madden committed Sep 19, 2024
1 parent fbd88bf commit 30b58f5
Show file tree
Hide file tree
Showing 80 changed files with 232 additions and 232 deletions.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions 07_publication/archive/chapters/2_load_functions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

######################.
### Load functions ###
######################.

# Author: Charlie Smith
# Date: 2023-11-14


source('./02_setup/save_df_as_parquet.R')
source("./07_publication/script/functions/retrieve_save_data.R")
source('./07_publication/script/functions/get_referrals_quarterly.R')
source('./07_publication/script/functions/get_referrals_monthly_sco.R')
source('./07_publication/script/functions/get_referrals_sex_age.R')
source('./07_publication/script/functions/get_referrals_simd.R')

source('./07_publication/script/functions/create_table_refs_quarterly.R')
source('./07_publication/script/functions/get_annual_summary_figures.R')

source('./07_publication/script/functions/make_chart_referrals_sco.R')
source('./07_publication/script/functions/make_chart_referrals_sex_age.R')
source('./07_publication/script/functions/make_chart_referrals_rate_simd.R')

source('./07_publication/script/functions/compile_excel_doc.R')
67 changes: 67 additions & 0 deletions 07_publication/archive/chapters/3_set_constants.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

#####################.
### Set constants ###
#####################.

# Author: Charlie Smith
# Date: 2023-11-14




# 1 - Establish data time frame -------------------------------------------

month_end <- ymd(month_end)
month_start <- ymd(month_end) - months(14)
date_range <- seq.Date(from = month_start, to = month_end, by = "month")

range_12_month <- seq.Date(from = month_end - months(11), to = month_end, by = "month")

# 2 - Production data -----------------------------------------------------
publication_month <- month_end + months(3)


production_date <- Sys.Date()
production_month <- format(as.Date(production_date), "%B %Y")

# 3 - Set safe place to save working data ---------------------------------

data_working_safe <- "../../../output/publication/data/"

reference_files_dir <- paste0(data_working_safe, 'reference_files/')
dir.create(paste0(data_working_safe, publication_month, '_release'))

data_working_safe <- paste0(data_working_safe, publication_month, '_release/')




# 4 - Reference -----------------------------------------------------------

# create HB vector
hb_vector <- c("NHS Scotland",
"NHS Ayrshire and Arran",
"NHS Borders",
"NHS Dumfries and Galloway",
"NHS Fife",
"NHS Forth Valley",
"NHS Grampian",
"NHS Greater Glasgow and Clyde",
"NHS Highland",
"NHS Lanarkshire",
"NHS Lothian",
"NHS Orkney",
"NHS Shetland",
"NHS Tayside",
"NHS Western Isles",
"NHS 24")


# chart dimensions
chart_width <- 24
chart_height <- 16


# 6 - Get next pub date ---------------------------------------------------
# (6 months after month_end, 1st Tuesday)
# next_pub_date <- id_next_pub(data_last = month_end)
File renamed without changes.
64 changes: 53 additions & 11 deletions 07_publication/script/chapters/2_load_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,60 @@
# Date: 2023-11-14



source('./02_setup/save_df_as_parquet.R')
source("./07_publication/script/functions/retrieve_save_data.R")
source('./07_publication/script/functions/get_referrals_quarterly.R')
source('./07_publication/script/functions/get_referrals_monthly_sco.R')
source('./07_publication/script/functions/get_referrals_sex_age.R')
source('./07_publication/script/functions/get_referrals_simd.R')

source('./07_publication/script/functions/create_table_refs_quarterly.R')
source('./07_publication/script/functions/get_annual_summary_figures.R')
source('./07_publication/update_2024_06/functions/add_sex_description.R')
source('./07_publication/update_2024_06/functions/append_quarter_ending.R')
source('./07_publication/update_2024_06/functions/summarise_by_quarter.R')
source('./07_publication/update_2024_06/functions/add_proportion_ds_hb.R')
source('./07_publication/update_2024_06/functions/add_hb_region.R')
source("./07_publication/update_2024_06/functions/get_appointments_df.R")
source("./07_publication/update_2024_06/functions/get_basic_data_referrals_df.R")
source('./07_publication/update_2024_06/functions/tidy_age_group_order.R')

source('./07_publication/update_2024_06/functions/summarise_referrals.R')
#source('./07_publication/update_2024_06/functions/referrals_by_source.R')
source('./07_publication/update_2024_06/functions/non_acceptance.R')
source('./07_publication/update_2024_06/functions/non_acceptance_reason.R')
source('./07_publication/update_2024_06/functions/non_acceptance_action.R')

source('./07_publication/update_2024_06/functions/summarise_referrals_basic_opti.R')
source('./07_publication/update_2024_06/functions/summarise_appointments_att.R')

source('./07_publication/update_2024_06/functions/compile_referrals_excel_summary.R')
source('./07_publication/update_2024_06/functions/compile_ref_source_excel_summary.R')
source('./07_publication/update_2024_06/functions/compile_non_acceptance_summary.R')
source('./07_publication/update_2024_06/functions/compile_non_acceptance_reason_summary.R')
source('./07_publication/update_2024_06/functions/compile_non_acceptance_action_summary.R')
source('./07_publication/update_2024_06/functions/compile_appointments_excel_summary.R')
source('./07_publication/update_2024_06/functions/compile_basic_opti_excel_summary.R')


source('./07_publication/update_2024_06/functions/create_table_referrals_quarterly.R')
source('./07_publication/update_2024_06/functions/create_table_acc_rate.R')
#source('./07_publication/update_2024_06/functions/create_table_acc_reason_action.R')
source('./07_publication/update_2024_06/functions/create_table_app_att.R')
source('./07_publication/update_2024_06/functions/create_table_basic_opti.R')

source('./07_publication/update_2024_06/functions/create_bar_chart_rej_reason.R')
source('./07_publication/update_2024_06/functions/create_bar_chart_rej_action.R')
source('./07_publication/update_2024_06/functions/create_bar_chart_dna_simd.R')
source('./07_publication/update_2024_06/functions/create_trend_plot_dna_rate.R')

source('./07_publication/update_2024_06/functions/create_pub_function.R')
source('./07_publication/update_2024_06/functions/identify_next_publication_date.R')

# compile data tables functions
source('./07_publication/update_2024_06/functions/compile_publication_data_tables.R')
source('./07_publication/update_2024_06/functions/update_dt_wording.R')
source('./07_publication/update_2024_06/functions/update_dt_values.R')
source('./07_publication/update_2024_06/functions/protect_worksheets.R')

source('./07_publication/update_2024_06/functions/summarise_referrals_sex_age.R')
source('./07_publication/update_2024_06/functions/create_stemleaf_ref_sex_age.R')
source('./07_publication/update_2024_06/functions/create_bar_chart_refs_simd.R')

source('./07_publication/update_2024_06/functions/get_forpub_refs_agesex.R')

source('./07_publication/script/functions/make_chart_referrals_sco.R')
source('./07_publication/script/functions/make_chart_referrals_sex_age.R')
source('./07_publication/script/functions/make_chart_referrals_rate_simd.R')

source('./07_publication/script/functions/compile_excel_doc.R')
105 changes: 88 additions & 17 deletions 07_publication/script/chapters/3_set_constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@ production_month <- format(as.Date(production_date), "%B %Y")

# 3 - Set safe place to save working data ---------------------------------

data_working_safe <- "../../../output/publication/data/"

reference_files_dir <- paste0(data_working_safe, 'reference_files/')
dir.create(paste0(data_working_safe, publication_month, '_release'))

data_working_safe <- paste0(data_working_safe, publication_month, '_release/')


ref_dir <- paste0(shorewise_pub_data_dir, "/referrals/")
ref_source_dir <- paste0(shorewise_pub_data_dir, "/referrals_by_ref_source/")
non_acc_dir <- paste0(shorewise_pub_data_dir, "/non_acceptance/")
non_acc_reason_dir <- paste0(shorewise_pub_data_dir, "/non_acceptance_reason/")
non_acc_action_dir <- paste0(shorewise_pub_data_dir, "/non_acceptance_action/")
apps_att_dir <- paste0(shorewise_pub_data_dir, "/appointments_att/")
basic_opti_dir <- paste0(shorewise_pub_data_dir, "/basic_v_opti/")
markdown_dir <- paste0(root_dir, "/markdown/")


# 4 - Reference -----------------------------------------------------------

# create HB vector
hb_vector <- c("NHS Scotland",
"NHS Ayrshire and Arran",
hb_vector <- c("NHS Ayrshire and Arran",
"NHS Borders",
"NHS Dumfries and Galloway",
"NHS Fife",
Expand All @@ -54,14 +53,86 @@ hb_vector <- c("NHS Scotland",
"NHS Shetland",
"NHS Tayside",
"NHS Western Isles",
"NHS 24")
"NHS 24",
"NHS Scotland")


# chart dimensions
chart_width <- 24
chart_height <- 16
vec_dataset_type <- c("CAMHS", "PT")

# create complete ds
df_ds_hb_name <- cross_join(as.data.frame(vec_dataset_type),
as.data.frame(hb_vector)) |>
rename(dataset_type = vec_dataset_type,
hb_name = hb_vector) |>
filter(!(#dataset_type == "CAMHS" &
hb_name == "NHS 24")) # remove invalid combo


# 6 - Get next pub date ---------------------------------------------------
# (6 months after month_end, 1st Tuesday)
# next_pub_date <- id_next_pub(data_last = month_end)
# 5. Plotting constants -------------------------------------------------------

# chart dimensions
chart_width = 18 # changed to scale better on a4 page # 24
chart_height = 12 # changed to scale better on a4 page # 16
bar_width = 0.5

# custom plotting theme (does not set legend formatting,
# requires panel.grid.major.x/y to be manually defined depending on orientation of plot)

theme_captnd <- function(){
font <- "Arial"
theme_minimal() %+replace%
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_rect(colour = "grey95", fill = NA, linewidth = 0.75),
plot.caption = element_text(size = 10, hjust = 1, margin = margin(t = 10)),
axis.title.x = element_text(size = 12, face = "bold",
margin = margin(t = 15)),
axis.title.y = element_text(size = 12, face = "bold",
margin = margin(r = 15), angle = 90),
axis.text.x = element_text(size = 11, color = "black"),
axis.text.y = element_text(size = 11, color = "black", hjust = 1),
axis.ticks = element_line(colour = "grey90")
)
}



# 6 - Get date labels for publication doc ----------------------------

# date labels
date_label <- format(as.Date(month_end), "%B %Y")
date_label_qt <- format((as.Date(month_end) %m-% months(3)), "%B %Y")
date_label_yr <- format((as.Date(month_end) %m-% months(12)), "%B %Y")
date_label_5qt <- format((as.Date(month_end) %m-% months(14)), "%B %Y")

# set pub_date as 3 months after month_end
pub_month <- as.Date(month_end %m+% months(3))
## Get next pub date and prev pub date
# (6 months after pub_date, 1st Tuesday)
next_pub_date <- id_next_pub(pub_month)
# (6 months after 1yr before pub_date, 1st Tuesday)
prev_pub_date <- id_next_pub(pub_month - months(12))

#pub_date for this publication itself
pub_date <- id_next_pub(pub_month -months(6))




# 7 - Constants for data tables -------------------------------------------


# # password for locking worksheets (doesn't seem to work...)
# str_password <- "13_DunDee_$dollar$"
#
# dq_template_1 = "dq_info_only_template.xlsx" # DQ Report template
# dq_template_1_update = "dq_report_template_DO_NOT_EDIT.xlsx"
# dq_template_2 = "record_trend_only_template.xlsx" # Record Counts Report template
#
# # set text font and size for added text
style_text <- createStyle(fontName = 'Arial', fontSize = 11)
style_date <- createStyle(numFmt = "mmm-yy", fontName = 'Arial', fontSize = 11, halign = "left")
style_count <- createStyle(numFmt = "#,##0", fontName = 'Arial', fontSize = 11, halign = "right")
style_percent <- createStyle(numFmt = "PERCENT", fontName = 'Arial', fontSize = 11, halign = "right")
File renamed without changes.
66 changes: 0 additions & 66 deletions 07_publication/update_2024_06/chapters/2_load_functions.R

This file was deleted.

Loading

0 comments on commit 30b58f5

Please sign in to comment.