Skip to content

TreatmentPatterns: Add patient-level groups as new cohorts #8

@mvankessel-EMC

Description

@mvankessel-EMC

Upload the patient-level results as cohorts per (combination) treatment and / or per pathway.

We can create a function that takes in several arguments:

  1. andromeda: The Andromeda object created by computePathways().
  2. cohortTableName: Name of the cohort table to write to.
  3. cdm: Optionally a CDM-Reference from CDMConnector.
  4. connectionDetails: Optionally ConnectionDetails from DatabaseConnector.
  5. resultSchema: Optionally a schema where to write to.
#' @title uploadCohorts
#'
#' Uploads patient level groups per (combination) event as seperate cohorts.
#'
#' @param andromeda
#' @param cohortTableName
#' @param cdm
#' @param connectionDetails
#' @param resultSchema
#'
#' @return `NULL`
#'
#' @export
#'
#' @examples
#' # <Example code>
uploadCohorts <- function(andromeda, cohortTableName, cdm = NULL, connectionDetails = NULL, resultSchema = NULL) {
# 1. Check inputs
# 2. Check if records to be uploaded are valid:
#   a. One person may belong to multiple cohorts
#   b. One person may belong to the same cohort for multiple different time periods
#   c. One person may not belong to the same cohort multiple times during the same period of time
#   d. A cohort may have zero or more members

# 3. Upload to database
# if cdm != NULL:
# > upload with CDMConnector
# else if connectionDetails != NULL:
# > upload with DatabaseConnector, to resultSchema
}

TreatmentPatterns example result to work with

library(TreatmentPatterns)
library(CDMConnector)
library(dplyr)

con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomiaDir())
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 %>%
  select(
    cohortId = "cohort_definition_id",
    cohortName = "cohort_name"
  ) %>%
  mutate(type = c("event", "event", "event", "event", "exit", "event", "event", "target"))

outputEnv <- computePathways(
  cohorts = cohorts,
  cohortTableName = "cohort_table",
  cdm = cdm
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions