The CDMConnector package allows us to work with cdm data in different
locations consistently. The
cdm_reference may be to tables
in a database, files on disk, or tables loaded into R. This allows
computation to take place wherever is most convenient.
Here we have a schematic of how CDMConnector can be used to create
cdm_references to different locations.
To show how this can work (and slightly overcomplicate things to show different options), let´s say we want to create a histogram with age of patients at diagnosis of tear of meniscus of knee (concept_id of “4035415”). We can start in the database and, after loading the required packages, subset our person table people to only include those people in the condition_occurrence table with condition_concept_id “4035415”
con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomia_dir()) cdm <- cdm_from_con(con, cdm_schema = "main") # first filter to only those with condition_concept_id "4035415" cdm$condition_occurrence %>% tally() cdm$condition_occurrence <- cdm$condition_occurrence %>% filter(condition_concept_id == "4035415") %>% select(person_id, condition_start_date) cdm$condition_occurrence %>% tally() # then left_join person table cdm$person %>% tally() cdm$person <- cdm$condition_occurrence %>% select(person_id) %>% left_join(select(cdm$person, person_id, year_of_birth), by = "person_id") cdm$person %>% tally()
We can save these tables to file
And now we can create a
cdm_reference to the files
And create an age at diagnosis variable
We can then bring in this result to R and make the histogram