Skip to content

Commit

Permalink
merge changes introduced by v0.4.3, remove time zone constraint on du…
Browse files Browse the repository at this point in the history
…ckdb tests, but restore it for Postgres tests

Merge branch 'develop' into feature/duckdb

# Conflicts:
#	DESCRIPTION
#	R/database.R
#	R/objects.R
#	tests/testthat/test-objects.R
  • Loading branch information
peterdutey committed Aug 2, 2022
2 parents c586fc2 + bf19c0a commit 959e06e
Show file tree
Hide file tree
Showing 14 changed files with 597 additions and 85 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ on:
- master
- develop
- 'feature/**'
pull_request:
branches:
- master
- develop
- 'bug_fix/**'

name: R-CMD-check

Expand Down
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Ramses
Type: Package
Title: R Package for Antimicrobial Stewardship & Surveillance
Version: 0.4.2
Version: 0.4.3
Authors@R: c(
person(given = "Peter",
family = "Dutey-Magni",
Expand Down Expand Up @@ -30,8 +30,8 @@ Imports:
duckdb (>= 0.4.0),
DBI,
rlang,
dplyr (>= 0.8.3),
dbplyr (>= 1.4.2),
dplyr (>= 1.0.1),
dbplyr (>= 2.1.0),
magrittr,
Rdpack (>= 0.7),
data.table,
Expand Down Expand Up @@ -61,7 +61,7 @@ Suggests:
Remotes:
ramses-antibiotics/snomedizer
RdMacros: Rdpack
RoxygenNote: 7.1.1
RoxygenNote: 7.2.0
VignetteBuilder: knitr,rmarkdown
Collate:
'Ramses-package.R'
Expand Down
18 changes: 17 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@

# Ramses 0.4.3

*2 August 2022*

## Improvements

* upgrade dependency on packages `dplyr` version >= 1.0.1 and `dbplyr` version >= 2.1.0
* improve `validate_inpatient_episodes()` [#85](https://github.com/ramses-antibiotics/ramses-package/issues/85)

## Bug fixes

* fix bug in `map_charlson_comorbidities()` with `tbl_df` objects [#84](https://github.com/ramses-antibiotics/ramses-package/issues/84)
* fix bug in `compute()` with `TherapyEpisode` objects [#83](https://github.com/ramses-antibiotics/ramses-package/issues/83)
* fix uncommon bug in `clinical_feature_*()` functions with PostgreSQL [#88](https://github.com/ramses-antibiotics/ramses-package/issues/88)


# Ramses 0.4.2

*28 January 2022*
Expand Down Expand Up @@ -95,4 +111,4 @@

*8 January 2021*

* First minor version
* First minor version
2 changes: 1 addition & 1 deletion R/clinical_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
dplyr::summarise(n = dplyr::n()) %>%
dplyr::collect()

if ( any(db_observation_codes[["n"]] > 1) ) {
if ( any(as.numeric(db_observation_codes[["n"]]) > 1) ) {
stop(paste0(
"Some codes are ambiguous (exist in multiple code systems): '",
paste(db_observation_codes[db_observation_codes[["n"]] > 1,
Expand Down
2 changes: 1 addition & 1 deletion R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ map_charlson_comorbidities <- function(df, icd_column){
icd_column <- names(df)[icd_column]
}

icd <- unique(df[, icd_column])
icd <- unique(df[[icd_column]])
loc <- lapply(charlson_regex, grep, icd, value = TRUE)
loc <- utils::stack(loc)
names(loc)[1] <- "icd_code"
Expand Down
9 changes: 5 additions & 4 deletions R/objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -594,19 +594,20 @@ setMethod("compute", "TherapyEpisode", function(x) {
.therapy_table_completeness_check(x, x@record)
x@record <- dplyr::compute(x@record)
x@therapy_table <- dplyr::compute(x@therapy_table)

.create_sql_primary_key(
conn = x@conn,
table = x@therapy_table$ops$x$x,
table = dbplyr::remote_name(x@therapy_table),
field = "t, patient_id, therapy_id",
override_index_name = paste0("idx_pk_", x@therapy_table$ops$x$x)
override_index_name = paste0("idx_pk_", dbplyr::remote_name(x@therapy_table))
)
.create_sql_index(
conn = x@conn,
table = x@therapy_table$ops$x$x,
table = dbplyr::remote_name(x@therapy_table),
# TODO deal with tz problem
# fields = "patient_id, (t_start at time zone 'UTC')",
fields = "patient_id, t_start",
override_index_name = paste0("idx_pt_time_", x@therapy_table$ops$x$x)
override_index_name = paste0("idx_pt_time_", dbplyr::remote_name(x@therapy_table))
)

x
Expand Down
12 changes: 10 additions & 2 deletions R/validate_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
if( any(duplicate_results) ){
stop(
simpleError(paste(
"The following variables must have unique values:",
"The following variables must have unique values",
"in the", substitute(data), "dataset:\n",
paste(paste0("`",
must_be_unique[duplicate_results],
names(duplicate_results),
"`"), collapse = ", "))
)
)
Expand Down Expand Up @@ -373,6 +374,13 @@ validate_inpatient_episodes <- function(patients,
stop("All patients in `episodes` must exist in `patients`")
}

variable_uniqueness <- .validate_values_unique(
data = patients,
col_names = patient_schema[
patient_schema$must_be_unique,
"variable_name"]
)

validation_result <- .validate_inpatient_spells(episodes)
validation_result <- append(
.validate_inpatient_episode_dates(data = episodes,
Expand Down
7 changes: 2 additions & 5 deletions man/Ramses-package.Rd

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

7 changes: 7 additions & 0 deletions tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ test_that("ICD-10-CM downloads and maps to Charlson", {
expect_true(icd10_charlson[icd10_charlson$icd_code=="J440", "comorb"] == "copd")
expect_true(icd10_charlson[icd10_charlson$icd_code=="J440", "comorb_group"] == "copd")
expect_equal(icd10_charlson[icd10_charlson$icd_code=="J440", "charlson_weights"], 1)

# Bug 84 fix verification
icd10cm_tbl <- dplyr::as_tibble(icd10cm)
icd10_charlson_tbl <- map_charlson_comorbidities(df = icd10cm_tbl, icd_column = "icd_code")
expect_true(icd10_charlson_tbl[icd10_charlson_tbl$icd_code=="J440", "comorb"] == "copd")
expect_true(icd10_charlson_tbl[icd10_charlson_tbl$icd_code=="J440", "comorb_group"] == "copd")
expect_equal(icd10_charlson_tbl[icd10_charlson_tbl$icd_code=="J440", "charlson_weights"], 1)
})

test_that("Infection mapping", {
Expand Down
Loading

0 comments on commit 959e06e

Please sign in to comment.