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

feat: 🚧 skeleton of the core diabetes classification #142

Open
wants to merge 6 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
105 changes: 105 additions & 0 deletions R/classify-diabetes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#' Classify diabetes status using Danish registers.
#'
#' @return The same object type as the input data, which would be a
#' [tibble::tibble()] type object.
#' @export
#' @seealso See the [vignette("function-flow", package = "osdc")] for a detailed
#' description of the internal implementation of this classification function.
#'
#' @examples
#' classify_diabetes(
#' kontakter = register_data$kontakter,
#' diagnoser = register_data$diagnoser,
#' lpr_diag = register_data$lpr_diag,
#' lpr_adm = register_data$lpr_adm,
#' sysi = register_data$sysi,
#' sssy = register_data$sssy,
#' lab_forsker = register_data$lab_forsker,
#' bef = register_data$bef,
#' lmdb = register_data$lmdb
#' )
classify_diabetes <- function(kontakter, diagnoser, lpr_diag, lpr_adm, sysi, sssy, lab_forsker, bef, lmdb) {
# Verification step -----
verify_required_variables(kontakter, "kontakter")
verify_required_variables(diagnoser, "diagnoser")
verify_required_variables(lpr_diag, "lpr_diag")
verify_required_variables(lpr_adm, "lpr_adm")
verify_required_variables(sysi, "sysi")
verify_required_variables(sssy, "sssy")
Comment on lines +27 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I've included this in include_podiatrist_services() too. Should it only be here?

verify_required_variables(lab_forsker, "lab_forsker")
verify_required_variables(bef, "bef")
verify_required_variables(lmdb, "lmdb")

# Initially processing -----
lpr2 <- join_lpr2(
lpr_diag = lpr_diag,
lpr_adm = lpr_adm
)

lpr3 <- join_lpr3(
kontakter = kontakter,
diagnoser = diagnoser
)

# pregnancy_dates <- get_pregrancy_dates(
# lpr2 = lpr2,
# lpr3 = lpr3
# )

# Inclusion steps -----
# diabetes_diagnosis <- include_diabetes_diagnosis(
# lpr2 = lpr2,
# lpr3 = lpr3
# )

# podiatrist_services <- include_podiatrist_services(
# sysi = sysi,
# sssy = sssy
# )

# gld_purchases <- include_gld_purchases(
# lmdb = lmdb
# )

included_hba1c <- include_hba1c(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
included_hba1c <- include_hba1c(
hba1c_over_threshold <- include_hba1c(

Or something to be more like the other inclusion step variable names (i.e., not start with an "included").

lab_forsker = lab_forsker
)

# Exclusion steps -----
exclusions <- gld_purchases |>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe name the output gld_hba1c_after_exclusions or something similar?

exclude_potential_pcos(bef = bef) |>
exclude_wld_purchases(lmdb = lmdb) |>
exclude_pregnancy(
# TODO: Need to think about arg naming here..
hba1c = included_hba1c,
pregnancy_dates = pregnancy_dates
)

# Joining into an initial dataset -----
# inclusions <- join_inclusions(
# included_diabetes_diagnosis,
# included_podiatrist_services,
# exclusions
# )

# inclusions |>
# get_diagnosis_dates() |>
# classify_t1d()
}

#' After inclusion and exclusion, classify those with type 1 diabetes.
#'
#' @param data Joined data output from the inclusion and exclusion steps.
#'
#' @return The same object type as the input data, which would be a
#' [tibble::tibble()] type object.
#' @keywords internal
#'
classify_t1d <- function(data) {
# data |>
# get_has_t1d_primary_diagnosis() |>
# get_only_insulin_purchases() |>
# get_majority_of_t1d_primary_diagnosis() |>
# get_insulin_purchases_within_180_days() |>
# get_insulin_is_two_thirds_of_gld_purchases()
}
Comment on lines +98 to +105
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is still present in the classify_diabetes() function environment, then adding the gld_hba1c_after_exclusions object as an input to get_insulin_purchases_within_180_days() would allow us to reuse the post-exclusion GLD data to assess insulin purchases in relation to the date of diabetes variable. This could be a way to solve what we discussed earlier today.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function outputs and helper functions currently described in #133 need a bit of aligning to match what ends up being implemented in this script (right now I've added another helper function, get_type_diagnosis_majority(), but that one only relates to hospital diagnoses, not GLD, so it should be fine for this PR). There will probably be some back-and-forth between the function flow docs and this script as we go along.

8 changes: 4 additions & 4 deletions R/include-hba1c.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' In the `lab_forsker` register, NPU27300 is HbA1c in the modern units (IFCC)
#' while NPU03835 is HbA1c in old units (DCCT).
#'
#' @param data The `lab_forsker` register.
#' @param lab_forsker The `lab_forsker` register.
#'
#' @return An object of the same input type, default as a [tibble::tibble()],
#' with two columns: `pnr` and `included_hba1c`.
Expand All @@ -13,12 +13,12 @@
#' \dontrun{
#' register_data$lab_forsker |> include_hba1c()
#' }
include_hba1c <- function(data) {
verify_required_variables(data, "lab_forsker")
include_hba1c <- function(lab_forsker) {
verify_required_variables(lab_forsker, "lab_forsker")
hba1c_criteria <- get_algorithm_logic("hba1c") |>
# To convert the string into an R expression.
rlang::parse_expr()
data |>
lab_forsker |>
column_names_to_lower() |>
# Use !! to inject the expression into filter.
dplyr::filter(!!hba1c_criteria) |>
Expand Down
Loading