### Install PatientProfiles Package Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Install the latest version of the PatientProfiles R package from CRAN. This is the standard method for obtaining the package. ```r install.packages("PatientProfiles") ``` -------------------------------- ### Add Age, Age Groups, Sex, and Prior Observation to Cohort Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Enhance a cohort table by adding age, age groups, sex, and days of prior observation relative to the cohort start date. Ensure the necessary functions are available. ```r cdm$cohort1 <- cdm$cohort1 |> addAge( indexDate = "cohort_start_date", ageGroup = list(c(0, 18), c(19, 65), c(66, 100)) ) |> addSex() |> addPriorObservation() cdm$cohort1 |> glimpse() ``` -------------------------------- ### Add Observation Windows to Cohort Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Adds flags indicating presence within specified observation windows relative to the cohort start date using addInObservation. ```r cdm$gibleed | addInObservation( indexDate = "cohort_start_date", window = list("obs_index_date" = c(0, 0), "in_1_year" = c(365, 365)), nameStyle = "{window_name}" ) | addObservationPeriodId() | dplyr::glimpse() ``` -------------------------------- ### Filter Cohort by Prior Observation Days Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Subset a cohort to include only individuals with a specified minimum number of days of prior observation before their cohort start date. This is useful for ensuring sufficient historical data. ```r cdm$cohort1 |> filter(prior_observation >= 365) ``` -------------------------------- ### Add Cohort Intersection Flag Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Add a flag to indicate the presence of another cohort (`cohort2`) within a specified time window relative to the primary cohort's dates. The window `c(-Inf, -1)` checks for occurrences before the cohort start date. ```r cdm$cohort1 <- cdm$cohort1 |> addCohortIntersectFlag( targetCohortTable = "cohort2", window = c(-Inf, -1) ) cdm$cohort1 |> glimpse() ``` -------------------------------- ### Connect to PostgreSQL CDM Database Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Establishes a connection to a PostgreSQL database containing OMOP CDM data. Ensure environment variables for database credentials are set. ```r library(RPostgres) library(CDMConnector) con <- dbConnect( drv = Postgres(), dbname = Sys.getenv("CDM5_POSTGRESQL_DBNAME"), host = Sys.getenv("CDM5_POSTGRESQL_HOST"), user = Sys.getenv("CDM5_POSTGRESQL_USER"), password = Sys.getenv("CDM5_POSTGRESQL_PASSWORD") ) cdm <- cdmFromCon( con = con, cdmSchema = Sys.getenv("CDM5_POSTGRESQL_CDM_SCHEMA"), writeSchema = Sys.getenv("CDM5_POSTGRESQL_RESULT_SCHEMA") ) ``` -------------------------------- ### Connect to Database and Generate Cohorts Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Connects to a DuckDB database, creates a CDM reference, and generates concept cohorts for 'gibleed' and 'conditions'. ```r con <- dbConnect(duckdb(), eunomiaDir()) cdm <- cdmFromCon(con = con, cdmSchema = "main", writeSchema = "main") |> generateConceptCohortSet( conceptSet = list(gibleed = 192671), name = "gibleed") |> generateConceptCohortSet( conceptSet = list(asthma = 317009, ulcerative_colitis = 81893), name = "conditions") ``` -------------------------------- ### Load CDMConnector and DuckDB Libraries Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Loads the necessary CDMConnector and DuckDB libraries for database interaction. ```r library(CDMConnector) library(duckdb) ``` -------------------------------- ### Inspect Initial Cohort Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Use `glimpse()` to inspect the structure and initial rows of a cohort table before modifications. ```r cdm$cohort1 |> glimpse() ``` -------------------------------- ### Create Mock OMOP CDM Data Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/paper.md Generates mock OMOP CDM data for use with the PatientProfiles package. This toy data is copied into an in-process duckdb database by default. Custom cohorts can be defined from existing cohort tables. ```r library(PatientProfiles) cdm <- mockPatientProfiles(numberIndividuals = 1000) # to customise cohorts cdm$my_flu_cohort <- cdm$cohort1 |> dplyr::filter(cohort_definition_id == 1L) |> omopgenerics::newCohortTable(cohortSetRef = dplyr::tibble( cohort_definition_id = 1L, cohort_name = "flu" )) cdm$target <- cdm$cohort2 |> omopgenerics::newCohortTable(cohortSetRef = dplyr::tibble( cohort_definition_id = c(1L, 2L, 3L), cohort_name = c("covid_test", "flu_test", "asthma") )) ``` -------------------------------- ### Create Mock PatientProfiles CDM Reference Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Generates a simulated CDM reference for testing purposes using mockPatientProfiles. This is useful when direct database access is not available. ```r cdm <- mockPatientProfiles(numberIndividuals = 1000, source = "duckdb") ``` -------------------------------- ### Inspect Cohort Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Use glimpse() to inspect the structure of a cohort table before adding characteristics. ```r cdm$cohort1 |> glimpse() ``` -------------------------------- ### Mock Patient Profiles CDM Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Creates a mock PatientProfiles CDM with a specified number of individuals and source database. Useful for testing and development. ```r library(PatientProfiles) library(duckdb) library(dplyr) cdm <- mockPatientProfiles(numberIndividuals = 10000, source = "duckdb") ``` -------------------------------- ### Inspect Cohort Table Before Multiple Additions Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Inspect the structure of cohort2 before adding multiple demographic characteristics at once. ```r cdm$cohort2 |> glimpse() ``` -------------------------------- ### Display CDM Reference Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Prints the CDM reference object to display information about the OMOP CDM tables and generated cohorts. ```r cdm ``` -------------------------------- ### Inspect Condition Occurrence Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Displays the structure and a sample of the 'condition_occurrence' table from the CDM reference. This helps in understanding the available columns and data types. ```r cdm$condition_occurrence | glimpse() #> Rows: ?? #> Columns: 6 #> Database: DuckDB 1.4.0 [root@Darwin 24.6.0:R 4.4.1/:memory:] #> $ person_id 814, 640, 731, 853, 505, 817, 270, 313, 138,... #> $ condition_start_date 2008-02-05, 1920-08-28, 1970-04-23, 1915-04... #> $ condition_end_date 2009-10-30, 1928-01-13, 1970-08-02, 1924-02... #> $ condition_occurrence_id 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1… #> $ condition_concept_id 5, 6, 8, 2, 7, 9, 2, 4, 2, 1, 5, 4, 3, 6, 8,... #> $ condition_type_concept_id 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... ``` -------------------------------- ### Load PatientProfiles and dplyr Libraries Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Loads the necessary PatientProfiles and dplyr libraries for data manipulation and analysis. ```r library(PatientProfiles) library(dplyr) ``` -------------------------------- ### Add Age with Custom Defaults Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add an 'age_from_year_of_birth' column, imposing January 1st as the month and day of birth. This is useful when only the year of birth is known. ```r cdm$condition_occurrence <- cdm$condition_occurrence |> addAge( indexDate = "condition_start_date", ageName = "age_from_year_of_birth", ageMissingMonth = 1, ageMissingDay = 1, ageImposeMonth = TRUE, ageImposeDay = TRUE ) cdm$condition_occurrence |> glimpse() ``` -------------------------------- ### Inspect Condition Occurrence Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Use glimpse() to inspect the structure of the condition_occurrence table. ```r cdm$condition_occurrence |> glimpse() ``` -------------------------------- ### Glimpse Person Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Displays the structure and column information of the person table within the CDM. Helps understand the available demographic fields. ```r cdm$person %>% dplyr::glimpse() ``` -------------------------------- ### Summarise Data with summariseResult() Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/paper.md Use summariseResult() to aggregate multiple columns into various estimates. Specify grouping, strata, variables, and estimate types for custom summaries. ```R cdm$cohort1 |> addCohortName() |> summariseResult( group = "cohort_name", strata = list("sex", c("sex", "prior_asthma")), variables = list(c("number_visits", "age"), c("covid_test_1_to_inf", "flu_test_1_to_inf")), estimates = list(c("median", "q25", "q75"), c("min", "max")) ) |> dplyr::glimpse() ``` -------------------------------- ### Glimpse Observation Period Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Displays the structure and column information of the observation_period table within the CDM. Useful for understanding patient observation spans. ```r cdm$observation_period %>% dplyr::glimpse() ``` -------------------------------- ### Cite PatientProfiles Package Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Provides the citation information for the PatientProfiles R package, including a standard citation and a BibTeX entry for LaTeX users. ```r citation("PatientProfiles") #> To cite package 'PatientProfiles' in publications use: #> #> Català M, Guo Y, Du M, Lopez-Guell K, Burn E, Mercade-Besora N #> (????). _PatientProfiles: Identify Characteristics of Patients in the #> OMOP Common Data Model_. R package version 1.4.3, #> . #> #> A BibTeX entry for LaTeX users is #> #> @Manual{ #> title = {PatientProfiles: Identify Characteristics of Patients in the OMOP Common Data Model}, #> author = {Martí Català and Yuchen Guo and Mike Du and Kim Lopez-Guell and Edward Burn and Nuria Mercade-Besora}, #> note = {R package version 1.4.3}, #> url = {https://darwin-eu.github.io/PatientProfiles/}, #> } ``` -------------------------------- ### Add Individual Demographic Characteristics Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add age, sex, and observation period characteristics individually to a cohort table. The default index date is 'cohort_start_date'. ```r cdm$cohort1 <- cdm$cohort1 |> addAge(ageGroup = list( "0 to 17" = c(0, 17), "18 to 65" = c(18, 65), ">= 66" = c(66, Inf) )) |> addSex() | addInObservation() | addPriorObservation() | addFutureObservation() cdm$cohort1 |> glimpse() ``` -------------------------------- ### Add Multiple Characteristics Sequentially Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add multiple demographic characteristics sequentially to a cohort table and time the operation. This method can be less efficient for large datasets. ```r tictoc::tic() cdm$cohort2 |> addAge(ageGroup = list( "0 to 17" = c(0, 17), "18 to 65" = c(18, 65), ">= 66" = c(66, Inf) )) | addSex() | addInObservation() | addPriorObservation() | addFutureObservation() tictoc::toc() ``` -------------------------------- ### Add Age Groups to Condition Occurrence Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add age groups (0-17, 18-65, >=66) to the condition_occurrence table using the condition_start_date as the index. This allows for categorized age analysis. ```r cdm$condition_occurrence <- cdm$condition_occurrence |> addAge(indexDate = "condition_start_date", ageGroup = list( "0 to 17" = c(0, 17), "18 to 65" = c(18, 65), ">= 66" = c(66, Inf) ) ) cdm$condition_occurrence |> glimpse() ``` -------------------------------- ### Add Observation Status and Prior/Future Observation Time Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add columns indicating if a patient was in observation on the index date, the prior observation time, and the future observation time. Results are NA if the patient is not under observation on the index date. ```r cdm$condition_occurrence <- cdm$condition_occurrence |> addInObservation(indexDate = "condition_start_date") |> addPriorObservation(indexDate = "condition_start_date") |> addFutureObservation(indexDate = "condition_start_date") cdm$condition_occurrence |> glimpse() ``` -------------------------------- ### Add Age and Sex to Condition Occurrences Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Augments the 'condition_occurrence' table by adding 'age' and 'sex' columns. 'age' is calculated based on 'condition_start_date', and 'sex' is directly added. ```r cdm$condition_occurrence <- cdm$condition_occurrence | addAge(indexDate = "condition_start_date") | addSex() cdm$condition_occurrence | glimpse() #> Rows: ?? #> Columns: 8 #> Database: DuckDB 1.4.0 [root@Darwin 24.6.0:R 4.4.1/:memory:] #> $ person_id 138, 174, 207, 216, 239, 270, 276, 313, 317,... #> $ condition_start_date 1939-09-09, 1912-06-21, 1926-12-14, 1928-05... #> $ condition_end_date 1948-11-09, 1927-04-21, 1937-09-29, 1931-04... #> $ condition_occurrence_id 9, 12, 23, 13, 32, 7, 20, 8, 24, 33, 14, 28,... #> $ condition_concept_id 2, 4, 3, 3, 7, 2, 10, 4, 4, 2, 6, 9, 5, 8, 7... #> $ condition_type_concept_id 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... #> $ age 6, 4, 13, 8, 32, 18, 0, 25, 19, 34, 45, 38, ... #> $ sex "Female", "Male", "Female", "Male", "Male", ... ``` -------------------------------- ### Add Multiple Demographics Efficiently Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add multiple demographic characteristics simultaneously using addDemographics() for improved efficiency, especially with large datasets. This function requires fewer joins. ```r tictoc::tic() cdm$cohort2 | addDemographics( age = TRUE, ageName = "age", ageGroup = list( "0 to 17" = c(0, 17), "18 to 65" = c(18, 65), ">= 66" = c(66, Inf) ), sex = TRUE, sexName = "sex", priorObservation = TRUE, priorObservationName = "prior_observation", futureObservation = FALSE, ) |> glimpse() tictoc::toc() ``` -------------------------------- ### Add Observation Period Information to Cohort Data Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/paper.md Applies `addInObservation` to identify observation windows and `addObservationPeriodId` to assign observation period IDs. Use this to enrich cohort data with temporal observation status. ```r cdm$gibleed |> addInObservation( indexDate = "cohort_start_date", window = list("obs_index_date" = c(0, 0), "in_1_year" = c(365, 365)), nameStyle = "{window_name}" ) |> addObservationPeriodId() |> dplyr::glimpse() ``` -------------------------------- ### Check Complete Observation within a Future Window Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add a variable indicating if a patient was in observation for at least a year in the future, using `completeInterval = FALSE` to check for any duration within the window. ```r cdm$condition_occurrence |> addInObservation( indexDate = "condition_start_date", window = c(365, Inf), completeInterval = FALSE ) |> glimpse() ``` -------------------------------- ### Add Age to Condition Occurrence Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add an 'age' column to the condition_occurrence table based on the condition_start_date. This function links to the person table to calculate age. ```r cdm$condition_occurrence <- cdm$condition_occurrence |> addAge(indexDate = "condition_start_date") cdm$condition_occurrence |> glimpse() ``` -------------------------------- ### Add First Cohort Intersection Date Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Use `addCohortIntersectDate` with `order = "first"` to add a column with the date of the first occurrence of a target cohort within a specified window. The `window` can be set to `c(-Inf, Inf)` to consider all time. ```r cdm$cohort1 <- cdm$cohort1 | addCohortIntersectDate( targetCohortTable = "cohort2", targetCohortId = 1, order = "first", window = c(-Inf, Inf) ) ``` -------------------------------- ### Add Cohort Intersection Days Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Calculates the number of days to the intersection with a target cohort. Use this when you need the time difference instead of a date. The `window` parameter defines the observation period. ```r cdm$cohort1 <- cdm$cohort1 |> addCohortIntersectDays( targetCohortTable = "cohort2", targetCohortId = 1, order = "last", window = c(-Inf, Inf) ) ``` -------------------------------- ### Summarize Patient Cohort Data Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Generates a summary of the enriched patient cohort data, including counts, medians, and ranges for various variables, stratified by demographic and cohort information. This is useful for descriptive statistics and cohort profiling. ```r cdm$gibleed |> addCohortName() |> summariseResult( group = "cohort_name", strata = list("sex", c("sex", "prior_asthma")), variables = list(c("number_visits", "age"), c("next_uc"), "age_group"), estimates = list(c("median", "q25", "q75"), c("min", "max"), "count") ) |> dplyr::glimpse() ``` -------------------------------- ### Count Cohort Intersections in a Window Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Use `addCohortIntersectCount` to add columns indicating the number of times a target cohort appears within specified windows relative to the main cohort. The `window` parameter accepts a named list for different time frames. ```r cdm$cohort1 <- cdm$cohort1 | addCohortIntersectCount( targetCohortTable = "cohort2", targetCohortId = 1, window = list("short_term" = c(1, 30), "mid_term" = c(31, 180)) ) ``` -------------------------------- ### Check Observation within a Window Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add a variable indicating if a patient was in observation within a specified window, e.g., from 180 days before to 30 days after the index date. ```r cdm$condition_occurrence |> addInObservation( indexDate = "condition_start_date", window = c(-180, 30) ) |> glimpse() ``` -------------------------------- ### Add Table Intersection Counts and Cohort Intersection Flags Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Calculates the number of visits within a window and flags prior occurrences of another cohort using addTableIntersectCount and addCohortIntersectFlag. ```r cdm$gibleed | addTableIntersectCount( tableName = "visit_occurrence", window = c(-365, 0), nameStyle = "number_visits" ) | addCohortIntersectFlag( targetCohortTable = "conditions", targetCohortId = 1, window = c(-Inf, 0), nameStyle = "prior_asthma" ) | dplyr::glimpse() ``` -------------------------------- ### Add Visit Count and Asthma Flag to Cohort Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/paper.md Use this snippet to add the number of visits and a flag for prior asthma records to a cohort. It requires the `addTableIntersectCount` and `addCohortIntersectFlag` functions. ```r cdm$cohort1 |> addTableIntersectCount( tableName = "visit_occurrence", window = c(-365, 0), nameStyle = "number_visits" ) |> addCohortIntersectFlag( cohortTableName = "cohort2", cohortId = 3, window = c(-Inf, 0), nameStyle = "prior_asthma" ) |> dplyr::glimpse() ``` -------------------------------- ### Combine Multiple Cohort Intersects Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Chains multiple cohort intersection operations using the pipe operator. This allows for combining date intersections and count intersections in a single pipeline. Ensure the `window` parameter is correctly set for each operation. ```r cdm$cohort1 <- cdm$cohort1 |> addCohortIntersectDate( targetCohortTable = "cohort2", targetCohortId = 1, order = "last", window = c(-Inf, Inf) ) |> addCohortIntersectCount( targetCohortTable = "cohort2", targetCohortId = 1, window = c(-Inf, Inf) ) ``` -------------------------------- ### Add Last Cohort Intersection Date Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Use `addCohortIntersectDate` with `order = "last"` to add a column with the date of the last occurrence of a target cohort within a specified window. The `window` can be set to `c(-Inf, Inf)` to consider all time. ```r cdm$cohort1 <- cdm$cohort1 | addCohortIntersectDate( targetCohortTable = "cohort2", targetCohortId = 1, order = "last", window = c(-Inf, Inf) ) ``` -------------------------------- ### Disconnect Mock CDM Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Disconnects from the mock CDM object after operations are complete. ```r mockDisconnect(cdm) ``` -------------------------------- ### Add Sex to Condition Occurrence Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/vignettes/demographics.rmd Add a 'sex' column to the condition_occurrence table. This is a time-invariant characteristic and does not require an index date. ```r cdm$condition_occurrence <- cdm$condition_occurrence |> addSex() cdm$condition_occurrence |> glimpse() ``` -------------------------------- ### Filter Condition Occurrences by Age and Sex Source: https://github.com/darwin-eu/patientprofiles/blob/main/README.md Filters the 'condition_occurrence' data to include only males aged between 18 and 65. This demonstrates how to apply demographic filters to the augmented data. ```r cdm$condition_occurrence | filter(age >= 18 & age <= 65) | filter(sex == "Male") #> # Source: SQL [?? x 8] #> # Database: DuckDB 1.4.0 [root@Darwin 24.6.0:R 4.4.1/:memory:] #> person_id condition_start_date condition_end_date condition_occurrence_id #> #> 1 239 1991-12-11 1996-11-27 32 #> 2 404 1982-10-31 1984-12-04 28 #> 3 682 1932-09-09 1937-08-15 10 #> 4 814 2008-02-05 2009-10-30 1 #> # ℹ 4 more variables: condition_concept_id , #> # condition_type_concept_id , age , sex ``` -------------------------------- ### Add Demographics and Cohort Intersections Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Enriches the primary cohort table with demographic data, visit counts, prior condition flags, and future cohort intersection dates. This is a foundational step for detailed patient analysis. ```r cdm$gibleed <- cdm$gibleed |> addDemographics() |> addTableIntersectCount( tableName = "visit_occurrence", window = c(-365, 0), nameStyle = "number_visits" ) |> addCohortIntersectFlag( targetCohortTable = "conditions", targetCohortId = 1, window = c(-Inf, 0), nameStyle = "prior_asthma" ) |> addCohortIntersectDate( targetCohortTable = "conditions", targetCohortId = 2, window = c(1, Inf), nameStyle = "next_uc" ) ``` -------------------------------- ### Add Next Cohort Intersection Date Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Appends a new column with the date of the next occurrence of a target cohort. Useful for analyzing future events relative to a primary cohort. ```r cdm$gibleed |> addCohortIntersectDate( targetCohortTable = "conditions", targetCohortId = 2, window = c(1, Inf), nameStyle = "next_uc" ) |> dplyr::glimpse() ``` -------------------------------- ### Add Demographics to Cohort Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/code.md Adds demographic information (age groups) to the 'gibleed' cohort using the addDemographics function from PatientProfiles. ```r library(PatientProfiles) cdm$gibleed | addDemographics( indexDate = "cohort_start_date", ageGroup = list("children" = c(0, 17), "adult" = c(18, Inf)) ) | dplyr::glimpse() ``` -------------------------------- ### Add Demographics to Cohort Table Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/paper.md Use `addDemographics` to enrich a cohort table with various demographic columns. Specify the `indexDate` and optionally define `ageGroup` ranges. The function requires the table to be part of a `cdm_reference` object and have a person identifier column. ```r cdm$my_flu_cohort |> addDemographics( indexDate = "cohort_start_date", ageGroup = list("children" = c(0, 17), "adult" = c(18, Inf)) ) |> dplyr::glimpse() ``` -------------------------------- ### Add Next Flu or Covid Test Date to Cohort Source: https://github.com/darwin-eu/patientprofiles/blob/main/paper/paper.md This snippet adds the date of the next flu or covid test after the index date to a cohort. It utilizes the `addCohortIntersectDate` function and requires specifying target cohorts and a window. ```r cdm$cohort1 |> addCohortIntersectDate( targetCohortTable = "cohort2", targetCohortId = c(1, 2), window = c(1, Inf) ) |> dplyr::glimpse() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.