diff --git a/R/classify-diabetes.R b/R/classify-diabetes.R new file mode 100644 index 0000000..09239a7 --- /dev/null +++ b/R/classify-diabetes.R @@ -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") + 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( + lab_forsker = lab_forsker + ) + + # Exclusion steps ----- + exclusions <- gld_purchases |> + 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() +} diff --git a/R/include-hba1c.R b/R/include-hba1c.R index 3180e7b..c89e080 100644 --- a/R/include-hba1c.R +++ b/R/include-hba1c.R @@ -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`. @@ -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) |>