darwin-eu-dev / PatientProfiles

https://darwin-eu-dev.github.io/PatientProfiles/
Apache License 2.0
6 stars 5 forks source link

bug in addTableIntersectFlag #637

Closed nmercadeb closed 4 months ago

nmercadeb commented 4 months ago

Working with the development version of PatientProfiles I get the following result for addTableIntersectFlag. Shouldn't subject 3 be "flagged" as well?

cdm_local <- omock::mockCdmReference() |>
  omock::mockPerson(n = 4) |>
  omock::mockObservationPeriod() |>
  omock::mockCohort(tableName = c("cohort1"), numberCohorts = 2)
cdm_local$table <- dplyr::tibble(
  person_id = c(1, 3, 4),
  date_start = as.Date(c("2002-01-01", "2000-01-01", "2000-01-01")),
  date_end = as.Date(c("2002-01-01", "2000-01-01", "2000-01-01"))
)
cdm <- CDMConnector::copy_cdm_to(con = DBI::dbConnect(duckdb::duckdb(), ":memory:"),
                                 cdm = cdm_local,
                                 schema = "main")
cdm$cohort1 %>% 
  PatientProfiles::addTableIntersectFlag(
    tableName = "table",
    indexDate = "cohort_start_date",
    targetStartDate = "date_start",
    targetEndDate = "date_end",
    window = c(-Inf, Inf),
    censorDate = NULL,
    nameStyle = "intersect_table"
  )

# Source:   table<og_027_1712845828> [8 x 5]
# Database: DuckDB v0.10.1 [nmercade@Windows 10 x64:R 4.2.2/:memory:]
  cohort_definition_id subject_id cohort_start_date cohort_end_date intersect_table
                 <int>      <int> <date>            <date>                    <dbl>
1                    1          1 2001-03-30        2003-06-14                    1
2                    1          1 2003-06-15        2005-11-23                    1
3                    1          4 1997-10-22        1999-05-28                    1
4                    2          1 2000-06-23        2001-07-15                    1
5                    2          1 2001-07-16        2001-12-03                    1
6                    2          1 2001-12-04        2006-09-27                    1
7                    1          3 2015-03-25        2015-04-14                    0
8                    2          3 2015-03-05        2015-07-06                    0
nmercadeb commented 4 months ago

Subject 3 was not in observation :')