Skip to content

Using cdmName argument #278

@edward-burn

Description

@edward-burn

Would it be possible to support the cdmName argument from cdmFromCon? Normally data partners are using this to specify the name they want to see in the shiny/ report/ etc

library(TreatmentPatterns)
#> Warning: package 'TreatmentPatterns' was built under R version 4.4.2
library(CDMConnector)
#> Warning: package 'CDMConnector' was built under R version 4.4.2
library(dplyr, warn.conflicts = FALSE)

con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomia_dir())
#> Warning: `eunomia_dir()` was deprecated in CDMConnector 1.7.0.
#> ℹ Please use `eunomiaDir()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
cdm <- cdmFromCon(con, cdmSchema = "main", writeSchema = "main", 
                  cdmName = "my_study_database")
#> Note: method with signature 'DBIConnection#Id' chosen for function 'dbExistsTable',
#>  target signature 'duckdb_connection#Id'.
#>  "duckdb_connection#ANY" would also be valid

cohortSet <- readCohortSet(
  path = system.file(package = "TreatmentPatterns", "exampleCohorts")
)
cdm <- generateCohortSet(
  cdm = cdm,
  cohortSet = cohortSet,
  name = "cohort_table"
)
#> ℹ Generating 8 cohorts
#> ℹ Generating cohort (1/8) - acetaminophen✔ Generating cohort (1/8) - acetaminophen [303ms]
#> ℹ Generating cohort (2/8) - amoxicillin✔ Generating cohort (2/8) - amoxicillin [207ms]
#> ℹ Generating cohort (3/8) - aspirin✔ Generating cohort (3/8) - aspirin [186ms]
#> ℹ Generating cohort (4/8) - clavulanate✔ Generating cohort (4/8) - clavulanate [166ms]
#> ℹ Generating cohort (5/8) - death✔ Generating cohort (5/8) - death [125ms]
#> ℹ Generating cohort (6/8) - doxylamine✔ Generating cohort (6/8) - doxylamine [176ms]
#> ℹ Generating cohort (7/8) - penicillinv✔ Generating cohort (7/8) - penicillinv [175ms]
#> ℹ Generating cohort (8/8) - viralsinusitis✔ Generating cohort (8/8) - viralsinusitis [255ms]
# convert subject_id to subject_id + 1e16 as 64 bit integer
cdm$cohort_table <- cdm$cohort_table %>%
  mutate(subject_id = bit64::as.integer64(.data$subject_id + 1e16)) %>%
  compute()

cdm$person <- cdm$person %>%
  mutate(person_id = bit64::as.integer64(.data$person_id + 1e16)) %>%
  compute()

cohorts <- cohortSet %>%
  # Remove 'cohort' and 'json' columns
  select(-"cohort", -"json") %>%
  mutate(type = c("event", "event", "event", "event", "exit", "event", "event", "target")) %>%
  rename(
    cohortId = "cohort_definition_id",
    cohortName = "cohort_name",
  ) %>%
  select("cohortId", "cohortName", "type")

outputEnv <- computePathways(
  cohorts = cohorts,
  cohortTableName = "cohort_table",
  cdm = cdm
)
#> -- Qualifying records for cohort definitions: 1, 2, 3, 4, 5, 6, 7, 8
#>  Records: 14041
#>  Subjects: 2693
#> -- Removing records < minEraDuration (0)
#>  Records: 11386
#>  Subjects: 2159
#> -- Removing events where index date < target index date + indexDateOffset (0)
#>  Records: 8381
#>  Subjects: 2159
#> -- splitEventCohorts
#>  Records: 8366
#>  Subjects: 2144
#> -- eraCollapse (30)
#>  Records: 8366
#>  Subjects: 2144
#> -- Iteration 1: minPostCombinationDuration (30), combinatinoWindow (30)
#>  Records: 558
#>  Subjects: 512
#> -- Iteration 2: minPostCombinationDuration (30), combinatinoWindow (30)
#>  Records: 554
#>  Subjects: 512
#> -- After Combination
#>  Records: 554
#>  Subjects: 512
#> -- filterTreatments (First)
#>  Records: 553
#>  Subjects: 512
#> -- treatment construction done
#>  Records: 553
#>  Subjects: 512

outputEnv$metadata |> 
  glimpse()
#> Rows: ??
#> Columns: 9
#> Database: sqlite 3.47.1 [C:\Users\eburn\AppData\Local\Temp\Rtmpsr0BmZ\file4d0812d96235.sqlite]
#> $ cdmSourceName         <chr> "Synthea synthetic health database"
#> $ cdmSourceAbbreviation <chr> "Synthea"
#> $ cdmReleaseDate        <date> 2019-05-25
#> $ vocabularyVersion     <chr> "v5.0 18-JAN-19"
#> $ executionStartDate    <chr> "2025-01-30"
#> $ packageVersion        <chr> "2.7.0"
#> $ rVersion              <chr> "R version 4.4.0 (2024-04-24 ucrt)"
#> $ platform              <chr> "x86_64-w64-mingw32"
#> $ execution_end_date    <chr> "2025-01-30"

Created on 2025-01-30 with reprex v2.1.0

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions