"mock db: check fullContribution requirement"
"Do not satisfy full contribution requirement for an interval"
"mock db: check periods follow calendar dates"
"mock db: check user point prevalence function"
"mock db: check user period prevalence function"
"mock db: check attrition with complete database intervals"
"Not observed during the complete database interval"
"mock db: test empty outcome table works"

resultList = list("incidence_estimate" = inc), zipName = "test",
test_that("writing results- expected errors", {
cdm <- generateDenominatorCohortSet(cdm = cdm,name = "denominator")
result = results, zipName = "test_should_fail",

con =  attr(attr(cdm, "cdm_source"), "dbcon"),
write_schema = "main", cdm_schema = "main", cdm_name = "mock"
test_that("mock db: check working example 2", {
# if outcomeWashout=NULL (all of history)
# then it won´t be possible to have any recurrent events
test_that("mock db: check study periods", {
# we expect 12 months of which the last in december
# now with completeDatabaseIntervals is TRUE
# we expect 10 months of which the last in november
# we expect one row with the overall results
# one person had the event before the study period
# one person had the event during the study period
as.Date("2010-02-05")) # date of first event
as.Date("2011-06-15")) # date of end of obs
test_that("mock db: check person days", {
# in 2019 we expect person 2 to contribute from 1st july to end of December
# in 2020 we expect person 2 to contribute all year
# and person 1 from 1st January to end of December
# in 2021 we expect person 2 to contribute all year
# and person 1 from 1st January up to 27th june (date of their outcome)
# in 2022 we expect person 2 to contribute all year
# (person 1 is out- they have had an event)
# check that even if startDate as during a period
# startDate during a year (with year as interval)
cdm = cdm, name = "denominator", cohortDateRange = c(as.Date("2010-02-01"), as.Date(NA))
# startDate during a month (with month as interval)
test_that("mock db: check washout windows", {
# more than six months since the last event
# two days since the end of the last event
# one day since the end of the last event
# expect all events if we have zero days washout
# expect three events if we have one days washout
# expect two events if we have two days washout
# expect one event if we have 365 days washout
# expect one event if we have NULL (all history washout)
# but, we will have move days when using the 365 day washout
# as the person came back to contribute more time at risk
# never satisfy criteria in study period
test_that("mock db: check events overlapping with start of a period", {
test_that("mock db: compare results from months and years", {
cdm = cdm, name = "denominator", cohortDateRange = c(as.Date("2010-01-01"), as.Date("2011-12-31"))
# consistent results for months and years
test_that("mock db: check entry and event on same day", {
test_that("mock db: cohort start overlaps with the outcome", {
test_that("mock db: check outcome in previous obeservation period", {
# 1) with outcome starting and ending before observation period start
observation_period_id = c("1", "2" ,"3"),
# with rep events - should have both people
# with inf wash out- should only have 1 person
# with 5 year wash out- should have 2 people at the start of the study period
test_that("mock db: multiple overlapping outcomes", {
test_that("mock db: cohort before period start ending after period", {
cdm = cdm, name = "denominator", cohortDateRange = c(as.Date("2001-01-01"), as.Date("2001-12-31"))
# regardless of washout we expect one event
# person 1s outcome starts before period and ends after
test_that("mock db: check full period requirement - year", {
# edge case first day to last of the year
test_that("mock db: check full period requirement - month", {
# edge case first day to last of the month
test_that("mock db: check completeDatabaseIntervals", {
# - we expect to start in 2020 (both start during 2019)
# - we expect to go up to 2021 (id 2 end date is in 2022)
# - now we expect only to use 2020 (id 2 obs end is in 21)
test_that("mock db: check insufficient study days", {
# so we should return an empty tibble if full periods are required
# and we´re looking for yearly incidence
test_that("mock db: check with and without study start and end date", {
# 1 event before obs start ending after obs end
cdm <- generateDenominatorCohortSet(cdm = cdm, name = "denominator1")
# given the settings above we would expect the same results for 2010
test_that("mock db: check study start and end date 1000", {
test_that("expected errors with mock", {
# outcome definition id doesn't exist in cohort set
# should only pick up one of the four observation periods,
# as the inclusion of the cohorts is only well defined for one
# (entry event in the observation period)
# Change the inclusion so that both patients have valid observation periods. Now 1 should have two, and 2 one.
# Should capture the final part of the first observation period, and the initial part of the second for person 1
# expect all events if we have ten days washout
# try event not counted for outcome but counted for washout as denominator (before observ period)
cohort_definition_id = c(1, 1, 1, 1, 1),
# now we would expect same number of events, but three less days in the denominator
# multiple events in one of the observation periods of person 1
# we should have 4 events with washout 0, but 3 events with washout 30
# The first event of person 1 will not be included in the observation period
# but should also influence the second event with the washout
# we should have 2 events with washout 30
expect_true(inc_PreWashEv %>% dplyr::select(person_days) %>% sum() ==
# three observation periods for 1 person and a
# couple of consecutive events lost to washout
# we should have 5 events with washout 1
expect_true(any("Not Male" == attrition(inc) %>%
cdm <- mockIncidencePrevalenceRef(sampleSize = 4)
cdm <- mockIncidencePrevalenceRef(sampleSize = 10)
cdm <- omopgenerics::insertTable(cdm = cdm,
# we should have cleaned up all the intermediate tables
attr(cdm, "write_schema") <- c(schema = "main", prefix = "test_")
inc1_count <- nrow(participants(inc1, 1) %>% dplyr::collect())
expect_true(nrow(participants(inc1, 1) %>% dplyr::collect()) == inc1_count)
# # we should have two tables with participants
#     schema = attr(cdm, "write_schema")
test_that("mock db: empty outcome cohort", {
cdm <- mockIncidencePrevalenceRef(sampleSize = 200)
cdm$outcome <-  cdm$outcome %>% dplyr::filter(cohort_definition_id == 99)
# make sure we also have a confidence interval even in the case of an empty outcome cohort
test_that("mock db: incidence using strata vars", {
cdm <- mockIncidencePrevalenceRef(sampleSize = 2000,
dplyr::mutate(my_strata = dplyr::if_else(year(cohort_start_date) < 1995,