Skip to contents

`r lifecycle::badge("experimental")` Same as `addPriorObservation()`, except query is not computed to a table.

Usage

addPriorObservationQuery(
  x,
  indexDate = "cohort_start_date",
  priorObservationName = "prior_observation",
  priorObservationType = "days"
)

Arguments

x

Table with individuals in the cdm.

indexDate

Variable in x that contains the date to compute the prior observation.

priorObservationName

name of the new column to be added.

priorObservationType

Whether to return a "date" or the number of "days".

Value

cohort table with added column containing prior observation of the individuals.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addPriorObservationQuery()
#> # Source:   SQL [?? x 5]
#> # Database: DuckDB 1.4.1 [unknown@Linux 6.11.0-1018-azure:R 4.5.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          1 1904-06-02        1934-05-13     
#>  2                    1          9 1975-03-02        2008-09-08     
#>  3                    1          7 1988-03-12        1992-04-17     
#>  4                    1          5 1926-05-30        1926-06-26     
#>  5                    3          3 1964-02-03        1973-12-16     
#>  6                    1          6 1924-10-05        1929-03-22     
#>  7                    3         10 1973-06-05        1989-11-18     
#>  8                    3          2 1958-07-25        1965-10-17     
#>  9                    3          4 1927-06-17        1939-02-20     
#> 10                    3          8 1908-06-14        1908-10-08     
#> # ℹ 1 more variable: prior_observation <int>

# }