if (FALSE) {
library(CohortGenerator)
initialSet <- getCohortDefinitionSet(
settingsFileName = "testdata/name/Cohorts.csv",
jsonFolder = "testdata/name/cohorts",
sqlFolder = "testdata/name/sql/sql_server",
cohortFileNameFormat = "%s",
cohortFileNameValue = c("cohortName"),
packageName = "CohortGenerator",
verbose = FALSE
)
print(initialSet[, c("cohortId", "cohortName")])
# Subset cohorts 1 & 2 by an "indication" cohort 3:
res <- addExcludeOnIndexSubsetDefinition(
cohortDefinitionSet = initialSet,
targetCohortIds = c(1, 2),
exclusionCohortIds = c(3),
subsetDefinitionId = 20,
subsetDefinitioName = "Exclude on index if in cohort 3"
)
print(res[, c("cohortId", "cohortName", "subsetParent", "subsetDefinitionId", "isSubset")])
# Get all subset definitions that were created using the addExcludeOnIndexSubsetDefinition:
subsetDefinitionId <- getExcludeOnIndexSubsetDefinitionIds(res)
# Filter the cohortDefinitionSet to those cohorts defined using an exclusion subset definition:
newCohorts <- res |>
dplyr::filter(subsetDefinitionId == subsetDefinitionId) |>
dplyr::select(cohortId, cohortName, subsetParent, isSubset)
print(newCohorts)
}
Run the code above in your browser using DataLab