Error in `CDMConnector::dateadd()`: No known SQL translation

start_tables <- CDMConnector::listTables(attr(attr(cdm, "cdm_source"), "dbcon"),
schema = attr(attr(cdm, "cdm_source"), "write_schema"))
end_tables <- CDMConnector::listTables(attr(attr(cdm, "cdm_source"), "dbcon"),

cdm <- mockIncidencePrevalenceRef(sampleSize = 100)
x <- dplyr::tibble(incidence_result = 0.65, analysis_id = 1)
attr(x, "settings") <- dplyr::tibble(analysis_id = 1, b = "a")
analysis_id = 1, denominator_cohort_name = "this"
class(x) <- c("IncidencePrevalenceResult", "IncidenceResult", class(x))
y <- dplyr::tibble(incidence_result = c(0.45, 0.99, 0.1),
attr(y, "settings") <- dplyr::tibble(analysis_id = c(2, 3, 4),
denominator_cohort_name = c("is", "a", "test")
class(y) <- c("IncidencePrevalenceResult", "IncidenceResult", class(y))
expectedInc <- dplyr::bind_rows(x, y, .id = "result_id")
class(x) <- c("PrevalenceResult", class(x)[!(class(x) == "IncidenceResult")])
class(y) <- c("PrevalenceResult", class(y)[!(class(y) == "IncidenceResult")])
expectedPrev <- dplyr::bind_rows(x, y, .id = "result_id")

test_that("mock db: check output format", {
# by default we don´t return the participants
cdm <- generateDenominatorCohortSet(cdm = cdm, name = "denominator")
expect_true(is.list(participants(prev, 1))) # list of references to participants
test_that("mock db: checks on working example", {
test_that("mock db: working examples 2", {
test_that("mock db: check minimum counts", {
expect_true(!is.na(prev$n_cases[3])) # don't suppress zero
test_that("mock db: check study time periods", {
# we expect 12 months of which the last in December
# the last month should also be included
# as the person goes up to the last day of the month
test_that("mock db: check fullContribution requirement", {
observation_period_id = c("1", "2", "3"),
expect_true(all(prev$n_population == c(2, 1, 1)))
"Do not satisfy full contribution requirement for an interval") %>%
test_that("mock db: check periods follow calendar dates", {
# check that even if study_start_date is during a period
# if completeDatabaseIntervals is TRUE we should go from 2010 to 2013
# but if FALSE we should go from 2011 to 2012
# where we expect the study to start on 2011-01-15
# where we expect the study to start the next month
test_that("mock db: check multiple outcome ids", {
cohort_definition_id = c(1, 2), # two different outcome ids
test_that("mock db: some empty result sets", {
test_that("mock db: check expected errors", {
test_that("mock db: check user point prevalence function", {
test_that("mock db: check user period prevalence function", {
test_that("mock db: multiple observation periods", {
# create data for hypothetical people to test
# three observation periods for 1 person
# and a couple of consecutive events lost to washout
cohort_definition_id = c(1, 1, 1, 1, 1, 1, 1),
# as for point prevalence, we would expect no positive n_cases at default
test_that("mock db: check confidence intervals", {
cdm <- mockIncidencePrevalenceRef(sampleSize = 1000)
# compare our wilson CIs with those from Hmisc
# for female cohort we should have a row for those excluded for not being male
expect_true(any("Not Female" == attrition(prev) %>%
expect_true(any("Not Male" == attrition(prev) %>%
# check we can pick out specific analysis attrition
test_that("mock db: check attrition with complete database intervals", {
dplyr::filter(reason == "Not observed during the complete database interval") %>%
test_that("mock db: check compute permanent", {
attr(attr(cdm, "cdm_source"), "write_schema") <- "main"
schema = attr(attr(cdm, "cdm_source"), "write_schema")
test_that("mock db: check participants", {
# we should have one new database table with our participants
# everything else should have been cleaned up along the way
prev_participants <- participants(prev, 1) %>% dplyr::collect()
end_tables2 <- CDMConnector::listTables(attr(attr(cdm, "cdm_source"), "dbcon"),
# we should have another new database table with our participants from the
# with participants from first analysis unchanged
test_that("mock db: overwriting participants", {
prev1_count <- nrow(participants(prev1, 1) %>% dplyr::collect())
# participants from prev1 should still be the same
# (ie no interference from having rerun the function)
expect_true(nrow(participants(prev1, 1) %>% dplyr::collect()) == prev1_count)
# we should have two tables with participants
test_that("mock db: if missing cohort attributes", {
test_that("mock db: test empty outcome table works", {
cdm[["outcome"]] <- cdm[["outcome"]] %>% dplyr::filter(cohort_definition_id == 33)
test_that("mock db: prevalence using strata vars", {
cdm <- mockIncidencePrevalenceRef(sampleSize = 1000,
cdm <- generateDenominatorCohortSet(cdm = cdm,
dplyr::mutate(my_strata = dplyr::if_else(year(cohort_start_date) < 1990,
# original without strata should be the same as "Overall" strata
expect_true(all(c("Overall", "my_strata and my_strata2") %in%