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

Atamborska/show proportions #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 28 additions & 12 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,52 @@ NULL

#' Yearly ICD-10 Code Usage from Hospital Admitted Patient Care Activity in England
#'
#' Yearly summary of ICD-10 code usage from 1st April 2013 to 31st March 2024.
#' All diagnosis codes are summarised to the 4-character level.
#' The code usage represents the total annual count of episodes which record in any primary or secondary position.
#' Restricted codes for which annual usage is not published, have been removed.
#' Yearly summary of 4-character ICD-10 code usage from 1st April 2013 to 31st March 2024.
#' The code usage represents the annual count of all episodes which record the given ICD-10 code in any primary or secondary position.
#' Restricted codes for which annual usage is not published have been removed.
#' @format A data frame with 135,951 rows and 5 columns:
#' \describe{
#' \item{start_date}{Start date of code usage count}
#' \item{end_date}{End date of code usage count}
#' \item{icd10_code}{The 4-character ICD-10 Code.
#' Note that the punctuation from the code has been removed for compatibility with OpenCodelists.}
#' \item{usage}{Yearly summary of code usage.}
#' \item{description}{Description of ICD-10 Code}
#' \item{usage}{Annual count of code usage.}
#' \item{description}{Description of the ICD-10 Code}
#' }
#' @source <https://digital.nhs.uk/data-and-information/publications/statistical/hospital-admitted-patient-care-activity>
#' @examples
#' # Filter to codes in the ICD-10 Chapter XIX: "Injury, poisoning..."
#' # (codes begin with letters "S" or "T"), with usage > 10,000.
#' # For each of these, select the year with the highest count.
#' icd10_usage |>
#' dplyr:: filter(grepl("^[ST]", icd10_code) & usage > 10000)|>
#' dplyr:: group_by(description) |>
#' dplyr:: slice_max(usage)
#' # Filter to codes present in the CPRD Aurum ICD-10 pregnancy codelist.
#' # This codelist is available in OpenCodelists.org
#' codelist<- read.csv(
#' "https://www.opencodelists.org/codelist/opensafely/pregnancy-icd10-aurum/5a7d8d12/download.csv")
#' icd10_usage |>
#' dplyr:: filter(icd10_code %in% codelist$code)
"icd10_usage"

#' Yearly OPCS Code Usage from Hospital Admitted Patient Care Activity in England
#'
#' Yearly summary of OPCS code usage from 1st April 2013 to 31st March 2024.
#' All procedure codes are summarised to the 4-character level.
#' The code usage represents total annual count of each procedure, recorded across the primary and the secondary procedure positions.
#' Restricted codes for which annual usage is not published, have been removed.
#' Yearly summary of 4-character OPCS code usage from 1st April 2013 to 31st March 2024.
#' The code usage represents the total annual count of each procedure, recorded across the primary and the secondary procedure positions.
#' Restricted codes for which annual usage is not published have been removed.
#' @format A data frame with 107,376 rows and 5 columns:
#' \describe{
#' \item{start_date}{Start date of code usage count}
#' \item{end_date}{End date of code usage count}
#' \item{opcs_code}{The 4-character OPCS code.
#' Note that the punctuation from the code has been removed for compatibility with OpenCodelists.}
#' \item{usage}{Yearly summary of code usage.}
#' \item{description}{Description of OPCS Code}
#' \item{usage}{Annual count of code usage.}
#' \item{description}{Description of the OPCS Code}
#' }
#' @source <https://digital.nhs.uk/data-and-information/publications/statistical/hospital-admitted-patient-care-activity>
#' @examples
#' # Filter to procedures involving "biopsy" after March 2020 (note each year runs April - March).
#' opcs_usage |>
#' dplyr:: filter(grepl("biopsy", description, ignore.case = TRUE) & lubridate:: year(end_date) > 2020)
"opcs_usage"
12 changes: 11 additions & 1 deletion R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ plot_summary <- function(data) {
#' @keywords internal
plot_individual <- function(data) {
scale_x_date_breaks <- unique(data$start_date)

data <- data |>
group_by(start_date, end_date) |>
summarise(
code = code,
description = description,
usage = usage,
annual_proportion = round(usage/sum(usage) * 100, 2))


ggplot(
data,
Expand All @@ -68,7 +77,8 @@ plot_individual <- function(data) {
"<br>",
"<b>Code:</b> ", code, "<br>",
"<b>Description:</b> ", description, "<br>",
"<b>Code usage:</b> ", scales::comma(usage)
"<b>Code usage:</b> ", scales::comma(usage), "<br>",
"<b>Proportion of annual usage: </b>", annual_proportion, "%"
))
) +
scale_x_date(
Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
}

utils::globalVariables(c(
"annual_proportion",
"start_date",
"end_date",
"snomed_concept_id",
Expand Down
26 changes: 20 additions & 6 deletions man/icd10_usage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions man/opcs_usage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading