Skip to content

Commit

Permalink
check if tables have been created in the cdm
Browse files Browse the repository at this point in the history
  • Loading branch information
cecicampanile committed Dec 20, 2024
1 parent c297a86 commit 12086dc
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/summariseObservationPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ summariseObservationPeriod <- function(observationPeriod,
) |>
omopgenerics::newSummarisedResult(settings = set)

omopgenerics::dropSourceTable(cdm, name = dplyr::starts_with(tablePrefix))

return(obsSr)
}

Expand Down Expand Up @@ -204,5 +206,6 @@ arrangeSr <- function(x, estimates) {
dplyr::left_join(order, by = c("variable_name", "group_level", "strata_level", "estimate_name")) |>
dplyr::arrange(.data$order_id) |>
dplyr::select(-"order_id")

return(x)
}
25 changes: 25 additions & 0 deletions tests/testthat/test-summariseAllConceptCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,30 @@ test_that("tableAllConceptCounts() works", {
expect_warning(t <- summariseAllConceptCounts(cdm, "death"))
expect_warning(inherits(tableAllConceptCounts(t),"gt_tbl"))

PatientProfiles::mockDisconnect(cdm = cdm)
})
test_that("no tables created", {
skip_on_cran()
# Load mock database ----
cdm <- cdmEunomia()

startNames <- CDMConnector::listSourceTables(cdm)

results <- summariseAllConceptCounts(cdm = cdm,
omopTableName = c("drug_exposure", "condition_occurrence"),
countBy = c("record", "person"),
year=TRUE,
sex = TRUE,
ageGroup = list(c(0,17),
c(18,65),
c(66, 100)),
dateRange = as.Date(c("2012-01-01", "2018-01-01")),
sample = 100)

endNames <- CDMConnector::listSourceTables(cdm)

expect_true(length(setdiff(endNames, startNames)) == 0)


PatientProfiles::mockDisconnect(cdm = cdm)
})
23 changes: 23 additions & 0 deletions tests/testthat/test-summariseClinicalRecords.R
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,26 @@ test_that("summariseClinicalRecords() works with mock data", {
PatientProfiles::mockDisconnect(cdm = cdm)
})

test_that("no tables created", {
skip_on_cran()
# Load mock database ----
cdm <- cdmEunomia()

startNames <- CDMConnector::listSourceTables(cdm)

results <- summariseClinicalRecords(cdm = cdm,
omopTableName = c("drug_exposure", "condition_occurrence"),
sex = TRUE,
ageGroup = list(c(0,17),
c(18,65),
c(66, 100)),
dateRange = as.Date(c("2012-01-01", "2018-01-01")),
sample = 100)

endNames <- CDMConnector::listSourceTables(cdm)

expect_true(length(setdiff(endNames, startNames)) == 0)


PatientProfiles::mockDisconnect(cdm = cdm)
})
25 changes: 25 additions & 0 deletions tests/testthat/test-summariseInObservation.R
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,28 @@ test_that("dateRange argument works", {
expect_equal(colnames(settings(z)), colnames(settings(x)))
PatientProfiles::mockDisconnect(cdm = cdm)
})

test_that("no tables created", {
skip_on_cran()
# Load mock database ----
cdm <- cdmEunomia()

startNames <- CDMConnector::listSourceTables(cdm)

results <- summariseInObservation(cdm$observation_period,
output = c("records", "person-days"),
interval = "years",
sex = TRUE,
ageGroup = list(c(0,17),
c(18,65),
c(66, 100)),
dateRange = as.Date(c("2012-01-01", "2018-01-01")))


endNames <- CDMConnector::listSourceTables(cdm)

expect_true(length(setdiff(endNames, startNames)) == 0)

PatientProfiles::mockDisconnect(cdm = cdm)
})

26 changes: 26 additions & 0 deletions tests/testthat/test-summariseMissingData.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,29 @@ test_that("col not present in table", {

PatientProfiles::mockDisconnect(cdm = cdm)
})

test_that("no tables created", {
skip_on_cran()
# Load mock database ----
cdm <- cdmEunomia()

startNames <- CDMConnector::listSourceTables(cdm)

results <- summariseMissingData(cdm = cdm,
omopTableName = c("drug_exposure", "condition_occurrence"),
year=TRUE,
sex = TRUE,
ageGroup = list(c(0,17),
c(18,65),
c(66, 100)),
dateRange = as.Date(c("2012-01-01", "2018-01-01")),
sample = 100)

endNames <- CDMConnector::listSourceTables(cdm)

expect_true(length(setdiff(endNames, startNames)) == 0)


PatientProfiles::mockDisconnect(cdm = cdm)
})

24 changes: 24 additions & 0 deletions tests/testthat/test-summariseObservationPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,30 @@ test_that("dateRnge argument works", {



PatientProfiles::mockDisconnect(cdm = cdm)
})


test_that("no tables created", {
skip_on_cran()
# Load mock database ----
cdm <- cdmEunomia()

startNames <- CDMConnector::listSourceTables(cdm)

results <- summariseObservationPeriod(cdm$observation_period,
sex = TRUE,
ageGroup = list(c(0,17),
c(18,65),
c(66, 100)),
dateRange = as.Date(c("2012-01-01", "2018-01-01")))


endNames <- CDMConnector::listSourceTables(cdm)

expect_true(length(setdiff(endNames, startNames)) == 0)


PatientProfiles::mockDisconnect(cdm = cdm)
})

26 changes: 26 additions & 0 deletions tests/testthat/test-summariseRecordCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,29 @@ test_that("sample argument works", {
expect_equal(y,z)
PatientProfiles::mockDisconnect(cdm = cdm)
})

test_that("no tables created", {
skip_on_cran()
# Load mock database ----
cdm <- cdmEunomia()

startNames <- CDMConnector::listSourceTables(cdm)

results <- summariseRecordCount(cdm = cdm,
omopTableName = c("drug_exposure", "condition_occurrence"),
interval = "years",
sex = TRUE,
ageGroup = list(c(0,17),
c(18,65),
c(66, 100)),
dateRange = as.Date(c("2012-01-01", "2018-01-01")),
sample = 100)

endNames <- CDMConnector::listSourceTables(cdm)

expect_true(length(setdiff(endNames, startNames)) == 0)


PatientProfiles::mockDisconnect(cdm = cdm)
})

0 comments on commit 12086dc

Please sign in to comment.