Skip to content

Commit

Permalink
refactor: ♻️ add contained_doses variable to output (#187)
Browse files Browse the repository at this point in the history
## Description

As per the documentation update, this adds the variable
`contained_doses` from the multiplication of volume and apk

Will not build correctly, since it depends on #185

## Checklist

- [x] Ran `just run-all`
  • Loading branch information
lwjohnst86 authored Feb 10, 2025
1 parent 0f3a865 commit 76621d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions R/include-gld-purchases.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ include_gld_purchases <- function(lmdb) {
column_names_to_lower() |>
# Use !! to inject the expression into filter.
dplyr::filter(!!criteria) |>
dplyr::mutate(
contained_doses = .data$volume * .data$apk,
# An indicator variable for later joins
has_gld_purchases = TRUE
) |>
# Keep only the columns we need.
dplyr::select(
"pnr",
# Change to date to work with later functions.
date = "eksd",
"atc",
"volume",
"apk",
"indo"
"contained_doses",
"has_gld_purchases",
indication_code = "indo"
)
}
9 changes: 7 additions & 2 deletions tests/testthat/test-include-gld-purchases.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ expected <- tibble::tribble(
"A10123",
) |>
dplyr::bind_cols(constants) |>
dplyr::rename(date = eksd) |>
dplyr::relocate(atc, .after = date)
dplyr::rename(date = eksd, indication_code = indo) |>
dplyr::mutate(
contained_doses = volume * apk,
has_gld_purchases = TRUE
) |>
dplyr::select(-volume, -apk) |>
dplyr::relocate(pnr, date, atc, contained_doses, has_gld_purchases, indication_code)

test_that("dataset needs expected variables", {
actual <- lmdb[-2]
Expand Down

0 comments on commit 76621d2

Please # to comment.