Skip to content

Commit

Permalink
demographics cohort, measurement cohort
Browse files Browse the repository at this point in the history
  • Loading branch information
edward-burn committed Sep 24, 2024
1 parent 76a1093 commit 0d117fe
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/testthat/test-demographicsCohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ test_that("Example: mixture of parameters", {
omock::mockObservationPeriod() |>
omock::mockCohort(name = c("cohort1"), numberCohorts = 5, seed = 2)
cdm <- cdm_local |> copyCdm()

isDuckdb <- attr(omopgenerics::cdmSource(cdm), "source_type") == "duckdb"
if(isDuckdb){
startTempTables <- countDuckdbTempTables(
con = attr(omopgenerics::cdmSource(cdm),
"dbcon"))
startPermanentTables <- countDuckdbPermanentTables(
con = attr(omopgenerics::cdmSource(cdm),
"dbcon"))
}

expect_no_error(
cdm$cohort3 <- cdm |>
demographicsCohort(name = "cohort3",
Expand All @@ -155,6 +166,22 @@ test_that("Example: mixture of parameters", {
minPriorObservation = 25)
)

if(isDuckdb){
endTempTables <- countDuckdbTempTables(
con = attr(omopgenerics::cdmSource(cdm),
"dbcon"))
endPermanentTables <- countDuckdbPermanentTables(
con = attr(omopgenerics::cdmSource(cdm),
"dbcon"))
# we should have only added 4 permanent tables (the new cohort table and
# three tables with settings, attrition, and codelist)
# no temp tables will have been created
expect_true(startTempTables == endTempTables)
expect_true(
startPermanentTables + 4 == endPermanentTables
)
}

cdm$cohort3 <- cdm$cohort3 |>
PatientProfiles::addPriorObservation()

Expand Down
30 changes: 29 additions & 1 deletion tests/testthat/test-measurementCohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,42 @@ test_that("mearurementCohorts works", {
)
cdm <- cdm |> copyCdm()

# simple example ----
isDuckdb <- attr(omopgenerics::cdmSource(cdm), "source_type") == "duckdb"
if(isDuckdb){
startTempTables <- countDuckdbTempTables(
con = attr(omopgenerics::cdmSource(cdm),
"dbcon"))
startPermanentTables <- countDuckdbPermanentTables(
con = attr(omopgenerics::cdmSource(cdm),
"dbcon"))
}

# simple example
cdm$cohort <- measurementCohort(
cdm = cdm,
name = "cohort",
conceptSet = list("normal_blood_pressure" = c(4326744, 4298393, 45770407)),
valueAsConcept = c(4124457),
valueAsNumber = list("8876" = c(70, 120))
)

if(isDuckdb){
# endTempTables <- countDuckdbTempTables(
# con = attr(omopgenerics::cdmSource(cdm),
# "dbcon"))
endPermanentTables <- countDuckdbPermanentTables(
con = attr(omopgenerics::cdmSource(cdm),
"dbcon"))
# we should have only added 4 permanent tables (the new cohort table and
# three tables with settings, attrition, and codelist)
# no temp tables will have been created
# expect_true(startTempTables == endTempTables)
expect_true(
startPermanentTables + 4 == endPermanentTables
)
}


expect_equal(
collectCohort(cdm$cohort, 1),
dplyr::tibble(
Expand Down

0 comments on commit 0d117fe

Please sign in to comment.