% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ExecuteCohortPathways.R
\name{executeCohortPathways}
\alias{executeCohortPathways}
\title{Execute cohort pathway analysis.}
\usage{
executeCohortPathways(
  connectionDetails = NULL,
  connection = NULL,
  cohortDatabaseSchema,
  cohortTableName = "cohort",
  outcomeDatabaseSchema = cohortDatabaseSchema,
  outcomeTableName = cohortTableName,
  tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"),
  targetCohortIds,
  eventCohortIds,
  analysisType = "post-index",
  lookbackStartDay = -365,
  lookbackEndDay = -1,
  minCellCount = 5,
  allowRepeats = FALSE,
  maxDepth = 5,
  collapseWindow = 30
)
}
\arguments{
\item{connectionDetails}{An object of type connectionDetails as created using the
\code{\link[DatabaseConnector]{createConnectionDetails}} function in the
DatabaseConnector package. Can be left NULL if \code{connection} is
provided.}

\item{connection}{An object of type \code{connection} as created using the
\code{\link[DatabaseConnector]{connect}} function in the
DatabaseConnector package. Can be left NULL if connectionDetails
is provided, in which case a new connection will be opened at the start
of the function, and closed when the function finishes.}

\item{cohortDatabaseSchema}{Schema name where your \strong{target} cohort table resides.
For SQL Server this should include both database and schema,
e.g. 'scratch.dbo'.}

\item{cohortTableName}{The name of the \strong{target} cohort table (default: "cohort").}

\item{outcomeDatabaseSchema}{Schema name where your \strong{event/outcome} cohort table resides.
Defaults to \code{cohortDatabaseSchema} if not specified.}

\item{outcomeTableName}{The name of the \strong{event/outcome} cohort table.
Defaults to \code{cohortTableName} if not specified.}

\item{tempEmulationSchema}{Some database platforms like Oracle and Impala do not truly support
temp tables. To emulate temp tables, provide a schema with write
privileges where temp tables can be created.}

\item{targetCohortIds}{A vector of one or more Cohort Ids corresponding to target cohort(s).}

\item{eventCohortIds}{A vector of one or more Cohort Ids corresponding to event cohort(s).}

\item{analysisType}{Character. Either \code{"post-index"} (default) to analyze events
after the index date, or \code{"pre-index"} to analyze events
before the index date.}

\item{lookbackStartDay}{(Only used when \code{analysisType = "pre-index"}.)
Start of the lookback window in days relative to the index date
(default: -365). Must be negative.}

\item{lookbackEndDay}{(Only used when \code{analysisType = "pre-index"}.)
End of the lookback window in days relative to the index date
(default: -1). Must be negative.}

\item{minCellCount}{(Default = 5) The minimum cell count for fields containing person
counts or fractions.}

\item{allowRepeats}{(Default = FALSE) Allow cohort events/combos to appear multiple
times in the same pathway.}

\item{maxDepth}{(Default = 5) Maximum number of steps in a given pathway.}

\item{collapseWindow}{(Default = 30) Any dates found within the specified collapse days
will be reassigned the earliest date.}
}
\value{
\if{html}{\out{<div class="sourceCode">}}\preformatted{                 A list of data frames containing pathway analysis results.
}\if{html}{\out{</div>}}
}
\description{
Runs the cohort pathways on all instantiated combinations of target and event cohorts.
Assumes the cohorts have already been instantiated.

Supports two analysis types:
\itemize{
\item \code{"post-index"} (default): events occurring \strong{after} the target cohort
index date (within the target cohort period).
\item \code{"pre-index"}: events occurring \strong{before} the target cohort index date,
in a configurable lookback window. For example, what events occurred in
the 365 days before cohort entry.
}

Target and event cohorts can reside in different schemas/tables:
\itemize{
\item \code{cohortDatabaseSchema} / \code{cohortTableName} for target cohorts.
\item \code{outcomeDatabaseSchema} / \code{outcomeTableName} for event (outcome) cohorts.
If not specified, defaults to the same as the target.
}
}
\examples{
\donttest{
if (requireNamespace("Eunomia", quietly = TRUE) &&
    exists("createCohorts", where = asNamespace("Eunomia"), inherits = FALSE)) {
  connectionDetails <- Eunomia::getEunomiaConnectionDetails()
  createCohorts <- get("createCohorts", envir = asNamespace("Eunomia"))
  createCohorts(connectionDetails)

  postIndexResults <- executeCohortPathways(
    connectionDetails = connectionDetails,
    cohortDatabaseSchema = "main",
    cohortTableName = "cohort",
    targetCohortIds = 4,
    eventCohortIds = c(1, 2, 3),
    maxDepth = 3
  )

  preIndexResults <- executeCohortPathways(
    connectionDetails = connectionDetails,
    cohortDatabaseSchema = "main",
    cohortTableName = "cohort",
    targetCohortIds = 4,
    eventCohortIds = c(1, 2, 3),
    analysisType = "pre-index",
    lookbackStartDay = -365,
    lookbackEndDay = -1,
    maxDepth = 3
  )

  names(postIndexResults)
  names(preIndexResults)
}
}

}
