Compute treatment patterns according to the specified parameters within specified cohorts. For more customization, or investigation of patient level outcomes, you can run computePathways and export separately.

executeTreatmentPatterns(
  cohorts,
  cohortTableName,
  outputPath,
  cdm = NULL,
  connectionDetails = NULL,
  cdmSchema = NULL,
  resultSchema = NULL,
  tempEmulationSchema = NULL,
  minEraDuration = 0,
  eraCollapseSize = 30,
  combinationWindow = 30,
  minCellCount = 5
)

Arguments

cohorts

(data.frame())
Data frame containing the following columns and data types:

cohortId numeric(1)

Cohort ID's of the cohorts to be used in the cohort table.

cohortName character(1)

Cohort names of the cohorts to be used in the cohort table.

type character(1) ["target", "event', "exit"]

Cohort type, describing if the cohort is a target, event, or exit cohort

cohortTableName

(character(1))
Cohort table name.

outputPath

(character(1))

cdm

(CDMConnector::cdm_from_con(): NULL)
Optional; Ignores connectionDetails, cdmSchema, and resultSchema.

connectionDetails

(DatabaseConnector::createConnectionDetails(): NULL)
Optional; In congruence with cdmSchema and resultSchema. Ignores cdm.

cdmSchema

(character(1): NULL)
Optional; In congruence with connectionDetails and resultSchema. Ignores cdm.

resultSchema

(character(1): NULL)
Optional; In congruence with connectionDetails and cdmSchema. Ignores cdm.

tempEmulationSchema

(character(1)) Schema to emulate temp tables.

minEraDuration

(integer(1): 0)
Minimum time an event era should last to be included in analysis

eraCollapseSize

(integer(1): 30)
Window of time between which two eras of the same event cohort are collapsed into one era

combinationWindow

(integer(1): 30)
Window of time two event cohorts need to overlap to be considered a combination treatment

minCellCount

(integer(1): 5)
Minimum count required per pathway. Censors data below x as <x. This minimum value will carry over to the sankey diagram and sunburst plot.

Value

(invisible(NULL))

Examples

# \donttest{
library(TreatmentPatterns)
library(CDMConnector)
library(dplyr)
if (require("CirceR", character.only = TRUE, quietly = TRUE)) {
  withr::local_envvar(
    R_USER_CACHE_DIR = tempfile(),
    EUNOMIA_DATA_FOLDER = Sys.getenv("EUNOMIA_DATA_FOLDER", unset = tempfile())
  )

  tryCatch({
    if (Sys.getenv("skip_eunomia_download_test") != "TRUE") {
      CDMConnector::downloadEunomiaData(overwrite = TRUE)
    }
  },
  error = function(e) NA)

  con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomia_dir())
  cdm <- cdmFromCon(con, cdmSchema = "main", writeSchema = "main")

  cohortSet <- readCohortSet(
    path = system.file(package = "TreatmentPatterns", "exampleCohorts")
  )

  cdm <- generateCohortSet(
    cdm = cdm,
    cohortSet = cohortSet,
    name = "cohort_table"
  )

  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")

  executeTreatmentPatterns(
    cohorts = cohorts,
    cohortTableName = "cohort_table",
    cdm = cdm,
    outputPath = tempdir()
  )
    
  DBI::dbDisconnect(con, shutdown = TRUE)
}
#> 
#> Download completed!
#>  Generating 8 cohorts
#>  Generating cohort (1/8) - acetaminophen
#>  Generating cohort (1/8) - acetaminophen [152ms]
#> 
#>  Generating cohort (2/8) - amoxicillin
#>  Generating cohort (2/8) - amoxicillin [161ms]
#> 
#>  Generating cohort (3/8) - aspirin
#>  Generating cohort (3/8) - aspirin [151ms]
#> 
#>  Generating cohort (4/8) - clavulanate
#>  Generating cohort (4/8) - clavulanate [160ms]
#> 
#>  Generating cohort (5/8) - death
#>  Generating cohort (5/8) - death [98ms]
#> 
#>  Generating cohort (6/8) - doxylamine
#>  Generating cohort (6/8) - doxylamine [147ms]
#> 
#>  Generating cohort (7/8) - penicillinv
#>  Generating cohort (7/8) - penicillinv [142ms]
#> 
#>  Generating cohort (8/8) - viralsinusitis
#>  Generating cohort (8/8) - viralsinusitis [227ms]
#> 
#> Warning: ! 5 casted column in cohort_table (cohort_attrition) as do not match expected
#>   column type:
#>  `number_records` from numeric to integer
#>  `number_subjects` from numeric to integer
#>  `reason_id` from numeric to integer
#>  `excluded_records` from numeric to integer
#>  `excluded_subjects` from numeric to integer
#> Warning: ! 1 column in cohort_table do not match expected column type:
#>  `subject_id` is numeric but expected integer
#> -- 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
#> Writing attrition to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/attrition.csv
#> Writing metadata to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/metadata.csv
#> Writing treatmentPathways to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/treatmentPathways.csv
#> Censoring 1540 pathways with a frequency <5 to mean.
#> Writing summaryStatsTherapyDuration to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/summaryEventDuration.csv
#> Writing countsYearPath to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/countsYear.csv
#> Writing countsAgePath to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/countsAge.csv
#> Writing countsSexPath to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/countsSex.csv
#> Zipping files to C:\Users\MVANKE~1\AppData\Local\Temp\RtmpUZ46Su/TreatmentPatterns-Output.zip
# }