Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate references #1032

Merged
merged 8 commits into from
Dec 17, 2024
Merged
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
45 changes: 40 additions & 5 deletions R/00-update_refs.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@
#
################################################################################

## MANUALLY UPDATE ##-----------------------------------------------------------

#' End date
#'
#' @return Get the end date of the latest update period
#' @export
#'
end_date <- function() {
## UPDATE ##
## MANUALLY UPDATE ##
# Specify update by indicating end of quarter date
# Q1 June = 30062024
# Q2 September = 30092024
# Q3 December = 31122024
# Q4 March = 31032024
lubridate::dmy(31122024)
# Q4 March = 31032025
end_date <- lubridate::dmy(31122024)

return(end_date)
}


Expand All @@ -43,7 +47,7 @@
#' @param type name of extract
#'
#' @return A logical TRUE/FALSE
check_year_valid <- function(

Check warning on line 50 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=50,col=1,[cyclocomp_linter] Functions should have cyclomatic complexity of less than 15, this has 33.
year,
type = c(
"acute",
Expand All @@ -68,27 +72,49 @@
"sds",
"sparra"
)) {
## MANUALLY UPDATE ##
# Check extracts which we do not have data for and ensure this is picked up
# by the following code:
# DN starts in 2015/16
# SPARRA starts in 2015/16
if (year <= "1415" && type %in% c("dn", "sparra")) {
return(FALSE)
# CMH starts in 2016/17
# Homelessness starts in 2016/17
# DD starts in 2016/17
} else if (year <= "1516" && type %in% c("cmh", "homelessness", "dd")) {
return(FALSE)
# Social Care data sets start in 2017/18 Q4
# Cost_DNAs start in 2017/18
} else if (year <= "1617" && type %in% c("ch", "hc", "sds", "at", "client", "cost_dna")) {

Check warning on line 89 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=89,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 92 characters.
return(FALSE)
# HHG starts in 2018/19
} else if (year <= "1718" && type %in% "hhg") {
return(FALSE)
# CMH stops in 2020/21
# DN stops in 2020/21
} else if (year >= "2122" && type %in% c("cmh", "dn")) {
return(FALSE)
# HHG stops in 2022/23
} else if (year >= "2324" && type %in% "hhg") {
return(FALSE)
## CHECK - what is the latest NSU cohort available?
# NSU is currently available for 2023/24
## CHECK - What period does SDS data get submitted?
# SDS is only available up to March 2024 currently.
} else if (year >= "2425" && type %in% c("nsu", "sds")) {
return(FALSE)
## CHECK - what data do we have available for Social Care and SPARRA?
} else if (year >= "2526" && type %in% c("ch", "hc", "sds", "at", "sparra")) {
return(FALSE)
}

return(TRUE)
}

#-------------------------------------------------------------------------------

## AUTOMATED REFS - please check to ensure these are used correctly ##

#' Delayed Discharge period
#'
Expand All @@ -100,7 +126,12 @@
#'
#' @family initialisation
get_dd_period <- function() {
"Jul16_Sep24"
first_part <- substr(previous_update(), 1, 3)

Check warning on line 129 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=129,col=3,[object_usage_linter] local variable 'first_part' assigned but may not be used
end_part <- substr(previous_update(), 7, 8)

Check warning on line 130 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=130,col=3,[object_usage_linter] local variable 'end_part' assigned but may not be used

dd_period <- as.character(stringr::str_glue("Jul16_{first_part}{end_part}"))

return(dd_period)
}


Expand All @@ -113,7 +144,11 @@
#'
#' @family initialisation
latest_update <- function() {
"Dec_2024"
month <- as.character(lubridate::month(end_date(), label = TRUE))

Check warning on line 147 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=147,col=3,[object_usage_linter] local variable 'month' assigned but may not be used
year <- as.character(lubridate::year(end_date()))

Check warning on line 148 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=148,col=3,[object_usage_linter] local variable 'year' assigned but may not be used
latest_update <- as.character(stringr::str_glue("{month}_{year}"))

return(latest_update)
}


Expand Down Expand Up @@ -141,11 +176,11 @@

latest_update_date <- lubridate::my(latest_update())

previous_update_year <- lubridate::year(

Check warning on line 179 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=179,col=3,[object_usage_linter] local variable 'previous_update_year' assigned but may not be used
latest_update_date - lubridate::period(months_ago, "months")
)

previous_update_month <- lubridate::month(

Check warning on line 183 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=183,col=3,[object_usage_linter] local variable 'previous_update_month' assigned but may not be used
latest_update_date - lubridate::period(months_ago, "months"),
label = TRUE,
abbr = TRUE
Expand All @@ -166,7 +201,7 @@
#'
fy <- function() {
# Latest FY
fy <- phsmethods::extract_fin_year(end_date()) %>% substr(1, 4)

Check warning on line 204 in R/00-update_refs.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/00-update_refs.R,line=204,col=3,[object_usage_linter] local variable 'fy' assigned but may not be used
}


Expand Down
Loading