-
Notifications
You must be signed in to change notification settings - Fork 1
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: function to join the LPR2 registers #118
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3d83ef8
feat: create (draft) function to include hba1c criteria
lwjohnst86 d7093bb
feat: internal function to extract logic from algorithm data. Untested
lwjohnst86 e65b1b6
docs: add roxygen docs to logic getter
lwjohnst86 e45e1e2
docs: keep this function as internal only
lwjohnst86 b4c36da
refactor: keep only earliest two dates, might not work with some data…
lwjohnst86 ed7bb34
docs: regenerated the roxygen docs
lwjohnst86 a44448d
Merged origin/main into main
lwjohnst86 b477b0a
Merged origin/main into main
lwjohnst86 fb401be
docs: apply suggestions from review
lwjohnst86 dfb0b79
Merge branch 'main' of https://github.com/steno-aarhus/osdc
lwjohnst86 f25c183
Merge branch 'main' of https://github.com/steno-aarhus/osdc
lwjohnst86 727ef7c
feat: :sparkles: add the function to join the LPR2 registers
lwjohnst86 0d3c2cd
test: :white_check_mark: add a unit test for the `join_lpr2()` function
lwjohnst86 2482433
chore: regenerate roxygen docs
lwjohnst86 e70cc5c
Merged origin/main into feat/include-hba1c-criteria
lwjohnst86 8c532f9
Merge branch 'feat/include-hba1c-criteria' of https://github.com/sten…
lwjohnst86 2668ef2
Merge branch 'main' of https://github.com/steno-aarhus/osdc into feat…
lwjohnst86 e784741
Expanded tests a bit to more accurately replicate real life data
acadc6c
Merge branch 'main' into feat/join-lpr2
Aastedet 6484724
Changed to inner join and added non-joinable rows to simulate bad dat…
4f8d296
Merge branch 'feat/join-lpr2' of https://github.com/steno-aarhus/osdc…
5f8e800
docs: lpr_adm should be first in argument list
lwjohnst86 8f73a6c
style: only reformatting
lwjohnst86 df9cc09
test: add helper script to set Arrow options for warnings
lwjohnst86 4b0f391
test: revise to test if other data sources also calculate correctly
lwjohnst86 2d61df6
Merged origin/main into feat/join-lpr2
lwjohnst86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#' Join together the LPR2 (`lpr_diag` and `lpr_adm`) registers. | ||
#' | ||
#' @param lpr_diag The diagnosis register. | ||
#' @param lpr_adm The admission register. | ||
#' | ||
#' @return The same class as the input, defaults to a [tibble::tibble()]. | ||
#' @keywords internal | ||
#' | ||
#' @examples | ||
#' register_data$lpr_adm |> | ||
#' join_lpr2(register_data$lpr_diag) | ||
join_lpr2 <- function(lpr_adm, lpr_diag) { | ||
verify_required_variables(lpr_adm, "lpr_adm") | ||
verify_required_variables(lpr_diag, "lpr_diag") | ||
dplyr::inner_join( | ||
column_names_to_lower(lpr_adm), | ||
column_names_to_lower(lpr_diag), | ||
by = "recnum" | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# There is a warning when using Arrow about using pull. It says to set | ||
# this option. | ||
options(arrow.pull_as_vector = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
actual_lpr_diag <- tibble::tibble( | ||
recnum = rep(1:6, each = 2), | ||
c_diag = 1:12, | ||
c_diagtype = rep(c("A", "B"), 6) | ||
) | ||
|
||
actual_lpr_adm <- tibble::tibble( | ||
pnr = rep(1:2, 3), | ||
recnum = 2:7, | ||
c_spec = 1:6, | ||
d_inddto = c("20230101", "20220101", "20210101", "20200101", "20190101", "20180101"), | ||
) | ||
|
||
expected_lpr2 <- tibble::tibble( | ||
pnr = rep(1:2, length.out = 10, each = 2), | ||
recnum = rep(2:6, length.out = 10, each = 2), | ||
c_spec = rep(1:5, length.out = 10, each = 2), | ||
d_inddto = rep(c("20230101", "20220101", "20210101", "20200101", "20190101"), each = 2), | ||
c_diag = 3:12, | ||
c_diagtype = rep(c("A", "B"), length.out = 10) | ||
) | ||
|
||
test_that("joining LPR2 correctly", { | ||
actual <- join_lpr2( | ||
actual_lpr_adm, | ||
actual_lpr_diag | ||
) | ||
|
||
expect_equal(actual, expected_lpr2) | ||
}) | ||
|
||
test_that("lpr_adm and lpr_diag must be in correct arg position", { | ||
expect_error(join_lpr2( | ||
actual_lpr_diag, | ||
actual_lpr_adm | ||
)) | ||
}) | ||
|
||
test_that("joining works for DuckDB Database", { | ||
actual <- arrow::to_duckdb(actual_lpr_adm) |> | ||
join_lpr2(arrow::to_duckdb(actual_lpr_diag)) | ||
|
||
actual_rows <- actual |> | ||
dplyr::count() |> | ||
dplyr::pull(n) |> | ||
as.integer() | ||
|
||
expect_contains(class(actual), "tbl_duckdb_connection") | ||
expect_identical(colnames(actual), colnames(expected_lpr2)) | ||
expect_identical(actual_rows, nrow(expected_lpr2)) | ||
}) | ||
|
||
test_that("joining works for Arrow Tables (from Parquet)", { | ||
actual <- arrow::as_arrow_table(actual_lpr_adm) |> | ||
join_lpr2(arrow::as_arrow_table(actual_lpr_diag)) | ||
|
||
actual_rows <- actual |> | ||
dplyr::count() |> | ||
dplyr::pull(n) |> | ||
as.integer() | ||
|
||
expect_contains(class(actual), "arrow_dplyr_query") | ||
expect_identical(names(actual), colnames(expected_lpr2)) | ||
expect_identical(actual_rows, nrow(expected_lpr2)) | ||
}) | ||
|
||
test_that("joining works for data.frame", { | ||
actual <- as.data.frame(actual_lpr_adm) |> | ||
join_lpr2(as.data.frame(actual_lpr_diag)) | ||
|
||
actual_rows <- actual |> | ||
dplyr::count() |> | ||
dplyr::pull(n) |> | ||
as.integer() | ||
|
||
expect_contains(class(actual), "data.frame") | ||
expect_identical(names(actual), colnames(expected_lpr2)) | ||
expect_identical(actual_rows, nrow(expected_lpr2)) | ||
}) | ||
|
||
test_that("joining works for data.table", { | ||
actual <- data.table::as.data.table(actual_lpr_adm) |> | ||
join_lpr2(data.table::as.data.table(actual_lpr_diag)) | ||
|
||
actual_rows <- actual |> | ||
dplyr::count() |> | ||
dplyr::pull(n) |> | ||
as.integer() | ||
|
||
expect_contains(class(actual), "data.table") | ||
expect_identical(colnames(actual), colnames(expected_lpr2)) | ||
expect_identical(actual_rows, nrow(expected_lpr2)) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
c_pattype
missing here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um,
c_pattype
isn't in the variable list.