From 737763cece643ff5ac9a98a081bfa924e6940bda Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Wed, 15 Nov 2023 02:03:31 +0100 Subject: [PATCH 01/41] added initial functionality to run the treatment patterns analysis. Needs to be updated for the cohorts --- R/runTreatmentPatterns.R | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 R/runTreatmentPatterns.R diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R new file mode 100644 index 0000000..8af127f --- /dev/null +++ b/R/runTreatmentPatterns.R @@ -0,0 +1,87 @@ +#' Run the treatment patterns analysis +#' +#' @param connection An database connection created using DatabaseConnector::connect +#' @param cdmDatabaseSchema the schema where the cdm is located +#' @param cohortDatabaseSchema A writable location on the database. +#' @param cohortsGenerated A table contianing the output of the createCohorts function, detailing the cohorts that have been instatiated +#' @param outputDir The output directory where the results should be saved +#' @param tablePrefix table prefix +#' @param outcomeTableName outcome cohort table name +#' @param logger logger object +#' @param cohortIds the cohortIds to be used form the cohort table +#' @param minCellCount minimum cell count +#' +#' @return the drug utilisation results +#' +#' @examples +#' @export + +runTreatmentPatterns <- function(connectionDetails, + cdmDatabaseSchema, + cohortDatabaseSchema, + cohortTable, + cohortsGenerated, + outputDir, + tablePrefix = NULL, + outcomeTableName, + logger = NULL, + cohortIds, + minCellCount = 5) { + # med level treatment patterns ----- + cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTable = outcomeTableName) + tpCohorts <- cohortsGenerated %>% + dplyr::inner_join(cohortCounts, + dplyr::join_by(cohortId)) %>% + dplyr::filter(cohortSubjects > 0) # make sure at least someone appears + + if (nrow(tpCohorts) > 0) { + # Select target cohort + targetCohorts <- cohortsGenerated %>% + filter(cohortName == "") %>% + select(cohortId, cohortName) + + # Select everything BUT target cohorts + eventCohorts <- cohortsGenerated %>% + filter(cohortName != "") %>% + select(cohortId, cohortName) + + cohorts <- dplyr::bind_rows( + targetCohorts %>% mutate(type = "target"), + eventCohorts %>% mutate(type = "event"), + exitCohorts %>% mutate(type = "exit") + ) + + # Compute pathways + pathways <- TreatmentPatterns::executeTreatmentPatterns( + cohorts = cohorts, + cohortTableName = outcomeTableName, + outputPath = outputFolder, + connectionDetails = connectionDetails, + cdmSchema = cdmDatabaseSchema, + resultSchema = cohortDatabaseSchema, + # Optional settings + includeTreatments = "startDate", + periodPriorToIndex = 0, + minEraDuration = 0, + splitEventCohorts = "", + splitTime = 30, + eraCollapseSize = 30, + combinationWindow = 30, + minPostCombinationDuration = 30, + filterTreatments = "First", + maxPathLength = 5, + minFreq = minCellCount, + addNoPaths = TRUE + ) + #export results + TreatmentPatterns::export( + andromeda = pathways, + outputPath = here::here(outputFolder), + ageWindow = c(18,45,65,150), #TODO: define this correctly + minFreq = minCellCount, + archiveName = NULL + ) + } +} From 074ce40502c2be35f3c6bff0c9f9342fa955121a Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Wed, 15 Nov 2023 02:08:27 +0100 Subject: [PATCH 02/41] updated run study and renamed arguments for consistency --- R/runStudy.R | 19 ++++++++++++++++++- R/runTreatmentPatterns.R | 9 ++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/R/runStudy.R b/R/runStudy.R index 310c539..dcb3359 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -23,10 +23,11 @@ runStudy <- function(connectionDetails, minCellCount) { if (instantiateCohorts){ - createCohorts(connectionDetails = connectionDetails, + cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, cohortTable = cohortTable, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema) + readr::write_csv(cohortsGenerated, file.path(outputFolder, "cohortsGenerated.csv")) } if (runDiagnostics){ @@ -41,4 +42,20 @@ runStudy <- function(connectionDetails, minCellCount = minCellCount ) } + + if (runPatternAnalysis) + { + if (!instantiateCohorts) + { + cohortsGenerated <- readr::read_csv("cohortsGenerated.csv") + } + runTreatmentPatterns(connectionDetails = connectionDetails, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTable = cohortTable, + cohortsGenerated = cohortsGenerated, + outputFolder = outputFolder, + cohortIds = cohortIds, + minCellCount = minCellCount) + } } \ No newline at end of file diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index 8af127f..90a3cb6 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -4,7 +4,7 @@ #' @param cdmDatabaseSchema the schema where the cdm is located #' @param cohortDatabaseSchema A writable location on the database. #' @param cohortsGenerated A table contianing the output of the createCohorts function, detailing the cohorts that have been instatiated -#' @param outputDir The output directory where the results should be saved +#' @param outputFolder The output directory where the results should be saved #' @param tablePrefix table prefix #' @param outcomeTableName outcome cohort table name #' @param logger logger object @@ -21,16 +21,15 @@ runTreatmentPatterns <- function(connectionDetails, cohortDatabaseSchema, cohortTable, cohortsGenerated, - outputDir, + outputFolder, tablePrefix = NULL, - outcomeTableName, logger = NULL, cohortIds, minCellCount = 5) { # med level treatment patterns ----- cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, cohortDatabaseSchema = cohortDatabaseSchema, - cohortTable = outcomeTableName) + cohortTable = cohortTable) tpCohorts <- cohortsGenerated %>% dplyr::inner_join(cohortCounts, dplyr::join_by(cohortId)) %>% @@ -56,7 +55,7 @@ runTreatmentPatterns <- function(connectionDetails, # Compute pathways pathways <- TreatmentPatterns::executeTreatmentPatterns( cohorts = cohorts, - cohortTableName = outcomeTableName, + cohortTableName = cohortTable, outputPath = outputFolder, connectionDetails = connectionDetails, cdmSchema = cdmDatabaseSchema, From 77f4d30e2c3f0b624c09021bb3220909ed8c5037 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Wed, 15 Nov 2023 02:11:10 +0100 Subject: [PATCH 03/41] put tp trigger in codeToRun and runStudy --- R/runStudy.R | 2 ++ extras/codeToRun.R | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/runStudy.R b/R/runStudy.R index dcb3359..0d7f11b 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -6,6 +6,7 @@ #' @param cohortDatabaseSchema name of a schema with write access for the creation of cohort table #' @param instantiateCohorts choose whether to instantiate the cohorts on your database #' @param runDiagnostics choose whether to run the cohort diagnostics +#' @param runPatternAnalysis choose whether to run the treatment patterns analysis #' @param outputFolder The folder where the results should be written #' @param databaseId a short name that can identify the database used #' @param minCellCount the minimum number of patients that can be shared for any single count in the results @@ -18,6 +19,7 @@ runStudy <- function(connectionDetails, cohortDatabaseSchema, instantiateCohorts = FALSE, runDiagnostics = FALSE, + runPatternAnalysis = FALSE, outputFolder, databaseId, minCellCount) { diff --git a/extras/codeToRun.R b/extras/codeToRun.R index fe7e09e..16f5dbf 100644 --- a/extras/codeToRun.R +++ b/extras/codeToRun.R @@ -80,7 +80,7 @@ outputFolder <- "results" #choose analysis to run instantiateCohorts <- TRUE runDiagnostics <- TRUE - +runPatternAnalysis <- TRUE ### Do not edit below here @@ -91,6 +91,7 @@ EhdenAlopecia::runStudy( cohortDatabaseSchema = cohortDatabaseSchema, instantiateCohorts = instantiateCohorts, runDiagnostics = runDiagnostics, + runPatternAnalysis = runPatternAnalysis, outputFolder = outputFolder, databaseId = databaseId, minCellCount = minCellCount From f46f1616dd519f5d871547f9f66828078b579a50 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Wed, 15 Nov 2023 02:11:37 +0100 Subject: [PATCH 04/41] removed print statement from createCohorts --- R/createCohorts.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/createCohorts.R b/R/createCohorts.R index 5d3a5d6..189f526 100644 --- a/R/createCohorts.R +++ b/R/createCohorts.R @@ -52,6 +52,5 @@ createCohorts <- function(connectionDetails, cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTableNames$cohortTable) - print(cohortCounts) return(cohortsGenerated) } \ No newline at end of file From e0f70555ae2782926db3488a2abb12fb46bd870e Mon Sep 17 00:00:00 2001 From: Maxim Moinat Date: Thu, 16 Nov 2023 07:16:05 +0100 Subject: [PATCH 05/41] add launching of Shiny app --- extras/launchShiny.R | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 extras/launchShiny.R diff --git a/extras/launchShiny.R b/extras/launchShiny.R new file mode 100644 index 0000000..bf4486a --- /dev/null +++ b/extras/launchShiny.R @@ -0,0 +1,23 @@ +library(CohortDiagnostics) + +# -- Load results into database +resultsPath <- "/Users/maxim/Documents/EHDEN-docs/AA Study-a-thon/results" +pathToZips <- file.path(resultsPath, "fixed_zips") +sqliteDbPath <- file.path(pathToZips, "AACohortDiagnosticsResults.sqlite") +createMergedResultsFile(pathToZips, sqliteDbPath = sqliteDbPath, overwrite = TRUE) + +# -- Local shiny app +launchDiagnosticsExplorer(sqliteDbPath = sqliteDbPath) + +# -- Publishing to Posit +# remotes::install_packages('OHDSI/OhdsiShinyModules') +launchDiagnosticsExplorer( + sqliteDbPath = sqliteDbPath, + makePublishable = TRUE, + publishDir = file.path(getwd(), "AACohortDiagnosticsExplorer"), + overwritePublishDir = TRUE +) + +# This will create a shiny app folder "MyStudyDiagnosticsExplorer" in your R working directory. +# The above will also overwrite the existing application folder and copy your sqlite file in to it. +# Following this, the shiny window should load and show a “publsh” button. From 6c718537dac08992f432882b846d3b8aa7fd8a0d Mon Sep 17 00:00:00 2001 From: Maxim Moinat Date: Thu, 16 Nov 2023 07:31:10 +0100 Subject: [PATCH 06/41] add treatment cohorts --- .Rbuildignore | 4 + .Rprofile | 1 + .gitignore | 9 + extras/package-maintenance.R | 26 +- inst/treatment_cohorts/101.json | 64 ++ inst/treatment_cohorts/102.json | 64 ++ inst/treatment_cohorts/103.json | 251 +++++++ inst/treatment_cohorts/104.json | 115 +++ inst/treatment_cohorts/105.json | 64 ++ inst/treatment_cohorts/106.json | 64 ++ inst/treatment_cohorts/107.json | 64 ++ inst/treatment_cohorts/108.json | 64 ++ inst/treatment_cohorts/109.json | 64 ++ inst/treatment_cohorts/110.json | 64 ++ inst/treatment_cohorts/111.json | 64 ++ inst/treatment_cohorts/112.json | 642 +++++++++++++++++ inst/treatment_cohorts/113.json | 98 +++ inst/treatment_cohorts/114.json | 64 ++ inst/treatment_cohorts/115.json | 132 ++++ inst/treatment_cohorts/116.json | 98 +++ inst/treatment_cohorts/117.json | 64 ++ inst/treatment_cohorts/119.json | 64 ++ inst/treatment_cohorts/120.json | 81 +++ inst/treatment_cohorts/121.json | 81 +++ inst/treatment_cohorts/122.json | 64 ++ inst/treatment_cohorts/123.json | 64 ++ inst/treatment_cohorts/124.json | 64 ++ inst/treatment_cohorts/125.json | 77 ++ inst/treatment_cohorts/126.json | 77 ++ inst/treatment_cohorts/127.json | 60 ++ renv/.gitignore | 7 + renv/activate.R | 1180 +++++++++++++++++++++++++++++++ 32 files changed, 3892 insertions(+), 7 deletions(-) create mode 100644 .Rbuildignore create mode 100644 .Rprofile create mode 100644 .gitignore create mode 100644 inst/treatment_cohorts/101.json create mode 100644 inst/treatment_cohorts/102.json create mode 100644 inst/treatment_cohorts/103.json create mode 100644 inst/treatment_cohorts/104.json create mode 100644 inst/treatment_cohorts/105.json create mode 100644 inst/treatment_cohorts/106.json create mode 100644 inst/treatment_cohorts/107.json create mode 100644 inst/treatment_cohorts/108.json create mode 100644 inst/treatment_cohorts/109.json create mode 100644 inst/treatment_cohorts/110.json create mode 100644 inst/treatment_cohorts/111.json create mode 100644 inst/treatment_cohorts/112.json create mode 100644 inst/treatment_cohorts/113.json create mode 100644 inst/treatment_cohorts/114.json create mode 100644 inst/treatment_cohorts/115.json create mode 100644 inst/treatment_cohorts/116.json create mode 100644 inst/treatment_cohorts/117.json create mode 100644 inst/treatment_cohorts/119.json create mode 100644 inst/treatment_cohorts/120.json create mode 100644 inst/treatment_cohorts/121.json create mode 100644 inst/treatment_cohorts/122.json create mode 100644 inst/treatment_cohorts/123.json create mode 100644 inst/treatment_cohorts/124.json create mode 100644 inst/treatment_cohorts/125.json create mode 100644 inst/treatment_cohorts/126.json create mode 100644 inst/treatment_cohorts/127.json create mode 100644 renv/.gitignore create mode 100644 renv/activate.R diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..d821302 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,4 @@ +^renv$ +^renv\.lock$ +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/.Rprofile b/.Rprofile new file mode 100644 index 0000000..81b960f --- /dev/null +++ b/.Rprofile @@ -0,0 +1 @@ +source("renv/activate.R") diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd0675b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata + +errorReport* +Results/* + +.DS_Store diff --git a/extras/package-maintenance.R b/extras/package-maintenance.R index d20b5cb..6889c61 100644 --- a/extras/package-maintenance.R +++ b/extras/package-maintenance.R @@ -17,13 +17,25 @@ cohortDefinitionSet <- ROhdsiWebApi::exportCohortDefinitionSet( write.csv(cohortDefinitionSet, 'inst/cohortDefinitionSet.csv') # Insert cohort definitions from ATLAS into package ----------------------- -for (cohortId in 92:97) { +for (cohortId in c(92:97, 100)) { ROhdsiWebApi::insertCohortDefinitionInPackage( - cohortId, - name = cohortId, - jsonFolder = "inst/cohorts", - sqlFolder = "inst/sql/sql_server", - baseUrl, - generateStats = FALSE + cohortId, + name = cohortId, + jsonFolder = "inst/cohorts", + sqlFolder = "inst/sql/sql_server", + baseUrl, + generateStats = FALSE + ) +} + +# Get treatment cohort definitions from Atlas ------------------------------ +for (cohortId in setdiff(101:127, 118)) { + ROhdsiWebApi::insertCohortDefinitionInPackage( + cohortId, + name = cohortId, + jsonFolder = "inst/treatment_cohorts", + sqlFolder = "inst/sql/sql_server", + baseUrl, + generateStats = FALSE ) } diff --git a/inst/treatment_cohorts/101.json b/inst/treatment_cohorts/101.json new file mode 100644 index 0000000..b4f806d --- /dev/null +++ b/inst/treatment_cohorts/101.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 0, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "(Alopecia) Corticosteroids, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 21602098, + "CONCEPT_NAME" : "CORTICOSTEROIDS, DERMATOLOGICAL PREPARATIONS", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "D07", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 2nd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/102.json b/inst/treatment_cohorts/102.json new file mode 100644 index 0000000..690d852 --- /dev/null +++ b/inst/treatment_cohorts/102.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "(Alopecia) Corticosteroids, systemic (i.e. oral and injected)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 21602723, + "CONCEPT_NAME" : "CORTICOSTEROIDS FOR SYSTEMIC USE, PLAIN", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "H02A", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 3rd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/103.json b/inst/treatment_cohorts/103.json new file mode 100644 index 0000000..aa40b54 --- /dev/null +++ b/inst/treatment_cohorts/103.json @@ -0,0 +1,251 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 2, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 2, + "name" : "(Alopecia) Immunotherapy, topical (all non-standard concepts)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 45017482, + "CONCEPT_NAME" : "DIPHENYLCYCLOPROPENONE 98% PWD", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "49452264202", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45274656, + "CONCEPT_NAME" : "DIPHENYLCYCLOPROPENONE POWDER", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "51927166800", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45052575, + "CONCEPT_NAME" : "DIPHENYLCYCLOPROPENONE PWDR", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "51552094302", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45257357, + "CONCEPT_NAME" : "DIPHENYLCYCLOPROPENONE PWDR", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "51552094301", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45239268, + "CONCEPT_NAME" : "2,4-DINITROCHLOROBENZENE CR", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "49452263001", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45187717, + "CONCEPT_NAME" : "2,4-DINITROCHLOROBENZENE CR", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "49452263002", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4258736, + "CONCEPT_NAME" : "Dinitrochlorobenzene", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N0000171188", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDFRT", + "CONCEPT_CLASS_ID" : "Chemical Structure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 576880, + "CONCEPT_NAME" : "DINITROCHLOROBENZENE 100 % MISCELL CRYSTALS", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "060171", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "GCN_SEQNO", + "CONCEPT_CLASS_ID" : "GCN_SEQNO" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45240352, + "CONCEPT_NAME" : "DINITROCHLOROBENZENE 99% CRYST", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "51927133000", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 576954, + "CONCEPT_NAME" : "SQUARIC ACID DIBUTYLESTER 100 % MISCELL LIQUID (GRAM)", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "043710", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "GCN_SEQNO", + "CONCEPT_CLASS_ID" : "GCN_SEQNO" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 579748, + "CONCEPT_NAME" : "SQUARIC ACID DIBUTYLESTER IN BUTYL ALCOHOL 150 mg MISCELL LIQUID (GRAM)", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "070912", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "GCN_SEQNO", + "CONCEPT_CLASS_ID" : "GCN_SEQNO" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 574411, + "CONCEPT_NAME" : "SQUARIC ACID DIBUTYLESTER MISCELL POWDER (GRAM)", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "022515", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "GCN_SEQNO", + "CONCEPT_CLASS_ID" : "GCN_SEQNO" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/104.json b/inst/treatment_cohorts/104.json new file mode 100644 index 0000000..714f657 --- /dev/null +++ b/inst/treatment_cohorts/104.json @@ -0,0 +1,115 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 3, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 3, + "name" : "(Alopecia) Immunomodulators (Azathioprine. Cyclosporine, Mycophenolate mofetil, Methotrexate)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 19014878, + "CONCEPT_NAME" : "Azathioprine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1256", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19010482, + "CONCEPT_NAME" : "Cyclosporine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3008", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19003999, + "CONCEPT_NAME" : "mycophenolate mofetil", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "68149", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1305058, + "CONCEPT_NAME" : "Methotrexate", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "6851", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/105.json b/inst/treatment_cohorts/105.json new file mode 100644 index 0000000..9380358 --- /dev/null +++ b/inst/treatment_cohorts/105.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 4, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 4, + "name" : "(Alopecia) Anthralin (i.e. dithranol), topical immunotherapeutic agent", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36211872, + "CONCEPT_NAME" : "Anthralin Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1153703", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/106.json b/inst/treatment_cohorts/106.json new file mode 100644 index 0000000..8b694ef --- /dev/null +++ b/inst/treatment_cohorts/106.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 5, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 5, + "name" : "(Alopecia) Minoxidil, arteriolar vasodilator", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1309068, + "CONCEPT_NAME" : "Minoxidil", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "6984", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/107.json b/inst/treatment_cohorts/107.json new file mode 100644 index 0000000..ddf2055 --- /dev/null +++ b/inst/treatment_cohorts/107.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 6, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 6, + "name" : "(Alopecia) Finasteride", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 996416, + "CONCEPT_NAME" : "Finasteride", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "25025", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/108.json b/inst/treatment_cohorts/108.json new file mode 100644 index 0000000..ee45d28 --- /dev/null +++ b/inst/treatment_cohorts/108.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 7, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 7, + "name" : "(Alopecia) Tretinoin, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36223379, + "CONCEPT_NAME" : "Tretinoin Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1158220", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/109.json b/inst/treatment_cohorts/109.json new file mode 100644 index 0000000..a4375a8 --- /dev/null +++ b/inst/treatment_cohorts/109.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 8, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 8, + "name" : "(Alopecia) Tofacitinib, JAK inhibitor, oral", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 42904205, + "CONCEPT_NAME" : "tofacitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1357536", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/110.json b/inst/treatment_cohorts/110.json new file mode 100644 index 0000000..11a3f37 --- /dev/null +++ b/inst/treatment_cohorts/110.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 9, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 9, + "name" : "(Alopecia) Baricitinib, JAK inhibitor, oral", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1510627, + "CONCEPT_NAME" : "baricitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "2047232", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/111.json b/inst/treatment_cohorts/111.json new file mode 100644 index 0000000..0156568 --- /dev/null +++ b/inst/treatment_cohorts/111.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 10, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 10, + "name" : "(Alopecia) Ruxolitinib, JAK inhibitor, oral", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40244464, + "CONCEPT_NAME" : "ruxolitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1193326", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/112.json b/inst/treatment_cohorts/112.json new file mode 100644 index 0000000..fa8129b --- /dev/null +++ b/inst/treatment_cohorts/112.json @@ -0,0 +1,642 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 11, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 11, + "name" : "(Alopecia) Clobetasol propionate, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 19114411, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Gel [embelin]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "544116", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44044472, + "CONCEPT_NAME" : "Clobetasol Topical Cream [Alti-Clobetasol Propionate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP1039103", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Branded Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19102575, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution [Clobex]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "404036", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793228, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam [Olux]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1992274", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793230, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Cream", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1992281", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793231, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Cream [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1992282", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793227, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1992273", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19002305, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Dermovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "103431", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19002304, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Dermovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "103430", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793721, + "CONCEPT_NAME" : "Clobetasol Propionate 0.25 MG/ML Topical Cream [Impoyz]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1995460", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793716, + "CONCEPT_NAME" : "Clobetasol Propionate 0.25 MG/ML Topical Cream", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1995455", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44122102, + "CONCEPT_NAME" : "Clobetasol Topical Ointment [Alti-Clobetasol Propionate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP1116733", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Branded Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44122104, + "CONCEPT_NAME" : "Clobetasol Topical Solution [Alti-Clobetasol Propionate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP1116735", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Branded Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1361309, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam [Tovet]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "2180345", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164516, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861495", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164517, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Cormax]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861497", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164518, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Embeline]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861498", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164519, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Isovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861500", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164524, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Lotion [Clobex]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861506", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164525, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861487", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164526, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution [Cormax]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861526", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164527, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution [Embeline]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861489", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164520, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861503", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164521, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Foam", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861353", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164522, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Foam [Olux]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861355", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164523, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Lotion", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861505", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164528, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861510", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164529, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Spray", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861512", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164530, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Spray [Clobex]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861513", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164501, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Gel", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861434", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164502, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Gel [Clobevate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861436", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164508, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861472", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164504, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Gel [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861440", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164505, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Ointment", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861448", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164506, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Cormax]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861449", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/113.json b/inst/treatment_cohorts/113.json new file mode 100644 index 0000000..992961f --- /dev/null +++ b/inst/treatment_cohorts/113.json @@ -0,0 +1,98 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 12, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 12, + "name" : "(Alopecia) Iron supplement", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36219948, + "CONCEPT_NAME" : "ferrous sulfate Oral Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1164414", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36219932, + "CONCEPT_NAME" : "ferrous gluconate Oral Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1164398", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36224164, + "CONCEPT_NAME" : "Ferrous fumarate Oral Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1159640", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/114.json b/inst/treatment_cohorts/114.json new file mode 100644 index 0000000..371811d --- /dev/null +++ b/inst/treatment_cohorts/114.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 13, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 13, + "name" : "(Alopecia) Vitamin E", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36226018, + "CONCEPT_NAME" : "Vitamin E Oral Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1161178", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/115.json b/inst/treatment_cohorts/115.json new file mode 100644 index 0000000..975c612 --- /dev/null +++ b/inst/treatment_cohorts/115.json @@ -0,0 +1,132 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 14, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 14, + "name" : "(Alopecia) Immunomodulators (Azathioprine. Cyclosporine, Mycophenolate mofetil, Methotrexate, Sulf.)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 19014878, + "CONCEPT_NAME" : "Azathioprine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1256", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19010482, + "CONCEPT_NAME" : "Cyclosporine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3008", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19003999, + "CONCEPT_NAME" : "mycophenolate mofetil", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "68149", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1305058, + "CONCEPT_NAME" : "Methotrexate", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "6851", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 964339, + "CONCEPT_NAME" : "Sulfasalazine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "9524", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/116.json b/inst/treatment_cohorts/116.json new file mode 100644 index 0000000..d987cca --- /dev/null +++ b/inst/treatment_cohorts/116.json @@ -0,0 +1,98 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 15, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 15, + "name" : "(Alopecia) JAK inhibitors group, oral (Ruxolitinib, Tofacitinib, Baricitinib)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40244464, + "CONCEPT_NAME" : "ruxolitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1193326", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1510627, + "CONCEPT_NAME" : "baricitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "2047232", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 42904205, + "CONCEPT_NAME" : "tofacitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1357536", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/117.json b/inst/treatment_cohorts/117.json new file mode 100644 index 0000000..fcfdfd1 --- /dev/null +++ b/inst/treatment_cohorts/117.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 16, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 16, + "name" : "(Alopecia) Tacrolimus, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36219038, + "CONCEPT_NAME" : "Tacrolimus Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1164204", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/119.json b/inst/treatment_cohorts/119.json new file mode 100644 index 0000000..c7e048c --- /dev/null +++ b/inst/treatment_cohorts/119.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 17, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 17, + "name" : "(Alopecia) Bexarotene, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36226250, + "CONCEPT_NAME" : "bexarotene Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1161188", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/120.json b/inst/treatment_cohorts/120.json new file mode 100644 index 0000000..873540e --- /dev/null +++ b/inst/treatment_cohorts/120.json @@ -0,0 +1,81 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 18, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 18, + "name" : "(Alopecia) Retinoids, topical (Bexarotene, Tretinoin)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36226250, + "CONCEPT_NAME" : "bexarotene Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1161188", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36223379, + "CONCEPT_NAME" : "Tretinoin Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1158220", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/121.json b/inst/treatment_cohorts/121.json new file mode 100644 index 0000000..280a1bc --- /dev/null +++ b/inst/treatment_cohorts/121.json @@ -0,0 +1,81 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 19, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 19, + "name" : "(Alopecia) Monclonal antibodies (Ustekinumab, dupilumab)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40161532, + "CONCEPT_NAME" : "ustekinumab", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "847083", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1593467, + "CONCEPT_NAME" : "dupilumab", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1876376", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/122.json b/inst/treatment_cohorts/122.json new file mode 100644 index 0000000..6396621 --- /dev/null +++ b/inst/treatment_cohorts/122.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 20, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 20, + "name" : "(Alopecia) Apremilast", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 44816294, + "CONCEPT_NAME" : "apremilast", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1492727", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/123.json b/inst/treatment_cohorts/123.json new file mode 100644 index 0000000..3599d93 --- /dev/null +++ b/inst/treatment_cohorts/123.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 21, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 21, + "name" : "(Alopecia) Abatacept", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1186087, + "CONCEPT_NAME" : "abatacept", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "614391", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/124.json b/inst/treatment_cohorts/124.json new file mode 100644 index 0000000..d4d9684 --- /dev/null +++ b/inst/treatment_cohorts/124.json @@ -0,0 +1,64 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 22, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 22, + "name" : "(Alopecia) Crisaborole", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1593397, + "CONCEPT_NAME" : "crisaborole", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1865953", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/125.json b/inst/treatment_cohorts/125.json new file mode 100644 index 0000000..0d53a18 --- /dev/null +++ b/inst/treatment_cohorts/125.json @@ -0,0 +1,77 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 23, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 23, + "name" : "(Alopecia) Psoralens and ultraviolet A (PUVA), photochemotherapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 2314256, + "CONCEPT_NAME" : "Photochemotherapy; psoralens and ultraviolet A (PUVA)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "96912", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4262683, + "CONCEPT_NAME" : "Photochemotherapy with psoralens and ultraviolet A", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "46467001", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/126.json b/inst/treatment_cohorts/126.json new file mode 100644 index 0000000..1a434b5 --- /dev/null +++ b/inst/treatment_cohorts/126.json @@ -0,0 +1,77 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 24, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 24, + "name" : "(Alopecia) Ultraviolet A (UVA) light therapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4138632, + "CONCEPT_NAME" : "Ultraviolet A light therapy to skin", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "425893002", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4039592, + "CONCEPT_NAME" : "Ultraviolet A therapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "229587005", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/127.json b/inst/treatment_cohorts/127.json new file mode 100644 index 0000000..818d2da --- /dev/null +++ b/inst/treatment_cohorts/127.json @@ -0,0 +1,60 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DeviceExposure" : { + "CodesetId" : 25, + "DeviceTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" + } + }, + "ConceptSets" : [ + { + "id" : 25, + "name" : "(Alopecia) Excimerlaser, dermatological, device", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 45762264, + "CONCEPT_NAME" : "Dermatological excimer laser system", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "468800009", + "DOMAIN_ID" : "Device", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Physical Object" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/renv/.gitignore b/renv/.gitignore new file mode 100644 index 0000000..0ec0cbb --- /dev/null +++ b/renv/.gitignore @@ -0,0 +1,7 @@ +library/ +local/ +cellar/ +lock/ +python/ +sandbox/ +staging/ diff --git a/renv/activate.R b/renv/activate.R new file mode 100644 index 0000000..cb5401f --- /dev/null +++ b/renv/activate.R @@ -0,0 +1,1180 @@ + +local({ + + # the requested version of renv + version <- "1.0.3" + attr(version, "sha") <- NULL + + # the project directory + project <- getwd() + + # use start-up diagnostics if enabled + diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE") + if (diagnostics) { + start <- Sys.time() + profile <- tempfile("renv-startup-", fileext = ".Rprof") + utils::Rprof(profile) + on.exit({ + utils::Rprof(NULL) + elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L) + writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed))) + writeLines(sprintf("- Profile: %s", profile)) + print(utils::summaryRprof(profile)) + }, add = TRUE) + } + + # figure out whether the autoloader is enabled + enabled <- local({ + + # first, check config option + override <- getOption("renv.config.autoloader.enabled") + if (!is.null(override)) + return(override) + + # next, check environment variables + # TODO: prefer using the configuration one in the future + envvars <- c( + "RENV_CONFIG_AUTOLOADER_ENABLED", + "RENV_AUTOLOADER_ENABLED", + "RENV_ACTIVATE_PROJECT" + ) + + for (envvar in envvars) { + envval <- Sys.getenv(envvar, unset = NA) + if (!is.na(envval)) + return(tolower(envval) %in% c("true", "t", "1")) + } + + # enable by default + TRUE + + }) + + if (!enabled) + return(FALSE) + + # avoid recursion + if (identical(getOption("renv.autoloader.running"), TRUE)) { + warning("ignoring recursive attempt to run renv autoloader") + return(invisible(TRUE)) + } + + # signal that we're loading renv during R startup + options(renv.autoloader.running = TRUE) + on.exit(options(renv.autoloader.running = NULL), add = TRUE) + + # signal that we've consented to use renv + options(renv.consent = TRUE) + + # load the 'utils' package eagerly -- this ensures that renv shims, which + # mask 'utils' packages, will come first on the search path + library(utils, lib.loc = .Library) + + # unload renv if it's already been loaded + if ("renv" %in% loadedNamespaces()) + unloadNamespace("renv") + + # load bootstrap tools + `%||%` <- function(x, y) { + if (is.null(x)) y else x + } + + catf <- function(fmt, ..., appendLF = TRUE) { + + quiet <- getOption("renv.bootstrap.quiet", default = FALSE) + if (quiet) + return(invisible()) + + msg <- sprintf(fmt, ...) + cat(msg, file = stdout(), sep = if (appendLF) "\n" else "") + + invisible(msg) + + } + + header <- function(label, + ..., + prefix = "#", + suffix = "-", + n = min(getOption("width"), 78)) + { + label <- sprintf(label, ...) + n <- max(n - nchar(label) - nchar(prefix) - 2L, 8L) + if (n <= 0) + return(paste(prefix, label)) + + tail <- paste(rep.int(suffix, n), collapse = "") + paste0(prefix, " ", label, " ", tail) + + } + + startswith <- function(string, prefix) { + substring(string, 1, nchar(prefix)) == prefix + } + + bootstrap <- function(version, library) { + + friendly <- renv_bootstrap_version_friendly(version) + section <- header(sprintf("Bootstrapping renv %s", friendly)) + catf(section) + + # attempt to download renv + catf("- Downloading renv ... ", appendLF = FALSE) + withCallingHandlers( + tarball <- renv_bootstrap_download(version), + error = function(err) { + catf("FAILED") + stop("failed to download:\n", conditionMessage(err)) + } + ) + catf("OK") + on.exit(unlink(tarball), add = TRUE) + + # now attempt to install + catf("- Installing renv ... ", appendLF = FALSE) + withCallingHandlers( + status <- renv_bootstrap_install(version, tarball, library), + error = function(err) { + catf("FAILED") + stop("failed to install:\n", conditionMessage(err)) + } + ) + catf("OK") + + # add empty line to break up bootstrapping from normal output + catf("") + + return(invisible()) + } + + renv_bootstrap_tests_running <- function() { + getOption("renv.tests.running", default = FALSE) + } + + renv_bootstrap_repos <- function() { + + # get CRAN repository + cran <- getOption("renv.repos.cran", "https://cloud.r-project.org") + + # check for repos override + repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA) + if (!is.na(repos)) { + + # check for RSPM; if set, use a fallback repository for renv + rspm <- Sys.getenv("RSPM", unset = NA) + if (identical(rspm, repos)) + repos <- c(RSPM = rspm, CRAN = cran) + + return(repos) + + } + + # check for lockfile repositories + repos <- tryCatch(renv_bootstrap_repos_lockfile(), error = identity) + if (!inherits(repos, "error") && length(repos)) + return(repos) + + # retrieve current repos + repos <- getOption("repos") + + # ensure @CRAN@ entries are resolved + repos[repos == "@CRAN@"] <- cran + + # add in renv.bootstrap.repos if set + default <- c(FALLBACK = "https://cloud.r-project.org") + extra <- getOption("renv.bootstrap.repos", default = default) + repos <- c(repos, extra) + + # remove duplicates that might've snuck in + dupes <- duplicated(repos) | duplicated(names(repos)) + repos[!dupes] + + } + + renv_bootstrap_repos_lockfile <- function() { + + lockpath <- Sys.getenv("RENV_PATHS_LOCKFILE", unset = "renv.lock") + if (!file.exists(lockpath)) + return(NULL) + + lockfile <- tryCatch(renv_json_read(lockpath), error = identity) + if (inherits(lockfile, "error")) { + warning(lockfile) + return(NULL) + } + + repos <- lockfile$R$Repositories + if (length(repos) == 0) + return(NULL) + + keys <- vapply(repos, `[[`, "Name", FUN.VALUE = character(1)) + vals <- vapply(repos, `[[`, "URL", FUN.VALUE = character(1)) + names(vals) <- keys + + return(vals) + + } + + renv_bootstrap_download <- function(version) { + + sha <- attr(version, "sha", exact = TRUE) + + methods <- if (!is.null(sha)) { + + # attempting to bootstrap a development version of renv + c( + function() renv_bootstrap_download_tarball(sha), + function() renv_bootstrap_download_github(sha) + ) + + } else { + + # attempting to bootstrap a release version of renv + c( + function() renv_bootstrap_download_tarball(version), + function() renv_bootstrap_download_cran_latest(version), + function() renv_bootstrap_download_cran_archive(version) + ) + + } + + for (method in methods) { + path <- tryCatch(method(), error = identity) + if (is.character(path) && file.exists(path)) + return(path) + } + + stop("All download methods failed") + + } + + renv_bootstrap_download_impl <- function(url, destfile) { + + mode <- "wb" + + # https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17715 + fixup <- + Sys.info()[["sysname"]] == "Windows" && + substring(url, 1L, 5L) == "file:" + + if (fixup) + mode <- "w+b" + + args <- list( + url = url, + destfile = destfile, + mode = mode, + quiet = TRUE + ) + + if ("headers" %in% names(formals(utils::download.file))) + args$headers <- renv_bootstrap_download_custom_headers(url) + + do.call(utils::download.file, args) + + } + + renv_bootstrap_download_custom_headers <- function(url) { + + headers <- getOption("renv.download.headers") + if (is.null(headers)) + return(character()) + + if (!is.function(headers)) + stopf("'renv.download.headers' is not a function") + + headers <- headers(url) + if (length(headers) == 0L) + return(character()) + + if (is.list(headers)) + headers <- unlist(headers, recursive = FALSE, use.names = TRUE) + + ok <- + is.character(headers) && + is.character(names(headers)) && + all(nzchar(names(headers))) + + if (!ok) + stop("invocation of 'renv.download.headers' did not return a named character vector") + + headers + + } + + renv_bootstrap_download_cran_latest <- function(version) { + + spec <- renv_bootstrap_download_cran_latest_find(version) + type <- spec$type + repos <- spec$repos + + baseurl <- utils::contrib.url(repos = repos, type = type) + ext <- if (identical(type, "source")) + ".tar.gz" + else if (Sys.info()[["sysname"]] == "Windows") + ".zip" + else + ".tgz" + name <- sprintf("renv_%s%s", version, ext) + url <- paste(baseurl, name, sep = "/") + + destfile <- file.path(tempdir(), name) + status <- tryCatch( + renv_bootstrap_download_impl(url, destfile), + condition = identity + ) + + if (inherits(status, "condition")) + return(FALSE) + + # report success and return + destfile + + } + + renv_bootstrap_download_cran_latest_find <- function(version) { + + # check whether binaries are supported on this system + binary <- + getOption("renv.bootstrap.binary", default = TRUE) && + !identical(.Platform$pkgType, "source") && + !identical(getOption("pkgType"), "source") && + Sys.info()[["sysname"]] %in% c("Darwin", "Windows") + + types <- c(if (binary) "binary", "source") + + # iterate over types + repositories + for (type in types) { + for (repos in renv_bootstrap_repos()) { + + # retrieve package database + db <- tryCatch( + as.data.frame( + utils::available.packages(type = type, repos = repos), + stringsAsFactors = FALSE + ), + error = identity + ) + + if (inherits(db, "error")) + next + + # check for compatible entry + entry <- db[db$Package %in% "renv" & db$Version %in% version, ] + if (nrow(entry) == 0) + next + + # found it; return spec to caller + spec <- list(entry = entry, type = type, repos = repos) + return(spec) + + } + } + + # if we got here, we failed to find renv + fmt <- "renv %s is not available from your declared package repositories" + stop(sprintf(fmt, version)) + + } + + renv_bootstrap_download_cran_archive <- function(version) { + + name <- sprintf("renv_%s.tar.gz", version) + repos <- renv_bootstrap_repos() + urls <- file.path(repos, "src/contrib/Archive/renv", name) + destfile <- file.path(tempdir(), name) + + for (url in urls) { + + status <- tryCatch( + renv_bootstrap_download_impl(url, destfile), + condition = identity + ) + + if (identical(status, 0L)) + return(destfile) + + } + + return(FALSE) + + } + + renv_bootstrap_download_tarball <- function(version) { + + # if the user has provided the path to a tarball via + # an environment variable, then use it + tarball <- Sys.getenv("RENV_BOOTSTRAP_TARBALL", unset = NA) + if (is.na(tarball)) + return() + + # allow directories + if (dir.exists(tarball)) { + name <- sprintf("renv_%s.tar.gz", version) + tarball <- file.path(tarball, name) + } + + # bail if it doesn't exist + if (!file.exists(tarball)) { + + # let the user know we weren't able to honour their request + fmt <- "- RENV_BOOTSTRAP_TARBALL is set (%s) but does not exist." + msg <- sprintf(fmt, tarball) + warning(msg) + + # bail + return() + + } + + catf("- Using local tarball '%s'.", tarball) + tarball + + } + + renv_bootstrap_download_github <- function(version) { + + enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE") + if (!identical(enabled, "TRUE")) + return(FALSE) + + # prepare download options + pat <- Sys.getenv("GITHUB_PAT") + if (nzchar(Sys.which("curl")) && nzchar(pat)) { + fmt <- "--location --fail --header \"Authorization: token %s\"" + extra <- sprintf(fmt, pat) + saved <- options("download.file.method", "download.file.extra") + options(download.file.method = "curl", download.file.extra = extra) + on.exit(do.call(base::options, saved), add = TRUE) + } else if (nzchar(Sys.which("wget")) && nzchar(pat)) { + fmt <- "--header=\"Authorization: token %s\"" + extra <- sprintf(fmt, pat) + saved <- options("download.file.method", "download.file.extra") + options(download.file.method = "wget", download.file.extra = extra) + on.exit(do.call(base::options, saved), add = TRUE) + } + + url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version) + name <- sprintf("renv_%s.tar.gz", version) + destfile <- file.path(tempdir(), name) + + status <- tryCatch( + renv_bootstrap_download_impl(url, destfile), + condition = identity + ) + + if (!identical(status, 0L)) + return(FALSE) + + renv_bootstrap_download_augment(destfile) + + return(destfile) + + } + + # Add Sha to DESCRIPTION. This is stop gap until #890, after which we + # can use renv::install() to fully capture metadata. + renv_bootstrap_download_augment <- function(destfile) { + sha <- renv_bootstrap_git_extract_sha1_tar(destfile) + if (is.null(sha)) { + return() + } + + # Untar + tempdir <- tempfile("renv-github-") + on.exit(unlink(tempdir, recursive = TRUE), add = TRUE) + untar(destfile, exdir = tempdir) + pkgdir <- dir(tempdir, full.names = TRUE)[[1]] + + # Modify description + desc_path <- file.path(pkgdir, "DESCRIPTION") + desc_lines <- readLines(desc_path) + remotes_fields <- c( + "RemoteType: github", + "RemoteHost: api.github.com", + "RemoteRepo: renv", + "RemoteUsername: rstudio", + "RemotePkgRef: rstudio/renv", + paste("RemoteRef: ", sha), + paste("RemoteSha: ", sha) + ) + writeLines(c(desc_lines[desc_lines != ""], remotes_fields), con = desc_path) + + # Re-tar + local({ + old <- setwd(tempdir) + on.exit(setwd(old), add = TRUE) + + tar(destfile, compression = "gzip") + }) + invisible() + } + + # Extract the commit hash from a git archive. Git archives include the SHA1 + # hash as the comment field of the tarball pax extended header + # (see https://www.kernel.org/pub/software/scm/git/docs/git-archive.html) + # For GitHub archives this should be the first header after the default one + # (512 byte) header. + renv_bootstrap_git_extract_sha1_tar <- function(bundle) { + + # open the bundle for reading + # We use gzcon for everything because (from ?gzcon) + # > Reading from a connection which does not supply a 'gzip' magic + # > header is equivalent to reading from the original connection + conn <- gzcon(file(bundle, open = "rb", raw = TRUE)) + on.exit(close(conn)) + + # The default pax header is 512 bytes long and the first pax extended header + # with the comment should be 51 bytes long + # `52 comment=` (11 chars) + 40 byte SHA1 hash + len <- 0x200 + 0x33 + res <- rawToChar(readBin(conn, "raw", n = len)[0x201:len]) + + if (grepl("^52 comment=", res)) { + sub("52 comment=", "", res) + } else { + NULL + } + } + + renv_bootstrap_install <- function(version, tarball, library) { + + # attempt to install it into project library + dir.create(library, showWarnings = FALSE, recursive = TRUE) + output <- renv_bootstrap_install_impl(library, tarball) + + # check for successful install + status <- attr(output, "status") + if (is.null(status) || identical(status, 0L)) + return(status) + + # an error occurred; report it + header <- "installation of renv failed" + lines <- paste(rep.int("=", nchar(header)), collapse = "") + text <- paste(c(header, lines, output), collapse = "\n") + stop(text) + + } + + renv_bootstrap_install_impl <- function(library, tarball) { + + # invoke using system2 so we can capture and report output + bin <- R.home("bin") + exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" + R <- file.path(bin, exe) + + args <- c( + "--vanilla", "CMD", "INSTALL", "--no-multiarch", + "-l", shQuote(path.expand(library)), + shQuote(path.expand(tarball)) + ) + + system2(R, args, stdout = TRUE, stderr = TRUE) + + } + + renv_bootstrap_platform_prefix <- function() { + + # construct version prefix + version <- paste(R.version$major, R.version$minor, sep = ".") + prefix <- paste("R", numeric_version(version)[1, 1:2], sep = "-") + + # include SVN revision for development versions of R + # (to avoid sharing platform-specific artefacts with released versions of R) + devel <- + identical(R.version[["status"]], "Under development (unstable)") || + identical(R.version[["nickname"]], "Unsuffered Consequences") + + if (devel) + prefix <- paste(prefix, R.version[["svn rev"]], sep = "-r") + + # build list of path components + components <- c(prefix, R.version$platform) + + # include prefix if provided by user + prefix <- renv_bootstrap_platform_prefix_impl() + if (!is.na(prefix) && nzchar(prefix)) + components <- c(prefix, components) + + # build prefix + paste(components, collapse = "/") + + } + + renv_bootstrap_platform_prefix_impl <- function() { + + # if an explicit prefix has been supplied, use it + prefix <- Sys.getenv("RENV_PATHS_PREFIX", unset = NA) + if (!is.na(prefix)) + return(prefix) + + # if the user has requested an automatic prefix, generate it + auto <- Sys.getenv("RENV_PATHS_PREFIX_AUTO", unset = NA) + if (auto %in% c("TRUE", "True", "true", "1")) + return(renv_bootstrap_platform_prefix_auto()) + + # empty string on failure + "" + + } + + renv_bootstrap_platform_prefix_auto <- function() { + + prefix <- tryCatch(renv_bootstrap_platform_os(), error = identity) + if (inherits(prefix, "error") || prefix %in% "unknown") { + + msg <- paste( + "failed to infer current operating system", + "please file a bug report at https://github.com/rstudio/renv/issues", + sep = "; " + ) + + warning(msg) + + } + + prefix + + } + + renv_bootstrap_platform_os <- function() { + + sysinfo <- Sys.info() + sysname <- sysinfo[["sysname"]] + + # handle Windows + macOS up front + if (sysname == "Windows") + return("windows") + else if (sysname == "Darwin") + return("macos") + + # check for os-release files + for (file in c("/etc/os-release", "/usr/lib/os-release")) + if (file.exists(file)) + return(renv_bootstrap_platform_os_via_os_release(file, sysinfo)) + + # check for redhat-release files + if (file.exists("/etc/redhat-release")) + return(renv_bootstrap_platform_os_via_redhat_release()) + + "unknown" + + } + + renv_bootstrap_platform_os_via_os_release <- function(file, sysinfo) { + + # read /etc/os-release + release <- utils::read.table( + file = file, + sep = "=", + quote = c("\"", "'"), + col.names = c("Key", "Value"), + comment.char = "#", + stringsAsFactors = FALSE + ) + + vars <- as.list(release$Value) + names(vars) <- release$Key + + # get os name + os <- tolower(sysinfo[["sysname"]]) + + # read id + id <- "unknown" + for (field in c("ID", "ID_LIKE")) { + if (field %in% names(vars) && nzchar(vars[[field]])) { + id <- vars[[field]] + break + } + } + + # read version + version <- "unknown" + for (field in c("UBUNTU_CODENAME", "VERSION_CODENAME", "VERSION_ID", "BUILD_ID")) { + if (field %in% names(vars) && nzchar(vars[[field]])) { + version <- vars[[field]] + break + } + } + + # join together + paste(c(os, id, version), collapse = "-") + + } + + renv_bootstrap_platform_os_via_redhat_release <- function() { + + # read /etc/redhat-release + contents <- readLines("/etc/redhat-release", warn = FALSE) + + # infer id + id <- if (grepl("centos", contents, ignore.case = TRUE)) + "centos" + else if (grepl("redhat", contents, ignore.case = TRUE)) + "redhat" + else + "unknown" + + # try to find a version component (very hacky) + version <- "unknown" + + parts <- strsplit(contents, "[[:space:]]")[[1L]] + for (part in parts) { + + nv <- tryCatch(numeric_version(part), error = identity) + if (inherits(nv, "error")) + next + + version <- nv[1, 1] + break + + } + + paste(c("linux", id, version), collapse = "-") + + } + + renv_bootstrap_library_root_name <- function(project) { + + # use project name as-is if requested + asis <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT_ASIS", unset = "FALSE") + if (asis) + return(basename(project)) + + # otherwise, disambiguate based on project's path + id <- substring(renv_bootstrap_hash_text(project), 1L, 8L) + paste(basename(project), id, sep = "-") + + } + + renv_bootstrap_library_root <- function(project) { + + prefix <- renv_bootstrap_profile_prefix() + + path <- Sys.getenv("RENV_PATHS_LIBRARY", unset = NA) + if (!is.na(path)) + return(paste(c(path, prefix), collapse = "/")) + + path <- renv_bootstrap_library_root_impl(project) + if (!is.null(path)) { + name <- renv_bootstrap_library_root_name(project) + return(paste(c(path, prefix, name), collapse = "/")) + } + + renv_bootstrap_paths_renv("library", project = project) + + } + + renv_bootstrap_library_root_impl <- function(project) { + + root <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA) + if (!is.na(root)) + return(root) + + type <- renv_bootstrap_project_type(project) + if (identical(type, "package")) { + userdir <- renv_bootstrap_user_dir() + return(file.path(userdir, "library")) + } + + } + + renv_bootstrap_validate_version <- function(version, description = NULL) { + + # resolve description file + # + # avoid passing lib.loc to `packageDescription()` below, since R will + # use the loaded version of the package by default anyhow. note that + # this function should only be called after 'renv' is loaded + # https://github.com/rstudio/renv/issues/1625 + description <- description %||% packageDescription("renv") + + # check whether requested version 'version' matches loaded version of renv + sha <- attr(version, "sha", exact = TRUE) + valid <- if (!is.null(sha)) + renv_bootstrap_validate_version_dev(sha, description) + else + renv_bootstrap_validate_version_release(version, description) + + if (valid) + return(TRUE) + + # the loaded version of renv doesn't match the requested version; + # give the user instructions on how to proceed + remote <- if (!is.null(description[["RemoteSha"]])) { + paste("rstudio/renv", description[["RemoteSha"]], sep = "@") + } else { + paste("renv", description[["Version"]], sep = "@") + } + + # display both loaded version + sha if available + friendly <- renv_bootstrap_version_friendly( + version = description[["Version"]], + sha = description[["RemoteSha"]] + ) + + fmt <- paste( + "renv %1$s was loaded from project library, but this project is configured to use renv %2$s.", + "- Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.", + "- Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", + sep = "\n" + ) + catf(fmt, friendly, renv_bootstrap_version_friendly(version), remote) + + FALSE + + } + + renv_bootstrap_validate_version_dev <- function(version, description) { + expected <- description[["RemoteSha"]] + is.character(expected) && startswith(expected, version) + } + + renv_bootstrap_validate_version_release <- function(version, description) { + expected <- description[["Version"]] + is.character(expected) && identical(expected, version) + } + + renv_bootstrap_hash_text <- function(text) { + + hashfile <- tempfile("renv-hash-") + on.exit(unlink(hashfile), add = TRUE) + + writeLines(text, con = hashfile) + tools::md5sum(hashfile) + + } + + renv_bootstrap_load <- function(project, libpath, version) { + + # try to load renv from the project library + if (!requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) + return(FALSE) + + # warn if the version of renv loaded does not match + renv_bootstrap_validate_version(version) + + # execute renv load hooks, if any + hooks <- getHook("renv::autoload") + for (hook in hooks) + if (is.function(hook)) + tryCatch(hook(), error = warnify) + + # load the project + renv::load(project) + + TRUE + + } + + renv_bootstrap_profile_load <- function(project) { + + # if RENV_PROFILE is already set, just use that + profile <- Sys.getenv("RENV_PROFILE", unset = NA) + if (!is.na(profile) && nzchar(profile)) + return(profile) + + # check for a profile file (nothing to do if it doesn't exist) + path <- renv_bootstrap_paths_renv("profile", profile = FALSE, project = project) + if (!file.exists(path)) + return(NULL) + + # read the profile, and set it if it exists + contents <- readLines(path, warn = FALSE) + if (length(contents) == 0L) + return(NULL) + + # set RENV_PROFILE + profile <- contents[[1L]] + if (!profile %in% c("", "default")) + Sys.setenv(RENV_PROFILE = profile) + + profile + + } + + renv_bootstrap_profile_prefix <- function() { + profile <- renv_bootstrap_profile_get() + if (!is.null(profile)) + return(file.path("profiles", profile, "renv")) + } + + renv_bootstrap_profile_get <- function() { + profile <- Sys.getenv("RENV_PROFILE", unset = "") + renv_bootstrap_profile_normalize(profile) + } + + renv_bootstrap_profile_set <- function(profile) { + profile <- renv_bootstrap_profile_normalize(profile) + if (is.null(profile)) + Sys.unsetenv("RENV_PROFILE") + else + Sys.setenv(RENV_PROFILE = profile) + } + + renv_bootstrap_profile_normalize <- function(profile) { + + if (is.null(profile) || profile %in% c("", "default")) + return(NULL) + + profile + + } + + renv_bootstrap_path_absolute <- function(path) { + + substr(path, 1L, 1L) %in% c("~", "/", "\\") || ( + substr(path, 1L, 1L) %in% c(letters, LETTERS) && + substr(path, 2L, 3L) %in% c(":/", ":\\") + ) + + } + + renv_bootstrap_paths_renv <- function(..., profile = TRUE, project = NULL) { + renv <- Sys.getenv("RENV_PATHS_RENV", unset = "renv") + root <- if (renv_bootstrap_path_absolute(renv)) NULL else project + prefix <- if (profile) renv_bootstrap_profile_prefix() + components <- c(root, renv, prefix, ...) + paste(components, collapse = "/") + } + + renv_bootstrap_project_type <- function(path) { + + descpath <- file.path(path, "DESCRIPTION") + if (!file.exists(descpath)) + return("unknown") + + desc <- tryCatch( + read.dcf(descpath, all = TRUE), + error = identity + ) + + if (inherits(desc, "error")) + return("unknown") + + type <- desc$Type + if (!is.null(type)) + return(tolower(type)) + + package <- desc$Package + if (!is.null(package)) + return("package") + + "unknown" + + } + + renv_bootstrap_user_dir <- function() { + dir <- renv_bootstrap_user_dir_impl() + path.expand(chartr("\\", "/", dir)) + } + + renv_bootstrap_user_dir_impl <- function() { + + # use local override if set + override <- getOption("renv.userdir.override") + if (!is.null(override)) + return(override) + + # use R_user_dir if available + tools <- asNamespace("tools") + if (is.function(tools$R_user_dir)) + return(tools$R_user_dir("renv", "cache")) + + # try using our own backfill for older versions of R + envvars <- c("R_USER_CACHE_DIR", "XDG_CACHE_HOME") + for (envvar in envvars) { + root <- Sys.getenv(envvar, unset = NA) + if (!is.na(root)) + return(file.path(root, "R/renv")) + } + + # use platform-specific default fallbacks + if (Sys.info()[["sysname"]] == "Windows") + file.path(Sys.getenv("LOCALAPPDATA"), "R/cache/R/renv") + else if (Sys.info()[["sysname"]] == "Darwin") + "~/Library/Caches/org.R-project.R/R/renv" + else + "~/.cache/R/renv" + + } + + renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) { + sha <- sha %||% attr(version, "sha", exact = TRUE) + parts <- c(version, sprintf(shafmt %||% " [sha: %s]", substring(sha, 1L, 7L))) + paste(parts, collapse = "") + } + + renv_bootstrap_exec <- function(project, libpath, version) { + if (!renv_bootstrap_load(project, libpath, version)) + renv_bootstrap_run(version, libpath) + } + + renv_bootstrap_run <- function(version, libpath) { + + # perform bootstrap + bootstrap(version, libpath) + + # exit early if we're just testing bootstrap + if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) + return(TRUE) + + # try again to load + if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { + return(renv::load(project = getwd())) + } + + # failed to download or load renv; warn the user + msg <- c( + "Failed to find an renv installation: the project will not be loaded.", + "Use `renv::activate()` to re-initialize the project." + ) + + warning(paste(msg, collapse = "\n"), call. = FALSE) + + } + + renv_json_read <- function(file = NULL, text = NULL) { + + jlerr <- NULL + + # if jsonlite is loaded, use that instead + if ("jsonlite" %in% loadedNamespaces()) { + + json <- catch(renv_json_read_jsonlite(file, text)) + if (!inherits(json, "error")) + return(json) + + jlerr <- json + + } + + # otherwise, fall back to the default JSON reader + json <- catch(renv_json_read_default(file, text)) + if (!inherits(json, "error")) + return(json) + + # report an error + if (!is.null(jlerr)) + stop(jlerr) + else + stop(json) + + } + + renv_json_read_jsonlite <- function(file = NULL, text = NULL) { + text <- paste(text %||% read(file), collapse = "\n") + jsonlite::fromJSON(txt = text, simplifyVector = FALSE) + } + + renv_json_read_default <- function(file = NULL, text = NULL) { + + # find strings in the JSON + text <- paste(text %||% read(file), collapse = "\n") + pattern <- '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + locs <- gregexpr(pattern, text, perl = TRUE)[[1]] + + # if any are found, replace them with placeholders + replaced <- text + strings <- character() + replacements <- character() + + if (!identical(c(locs), -1L)) { + + # get the string values + starts <- locs + ends <- locs + attr(locs, "match.length") - 1L + strings <- substring(text, starts, ends) + + # only keep those requiring escaping + strings <- grep("[[\\]{}:]", strings, perl = TRUE, value = TRUE) + + # compute replacements + replacements <- sprintf('"\032%i\032"', seq_along(strings)) + + # replace the strings + mapply(function(string, replacement) { + replaced <<- sub(string, replacement, replaced, fixed = TRUE) + }, strings, replacements) + + } + + # transform the JSON into something the R parser understands + transformed <- replaced + transformed <- gsub("{}", "`names<-`(list(), character())", transformed, fixed = TRUE) + transformed <- gsub("[[{]", "list(", transformed, perl = TRUE) + transformed <- gsub("[]}]", ")", transformed, perl = TRUE) + transformed <- gsub(":", "=", transformed, fixed = TRUE) + text <- paste(transformed, collapse = "\n") + + # parse it + json <- parse(text = text, keep.source = FALSE, srcfile = NULL)[[1L]] + + # construct map between source strings, replaced strings + map <- as.character(parse(text = strings)) + names(map) <- as.character(parse(text = replacements)) + + # convert to list + map <- as.list(map) + + # remap strings in object + remapped <- renv_json_remap(json, map) + + # evaluate + eval(remapped, envir = baseenv()) + + } + + renv_json_remap <- function(json, map) { + + # fix names + if (!is.null(names(json))) { + lhs <- match(names(json), names(map), nomatch = 0L) + rhs <- match(names(map), names(json), nomatch = 0L) + names(json)[rhs] <- map[lhs] + } + + # fix values + if (is.character(json)) + return(map[[json]] %||% json) + + # handle true, false, null + if (is.name(json)) { + text <- as.character(json) + if (text == "true") + return(TRUE) + else if (text == "false") + return(FALSE) + else if (text == "null") + return(NULL) + } + + # recurse + if (is.recursive(json)) { + for (i in seq_along(json)) { + json[i] <- list(renv_json_remap(json[[i]], map)) + } + } + + json + + } + + # load the renv profile, if any + renv_bootstrap_profile_load(project) + + # construct path to library root + root <- renv_bootstrap_library_root(project) + + # construct library prefix for platform + prefix <- renv_bootstrap_platform_prefix() + + # construct full libpath + libpath <- file.path(root, prefix) + + # run bootstrap code + renv_bootstrap_exec(project, libpath, version) + + invisible() + +}) From f91d7a35842e6bce705e181a32c83d3a6a3ac3b2 Mon Sep 17 00:00:00 2001 From: Maxim Moinat Date: Fri, 17 Nov 2023 09:36:44 +0100 Subject: [PATCH 07/41] update treatment cohorts --- extras/launchShiny.R | 2 +- extras/package-maintenance.R | 12 +- inst/cohorts/100.json | 1677 ++++++++++++++++--------------- inst/treatment_cohorts/101.json | 10 +- inst/treatment_cohorts/102.json | 12 +- inst/treatment_cohorts/103.json | 12 +- inst/treatment_cohorts/104.json | 12 +- inst/treatment_cohorts/105.json | 12 +- inst/treatment_cohorts/106.json | 12 +- inst/treatment_cohorts/107.json | 12 +- inst/treatment_cohorts/108.json | 12 +- inst/treatment_cohorts/109.json | 12 +- inst/treatment_cohorts/110.json | 12 +- inst/treatment_cohorts/111.json | 12 +- inst/treatment_cohorts/112.json | 12 +- inst/treatment_cohorts/113.json | 12 +- inst/treatment_cohorts/114.json | 12 +- inst/treatment_cohorts/115.json | 12 +- inst/treatment_cohorts/116.json | 12 +- inst/treatment_cohorts/117.json | 12 +- inst/treatment_cohorts/119.json | 12 +- inst/treatment_cohorts/120.json | 12 +- inst/treatment_cohorts/121.json | 12 +- inst/treatment_cohorts/122.json | 12 +- inst/treatment_cohorts/123.json | 12 +- inst/treatment_cohorts/124.json | 12 +- inst/treatment_cohorts/125.json | 12 +- inst/treatment_cohorts/126.json | 12 +- inst/treatment_cohorts/127.json | 12 +- 29 files changed, 1128 insertions(+), 873 deletions(-) diff --git a/extras/launchShiny.R b/extras/launchShiny.R index bf4486a..b417f8d 100644 --- a/extras/launchShiny.R +++ b/extras/launchShiny.R @@ -2,7 +2,7 @@ library(CohortDiagnostics) # -- Load results into database resultsPath <- "/Users/maxim/Documents/EHDEN-docs/AA Study-a-thon/results" -pathToZips <- file.path(resultsPath, "fixed_zips") +pathToZips <- file.path(resultsPath, "zips") sqliteDbPath <- file.path(pathToZips, "AACohortDiagnosticsResults.sqlite") createMergedResultsFile(pathToZips, sqliteDbPath = sqliteDbPath, overwrite = TRUE) diff --git a/extras/package-maintenance.R b/extras/package-maintenance.R index 6889c61..94c652a 100644 --- a/extras/package-maintenance.R +++ b/extras/package-maintenance.R @@ -30,12 +30,8 @@ for (cohortId in c(92:97, 100)) { # Get treatment cohort definitions from Atlas ------------------------------ for (cohortId in setdiff(101:127, 118)) { - ROhdsiWebApi::insertCohortDefinitionInPackage( - cohortId, - name = cohortId, - jsonFolder = "inst/treatment_cohorts", - sqlFolder = "inst/sql/sql_server", - baseUrl, - generateStats = FALSE - ) + print(cohortId) + object <- getCohortDefinition(cohortId = cohortId, baseUrl = baseUrl) + json <- ROhdsiWebApi:::.toJSON(object$expression, pretty = TRUE) + writeLines(json, file.path("inst", "treatment_cohorts", paste0(cohortId, ".json"))) } diff --git a/inst/cohorts/100.json b/inst/cohorts/100.json index de4d489..07a4827 100644 --- a/inst/cohorts/100.json +++ b/inst/cohorts/100.json @@ -1,802 +1,905 @@ { - "ConceptSets": [ - { - "id": 3, - "name": "(Alopecia) AT+AU", - "expression": { - "items": [ - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "86166000", - "CONCEPT_ID": 4312756, - "CONCEPT_NAME": "Alopecia universalis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - } - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "19754005", - "CONCEPT_ID": 4056343, - "CONCEPT_NAME": "Alopecia totalis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 3, + "First" : true, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "bt", + "Extent" : "2022-12-31" + }, + "ConditionTypeExclude" : false + } } - ] + ], + "ObservationWindow" : { + "PriorDays" : 730, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "First" } - }, - { - "id": 4, - "name": "(Alopecia) Exclusion - optimised", - "expression": { - "items": [ - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "402637002", - "CONCEPT_ID": 4291286, - "CONCEPT_NAME": "Alopecia due to disturbance of hair cycle", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "239050000", - "CONCEPT_ID": 4082365, - "CONCEPT_NAME": "Alopecia, nail dystrophy, ophthalmic complications, thyroid dysfunction, hypohidrosis, ephelides, enteropathy and respiratory tract infections", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "719275009", - "CONCEPT_ID": 36717706, - "CONCEPT_NAME": "Primary hypergonadotropic hypogonadism and partial alopecia syndrome", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201144006", - "CONCEPT_ID": 4067168, - "CONCEPT_NAME": "Alopecia hereditaria", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "716191002", - "CONCEPT_ID": 37396390, - "CONCEPT_NAME": "Perniola Krajewska Carnevale syndrome", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "5441008", - "CONCEPT_ID": 4182398, - "CONCEPT_NAME": "Tinea capitis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "31082002", - "CONCEPT_ID": 4150045, - "CONCEPT_NAME": "Frostbite alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201139004", - "CONCEPT_ID": 4066852, - "CONCEPT_NAME": "Cachectic alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "239010003", - "CONCEPT_ID": 4082356, - "CONCEPT_NAME": "Alopecia, onychodysplasia, hypohidrosis, deafness ectodermal dysplasia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201141003", - "CONCEPT_ID": 4063460, - "CONCEPT_NAME": "Alopecia neurotica", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201132008", - "CONCEPT_ID": 4063457, - "CONCEPT_NAME": "Frontal alopecia of women", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "716088000", - "CONCEPT_ID": 37396320, - "CONCEPT_NAME": "Follicular hamartoma with alopecia and cystic fibrosis syndrome", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "111024006", - "CONCEPT_ID": 4007459, - "CONCEPT_NAME": "Alopecia liminaris frontalis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "1108009", - "CONCEPT_ID": 4004847, - "CONCEPT_NAME": "Female pattern alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201140002", - "CONCEPT_ID": 4067082, - "CONCEPT_NAME": "Alopecia follicularis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "237616002", - "CONCEPT_ID": 4130165, - "CONCEPT_NAME": "Hypogonadism, diabetes mellitus, alopecia, mental retardation and electrocardiographic abnormalities", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "237895001", - "CONCEPT_ID": 4035150, - "CONCEPT_NAME": "Vitamin D-dependent rickets type II without alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "239019002", - "CONCEPT_ID": 4033634, - "CONCEPT_NAME": "Odonto-onychial dysplasia with alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "39479004", - "CONCEPT_ID": 140173, - "CONCEPT_NAME": "Telogen effluvium", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "17155009", - "CONCEPT_ID": 4062972, - "CONCEPT_NAME": "Trichotillomania", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "763630007", - "CONCEPT_ID": 35622259, - "CONCEPT_NAME": "Satoyoshi syndrome", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "402639004", - "CONCEPT_ID": 4291287, - "CONCEPT_NAME": "Alopecia due to friction and trauma", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201135005", - "CONCEPT_ID": 4063459, - "CONCEPT_NAME": "Alopecia senilis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "54539003", - "CONCEPT_ID": 4185073, - "CONCEPT_NAME": "Endocrine alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "73383004", - "CONCEPT_ID": 4250506, - "CONCEPT_NAME": "Drug-related alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201142005", - "CONCEPT_ID": 4067083, - "CONCEPT_NAME": "Peroneal alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "2965006", - "CONCEPT_ID": 4105584, - "CONCEPT_NAME": "Congenital alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201138007", - "CONCEPT_ID": 4065243, - "CONCEPT_NAME": "Diffuse alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201137002", - "CONCEPT_ID": 4065242, - "CONCEPT_NAME": "Alopecia localis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "67488005", - "CONCEPT_ID": 4285863, - "CONCEPT_NAME": "Traumatic alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "22934003", - "CONCEPT_ID": 4046566, - "CONCEPT_NAME": "Radiation alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201133003", - "CONCEPT_ID": 4066851, - "CONCEPT_NAME": "Premature alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "201136006", - "CONCEPT_ID": 4067081, - "CONCEPT_NAME": "Alopecia febrilis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "27382006", - "CONCEPT_ID": 4099746, - "CONCEPT_NAME": "Alopecia mucinosa", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "67772009", - "CONCEPT_ID": 4194637, - "CONCEPT_NAME": "Thermal burn alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "400088006", - "CONCEPT_ID": 4266794, - "CONCEPT_NAME": "Scarring alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "65130004", - "CONCEPT_ID": 4274978, - "CONCEPT_NAME": "Nutritional alopecia", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true + }, + "ConceptSets" : [ + { + "id" : 3, + "name" : "(Alopecia) AT+AU", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4312756, + "CONCEPT_NAME" : "Alopecia universalis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "86166000", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4056343, + "CONCEPT_NAME" : "Alopecia totalis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19754005", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] } - ] - } - }, - { - "id": 5, - "name": "(Alopecia) AT+AU+AA", - "expression": { - "items": [ - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "68225006", - "CONCEPT_ID": 141933, - "CONCEPT_NAME": "Alopecia areata", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "86166000", - "CONCEPT_ID": 4312756, - "CONCEPT_NAME": "Alopecia universalis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "19754005", - "CONCEPT_ID": 4056343, - "CONCEPT_NAME": "Alopecia totalis", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "includeDescendants": true - }, - { - "concept": { - "CONCEPT_CLASS_ID": "Clinical Finding", - "CONCEPT_CODE": "720980004", - "CONCEPT_ID": 36715349, - "CONCEPT_NAME": "Alopecia, psychomotor epilepsy, periodontal pyorrhea, intellectual disability syndrome", - "DOMAIN_ID": "Condition", - "INVALID_REASON": "V", - "INVALID_REASON_CAPTION": "Valid", - "STANDARD_CONCEPT": "S", - "STANDARD_CONCEPT_CAPTION": "Standard", - "VOCABULARY_ID": "SNOMED" - }, - "isExcluded": true + }, + { + "id" : 4, + "name" : "(Alopecia) Exclusion - optimised", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4291286, + "CONCEPT_NAME" : "Alopecia due to disturbance of hair cycle", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "402637002", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4082365, + "CONCEPT_NAME" : "Alopecia, nail dystrophy, ophthalmic complications, thyroid dysfunction, hypohidrosis, ephelides, enteropathy and respiratory tract infections", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "239050000", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36717706, + "CONCEPT_NAME" : "Primary hypergonadotropic hypogonadism and partial alopecia syndrome", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "719275009", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4067168, + "CONCEPT_NAME" : "Alopecia hereditaria", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201144006", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37396390, + "CONCEPT_NAME" : "Perniola Krajewska Carnevale syndrome", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "716191002", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4182398, + "CONCEPT_NAME" : "Tinea capitis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "5441008", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4150045, + "CONCEPT_NAME" : "Frostbite alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "31082002", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4066852, + "CONCEPT_NAME" : "Cachectic alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201139004", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4082356, + "CONCEPT_NAME" : "Alopecia, onychodysplasia, hypohidrosis, deafness ectodermal dysplasia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "239010003", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4063460, + "CONCEPT_NAME" : "Alopecia neurotica", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201141003", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4063457, + "CONCEPT_NAME" : "Frontal alopecia of women", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201132008", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37396320, + "CONCEPT_NAME" : "Follicular hamartoma with alopecia and cystic fibrosis syndrome", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "716088000", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4007459, + "CONCEPT_NAME" : "Alopecia liminaris frontalis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "111024006", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4004847, + "CONCEPT_NAME" : "Female pattern alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1108009", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4067082, + "CONCEPT_NAME" : "Alopecia follicularis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201140002", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4130165, + "CONCEPT_NAME" : "Hypogonadism, diabetes mellitus, alopecia, mental retardation and electrocardiographic abnormalities", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "237616002", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4035150, + "CONCEPT_NAME" : "Vitamin D-dependent rickets type II without alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "237895001", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4033634, + "CONCEPT_NAME" : "Odonto-onychial dysplasia with alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "239019002", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 140173, + "CONCEPT_NAME" : "Telogen effluvium", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "39479004", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4062972, + "CONCEPT_NAME" : "Trichotillomania", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "17155009", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35622259, + "CONCEPT_NAME" : "Satoyoshi syndrome", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "763630007", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4291287, + "CONCEPT_NAME" : "Alopecia due to friction and trauma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "402639004", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4063459, + "CONCEPT_NAME" : "Alopecia senilis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201135005", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4185073, + "CONCEPT_NAME" : "Endocrine alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "54539003", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4250506, + "CONCEPT_NAME" : "Drug-related alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73383004", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4067083, + "CONCEPT_NAME" : "Peroneal alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201142005", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4105584, + "CONCEPT_NAME" : "Congenital alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "2965006", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4065243, + "CONCEPT_NAME" : "Diffuse alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201138007", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4065242, + "CONCEPT_NAME" : "Alopecia localis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201137002", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4285863, + "CONCEPT_NAME" : "Traumatic alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "67488005", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4046566, + "CONCEPT_NAME" : "Radiation alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "22934003", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4066851, + "CONCEPT_NAME" : "Premature alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201133003", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4067081, + "CONCEPT_NAME" : "Alopecia febrilis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "201136006", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4099746, + "CONCEPT_NAME" : "Alopecia mucinosa", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "27382006", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4194637, + "CONCEPT_NAME" : "Thermal burn alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "67772009", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4266794, + "CONCEPT_NAME" : "Scarring alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "400088006", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4274978, + "CONCEPT_NAME" : "Nutritional alopecia", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "65130004", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] } - ] - } - } - ], - "PrimaryCriteria": { - "CriteriaList": [ + }, { - "ConditionOccurrence": { - "CodesetId": 3, - "OccurrenceStartDate": { - "Value": "2015-01-01", - "Extent": "2022-12-31", - "Op": "bt" - }, - "First": true - } + "id" : 5, + "name" : "(Alopecia) AT+AU+AA", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 141933, + "CONCEPT_NAME" : "Alopecia areata", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "68225006", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4312756, + "CONCEPT_NAME" : "Alopecia universalis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "86166000", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4056343, + "CONCEPT_NAME" : "Alopecia totalis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19754005", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36715349, + "CONCEPT_NAME" : "Alopecia, psychomotor epilepsy, periodontal pyorrhea, intellectual disability syndrome", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "720980004", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : true, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } } - ], - "ObservationWindow": { - "PriorDays": 730, - "PostDays": 0 - }, - "PrimaryCriteriaLimit": { - "Type": "First" - } - }, - "QualifiedLimit": { - "Type": "First" + ], + "QualifiedLimit" : { + "Type" : "First" }, - "ExpressionLimit": { - "Type": "First" + "ExpressionLimit" : { + "Type" : "First" }, - "InclusionRules": [ - { - "name": "iv. Repeated diagnosis", - "description": "Have a minimum of two respective diagnoses in the entire follow-up period, at least 30 days apart, to rule out a misdiagnosis (e.g. hair loss associated with chemotherapy)", - "expression": { - "Type": "ALL", - "CriteriaList": [ - { - "Criteria": { - "ConditionOccurrence": { - "CorrelatedCriteria": { - "Type": "ALL", - "CriteriaList": [ - { - "Criteria": { - "ConditionOccurrence": { - "CodesetId": 5 - } - }, - "StartWindow": { - "Start": { - "Days": 30, - "Coeff": 1 - }, - "End": { - "Coeff": 1 - }, - "UseEventEnd": false - }, - "Occurrence": { - "Type": 2, - "Count": 1 + "InclusionRules" : [ + { + "name" : "iv. Repeated diagnosis", + "description" : "Have a minimum of two respective diagnoses in the entire follow-up period, at least 30 days apart, to rule out a misdiagnosis (e.g. hair loss associated with chemotherapy)", + "expression" : { + "Type" : "ALL", + "CriteriaList" : [ + { + "Criteria" : { + "ConditionOccurrence" : { + "CorrelatedCriteria" : { + "Type" : "ALL", + "CriteriaList" : [ + { + "Criteria" : { + "ConditionOccurrence" : { + "CodesetId" : 5, + "ConditionTypeExclude" : false + } + }, + "StartWindow" : { + "Start" : { + "Days" : 30, + "Coeff" : 1 + }, + "End" : { + "Coeff" : 1 + }, + "UseIndexEnd" : false, + "UseEventEnd" : false + }, + "RestrictVisit" : false, + "IgnoreObservationPeriod" : false, + "Occurrence" : { + "Type" : 2, + "Count" : 1, + "IsDistinct" : false + } + } + ], + "DemographicCriteriaList" : [], + "Groups" : [] + }, + "CodesetId" : 5, + "ConditionTypeExclude" : false + } + }, + "StartWindow" : { + "Start" : { + "Coeff" : -1 + }, + "End" : { + "Days" : 2920, + "Coeff" : 1 + }, + "UseIndexEnd" : false, + "UseEventEnd" : false + }, + "RestrictVisit" : false, + "IgnoreObservationPeriod" : false, + "Occurrence" : { + "Type" : 2, + "Count" : 1, + "IsDistinct" : false } - } - ], - "DemographicCriteriaList": [], - "Groups": [] - }, - "CodesetId": 5 - } - }, - "StartWindow": { - "Start": { - "Coeff": -1 - }, - "End": { - "Days": 2920, - "Coeff": 1 - }, - "UseEventEnd": false - }, - "Occurrence": { - "Type": 2, - "Count": 1 - } + } + ], + "DemographicCriteriaList" : [], + "Groups" : [] } - ], - "DemographicCriteriaList": [], - "Groups": [] - } - }, - { - "name": "v. No alternative diagnoses", - "description": "In the two years subsequent to the index date, have no occurrence of an alternative diagnosis or specified treatment", - "expression": { - "Type": "ALL", - "CriteriaList": [ - { - "Criteria": { - "ConditionOccurrence": { - "CodesetId": 4 - } - }, - "StartWindow": { - "Start": { - "Days": 0, - "Coeff": -1 - }, - "End": { - "Days": 730, - "Coeff": 1 - }, - "UseEventEnd": false - }, - "Occurrence": { - "Type": 0, - "Count": 0 - } + }, + { + "name" : "v. No alternative diagnoses", + "description" : "In the two years subsequent to the index date, have no occurrence of an alternative diagnosis or specified treatment", + "expression" : { + "Type" : "ALL", + "CriteriaList" : [ + { + "Criteria" : { + "ConditionOccurrence" : { + "CodesetId" : 4, + "ConditionTypeExclude" : false + } + }, + "StartWindow" : { + "Start" : { + "Days" : 0, + "Coeff" : -1 + }, + "End" : { + "Days" : 730, + "Coeff" : 1 + }, + "UseIndexEnd" : false, + "UseEventEnd" : false + }, + "RestrictVisit" : false, + "IgnoreObservationPeriod" : false, + "Occurrence" : { + "Type" : 0, + "Count" : 0, + "IsDistinct" : false + } + } + ], + "DemographicCriteriaList" : [], + "Groups" : [] } - ], - "DemographicCriteriaList": [], - "Groups": [] } - } ], - "CensoringCriteria": [], - "CollapseSettings": { - "CollapseType": "ERA", - "EraPad": 0 + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 }, - "CensorWindow": {}, - "cdmVersionRange": ">=5.0.0" - } \ No newline at end of file + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/treatment_cohorts/101.json b/inst/treatment_cohorts/101.json index b4f806d..0422117 100644 --- a/inst/treatment_cohorts/101.json +++ b/inst/treatment_cohorts/101.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -55,10 +55,16 @@ "Type" : "First" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/102.json b/inst/treatment_cohorts/102.json index 690d852..0d21f8e 100644 --- a/inst/treatment_cohorts/102.json +++ b/inst/treatment_cohorts/102.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/103.json b/inst/treatment_cohorts/103.json index aa40b54..3eea489 100644 --- a/inst/treatment_cohorts/103.json +++ b/inst/treatment_cohorts/103.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -239,13 +239,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/104.json b/inst/treatment_cohorts/104.json index 714f657..17fecd6 100644 --- a/inst/treatment_cohorts/104.json +++ b/inst/treatment_cohorts/104.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -103,13 +103,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/105.json b/inst/treatment_cohorts/105.json index 9380358..6355e3e 100644 --- a/inst/treatment_cohorts/105.json +++ b/inst/treatment_cohorts/105.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/106.json b/inst/treatment_cohorts/106.json index 8b694ef..57cbcb7 100644 --- a/inst/treatment_cohorts/106.json +++ b/inst/treatment_cohorts/106.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/107.json b/inst/treatment_cohorts/107.json index ddf2055..cf67737 100644 --- a/inst/treatment_cohorts/107.json +++ b/inst/treatment_cohorts/107.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/108.json b/inst/treatment_cohorts/108.json index ee45d28..6f51c23 100644 --- a/inst/treatment_cohorts/108.json +++ b/inst/treatment_cohorts/108.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/109.json b/inst/treatment_cohorts/109.json index a4375a8..ec6b8d7 100644 --- a/inst/treatment_cohorts/109.json +++ b/inst/treatment_cohorts/109.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/110.json b/inst/treatment_cohorts/110.json index 11a3f37..909b0d0 100644 --- a/inst/treatment_cohorts/110.json +++ b/inst/treatment_cohorts/110.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/111.json b/inst/treatment_cohorts/111.json index 0156568..341a697 100644 --- a/inst/treatment_cohorts/111.json +++ b/inst/treatment_cohorts/111.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/112.json b/inst/treatment_cohorts/112.json index fa8129b..5bec38c 100644 --- a/inst/treatment_cohorts/112.json +++ b/inst/treatment_cohorts/112.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -630,13 +630,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/113.json b/inst/treatment_cohorts/113.json index 992961f..3161d47 100644 --- a/inst/treatment_cohorts/113.json +++ b/inst/treatment_cohorts/113.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -86,13 +86,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/114.json b/inst/treatment_cohorts/114.json index 371811d..bde0f4f 100644 --- a/inst/treatment_cohorts/114.json +++ b/inst/treatment_cohorts/114.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/115.json b/inst/treatment_cohorts/115.json index 975c612..6bb09d3 100644 --- a/inst/treatment_cohorts/115.json +++ b/inst/treatment_cohorts/115.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -120,13 +120,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/116.json b/inst/treatment_cohorts/116.json index d987cca..f4f2d5c 100644 --- a/inst/treatment_cohorts/116.json +++ b/inst/treatment_cohorts/116.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -86,13 +86,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/117.json b/inst/treatment_cohorts/117.json index fcfdfd1..d53f30b 100644 --- a/inst/treatment_cohorts/117.json +++ b/inst/treatment_cohorts/117.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/119.json b/inst/treatment_cohorts/119.json index c7e048c..481b502 100644 --- a/inst/treatment_cohorts/119.json +++ b/inst/treatment_cohorts/119.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/120.json b/inst/treatment_cohorts/120.json index 873540e..78fc732 100644 --- a/inst/treatment_cohorts/120.json +++ b/inst/treatment_cohorts/120.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -69,13 +69,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/121.json b/inst/treatment_cohorts/121.json index 280a1bc..2e95520 100644 --- a/inst/treatment_cohorts/121.json +++ b/inst/treatment_cohorts/121.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -69,13 +69,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/122.json b/inst/treatment_cohorts/122.json index 6396621..bd5ebab 100644 --- a/inst/treatment_cohorts/122.json +++ b/inst/treatment_cohorts/122.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/123.json b/inst/treatment_cohorts/123.json index 3599d93..efac4b9 100644 --- a/inst/treatment_cohorts/123.json +++ b/inst/treatment_cohorts/123.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/124.json b/inst/treatment_cohorts/124.json index d4d9684..d7caa87 100644 --- a/inst/treatment_cohorts/124.json +++ b/inst/treatment_cohorts/124.json @@ -18,7 +18,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -52,13 +52,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "GapDays" : 0, + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/125.json b/inst/treatment_cohorts/125.json index 0d53a18..8c32149 100644 --- a/inst/treatment_cohorts/125.json +++ b/inst/treatment_cohorts/125.json @@ -14,7 +14,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -65,13 +65,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "StartDate", + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/126.json b/inst/treatment_cohorts/126.json index 1a434b5..8838604 100644 --- a/inst/treatment_cohorts/126.json +++ b/inst/treatment_cohorts/126.json @@ -14,7 +14,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -65,13 +65,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "StartDate", + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} diff --git a/inst/treatment_cohorts/127.json b/inst/treatment_cohorts/127.json index 818d2da..85ddccc 100644 --- a/inst/treatment_cohorts/127.json +++ b/inst/treatment_cohorts/127.json @@ -14,7 +14,7 @@ "PostDays" : 0 }, "PrimaryCriteriaLimit" : { - "Type" : "First" + "Type" : "All" } }, "ConceptSets" : [ @@ -48,13 +48,19 @@ "Type" : "First" }, "ExpressionLimit" : { - "Type" : "First" + "Type" : "All" }, "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "StartDate", + "Offset" : 0 + } + }, "CensoringCriteria" : [], "CollapseSettings" : { "CollapseType" : "ERA", "EraPad" : 0 }, "CensorWindow" : {} -} \ No newline at end of file +} From d0ff72de86be175c5de890630ef55f1a02ca74ce Mon Sep 17 00:00:00 2001 From: Maxim Moinat Date: Fri, 17 Nov 2023 13:25:11 +0100 Subject: [PATCH 08/41] update treatment cohorts --- inst/treatment_cohorts/101.json | 1 + inst/treatment_cohorts/102.json | 1 + inst/treatment_cohorts/103.json | 1 + inst/treatment_cohorts/104.json | 1 + inst/treatment_cohorts/105.json | 1 + inst/treatment_cohorts/106.json | 1 + inst/treatment_cohorts/107.json | 1 + inst/treatment_cohorts/108.json | 1 + inst/treatment_cohorts/109.json | 1 + inst/treatment_cohorts/110.json | 1 + inst/treatment_cohorts/111.json | 1 + inst/treatment_cohorts/112.json | 1 + inst/treatment_cohorts/113.json | 1 + inst/treatment_cohorts/114.json | 1 + inst/treatment_cohorts/115.json | 1 + inst/treatment_cohorts/116.json | 1 + inst/treatment_cohorts/117.json | 1 + inst/treatment_cohorts/119.json | 1 + inst/treatment_cohorts/120.json | 1 + inst/treatment_cohorts/121.json | 1 + inst/treatment_cohorts/122.json | 1 + inst/treatment_cohorts/123.json | 1 + inst/treatment_cohorts/124.json | 1 + inst/treatment_cohorts/125.json | 2 +- inst/treatment_cohorts/126.json | 2 +- inst/treatment_cohorts/127.json | 2 +- 26 files changed, 26 insertions(+), 3 deletions(-) diff --git a/inst/treatment_cohorts/101.json b/inst/treatment_cohorts/101.json index 0422117..1c7ee7c 100644 --- a/inst/treatment_cohorts/101.json +++ b/inst/treatment_cohorts/101.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 0, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/102.json b/inst/treatment_cohorts/102.json index 0d21f8e..56b59cd 100644 --- a/inst/treatment_cohorts/102.json +++ b/inst/treatment_cohorts/102.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 1, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/103.json b/inst/treatment_cohorts/103.json index 3eea489..74af237 100644 --- a/inst/treatment_cohorts/103.json +++ b/inst/treatment_cohorts/103.json @@ -244,6 +244,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 2, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/104.json b/inst/treatment_cohorts/104.json index 17fecd6..d1ba597 100644 --- a/inst/treatment_cohorts/104.json +++ b/inst/treatment_cohorts/104.json @@ -108,6 +108,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 3, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/105.json b/inst/treatment_cohorts/105.json index 6355e3e..49d575e 100644 --- a/inst/treatment_cohorts/105.json +++ b/inst/treatment_cohorts/105.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 4, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/106.json b/inst/treatment_cohorts/106.json index 57cbcb7..e43670f 100644 --- a/inst/treatment_cohorts/106.json +++ b/inst/treatment_cohorts/106.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 5, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/107.json b/inst/treatment_cohorts/107.json index cf67737..abcc582 100644 --- a/inst/treatment_cohorts/107.json +++ b/inst/treatment_cohorts/107.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 6, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/108.json b/inst/treatment_cohorts/108.json index 6f51c23..e40f423 100644 --- a/inst/treatment_cohorts/108.json +++ b/inst/treatment_cohorts/108.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 7, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/109.json b/inst/treatment_cohorts/109.json index ec6b8d7..cadfbaf 100644 --- a/inst/treatment_cohorts/109.json +++ b/inst/treatment_cohorts/109.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 8, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/110.json b/inst/treatment_cohorts/110.json index 909b0d0..e78f4ec 100644 --- a/inst/treatment_cohorts/110.json +++ b/inst/treatment_cohorts/110.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 9, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/111.json b/inst/treatment_cohorts/111.json index 341a697..f898661 100644 --- a/inst/treatment_cohorts/111.json +++ b/inst/treatment_cohorts/111.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 10, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/112.json b/inst/treatment_cohorts/112.json index 5bec38c..7ebc565 100644 --- a/inst/treatment_cohorts/112.json +++ b/inst/treatment_cohorts/112.json @@ -635,6 +635,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 11, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/113.json b/inst/treatment_cohorts/113.json index 3161d47..9dc9124 100644 --- a/inst/treatment_cohorts/113.json +++ b/inst/treatment_cohorts/113.json @@ -91,6 +91,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 12, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/114.json b/inst/treatment_cohorts/114.json index bde0f4f..3fa0850 100644 --- a/inst/treatment_cohorts/114.json +++ b/inst/treatment_cohorts/114.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 13, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/115.json b/inst/treatment_cohorts/115.json index 6bb09d3..6cb6fdc 100644 --- a/inst/treatment_cohorts/115.json +++ b/inst/treatment_cohorts/115.json @@ -125,6 +125,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 14, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/116.json b/inst/treatment_cohorts/116.json index f4f2d5c..9448584 100644 --- a/inst/treatment_cohorts/116.json +++ b/inst/treatment_cohorts/116.json @@ -91,6 +91,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 15, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/117.json b/inst/treatment_cohorts/117.json index d53f30b..caca4ff 100644 --- a/inst/treatment_cohorts/117.json +++ b/inst/treatment_cohorts/117.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 16, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/119.json b/inst/treatment_cohorts/119.json index 481b502..4d383f8 100644 --- a/inst/treatment_cohorts/119.json +++ b/inst/treatment_cohorts/119.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 17, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/120.json b/inst/treatment_cohorts/120.json index 78fc732..b2fcd09 100644 --- a/inst/treatment_cohorts/120.json +++ b/inst/treatment_cohorts/120.json @@ -74,6 +74,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 18, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/121.json b/inst/treatment_cohorts/121.json index 2e95520..9a70c3d 100644 --- a/inst/treatment_cohorts/121.json +++ b/inst/treatment_cohorts/121.json @@ -74,6 +74,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 19, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/122.json b/inst/treatment_cohorts/122.json index bd5ebab..6b153bf 100644 --- a/inst/treatment_cohorts/122.json +++ b/inst/treatment_cohorts/122.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 20, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/123.json b/inst/treatment_cohorts/123.json index efac4b9..b27a351 100644 --- a/inst/treatment_cohorts/123.json +++ b/inst/treatment_cohorts/123.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 21, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/124.json b/inst/treatment_cohorts/124.json index d7caa87..8016fce 100644 --- a/inst/treatment_cohorts/124.json +++ b/inst/treatment_cohorts/124.json @@ -57,6 +57,7 @@ "InclusionRules" : [], "EndStrategy" : { "CustomEra" : { + "DrugCodesetId" : 22, "GapDays" : 0, "Offset" : 0 } diff --git a/inst/treatment_cohorts/125.json b/inst/treatment_cohorts/125.json index 8c32149..5946683 100644 --- a/inst/treatment_cohorts/125.json +++ b/inst/treatment_cohorts/125.json @@ -70,7 +70,7 @@ "InclusionRules" : [], "EndStrategy" : { "DateOffset" : { - "DateField" : "StartDate", + "DateField" : "EndDate", "Offset" : 0 } }, diff --git a/inst/treatment_cohorts/126.json b/inst/treatment_cohorts/126.json index 8838604..e0f923d 100644 --- a/inst/treatment_cohorts/126.json +++ b/inst/treatment_cohorts/126.json @@ -70,7 +70,7 @@ "InclusionRules" : [], "EndStrategy" : { "DateOffset" : { - "DateField" : "StartDate", + "DateField" : "EndDate", "Offset" : 0 } }, diff --git a/inst/treatment_cohorts/127.json b/inst/treatment_cohorts/127.json index 85ddccc..cc15733 100644 --- a/inst/treatment_cohorts/127.json +++ b/inst/treatment_cohorts/127.json @@ -53,7 +53,7 @@ "InclusionRules" : [], "EndStrategy" : { "DateOffset" : { - "DateField" : "StartDate", + "DateField" : "EndDate", "Offset" : 0 } }, From 94c1ae0e9951c46983c8b44a43c43c9706e121fd Mon Sep 17 00:00:00 2001 From: Maxim Moinat Date: Fri, 17 Nov 2023 13:29:20 +0100 Subject: [PATCH 09/41] update cohort definition set --- extras/package-maintenance.R | 2 +- inst/cohortDefinitionSet.csv | 9474 ++++++++++++++++++++++++++++++++++ 2 files changed, 9475 insertions(+), 1 deletion(-) diff --git a/extras/package-maintenance.R b/extras/package-maintenance.R index 94c652a..eeeaf1c 100644 --- a/extras/package-maintenance.R +++ b/extras/package-maintenance.R @@ -12,7 +12,7 @@ getCdmSources(baseUrl) cohortDefinitionSet <- ROhdsiWebApi::exportCohortDefinitionSet( baseUrl, - c(92:97, 100) + c(92:97, 100, setdiff(101:127, 118)) ) write.csv(cohortDefinitionSet, 'inst/cohortDefinitionSet.csv') diff --git a/inst/cohortDefinitionSet.csv b/inst/cohortDefinitionSet.csv index 6e6254d..9d3f4cf 100644 --- a/inst/cohortDefinitionSet.csv +++ b/inst/cohortDefinitionSet.csv @@ -6078,3 +6078,9477 @@ iii. Have a baseline period of two years preceding the index date during which d iv. Have a minimum of two respective diagnoses in the entire follow-up period, at least 30 days apart, to rule out a misdiagnosis (e.g. hair loss associated with chemotherapy) AND v. In the two years subsequent to the index date, have no occurrence of an alternative diagnosis or specified treatment Note: does not check for earlier AT/AU/AA.",FALSE +"8",101,101,"(Alopecia) Cohort, drug group 1, Corticosteroids, topical","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 0 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (21602098) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (21602098) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results +WHERE Results.ordinal = 1 +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 0 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 0 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 0, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 0, + ""name"" : ""(Alopecia) Corticosteroids, topical"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 21602098, + ""CONCEPT_NAME"" : ""CORTICOSTEROIDS, DERMATOLOGICAL PREPARATIONS"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""D07"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""ATC"", + ""CONCEPT_CLASS_ID"" : ""ATC 2nd"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""First"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 0, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"9",102,102,"(Alopecia) Cohort, drug group 2, Corticosteroids, systemic (i.e. oral and injected)","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 1 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (21602723) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (21602723) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 1 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 1 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 1, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 1, + ""name"" : ""(Alopecia) Corticosteroids, systemic (i.e. oral and injected)"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 21602723, + ""CONCEPT_NAME"" : ""CORTICOSTEROIDS FOR SYSTEMIC USE, PLAIN"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""H02A"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""ATC"", + ""CONCEPT_CLASS_ID"" : ""ATC 3rd"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 1, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"10",103,103,"(Alopecia) Cohort, drug group 3, Immunotherapy, topical (all non-standard concepts)","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 2 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (45017482,45274656,45052575,45257357,45239268,45187717,4258736,576880,45240352,576954,579748,574411) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (45017482,45274656,45052575,45257357,45239268,45187717,4258736,576880,45240352,576954,579748,574411) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 2) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 2 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 2 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 2, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 2, + ""name"" : ""(Alopecia) Immunotherapy, topical (all non-standard concepts)"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 45017482, + ""CONCEPT_NAME"" : ""DIPHENYLCYCLOPROPENONE 98% PWD"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""49452264202"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""NDC"", + ""CONCEPT_CLASS_ID"" : ""11-digit NDC"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 45274656, + ""CONCEPT_NAME"" : ""DIPHENYLCYCLOPROPENONE POWDER"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""51927166800"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""NDC"", + ""CONCEPT_CLASS_ID"" : ""11-digit NDC"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 45052575, + ""CONCEPT_NAME"" : ""DIPHENYLCYCLOPROPENONE PWDR"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""51552094302"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""NDC"", + ""CONCEPT_CLASS_ID"" : ""11-digit NDC"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 45257357, + ""CONCEPT_NAME"" : ""DIPHENYLCYCLOPROPENONE PWDR"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""51552094301"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""NDC"", + ""CONCEPT_CLASS_ID"" : ""11-digit NDC"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 45239268, + ""CONCEPT_NAME"" : ""2,4-DINITROCHLOROBENZENE CR"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""49452263001"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""NDC"", + ""CONCEPT_CLASS_ID"" : ""11-digit NDC"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 45187717, + ""CONCEPT_NAME"" : ""2,4-DINITROCHLOROBENZENE CR"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""49452263002"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""NDC"", + ""CONCEPT_CLASS_ID"" : ""11-digit NDC"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 4258736, + ""CONCEPT_NAME"" : ""Dinitrochlorobenzene"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""N0000171188"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""NDFRT"", + ""CONCEPT_CLASS_ID"" : ""Chemical Structure"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 576880, + ""CONCEPT_NAME"" : ""DINITROCHLOROBENZENE 100 % MISCELL CRYSTALS"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""060171"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""GCN_SEQNO"", + ""CONCEPT_CLASS_ID"" : ""GCN_SEQNO"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 45240352, + ""CONCEPT_NAME"" : ""DINITROCHLOROBENZENE 99% CRYST"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""51927133000"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""NDC"", + ""CONCEPT_CLASS_ID"" : ""11-digit NDC"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 576954, + ""CONCEPT_NAME"" : ""SQUARIC ACID DIBUTYLESTER 100 % MISCELL LIQUID (GRAM)"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""043710"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""GCN_SEQNO"", + ""CONCEPT_CLASS_ID"" : ""GCN_SEQNO"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 579748, + ""CONCEPT_NAME"" : ""SQUARIC ACID DIBUTYLESTER IN BUTYL ALCOHOL 150 mg MISCELL LIQUID (GRAM)"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""070912"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""GCN_SEQNO"", + ""CONCEPT_CLASS_ID"" : ""GCN_SEQNO"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 574411, + ""CONCEPT_NAME"" : ""SQUARIC ACID DIBUTYLESTER MISCELL POWDER (GRAM)"", + ""STANDARD_CONCEPT"" : ""N"", + ""STANDARD_CONCEPT_CAPTION"" : ""Non-Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""022515"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""GCN_SEQNO"", + ""CONCEPT_CLASS_ID"" : ""GCN_SEQNO"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 2, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"11",104,104,"(Alopecia) Cohort, drug group 4, Immunomodulators (Aza. Cyclo, Myco, Metho)","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 3 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (19014878,19010482,19003999,1305058) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (19014878,19010482,19003999,1305058) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 3) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 3 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 3 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 3, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 3, + ""name"" : ""(Alopecia) Immunomodulators (Azathioprine. Cyclosporine, Mycophenolate mofetil, Methotrexate)"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 19014878, + ""CONCEPT_NAME"" : ""Azathioprine"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1256"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 19010482, + ""CONCEPT_NAME"" : ""Cyclosporine"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""3008"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 19003999, + ""CONCEPT_NAME"" : ""mycophenolate mofetil"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""68149"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 1305058, + ""CONCEPT_NAME"" : ""Methotrexate"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""6851"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 3, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"12",105,105,"(Alopecia) Cohort, drug group 5, Anthralin","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 4 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (36211872) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (36211872) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 4) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 4 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 4 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 4, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 4, + ""name"" : ""(Alopecia) Anthralin (i.e. dithranol), topical immunotherapeutic agent"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 36211872, + ""CONCEPT_NAME"" : ""Anthralin Topical Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1153703"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 4, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"13",106,106,"(Alopecia) Cohort, drug group 6, Minoxidil","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 5 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (1309068) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (1309068) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 5) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 5 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 5 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 5, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 5, + ""name"" : ""(Alopecia) Minoxidil, arteriolar vasodilator"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 1309068, + ""CONCEPT_NAME"" : ""Minoxidil"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""6984"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 5, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"14",107,107,"(Alopecia) Cohort, drug group 7, Finasteride","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 6 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (996416) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (996416) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 6) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 6 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 6 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 6, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 6, + ""name"" : ""(Alopecia) Finasteride"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 996416, + ""CONCEPT_NAME"" : ""Finasteride"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""25025"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 6, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"15",108,108,"(Alopecia) Cohort, drug group 8, Tretinoin","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 7 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (36223379) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (36223379) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 7) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 7 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 7 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 7, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 7, + ""name"" : ""(Alopecia) Tretinoin, topical"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 36223379, + ""CONCEPT_NAME"" : ""Tretinoin Topical Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1158220"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 7, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"16",109,109,"(Alopecia) Cohort, drug group 9, Tofacitinib","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 8 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (42904205) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (42904205) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 8) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 8 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 8 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 8, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 8, + ""name"" : ""(Alopecia) Tofacitinib, JAK inhibitor, oral"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 42904205, + ""CONCEPT_NAME"" : ""tofacitinib"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1357536"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 8, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"17",110,110,"(Alopecia) Cohort, drug group 10, Baricitinib","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 9 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (1510627) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (1510627) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 9) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 9 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 9 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 9, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 9, + ""name"" : ""(Alopecia) Baricitinib, JAK inhibitor, oral"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 1510627, + ""CONCEPT_NAME"" : ""baricitinib"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""2047232"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 9, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"18",111,111,"(Alopecia) Cohort, drug group 11, Ruxolitinib","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 10 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (40244464) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (40244464) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 10) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 10 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 10 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 10, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 10, + ""name"" : ""(Alopecia) Ruxolitinib, JAK inhibitor, oral"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 40244464, + ""CONCEPT_NAME"" : ""ruxolitinib"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1193326"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 10, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"19",112,112,"(Alopecia) Cohort, drug group 12, Clobetasol propionate","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 11 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (19114411,44044472,19102575,793228,793230,793231,793227,19002305,19002304,793721,793716,44122102,44122104,1361309,40164516,40164517,40164518,40164519,40164524,40164525,40164526,40164527,40164520,40164521,40164522,40164523,40164528,40164529,40164530,40164501,40164502,40164508,40164504,40164505,40164506) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (19114411,44044472,19102575,793228,793230,793231,793227,19002305,19002304,793721,793716,44122102,44122104,1361309,40164516,40164517,40164518,40164519,40164524,40164525,40164526,40164527,40164520,40164521,40164522,40164523,40164528,40164529,40164530,40164501,40164502,40164508,40164504,40164505,40164506) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 11) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 11 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 11 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 11, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 11, + ""name"" : ""(Alopecia) Clobetasol propionate, topical"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 19114411, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.0005 MG/MG Topical Gel [embelin]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""544116"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 44044472, + ""CONCEPT_NAME"" : ""Clobetasol Topical Cream [Alti-Clobetasol Propionate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""OMOP1039103"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm Extension"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug Form"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 19102575, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Solution [Clobex]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""404036"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 793228, + ""CONCEPT_NAME"" : ""Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam [Olux]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1992274"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 793230, + ""CONCEPT_NAME"" : ""Emollient Clobetasol Propionate 0.5 MG/ML Topical Cream"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1992281"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 793231, + ""CONCEPT_NAME"" : ""Emollient Clobetasol Propionate 0.5 MG/ML Topical Cream [Temovate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1992282"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 793227, + ""CONCEPT_NAME"" : ""Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1992273"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 19002305, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Dermovate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""103431"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 19002304, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Cream [Dermovate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""103430"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 793721, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.25 MG/ML Topical Cream [Impoyz]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1995460"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 793716, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.25 MG/ML Topical Cream"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1995455"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 44122102, + ""CONCEPT_NAME"" : ""Clobetasol Topical Ointment [Alti-Clobetasol Propionate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""OMOP1116733"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm Extension"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug Form"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 44122104, + ""CONCEPT_NAME"" : ""Clobetasol Topical Solution [Alti-Clobetasol Propionate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""OMOP1116735"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm Extension"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug Form"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 1361309, + ""CONCEPT_NAME"" : ""Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam [Tovet]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""2180345"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164516, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Cream"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861495"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164517, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Cream [Cormax]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861497"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164518, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Cream [Embeline]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861498"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164519, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Cream [Isovate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861500"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164524, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Lotion [Clobex]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861506"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164525, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Solution"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861487"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164526, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Solution [Cormax]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861526"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164527, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Solution [Embeline]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861489"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164520, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Cream [Temovate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861503"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164521, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Foam"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861353"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164522, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Foam [Olux]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861355"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164523, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Lotion"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861505"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164528, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Solution [Temovate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861510"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164529, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Spray"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861512"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164530, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.5 MG/ML Topical Spray [Clobex]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861513"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164501, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.0005 MG/MG Topical Gel"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861434"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164502, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.0005 MG/MG Topical Gel [Clobevate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861436"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164508, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Temovate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861472"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164504, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.0005 MG/MG Topical Gel [Temovate]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861440"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164505, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.0005 MG/MG Topical Ointment"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861448"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 40164506, + ""CONCEPT_NAME"" : ""Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Cormax]"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""861449"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Branded Drug"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 11, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"20",113,113,"(Alopecia) Cohort, drug group 13, Iron","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 12 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (36219948,36219932,36224164) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (36219948,36219932,36224164) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 12) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 12 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 12 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 12, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 12, + ""name"" : ""(Alopecia) Iron supplement"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 36219948, + ""CONCEPT_NAME"" : ""ferrous sulfate Oral Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1164414"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 36219932, + ""CONCEPT_NAME"" : ""ferrous gluconate Oral Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1164398"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 36224164, + ""CONCEPT_NAME"" : ""Ferrous fumarate Oral Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1159640"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 12, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"21",114,114,"(Alopecia) Cohort, drug group 14, Vitamin E","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 13 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (36226018) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (36226018) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 13) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 13 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 13 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 13, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 13, + ""name"" : ""(Alopecia) Vitamin E"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 36226018, + ""CONCEPT_NAME"" : ""Vitamin E Oral Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1161178"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 13, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"22",115,115,"(Alopecia) Cohort, drug group 15, Immunomodulators (Aza. Cyclo, Myco, Metho, Sulf.)","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 14 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (19014878,19010482,19003999,1305058,964339) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (19014878,19010482,19003999,1305058,964339) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 14) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 14 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 14 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 14, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 14, + ""name"" : ""(Alopecia) Immunomodulators (Azathioprine. Cyclosporine, Mycophenolate mofetil, Methotrexate, Sulf.)"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 19014878, + ""CONCEPT_NAME"" : ""Azathioprine"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1256"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 19010482, + ""CONCEPT_NAME"" : ""Cyclosporine"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""3008"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 19003999, + ""CONCEPT_NAME"" : ""mycophenolate mofetil"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""68149"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 1305058, + ""CONCEPT_NAME"" : ""Methotrexate"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""6851"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 964339, + ""CONCEPT_NAME"" : ""Sulfasalazine"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""9524"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 14, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"23",116,116,"(Alopecia) Cohort, drug group 16, JAK inhibitors group, oral (Ruxolitinib, Tofacitinib, Baricitinib)","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 15 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (40244464,1510627,42904205) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (40244464,1510627,42904205) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 15) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 15 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 15 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 15, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 15, + ""name"" : ""(Alopecia) JAK inhibitors group, oral (Ruxolitinib, Tofacitinib, Baricitinib)"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 40244464, + ""CONCEPT_NAME"" : ""ruxolitinib"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1193326"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 1510627, + ""CONCEPT_NAME"" : ""baricitinib"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""2047232"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 42904205, + ""CONCEPT_NAME"" : ""tofacitinib"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1357536"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 15, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"24",117,117,"(Alopecia) Cohort, drug group 17, Tacrolimus","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 16 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (36219038) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (36219038) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 16) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 16 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 16 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 16, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 16, + ""name"" : ""(Alopecia) Tacrolimus, topical"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 36219038, + ""CONCEPT_NAME"" : ""Tacrolimus Topical Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1164204"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 16, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"25",119,119,"(Alopecia) Cohort, drug group 18, Bexarotene","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 17 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (36226250) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (36226250) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 17) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 17 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 17 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 17, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 17, + ""name"" : ""(Alopecia) Bexarotene, topical"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 36226250, + ""CONCEPT_NAME"" : ""bexarotene Topical Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1161188"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 17, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"26",120,120,"(Alopecia) Cohort, drug group 19, Retinoids (Bexarotene, Tretinoin)","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 18 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (36226250,36223379) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (36226250,36223379) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 18) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 18 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 18 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 18, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 18, + ""name"" : ""(Alopecia) Retinoids, topical (Bexarotene, Tretinoin)"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 36226250, + ""CONCEPT_NAME"" : ""bexarotene Topical Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1161188"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 36223379, + ""CONCEPT_NAME"" : ""Tretinoin Topical Product"", + ""STANDARD_CONCEPT"" : ""C"", + ""STANDARD_CONCEPT_CAPTION"" : ""Classification"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1158220"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Clinical Dose Group"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 18, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"27",121,121,"(Alopecia) Cohort, drug group 20, Monclonal antibodies (Ustekinumab, dupilumab)","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 19 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (40161532,1593467) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (40161532,1593467) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 19) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 19 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 19 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 19, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 19, + ""name"" : ""(Alopecia) Monclonal antibodies (Ustekinumab, dupilumab)"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 40161532, + ""CONCEPT_NAME"" : ""ustekinumab"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""847083"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 1593467, + ""CONCEPT_NAME"" : ""dupilumab"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1876376"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 19, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"28",122,122,"(Alopecia) Cohort, drug group 21, Apremilast","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 20 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (44816294) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (44816294) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 20) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 20 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 20 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 20, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 20, + ""name"" : ""(Alopecia) Apremilast"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 44816294, + ""CONCEPT_NAME"" : ""apremilast"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1492727"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 20, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"29",123,123,"(Alopecia) Cohort, drug group 22, Abatacept","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 21 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (1186087) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (1186087) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 21) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 21 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 21 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 21, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 21, + ""name"" : ""(Alopecia) Abatacept"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 1186087, + ""CONCEPT_NAME"" : ""abatacept"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""614391"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 21, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"30",124,124,"(Alopecia) Cohort, drug group 23, Crisaborole","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 22 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (1593397) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (1593397) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.drug_exposure_start_date as start_date, + COALESCE(C.DRUG_EXPOSURE_END_DATE, DATEADD(day,C.DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,C.DRUG_EXPOSURE_START_DATE)) as end_date, + C.visit_occurrence_id,C.drug_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 22) +) C + +WHERE C.drug_exposure_start_date >= DATEFROMPARTS(2015, 1, 1) +-- End Drug Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- custom era strategy + +with ctePersons(person_id) as ( + select distinct person_id from #included_events +) + +select person_id, drug_exposure_start_date, drug_exposure_end_date +INTO #drugTarget +FROM ( + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 22 AND de.drug_concept_id = cs.concept_id + + UNION ALL + + select de.PERSON_ID, DRUG_EXPOSURE_START_DATE, COALESCE(DRUG_EXPOSURE_END_DATE, DATEADD(day,DAYS_SUPPLY,DRUG_EXPOSURE_START_DATE), DATEADD(day,1,DRUG_EXPOSURE_START_DATE)) as DRUG_EXPOSURE_END_DATE + FROM @cdm_database_schema.DRUG_EXPOSURE de + JOIN ctePersons p on de.person_id = p.person_id + JOIN #Codesets cs on cs.codeset_id = 22 AND de.drug_source_concept_id = cs.concept_id +) E +; + +select et.event_id, et.person_id, ERAS.era_end_date as end_date +INTO #strategy_ends +from #included_events et +JOIN +( + select ENDS.person_id, min(drug_exposure_start_date) as era_start_date, DATEADD(day,0, ENDS.era_end_date) as era_end_date + from + ( + select de.person_id, de.drug_exposure_start_date, MIN(e.END_DATE) as era_end_date + FROM #drugTarget DE + JOIN + ( + --cteEndDates + select PERSON_ID, DATEADD(day,-1 * 0,EVENT_DATE) as END_DATE -- unpad the end date by 0 + FROM + ( + select PERSON_ID, EVENT_DATE, EVENT_TYPE, + MAX(START_ORDINAL) OVER (PARTITION BY PERSON_ID ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal, + ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY EVENT_DATE, EVENT_TYPE) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date + from + ( + -- select the start dates, assigning a row number to each + Select PERSON_ID, DRUG_EXPOSURE_START_DATE AS EVENT_DATE, 0 as EVENT_TYPE, ROW_NUMBER() OVER (PARTITION BY PERSON_ID ORDER BY DRUG_EXPOSURE_START_DATE) as START_ORDINAL + from #drugTarget D + + UNION ALL + + -- add the end dates with NULL as the row number, padding the end dates by 0 to allow a grace period for overlapping ranges. + select PERSON_ID, DATEADD(day,0,DRUG_EXPOSURE_END_DATE), 1 as EVENT_TYPE, NULL + FROM #drugTarget D + ) RAWDATA + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 + ) E on DE.PERSON_ID = E.PERSON_ID and E.END_DATE >= DE.DRUG_EXPOSURE_START_DATE + GROUP BY de.person_id, de.drug_exposure_start_date + ) ENDS + GROUP BY ENDS.person_id, ENDS.era_end_date +) ERAS on ERAS.person_id = et.person_id +WHERE et.start_date between ERAS.era_start_date and ERAS.era_end_date; + +TRUNCATE TABLE #drugTarget; +DROP TABLE #drugTarget; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- By default, cohort exit at the event's op end date +select event_id, person_id, op_end_date as end_date from #included_events +UNION ALL +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DrugExposure"" : { + ""CodesetId"" : 22, + ""OccurrenceStartDate"" : { + ""Value"" : ""2015-01-01"", + ""Op"" : ""gte"" + }, + ""DrugTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 22, + ""name"" : ""(Alopecia) Crisaborole"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 1593397, + ""CONCEPT_NAME"" : ""crisaborole"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""1865953"", + ""DOMAIN_ID"" : ""Drug"", + ""VOCABULARY_ID"" : ""RxNorm"", + ""CONCEPT_CLASS_ID"" : ""Ingredient"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""CustomEra"" : { + ""DrugCodesetId"" : 22, + ""GapDays"" : 0, + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"31",125,125,"(Alopecia) Cohort, procedure 1, Psoralens and ultraviolet A (PUVA)","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 23 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (2314256,4262683) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (2314256,4262683) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Procedure Occurrence Criteria +select C.person_id, C.procedure_occurrence_id as event_id, C.procedure_date as start_date, DATEADD(d,1,C.procedure_date) as END_DATE, + C.visit_occurrence_id, C.procedure_date as sort_date +from +( + select po.* + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 23) +) C + + +-- End Procedure Occurrence Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,0,end_date) > op_end_date then op_end_date else DATEADD(day,0,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""ProcedureOccurrence"" : { + ""CodesetId"" : 23, + ""ProcedureTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 23, + ""name"" : ""(Alopecia) Psoralens and ultraviolet A (PUVA), photochemotherapy"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 2314256, + ""CONCEPT_NAME"" : ""Photochemotherapy; psoralens and ultraviolet A (PUVA)"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""96912"", + ""DOMAIN_ID"" : ""Procedure"", + ""VOCABULARY_ID"" : ""CPT4"", + ""CONCEPT_CLASS_ID"" : ""CPT4"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 4262683, + ""CONCEPT_NAME"" : ""Photochemotherapy with psoralens and ultraviolet A"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""46467001"", + ""DOMAIN_ID"" : ""Procedure"", + ""VOCABULARY_ID"" : ""SNOMED"", + ""CONCEPT_CLASS_ID"" : ""Procedure"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""DateOffset"" : { + ""DateField"" : ""EndDate"", + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"32",126,126,"(Alopecia) Cohort, procedure 2, Ultraviolet A (UVA) light therapy","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 24 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (4138632,4039592) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (4138632,4039592) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Procedure Occurrence Criteria +select C.person_id, C.procedure_occurrence_id as event_id, C.procedure_date as start_date, DATEADD(d,1,C.procedure_date) as END_DATE, + C.visit_occurrence_id, C.procedure_date as sort_date +from +( + select po.* + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 24) +) C + + +-- End Procedure Occurrence Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,0,end_date) > op_end_date then op_end_date else DATEADD(day,0,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""ProcedureOccurrence"" : { + ""CodesetId"" : 24, + ""ProcedureTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 24, + ""name"" : ""(Alopecia) Ultraviolet A (UVA) light therapy"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 4138632, + ""CONCEPT_NAME"" : ""Ultraviolet A light therapy to skin"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""425893002"", + ""DOMAIN_ID"" : ""Procedure"", + ""VOCABULARY_ID"" : ""SNOMED"", + ""CONCEPT_CLASS_ID"" : ""Procedure"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + }, + { + ""concept"" : { + ""CONCEPT_ID"" : 4039592, + ""CONCEPT_NAME"" : ""Ultraviolet A therapy"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""229587005"", + ""DOMAIN_ID"" : ""Procedure"", + ""VOCABULARY_ID"" : ""SNOMED"", + ""CONCEPT_CLASS_ID"" : ""Procedure"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""DateOffset"" : { + ""DateField"" : ""EndDate"", + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE +"33",127,127,"(Alopecia) Cohort, procedure 3, Excimerlaser","CREATE TABLE #Codesets ( + codeset_id int NOT NULL, + concept_id bigint NOT NULL +) +; + +INSERT INTO #Codesets (codeset_id, concept_id) +SELECT 25 as codeset_id, c.concept_id FROM (select distinct I.concept_id FROM +( + select concept_id from @vocabulary_database_schema.CONCEPT where concept_id in (45762264) +UNION select c.concept_id + from @vocabulary_database_schema.CONCEPT c + join @vocabulary_database_schema.CONCEPT_ANCESTOR ca on c.concept_id = ca.descendant_concept_id + and ca.ancestor_concept_id in (45762264) + and c.invalid_reason is null + +) I +) C +; + +with primary_events (event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id) as +( +-- Begin Primary Events +select P.ordinal as event_id, P.person_id, P.start_date, P.end_date, op_start_date, op_end_date, cast(P.visit_occurrence_id as bigint) as visit_occurrence_id +FROM +( + select E.person_id, E.start_date, E.end_date, + row_number() OVER (PARTITION BY E.person_id ORDER BY E.sort_date ASC) ordinal, + OP.observation_period_start_date as op_start_date, OP.observation_period_end_date as op_end_date, cast(E.visit_occurrence_id as bigint) as visit_occurrence_id + FROM + ( + -- Begin Device Exposure Criteria +select C.person_id, C.device_exposure_id as event_id, C.device_exposure_start_date as start_date, COALESCE(C.device_exposure_end_date, DATEADD(day,1,C.device_exposure_start_date)) as end_date, + C.visit_occurrence_id, C.device_exposure_start_date as sort_date +from +( + select de.* + FROM @cdm_database_schema.DEVICE_EXPOSURE de +JOIN #Codesets cs on (de.device_concept_id = cs.concept_id and cs.codeset_id = 25) +) C + + +-- End Device Exposure Criteria + + ) E + JOIN @cdm_database_schema.observation_period OP on E.person_id = OP.person_id and E.start_date >= OP.observation_period_start_date and E.start_date <= op.observation_period_end_date + WHERE DATEADD(day,0,OP.OBSERVATION_PERIOD_START_DATE) <= E.START_DATE AND DATEADD(day,0,E.START_DATE) <= OP.OBSERVATION_PERIOD_END_DATE +) P + +-- End Primary Events + +) +SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, visit_occurrence_id +INTO #qualified_events +FROM +( + select pe.event_id, pe.person_id, pe.start_date, pe.end_date, pe.op_start_date, pe.op_end_date, row_number() over (partition by pe.person_id order by pe.start_date ASC) as ordinal, cast(pe.visit_occurrence_id as bigint) as visit_occurrence_id + FROM primary_events pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +with cteIncludedEvents(event_id, person_id, start_date, end_date, op_start_date, op_end_date, ordinal) as +( + SELECT event_id, person_id, start_date, end_date, op_start_date, op_end_date, row_number() over (partition by person_id order by start_date ASC) as ordinal + from + ( + select Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date, SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on I.person_id = Q.person_id and I.event_id = Q.event_id + GROUP BY Q.event_id, Q.person_id, Q.start_date, Q.end_date, Q.op_start_date, Q.op_end_date + ) MG -- matching groups + +) +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM cteIncludedEvents Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,0,end_date) > op_end_date then op_end_date else DATEADD(day,0,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +with cohort_ends (event_id, person_id, end_date) as +( + -- cohort exit dates + -- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + +), +first_ends (person_id, start_date, end_date) as +( + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, E.end_date, row_number() over (partition by I.person_id, I.event_id order by E.end_date) as ordinal + from #included_events I + join cohort_ends E on I.event_id = E.event_id and I.person_id = E.person_id and E.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) +select person_id, start_date, end_date +INTO #cohort_rows +from first_ends; + +with cteEndDates (person_id, end_date) AS -- the magic +( + SELECT + person_id + , DATEADD(day,-1 * 0, event_date) as end_date + FROM + ( + SELECT + person_id + , event_date + , event_type + , MAX(start_ordinal) OVER (PARTITION BY person_id ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING) AS start_ordinal + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY event_date, event_type) AS overall_ord + FROM + ( + SELECT + person_id + , start_date AS event_date + , -1 AS event_type + , ROW_NUMBER() OVER (PARTITION BY person_id ORDER BY start_date) AS start_ordinal + FROM #cohort_rows + + UNION ALL + + + SELECT + person_id + , DATEADD(day,0,end_date) as end_date + , 1 AS event_type + , NULL + FROM #cohort_rows + ) RAWDATA + ) e + WHERE (2 * e.start_ordinal) - e.overall_ord = 0 +), +cteEnds (person_id, start_date, end_date) AS +( + SELECT + c.person_id + , c.start_date + , MIN(e.end_date) AS end_date + FROM #cohort_rows c + JOIN cteEndDates e ON c.person_id = e.person_id AND e.end_date >= c.start_date + GROUP BY c.person_id, c.start_date +) +select person_id, min(start_date) as start_date, end_date +into #final_cohort +from cteEnds +group by person_id, end_date +; + +DELETE FROM @target_database_schema.@target_cohort_table where cohort_definition_id = @target_cohort_id; +INSERT INTO @target_database_schema.@target_cohort_table (cohort_definition_id, subject_id, cohort_start_date, cohort_end_date) +select @target_cohort_id as cohort_definition_id, person_id, start_date, end_date +FROM #final_cohort CO +; + + + + +TRUNCATE TABLE #strategy_ends; +DROP TABLE #strategy_ends; + + +TRUNCATE TABLE #cohort_rows; +DROP TABLE #cohort_rows; + +TRUNCATE TABLE #final_cohort; +DROP TABLE #final_cohort; + +TRUNCATE TABLE #inclusion_events; +DROP TABLE #inclusion_events; + +TRUNCATE TABLE #qualified_events; +DROP TABLE #qualified_events; + +TRUNCATE TABLE #included_events; +DROP TABLE #included_events; + +TRUNCATE TABLE #Codesets; +DROP TABLE #Codesets; +","{ + ""cdmVersionRange"" : "">=5.0.0"", + ""PrimaryCriteria"" : { + ""CriteriaList"" : [ + { + ""DeviceExposure"" : { + ""CodesetId"" : 25, + ""DeviceTypeExclude"" : false + } + } + ], + ""ObservationWindow"" : { + ""PriorDays"" : 0, + ""PostDays"" : 0 + }, + ""PrimaryCriteriaLimit"" : { + ""Type"" : ""All"" + } + }, + ""ConceptSets"" : [ + { + ""id"" : 25, + ""name"" : ""(Alopecia) Excimerlaser, dermatological, device"", + ""expression"" : { + ""items"" : [ + { + ""concept"" : { + ""CONCEPT_ID"" : 45762264, + ""CONCEPT_NAME"" : ""Dermatological excimer laser system"", + ""STANDARD_CONCEPT"" : ""S"", + ""STANDARD_CONCEPT_CAPTION"" : ""Standard"", + ""INVALID_REASON"" : ""V"", + ""INVALID_REASON_CAPTION"" : ""Valid"", + ""CONCEPT_CODE"" : ""468800009"", + ""DOMAIN_ID"" : ""Device"", + ""VOCABULARY_ID"" : ""SNOMED"", + ""CONCEPT_CLASS_ID"" : ""Physical Object"" + }, + ""isExcluded"" : false, + ""includeDescendants"" : true, + ""includeMapped"" : false + } + ] + } + } + ], + ""QualifiedLimit"" : { + ""Type"" : ""First"" + }, + ""ExpressionLimit"" : { + ""Type"" : ""All"" + }, + ""InclusionRules"" : [], + ""EndStrategy"" : { + ""DateOffset"" : { + ""DateField"" : ""EndDate"", + ""Offset"" : 0 + } + }, + ""CensoringCriteria"" : [], + ""CollapseSettings"" : { + ""CollapseType"" : ""ERA"", + ""EraPad"" : 0 + }, + ""CensorWindow"" : {} +}",NA,FALSE From a69e0350ce709afdae5be6af4bc1cf872ee69ef2 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Fri, 17 Nov 2023 14:23:54 +0100 Subject: [PATCH 10/41] added treatmentpatterns analysis --- R/createCohorts.R | 6 ++++-- R/runStudy.R | 28 ++++++++++++++++++++-------- R/runTreatmentPatterns.R | 9 ++++----- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/R/createCohorts.R b/R/createCohorts.R index 189f526..b248fe9 100644 --- a/R/createCohorts.R +++ b/R/createCohorts.R @@ -2,12 +2,14 @@ #' #' @param connectionDetails connection details generated using DatabaseConnector::createConnectionDetails() #' @param cohortTable Name of the table to be created where cohorts will be stored +#' @param type Which cohorts to create #' @param cdmDatabaseSchema name of the schema where the cdm is stored #' @param cohortDatabaseSchema name of a schema with write access for the creation of cohort table #' #' @export createCohorts <- function(connectionDetails, - cohortTable, + cohortTable, + type = c("cohorts", "treatments"), cdmDatabaseSchema, cohortDatabaseSchema){ @@ -17,7 +19,7 @@ createCohorts <- function(connectionDetails, # Fill the cohort set using cohorts included in this # package as an example - cohortJsonFiles <- list.files(path = system.file("cohorts", package = "EhdenAlopecia"), full.names = TRUE) + cohortJsonFiles <- list.files(path = system.file(type, package = "EhdenAlopecia"), full.names = TRUE) for (i in 1:length(cohortJsonFiles)) { cohortJsonFileName <- cohortJsonFiles[i] cohortName <- tools::file_path_sans_ext(basename(cohortJsonFileName)) diff --git a/R/runStudy.R b/R/runStudy.R index 0d7f11b..26bead6 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -18,6 +18,7 @@ runStudy <- function(connectionDetails, cdmDatabaseSchema, cohortDatabaseSchema, instantiateCohorts = FALSE, + instantiateTreatmentCohorts = FALSE, runDiagnostics = FALSE, runPatternAnalysis = FALSE, outputFolder, @@ -26,7 +27,8 @@ runStudy <- function(connectionDetails, if (instantiateCohorts){ cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, - cohortTable = cohortTable, + cohortTable = cohortTable, + type = "cohorts", cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema) readr::write_csv(cohortsGenerated, file.path(outputFolder, "cohortsGenerated.csv")) @@ -34,7 +36,7 @@ runStudy <- function(connectionDetails, if (runDiagnostics){ cohortDefinitionSet <- readr::read_csv("inst/cohortDefinitionSet.csv") - CohortDiagnostics::executeDiagnostics(cohortDefinitionSet = cohortDefinitionSet, + CohortDiagnostics::executeDiagnostics(cohortDefinitionSet = cohortDefinitionSet, connectionDetails = connectionDetails, cohortTable = cohortTable, cohortDatabaseSchema = cohortDatabaseSchema, @@ -45,13 +47,22 @@ runStudy <- function(connectionDetails, ) } - if (runPatternAnalysis) - { - if (!instantiateCohorts) - { - cohortsGenerated <- readr::read_csv("cohortsGenerated.csv") + if (runPatternAnalysis){ + if (instantiateTreatmentCohorts){ + cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, + cohortTable = cohortTable, + type = "treatments", + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema) + readr::write_csv(cohortsGenerated, file.path(outputFolder, "treatmentCohortsGenerated.csv")) } - runTreatmentPatterns(connectionDetails = connectionDetails, + targetCohortsGenerated <- readr::read_csv(file.path(outputFolder, "treatmentCohortsGenerated.csv")) + treatmentCohortsGenerated <- readr::read_csv(file.path(outputFolder, "treatmentCohortsGenerated.csv")) + cohortsGenerated <- targetCohortsGenerated %>% + dplyr::bind_rows(treatmentCohortsGenerated) + for (cohort in c(92, 93, 94, 95, 96 ,97, 100)){ + cohortIds <- c(cohort, 101:127) + runTreatmentPatterns(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, @@ -59,5 +70,6 @@ runStudy <- function(connectionDetails, outputFolder = outputFolder, cohortIds = cohortIds, minCellCount = minCellCount) + } } } \ No newline at end of file diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index 90a3cb6..5c79899 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -38,18 +38,17 @@ runTreatmentPatterns <- function(connectionDetails, if (nrow(tpCohorts) > 0) { # Select target cohort targetCohorts <- cohortsGenerated %>% - filter(cohortName == "") %>% + filter(cohortName == cohortIds[1]) %>% select(cohortId, cohortName) # Select everything BUT target cohorts eventCohorts <- cohortsGenerated %>% - filter(cohortName != "") %>% + filter(cohortName != cohortsIds[1]) %>% select(cohortId, cohortName) cohorts <- dplyr::bind_rows( targetCohorts %>% mutate(type = "target"), - eventCohorts %>% mutate(type = "event"), - exitCohorts %>% mutate(type = "exit") + eventCohorts %>% mutate(type = "event") ) # Compute pathways @@ -78,7 +77,7 @@ runTreatmentPatterns <- function(connectionDetails, TreatmentPatterns::export( andromeda = pathways, outputPath = here::here(outputFolder), - ageWindow = c(18,45,65,150), #TODO: define this correctly + ageWindow = c(2,6,11,17,65,150), minFreq = minCellCount, archiveName = NULL ) From a8e949ca3b7db72a2abaaf910fe33a2a3651d417 Mon Sep 17 00:00:00 2001 From: "Ross D. Williams" <34747165+rossdwilliams@users.noreply.github.com> Date: Fri, 17 Nov 2023 17:13:58 +0100 Subject: [PATCH 11/41] fix typo --- R/runTreatmentPatterns.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index 5c79899..e39978e 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -43,7 +43,7 @@ runTreatmentPatterns <- function(connectionDetails, # Select everything BUT target cohorts eventCohorts <- cohortsGenerated %>% - filter(cohortName != cohortsIds[1]) %>% + filter(cohortName != cohortIds[1]) %>% select(cohortId, cohortName) cohorts <- dplyr::bind_rows( From 2b147deee6f6adc0bb25ce45de15cea65bb52565 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Fri, 17 Nov 2023 19:13:58 +0100 Subject: [PATCH 12/41] cohorts only with counts --- .Rprofile | 1 - DESCRIPTION | 2 +- R/createCohorts.R | 2 +- R/runStudy.R | 53 +++- R/runTreatmentPatterns.R | 24 +- extras/codeToRun.R | 26 +- inst/cohorts/101.json | 71 +++++ inst/cohorts/102.json | 71 +++++ inst/cohorts/103.json | 258 ++++++++++++++++ inst/cohorts/104.json | 122 ++++++++ inst/cohorts/105.json | 71 +++++ inst/cohorts/106.json | 71 +++++ inst/cohorts/107.json | 71 +++++ inst/cohorts/108.json | 71 +++++ inst/cohorts/109.json | 71 +++++ inst/cohorts/110.json | 71 +++++ inst/cohorts/111.json | 71 +++++ inst/cohorts/112.json | 649 +++++++++++++++++++++++++++++++++++++++ inst/cohorts/113.json | 105 +++++++ inst/cohorts/114.json | 71 +++++ inst/cohorts/115.json | 139 +++++++++ inst/cohorts/116.json | 105 +++++++ inst/cohorts/117.json | 71 +++++ inst/cohorts/119.json | 71 +++++ inst/cohorts/120.json | 88 ++++++ inst/cohorts/121.json | 88 ++++++ inst/cohorts/122.json | 71 +++++ inst/cohorts/123.json | 71 +++++ inst/cohorts/124.json | 71 +++++ inst/cohorts/125.json | 83 +++++ inst/cohorts/126.json | 83 +++++ inst/cohorts/127.json | 66 ++++ 32 files changed, 2917 insertions(+), 42 deletions(-) delete mode 100644 .Rprofile create mode 100644 inst/cohorts/101.json create mode 100644 inst/cohorts/102.json create mode 100644 inst/cohorts/103.json create mode 100644 inst/cohorts/104.json create mode 100644 inst/cohorts/105.json create mode 100644 inst/cohorts/106.json create mode 100644 inst/cohorts/107.json create mode 100644 inst/cohorts/108.json create mode 100644 inst/cohorts/109.json create mode 100644 inst/cohorts/110.json create mode 100644 inst/cohorts/111.json create mode 100644 inst/cohorts/112.json create mode 100644 inst/cohorts/113.json create mode 100644 inst/cohorts/114.json create mode 100644 inst/cohorts/115.json create mode 100644 inst/cohorts/116.json create mode 100644 inst/cohorts/117.json create mode 100644 inst/cohorts/119.json create mode 100644 inst/cohorts/120.json create mode 100644 inst/cohorts/121.json create mode 100644 inst/cohorts/122.json create mode 100644 inst/cohorts/123.json create mode 100644 inst/cohorts/124.json create mode 100644 inst/cohorts/125.json create mode 100644 inst/cohorts/126.json create mode 100644 inst/cohorts/127.json diff --git a/.Rprofile b/.Rprofile deleted file mode 100644 index 81b960f..0000000 --- a/.Rprofile +++ /dev/null @@ -1 +0,0 @@ -source("renv/activate.R") diff --git a/DESCRIPTION b/DESCRIPTION index 7d4b031..39580b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,4 +1,4 @@ -Package: EhdenAlopecia +Package: EhdenAlopecia Version: 1.1.1 Authors@R: person("Ross", "Williams", , "r.williams@derasmusmc.nl", role = c("aut", "cre")) Description: This package creates the cohorts for this EHDEN Alopecia study study. Based on this cohort diagnostics, incidence and prevalence rates and treatment patterns are analysis are performed. diff --git a/R/createCohorts.R b/R/createCohorts.R index b248fe9..3b2548e 100644 --- a/R/createCohorts.R +++ b/R/createCohorts.R @@ -9,7 +9,7 @@ #' @export createCohorts <- function(connectionDetails, cohortTable, - type = c("cohorts", "treatments"), + type = c("cohorts"), cdmDatabaseSchema, cohortDatabaseSchema){ diff --git a/R/runStudy.R b/R/runStudy.R index 26bead6..575b77c 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -18,19 +18,30 @@ runStudy <- function(connectionDetails, cdmDatabaseSchema, cohortDatabaseSchema, instantiateCohorts = FALSE, - instantiateTreatmentCohorts = FALSE, + # instantiateTreatmentCohorts = FALSE, runDiagnostics = FALSE, runPatternAnalysis = FALSE, outputFolder, databaseId, minCellCount) { + if (!dir.exists(outputFolder)) { + dir.create(outputFolder) + } + if (instantiateCohorts){ cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, cohortTable = cohortTable, type = "cohorts", cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema) + cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTable = cohortTable) + cohortsGenerated <- cohortsGenerated %>% + left_join(cohortCounts, by = "cohortId") + cohortsGenerated <- cohortsGenerated %>% + filter(cohortSubjects > 0) readr::write_csv(cohortsGenerated, file.path(outputFolder, "cohortsGenerated.csv")) } @@ -48,20 +59,29 @@ runStudy <- function(connectionDetails, } if (runPatternAnalysis){ - if (instantiateTreatmentCohorts){ - cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, - cohortTable = cohortTable, - type = "treatments", - cdmDatabaseSchema = cdmDatabaseSchema, - cohortDatabaseSchema = cohortDatabaseSchema) - readr::write_csv(cohortsGenerated, file.path(outputFolder, "treatmentCohortsGenerated.csv")) - } - targetCohortsGenerated <- readr::read_csv(file.path(outputFolder, "treatmentCohortsGenerated.csv")) - treatmentCohortsGenerated <- readr::read_csv(file.path(outputFolder, "treatmentCohortsGenerated.csv")) - cohortsGenerated <- targetCohortsGenerated %>% - dplyr::bind_rows(treatmentCohortsGenerated) - for (cohort in c(92, 93, 94, 95, 96 ,97, 100)){ - cohortIds <- c(cohort, 101:127) + # if (instantiateTreatmentCohorts){ + # cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, + # cohortTable = cohortTable, + # type = "treatment_cohorts", + # cdmDatabaseSchema = cdmDatabaseSchema, + # cohortDatabaseSchema = cohortDatabaseSchema) + # readr::write_csv(cohortsGenerated, file.path(outputFolder, "treatmentCohortsGenerated.csv")) + # } + targetCohortsGenerated <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% + filter(cohortId <= 100) + + treatmentCohortsGenerated <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% + filter(cohortId > 100) + # cohortsGenerated <- targetCohortsGenerated[1,] %>% + # dplyr::bind_rows(treatmentCohortsGenerated) + for (i in seq(1:length(targetCohortsGenerated$cohortId))) { + # i <- 1 + cohortsGenerated <- targetCohortsGenerated[i,] %>% + dplyr::bind_rows(treatmentCohortsGenerated) + + # cohortIds <- c(cohort, 101:127) + # cohort <- 100 + cohortIds <- cohortsGenerated$cohortId runTreatmentPatterns(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, @@ -70,6 +90,7 @@ runStudy <- function(connectionDetails, outputFolder = outputFolder, cohortIds = cohortIds, minCellCount = minCellCount) - } + + } } } \ No newline at end of file diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index 5c79899..0861562 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -26,24 +26,24 @@ runTreatmentPatterns <- function(connectionDetails, logger = NULL, cohortIds, minCellCount = 5) { - # med level treatment patterns ----- - cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTable = cohortTable) - tpCohorts <- cohortsGenerated %>% - dplyr::inner_join(cohortCounts, - dplyr::join_by(cohortId)) %>% - dplyr::filter(cohortSubjects > 0) # make sure at least someone appears + # # med level treatment patterns ----- + # cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, + # cohortDatabaseSchema = cohortDatabaseSchema, + # cohortTable = cohortTable) + # tpCohorts <- cohortsGenerated %>% + # dplyr::inner_join(cohortCounts, + # dplyr::join_by(cohortId)) %>% + # dplyr::filter(cohortSubjects > 0) # make sure at least someone appears - if (nrow(tpCohorts) > 0) { + # if (nrow(tpCohorts) > 0) { # Select target cohort targetCohorts <- cohortsGenerated %>% - filter(cohortName == cohortIds[1]) %>% + filter(cohortName == cohortIds[1]) %>% select(cohortId, cohortName) # Select everything BUT target cohorts eventCohorts <- cohortsGenerated %>% - filter(cohortName != cohortsIds[1]) %>% + filter(cohortName != cohortIds[1]) %>% select(cohortId, cohortName) cohorts <- dplyr::bind_rows( @@ -81,5 +81,5 @@ runTreatmentPatterns <- function(connectionDetails, minFreq = minCellCount, archiveName = NULL ) - } + # } } diff --git a/extras/codeToRun.R b/extras/codeToRun.R index 16f5dbf..efaf011 100644 --- a/extras/codeToRun.R +++ b/extras/codeToRun.R @@ -35,9 +35,10 @@ #Load the library library(EhdenAlopecia) +library(dplyr) # database metadata and connection details ----- # The name/ acronym for the database -databaseId <- "" +databaseId <- "IPCI" # Database connection details ----- #connection details @@ -45,21 +46,22 @@ databaseId <- "" # Details for connecting to the server: -dbms <- "" -user <- "" -pw <- "" -server <- "" -port <- "" +dbms <- Sys.getenv("dbms") +user <- Sys.getenv("user") +password <- Sys.getenv("password") +server <- Sys.getenv("host") +port <- Sys.getenv +connectionString <- Sys.getenv("connectionString") connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, - server = server, + connectionString = connectionString, user = user, - password = pw, + password = password, port = port) -cdmDatabaseSchema <- "" -cohortDatabaseSchema <- "" +cdmDatabaseSchema <- "cdm" +cohortDatabaseSchema <- "cbarboza" # Name of table prefix to use in the result schema for tables created during the study. @@ -79,7 +81,8 @@ outputFolder <- "results" #choose analysis to run instantiateCohorts <- TRUE -runDiagnostics <- TRUE +runDiagnostics <- FALSE +instantiateTreatmentCohorts <- FALSE runPatternAnalysis <- TRUE ### Do not edit below here @@ -91,6 +94,7 @@ EhdenAlopecia::runStudy( cohortDatabaseSchema = cohortDatabaseSchema, instantiateCohorts = instantiateCohorts, runDiagnostics = runDiagnostics, + instantiateTreatmentCohorts = instantiateTreatmentCohorts, runPatternAnalysis = runPatternAnalysis, outputFolder = outputFolder, databaseId = databaseId, diff --git a/inst/cohorts/101.json b/inst/cohorts/101.json new file mode 100644 index 0000000..1c7ee7c --- /dev/null +++ b/inst/cohorts/101.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 0, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "(Alopecia) Corticosteroids, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 21602098, + "CONCEPT_NAME" : "CORTICOSTEROIDS, DERMATOLOGICAL PREPARATIONS", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "D07", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 2nd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "First" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 0, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/102.json b/inst/cohorts/102.json new file mode 100644 index 0000000..56b59cd --- /dev/null +++ b/inst/cohorts/102.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "(Alopecia) Corticosteroids, systemic (i.e. oral and injected)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 21602723, + "CONCEPT_NAME" : "CORTICOSTEROIDS FOR SYSTEMIC USE, PLAIN", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "H02A", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 3rd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 1, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/103.json b/inst/cohorts/103.json new file mode 100644 index 0000000..74af237 --- /dev/null +++ b/inst/cohorts/103.json @@ -0,0 +1,258 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 2, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 2, + "name" : "(Alopecia) Immunotherapy, topical (all non-standard concepts)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 45017482, + "CONCEPT_NAME" : "DIPHENYLCYCLOPROPENONE 98% PWD", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "49452264202", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45274656, + "CONCEPT_NAME" : "DIPHENYLCYCLOPROPENONE POWDER", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "51927166800", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45052575, + "CONCEPT_NAME" : "DIPHENYLCYCLOPROPENONE PWDR", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "51552094302", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45257357, + "CONCEPT_NAME" : "DIPHENYLCYCLOPROPENONE PWDR", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "51552094301", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45239268, + "CONCEPT_NAME" : "2,4-DINITROCHLOROBENZENE CR", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "49452263001", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45187717, + "CONCEPT_NAME" : "2,4-DINITROCHLOROBENZENE CR", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "49452263002", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4258736, + "CONCEPT_NAME" : "Dinitrochlorobenzene", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N0000171188", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDFRT", + "CONCEPT_CLASS_ID" : "Chemical Structure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 576880, + "CONCEPT_NAME" : "DINITROCHLOROBENZENE 100 % MISCELL CRYSTALS", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "060171", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "GCN_SEQNO", + "CONCEPT_CLASS_ID" : "GCN_SEQNO" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45240352, + "CONCEPT_NAME" : "DINITROCHLOROBENZENE 99% CRYST", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "51927133000", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "NDC", + "CONCEPT_CLASS_ID" : "11-digit NDC" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 576954, + "CONCEPT_NAME" : "SQUARIC ACID DIBUTYLESTER 100 % MISCELL LIQUID (GRAM)", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "043710", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "GCN_SEQNO", + "CONCEPT_CLASS_ID" : "GCN_SEQNO" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 579748, + "CONCEPT_NAME" : "SQUARIC ACID DIBUTYLESTER IN BUTYL ALCOHOL 150 mg MISCELL LIQUID (GRAM)", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "070912", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "GCN_SEQNO", + "CONCEPT_CLASS_ID" : "GCN_SEQNO" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 574411, + "CONCEPT_NAME" : "SQUARIC ACID DIBUTYLESTER MISCELL POWDER (GRAM)", + "STANDARD_CONCEPT" : "N", + "STANDARD_CONCEPT_CAPTION" : "Non-Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "022515", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "GCN_SEQNO", + "CONCEPT_CLASS_ID" : "GCN_SEQNO" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 2, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/104.json b/inst/cohorts/104.json new file mode 100644 index 0000000..d1ba597 --- /dev/null +++ b/inst/cohorts/104.json @@ -0,0 +1,122 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 3, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 3, + "name" : "(Alopecia) Immunomodulators (Azathioprine. Cyclosporine, Mycophenolate mofetil, Methotrexate)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 19014878, + "CONCEPT_NAME" : "Azathioprine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1256", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19010482, + "CONCEPT_NAME" : "Cyclosporine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3008", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19003999, + "CONCEPT_NAME" : "mycophenolate mofetil", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "68149", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1305058, + "CONCEPT_NAME" : "Methotrexate", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "6851", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 3, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/105.json b/inst/cohorts/105.json new file mode 100644 index 0000000..49d575e --- /dev/null +++ b/inst/cohorts/105.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 4, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 4, + "name" : "(Alopecia) Anthralin (i.e. dithranol), topical immunotherapeutic agent", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36211872, + "CONCEPT_NAME" : "Anthralin Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1153703", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 4, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/106.json b/inst/cohorts/106.json new file mode 100644 index 0000000..e43670f --- /dev/null +++ b/inst/cohorts/106.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 5, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 5, + "name" : "(Alopecia) Minoxidil, arteriolar vasodilator", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1309068, + "CONCEPT_NAME" : "Minoxidil", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "6984", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 5, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/107.json b/inst/cohorts/107.json new file mode 100644 index 0000000..abcc582 --- /dev/null +++ b/inst/cohorts/107.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 6, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 6, + "name" : "(Alopecia) Finasteride", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 996416, + "CONCEPT_NAME" : "Finasteride", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "25025", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 6, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/108.json b/inst/cohorts/108.json new file mode 100644 index 0000000..e40f423 --- /dev/null +++ b/inst/cohorts/108.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 7, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 7, + "name" : "(Alopecia) Tretinoin, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36223379, + "CONCEPT_NAME" : "Tretinoin Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1158220", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 7, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/109.json b/inst/cohorts/109.json new file mode 100644 index 0000000..cadfbaf --- /dev/null +++ b/inst/cohorts/109.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 8, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 8, + "name" : "(Alopecia) Tofacitinib, JAK inhibitor, oral", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 42904205, + "CONCEPT_NAME" : "tofacitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1357536", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 8, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/110.json b/inst/cohorts/110.json new file mode 100644 index 0000000..e78f4ec --- /dev/null +++ b/inst/cohorts/110.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 9, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 9, + "name" : "(Alopecia) Baricitinib, JAK inhibitor, oral", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1510627, + "CONCEPT_NAME" : "baricitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "2047232", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 9, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/111.json b/inst/cohorts/111.json new file mode 100644 index 0000000..f898661 --- /dev/null +++ b/inst/cohorts/111.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 10, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 10, + "name" : "(Alopecia) Ruxolitinib, JAK inhibitor, oral", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40244464, + "CONCEPT_NAME" : "ruxolitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1193326", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 10, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/112.json b/inst/cohorts/112.json new file mode 100644 index 0000000..7ebc565 --- /dev/null +++ b/inst/cohorts/112.json @@ -0,0 +1,649 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 11, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 11, + "name" : "(Alopecia) Clobetasol propionate, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 19114411, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Gel [embelin]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "544116", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44044472, + "CONCEPT_NAME" : "Clobetasol Topical Cream [Alti-Clobetasol Propionate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP1039103", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Branded Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19102575, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution [Clobex]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "404036", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793228, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam [Olux]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1992274", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793230, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Cream", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1992281", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793231, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Cream [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1992282", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793227, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1992273", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19002305, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Dermovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "103431", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19002304, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Dermovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "103430", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793721, + "CONCEPT_NAME" : "Clobetasol Propionate 0.25 MG/ML Topical Cream [Impoyz]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1995460", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 793716, + "CONCEPT_NAME" : "Clobetasol Propionate 0.25 MG/ML Topical Cream", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1995455", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44122102, + "CONCEPT_NAME" : "Clobetasol Topical Ointment [Alti-Clobetasol Propionate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP1116733", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Branded Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44122104, + "CONCEPT_NAME" : "Clobetasol Topical Solution [Alti-Clobetasol Propionate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP1116735", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Branded Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1361309, + "CONCEPT_NAME" : "Emollient Clobetasol Propionate 0.5 MG/ML Topical Foam [Tovet]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "2180345", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164516, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861495", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164517, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Cormax]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861497", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164518, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Embeline]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861498", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164519, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Isovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861500", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164524, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Lotion [Clobex]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861506", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164525, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861487", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164526, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution [Cormax]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861526", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164527, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution [Embeline]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861489", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164520, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Cream [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861503", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164521, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Foam", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861353", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164522, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Foam [Olux]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861355", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164523, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Lotion", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861505", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164528, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Solution [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861510", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164529, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Spray", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861512", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164530, + "CONCEPT_NAME" : "Clobetasol Propionate 0.5 MG/ML Topical Spray [Clobex]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861513", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164501, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Gel", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861434", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164502, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Gel [Clobevate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861436", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164508, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861472", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164504, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Gel [Temovate]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861440", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164505, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Ointment", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861448", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40164506, + "CONCEPT_NAME" : "Clobetasol Propionate 0.0005 MG/MG Topical Ointment [Cormax]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "861449", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Branded Drug" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 11, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/113.json b/inst/cohorts/113.json new file mode 100644 index 0000000..9dc9124 --- /dev/null +++ b/inst/cohorts/113.json @@ -0,0 +1,105 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 12, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 12, + "name" : "(Alopecia) Iron supplement", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36219948, + "CONCEPT_NAME" : "ferrous sulfate Oral Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1164414", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36219932, + "CONCEPT_NAME" : "ferrous gluconate Oral Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1164398", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36224164, + "CONCEPT_NAME" : "Ferrous fumarate Oral Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1159640", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 12, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/114.json b/inst/cohorts/114.json new file mode 100644 index 0000000..3fa0850 --- /dev/null +++ b/inst/cohorts/114.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 13, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 13, + "name" : "(Alopecia) Vitamin E", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36226018, + "CONCEPT_NAME" : "Vitamin E Oral Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1161178", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 13, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/115.json b/inst/cohorts/115.json new file mode 100644 index 0000000..6cb6fdc --- /dev/null +++ b/inst/cohorts/115.json @@ -0,0 +1,139 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 14, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 14, + "name" : "(Alopecia) Immunomodulators (Azathioprine. Cyclosporine, Mycophenolate mofetil, Methotrexate, Sulf.)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 19014878, + "CONCEPT_NAME" : "Azathioprine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1256", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19010482, + "CONCEPT_NAME" : "Cyclosporine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3008", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19003999, + "CONCEPT_NAME" : "mycophenolate mofetil", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "68149", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1305058, + "CONCEPT_NAME" : "Methotrexate", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "6851", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 964339, + "CONCEPT_NAME" : "Sulfasalazine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "9524", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 14, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/116.json b/inst/cohorts/116.json new file mode 100644 index 0000000..9448584 --- /dev/null +++ b/inst/cohorts/116.json @@ -0,0 +1,105 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 15, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 15, + "name" : "(Alopecia) JAK inhibitors group, oral (Ruxolitinib, Tofacitinib, Baricitinib)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40244464, + "CONCEPT_NAME" : "ruxolitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1193326", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1510627, + "CONCEPT_NAME" : "baricitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "2047232", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 42904205, + "CONCEPT_NAME" : "tofacitinib", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1357536", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 15, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/117.json b/inst/cohorts/117.json new file mode 100644 index 0000000..caca4ff --- /dev/null +++ b/inst/cohorts/117.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 16, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 16, + "name" : "(Alopecia) Tacrolimus, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36219038, + "CONCEPT_NAME" : "Tacrolimus Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1164204", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 16, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/119.json b/inst/cohorts/119.json new file mode 100644 index 0000000..4d383f8 --- /dev/null +++ b/inst/cohorts/119.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 17, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 17, + "name" : "(Alopecia) Bexarotene, topical", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36226250, + "CONCEPT_NAME" : "bexarotene Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1161188", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 17, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/120.json b/inst/cohorts/120.json new file mode 100644 index 0000000..b2fcd09 --- /dev/null +++ b/inst/cohorts/120.json @@ -0,0 +1,88 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 18, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 18, + "name" : "(Alopecia) Retinoids, topical (Bexarotene, Tretinoin)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 36226250, + "CONCEPT_NAME" : "bexarotene Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1161188", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36223379, + "CONCEPT_NAME" : "Tretinoin Topical Product", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1158220", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Dose Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 18, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/121.json b/inst/cohorts/121.json new file mode 100644 index 0000000..9a70c3d --- /dev/null +++ b/inst/cohorts/121.json @@ -0,0 +1,88 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 19, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 19, + "name" : "(Alopecia) Monclonal antibodies (Ustekinumab, dupilumab)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40161532, + "CONCEPT_NAME" : "ustekinumab", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "847083", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1593467, + "CONCEPT_NAME" : "dupilumab", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1876376", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 19, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/122.json b/inst/cohorts/122.json new file mode 100644 index 0000000..6b153bf --- /dev/null +++ b/inst/cohorts/122.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 20, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 20, + "name" : "(Alopecia) Apremilast", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 44816294, + "CONCEPT_NAME" : "apremilast", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1492727", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 20, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/123.json b/inst/cohorts/123.json new file mode 100644 index 0000000..b27a351 --- /dev/null +++ b/inst/cohorts/123.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 21, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 21, + "name" : "(Alopecia) Abatacept", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1186087, + "CONCEPT_NAME" : "abatacept", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "614391", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 21, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/124.json b/inst/cohorts/124.json new file mode 100644 index 0000000..8016fce --- /dev/null +++ b/inst/cohorts/124.json @@ -0,0 +1,71 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 22, + "OccurrenceStartDate" : { + "Value" : "2015-01-01", + "Op" : "gte" + }, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 22, + "name" : "(Alopecia) Crisaborole", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1593397, + "CONCEPT_NAME" : "crisaborole", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1865953", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 22, + "GapDays" : 0, + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/125.json b/inst/cohorts/125.json new file mode 100644 index 0000000..5946683 --- /dev/null +++ b/inst/cohorts/125.json @@ -0,0 +1,83 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 23, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 23, + "name" : "(Alopecia) Psoralens and ultraviolet A (PUVA), photochemotherapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 2314256, + "CONCEPT_NAME" : "Photochemotherapy; psoralens and ultraviolet A (PUVA)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "96912", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4262683, + "CONCEPT_NAME" : "Photochemotherapy with psoralens and ultraviolet A", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "46467001", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/126.json b/inst/cohorts/126.json new file mode 100644 index 0000000..e0f923d --- /dev/null +++ b/inst/cohorts/126.json @@ -0,0 +1,83 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 24, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 24, + "name" : "(Alopecia) Ultraviolet A (UVA) light therapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4138632, + "CONCEPT_NAME" : "Ultraviolet A light therapy to skin", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "425893002", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4039592, + "CONCEPT_NAME" : "Ultraviolet A therapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "229587005", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} diff --git a/inst/cohorts/127.json b/inst/cohorts/127.json new file mode 100644 index 0000000..cc15733 --- /dev/null +++ b/inst/cohorts/127.json @@ -0,0 +1,66 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DeviceExposure" : { + "CodesetId" : 25, + "DeviceTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 25, + "name" : "(Alopecia) Excimerlaser, dermatological, device", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 45762264, + "CONCEPT_NAME" : "Dermatological excimer laser system", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "468800009", + "DOMAIN_ID" : "Device", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Physical Object" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} From d30d80b745628c4afabecefa6d74d8c822898128 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Fri, 17 Nov 2023 19:18:42 +0100 Subject: [PATCH 13/41] added subfolder saving --- R/runStudy.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/runStudy.R b/R/runStudy.R index 26bead6..ba9bf2a 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -62,12 +62,16 @@ runStudy <- function(connectionDetails, dplyr::bind_rows(treatmentCohortsGenerated) for (cohort in c(92, 93, 94, 95, 96 ,97, 100)){ cohortIds <- c(cohort, 101:127) + outputSubDir <- file.path(outputDir, 'treatmentPatterns', cohort) + if (!dir.exists(outputSubDir)) { + dir.create(outputSubDir, recursive = TRUE) + } runTreatmentPatterns(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, cohortsGenerated = cohortsGenerated, - outputFolder = outputFolder, + outputFolder = outputSubDir, cohortIds = cohortIds, minCellCount = minCellCount) } From 31342055add325e22121c21b23e5973d00564032 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 09:59:28 +0100 Subject: [PATCH 14/41] edhen friday --- .Rbuildignore | 2 ++ .gitignore | 3 ++ NAMESPACE | 6 ++++ R/createCohorts.R | 62 ++++++++++++++++++++++++++++--------- R/runStudy.R | 55 ++++++++++++++------------------ R/runTreatmentPatterns.R | 18 +++-------- extras/codeToRun.R | 3 -- man/createCohorts.Rd | 3 ++ man/runStudy.Rd | 3 ++ man/runTreatmentPatterns.Rd | 46 +++++++++++++++++++++++++++ 10 files changed, 138 insertions(+), 63 deletions(-) create mode 100644 man/runTreatmentPatterns.Rd diff --git a/.Rbuildignore b/.Rbuildignore index d821302..b6ac0b4 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,5 @@ ^renv\.lock$ ^.*\.Rproj$ ^\.Rproj\.user$ +^CodeToRunSynthea\.R +^CodeToRunIPCI\.R \ No newline at end of file diff --git a/.gitignore b/.gitignore index cd0675b..a8cfe08 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ errorReport* Results/* .DS_Store +CodeToRunSynthea.R +CodeToRunSnowflake.R +CodeToRunIPCI.R \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index 1dd48d8..7d2224f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,4 +3,10 @@ export("%>%") export(createCohorts) export(runStudy) +export(runTreatmentPatterns) +import(CohortDiagnostics) +import(CohortGenerator) +import(TreatmentPatterns) +import(dplyr) +import(readr) importFrom(magrittr,"%>%") diff --git a/R/createCohorts.R b/R/createCohorts.R index 3b2548e..48aee13 100644 --- a/R/createCohorts.R +++ b/R/createCohorts.R @@ -21,19 +21,19 @@ createCohorts <- function(connectionDetails, # package as an example cohortJsonFiles <- list.files(path = system.file(type, package = "EhdenAlopecia"), full.names = TRUE) for (i in 1:length(cohortJsonFiles)) { - cohortJsonFileName <- cohortJsonFiles[i] - cohortName <- tools::file_path_sans_ext(basename(cohortJsonFileName)) - # Here we read in the JSON in order to create the SQL - # using [CirceR](https://ohdsi.github.io/CirceR/) - # If you have your JSON and SQL stored differenly, you can - # modify this to read your JSON/SQL files however you require - cohortJson <- readChar(cohortJsonFileName, file.info(cohortJsonFileName)$size) - cohortExpression <- CirceR::cohortExpressionFromJson(cohortJson) - cohortSql <- CirceR::buildCohortQuery(cohortExpression, options = CirceR::createGenerateOptions(generateStats = FALSE)) - cohortsToCreate <- rbind(cohortsToCreate, data.frame(cohortId = as.numeric(cohortName), - cohortName = cohortName, - sql = cohortSql, - stringsAsFactors = FALSE)) + cohortJsonFileName <- cohortJsonFiles[i] + cohortName <- tools::file_path_sans_ext(basename(cohortJsonFileName)) + # Here we read in the JSON in order to create the SQL + # using [CirceR](https://ohdsi.github.io/CirceR/) + # If you have your JSON and SQL stored differenly, you can + # modify this to read your JSON/SQL files however you require + cohortJson <- readChar(cohortJsonFileName, file.info(cohortJsonFileName)$size) + cohortExpression <- CirceR::cohortExpressionFromJson(cohortJson) + cohortSql <- CirceR::buildCohortQuery(cohortExpression, options = CirceR::createGenerateOptions(generateStats = FALSE)) + cohortsToCreate <- rbind(cohortsToCreate, data.frame(cohortId = as.numeric(cohortName), + cohortName = cohortName, + sql = cohortSql, + stringsAsFactors = FALSE)) } @@ -41,8 +41,8 @@ createCohorts <- function(connectionDetails, # Create the cohort tables to hold the cohort generation results cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = cohortTable) CohortGenerator::createCohortTables(connectionDetails = connectionDetails, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTableNames = cohortTableNames) + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTableNames = cohortTableNames) # Generate the cohorts cohortsGenerated <- CohortGenerator::generateCohortSet(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, @@ -55,4 +55,36 @@ createCohorts <- function(connectionDetails, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTableNames$cohortTable) return(cohortsGenerated) +} + +#' Instantiate cohorts against an omop cdm instance +#' +#' @param connectionDetails connection details generated using DatabaseConnector::createConnectionDetails() +#' @param cohortTable Name of the table to be created where cohorts will be stored +#' @param type Which cohorts to create +#' @param cdmDatabaseSchema name of the schema where the cdm is stored +#' @param cohortDatabaseSchema name of a schema with write access for the creation of cohort table +#' +#' @export +createCohortsCDM <- function(cdm, + cohortTable, + type = c("cohorts"), + cdmDatabaseSchema, + cohortDatabaseSchema){ + + alopecia_ehden <- CDMConnector::readCohortSet(system.file("cohorts", package = "EhdenAlopecia")) + + cdm <- CDMConnector::generateCohortSet(cdm, + alopecia_ehden, + name = "alopecia_ehden", + computeAttrition = TRUE, + overwrite = TRUE) + + + + # Get the cohort counts + cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTable = cohortTableNames$cohortTable) + return(cohortsGenerated) } \ No newline at end of file diff --git a/R/runStudy.R b/R/runStudy.R index 575b77c..59690a3 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -10,7 +10,8 @@ #' @param outputFolder The folder where the results should be written #' @param databaseId a short name that can identify the database used #' @param minCellCount the minimum number of patients that can be shared for any single count in the results -#' +#' +#' @import dplyr TreatmentPatterns CohortGenerator CohortDiagnostics readr #' @export runStudy <- function(connectionDetails, @@ -18,17 +19,17 @@ runStudy <- function(connectionDetails, cdmDatabaseSchema, cohortDatabaseSchema, instantiateCohorts = FALSE, - # instantiateTreatmentCohorts = FALSE, runDiagnostics = FALSE, runPatternAnalysis = FALSE, outputFolder, databaseId, minCellCount) { + # Create output folder if (!dir.exists(outputFolder)) { dir.create(outputFolder) } - + # Instantiate cohorts if (instantiateCohorts){ cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, cohortTable = cohortTable, @@ -44,7 +45,7 @@ runStudy <- function(connectionDetails, filter(cohortSubjects > 0) readr::write_csv(cohortsGenerated, file.path(outputFolder, "cohortsGenerated.csv")) } - + # CohortDiagnostics if (runDiagnostics){ cohortDefinitionSet <- readr::read_csv("inst/cohortDefinitionSet.csv") CohortDiagnostics::executeDiagnostics(cohortDefinitionSet = cohortDefinitionSet, @@ -58,38 +59,30 @@ runStudy <- function(connectionDetails, ) } + # TreatmentPatterns if (runPatternAnalysis){ - # if (instantiateTreatmentCohorts){ - # cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, - # cohortTable = cohortTable, - # type = "treatment_cohorts", - # cdmDatabaseSchema = cdmDatabaseSchema, - # cohortDatabaseSchema = cohortDatabaseSchema) - # readr::write_csv(cohortsGenerated, file.path(outputFolder, "treatmentCohortsGenerated.csv")) - # } - targetCohortsGenerated <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% + # Target and treatment cohorts sections + targetCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% filter(cohortId <= 100) - - treatmentCohortsGenerated <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% + treatmentCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% filter(cohortId > 100) - # cohortsGenerated <- targetCohortsGenerated[1,] %>% - # dplyr::bind_rows(treatmentCohortsGenerated) - for (i in seq(1:length(targetCohortsGenerated$cohortId))) { - # i <- 1 - cohortsGenerated <- targetCohortsGenerated[i,] %>% - dplyr::bind_rows(treatmentCohortsGenerated) - - # cohortIds <- c(cohort, 101:127) - # cohort <- 100 + for (i in seq(1:length(targetCohorts$cohortId))) { + outputSubDir <- file.path(outputFolder, 'treatmentPatterns', i) + if (!dir.exists(outputSubDir)) { + dir.create(outputSubDir, recursive = TRUE) + } + # TreatmentPathways for each target cohort with treatments + cohortsGenerated <- targetCohorts[i,] %>% + dplyr::bind_rows(treatmentCohorts) cohortIds <- cohortsGenerated$cohortId runTreatmentPatterns(connectionDetails = connectionDetails, - cdmDatabaseSchema = cdmDatabaseSchema, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTable = cohortTable, - cohortsGenerated = cohortsGenerated, - outputFolder = outputFolder, - cohortIds = cohortIds, - minCellCount = minCellCount) + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTable = cohortTable, + cohortsGenerated = cohortsGenerated, + outputFolder = outputSubDir, + cohortIds = cohortIds, + minCellCount = minCellCount) } } diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index 0861562..3bba1c0 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -10,12 +10,12 @@ #' @param logger logger object #' @param cohortIds the cohortIds to be used form the cohort table #' @param minCellCount minimum cell count -#' +#' +#' @import dplyr TreatmentPatterns CohortGenerator CohortDiagnostics readr +#' #' @return the drug utilisation results #' -#' @examples #' @export - runTreatmentPatterns <- function(connectionDetails, cdmDatabaseSchema, cohortDatabaseSchema, @@ -26,16 +26,7 @@ runTreatmentPatterns <- function(connectionDetails, logger = NULL, cohortIds, minCellCount = 5) { - # # med level treatment patterns ----- - # cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, - # cohortDatabaseSchema = cohortDatabaseSchema, - # cohortTable = cohortTable) - # tpCohorts <- cohortsGenerated %>% - # dplyr::inner_join(cohortCounts, - # dplyr::join_by(cohortId)) %>% - # dplyr::filter(cohortSubjects > 0) # make sure at least someone appears - - # if (nrow(tpCohorts) > 0) { + # Select target cohort targetCohorts <- cohortsGenerated %>% filter(cohortName == cohortIds[1]) %>% @@ -81,5 +72,4 @@ runTreatmentPatterns <- function(connectionDetails, minFreq = minCellCount, archiveName = NULL ) - # } } diff --git a/extras/codeToRun.R b/extras/codeToRun.R index efaf011..3d019cf 100644 --- a/extras/codeToRun.R +++ b/extras/codeToRun.R @@ -44,7 +44,6 @@ databaseId <- "IPCI" #connection details #User specified input - # Details for connecting to the server: dbms <- Sys.getenv("dbms") user <- Sys.getenv("user") @@ -86,7 +85,6 @@ instantiateTreatmentCohorts <- FALSE runPatternAnalysis <- TRUE ### Do not edit below here - EhdenAlopecia::runStudy( connectionDetails = connectionDetails, cohortTable = cohortTable, @@ -94,7 +92,6 @@ EhdenAlopecia::runStudy( cohortDatabaseSchema = cohortDatabaseSchema, instantiateCohorts = instantiateCohorts, runDiagnostics = runDiagnostics, - instantiateTreatmentCohorts = instantiateTreatmentCohorts, runPatternAnalysis = runPatternAnalysis, outputFolder = outputFolder, databaseId = databaseId, diff --git a/man/createCohorts.Rd b/man/createCohorts.Rd index cf93d21..313102f 100644 --- a/man/createCohorts.Rd +++ b/man/createCohorts.Rd @@ -7,6 +7,7 @@ createCohorts( connectionDetails, cohortTable, + type = c("cohorts"), cdmDatabaseSchema, cohortDatabaseSchema ) @@ -16,6 +17,8 @@ createCohorts( \item{cohortTable}{Name of the table to be created where cohorts will be stored} +\item{type}{Which cohorts to create} + \item{cdmDatabaseSchema}{name of the schema where the cdm is stored} \item{cohortDatabaseSchema}{name of a schema with write access for the creation of cohort table} diff --git a/man/runStudy.Rd b/man/runStudy.Rd index 6a911cb..9cf619c 100644 --- a/man/runStudy.Rd +++ b/man/runStudy.Rd @@ -11,6 +11,7 @@ runStudy( cohortDatabaseSchema, instantiateCohorts = FALSE, runDiagnostics = FALSE, + runPatternAnalysis = FALSE, outputFolder, databaseId, minCellCount @@ -29,6 +30,8 @@ runStudy( \item{runDiagnostics}{choose whether to run the cohort diagnostics} +\item{runPatternAnalysis}{choose whether to run the treatment patterns analysis} + \item{outputFolder}{The folder where the results should be written} \item{databaseId}{a short name that can identify the database used} diff --git a/man/runTreatmentPatterns.Rd b/man/runTreatmentPatterns.Rd new file mode 100644 index 0000000..42e7ce6 --- /dev/null +++ b/man/runTreatmentPatterns.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/runTreatmentPatterns.R +\name{runTreatmentPatterns} +\alias{runTreatmentPatterns} +\title{Run the treatment patterns analysis} +\usage{ +runTreatmentPatterns( + connectionDetails, + cdmDatabaseSchema, + cohortDatabaseSchema, + cohortTable, + cohortsGenerated, + outputFolder, + tablePrefix = NULL, + logger = NULL, + cohortIds, + minCellCount = 5 +) +} +\arguments{ +\item{cdmDatabaseSchema}{the schema where the cdm is located} + +\item{cohortDatabaseSchema}{A writable location on the database.} + +\item{cohortsGenerated}{A table contianing the output of the createCohorts function, detailing the cohorts that have been instatiated} + +\item{outputFolder}{The output directory where the results should be saved} + +\item{tablePrefix}{table prefix} + +\item{logger}{logger object} + +\item{cohortIds}{the cohortIds to be used form the cohort table} + +\item{minCellCount}{minimum cell count} + +\item{connection}{An database connection created using DatabaseConnector::connect} + +\item{outcomeTableName}{outcome cohort table name} +} +\value{ +the drug utilisation results +} +\description{ +Run the treatment patterns analysis +} From 06aa5dceb41639be92ceac69f326b0bd927cc9df Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 11:01:34 +0100 Subject: [PATCH 15/41] fixes style --- R/createCohorts.R | 4 ++++ R/runStudy.R | 34 +++++++++++++++++++--------------- R/runTreatmentPatterns.R | 2 +- extras/codeToRun.R | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/R/createCohorts.R b/R/createCohorts.R index 48aee13..8fa9e40 100644 --- a/R/createCohorts.R +++ b/R/createCohorts.R @@ -5,6 +5,10 @@ #' @param type Which cohorts to create #' @param cdmDatabaseSchema name of the schema where the cdm is stored #' @param cohortDatabaseSchema name of a schema with write access for the creation of cohort table +#' +#' @import dplyr +#' @importFrom CirceR cohortExpressionFromJson buildCohortQuery +#' @importFrom CohortGenerator getCohortTableNames createCohortTables generateCohortSet getCohortCounts #' #' @export createCohorts <- function(connectionDetails, diff --git a/R/runStudy.R b/R/runStudy.R index 59690a3..3cd7a42 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -11,7 +11,9 @@ #' @param databaseId a short name that can identify the database used #' @param minCellCount the minimum number of patients that can be shared for any single count in the results #' -#' @import dplyr TreatmentPatterns CohortGenerator CohortDiagnostics readr +#' @import dplyr TreatmentPatterns CohortDiagnostics readr +#' @importFrom CohortGenerator getCohortCounts +#' @importFrom CohortDiagnostics executeDiagnostics #' @export runStudy <- function(connectionDetails, @@ -29,13 +31,14 @@ runStudy <- function(connectionDetails, if (!dir.exists(outputFolder)) { dir.create(outputFolder) } + # Instantiate cohorts - if (instantiateCohorts){ + if (instantiateCohorts) { cohortsGenerated <- createCohorts(connectionDetails = connectionDetails, - cohortTable = cohortTable, - type = "cohorts", - cdmDatabaseSchema = cdmDatabaseSchema, - cohortDatabaseSchema = cohortDatabaseSchema) + cohortTable = cohortTable, + type = "cohorts", + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema) cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable) @@ -45,17 +48,18 @@ runStudy <- function(connectionDetails, filter(cohortSubjects > 0) readr::write_csv(cohortsGenerated, file.path(outputFolder, "cohortsGenerated.csv")) } + # CohortDiagnostics - if (runDiagnostics){ + if (runDiagnostics) { cohortDefinitionSet <- readr::read_csv("inst/cohortDefinitionSet.csv") CohortDiagnostics::executeDiagnostics(cohortDefinitionSet = cohortDefinitionSet, - connectionDetails = connectionDetails, - cohortTable = cohortTable, - cohortDatabaseSchema = cohortDatabaseSchema, - cdmDatabaseSchema = cdmDatabaseSchema, - exportFolder = outputFolder, - databaseId = databaseId, - minCellCount = minCellCount + connectionDetails = connectionDetails, + cohortTable = cohortTable, + cohortDatabaseSchema = cohortDatabaseSchema, + cdmDatabaseSchema = cdmDatabaseSchema, + exportFolder = outputFolder, + databaseId = databaseId, + minCellCount = minCellCount ) } @@ -67,7 +71,7 @@ runStudy <- function(connectionDetails, treatmentCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% filter(cohortId > 100) for (i in seq(1:length(targetCohorts$cohortId))) { - outputSubDir <- file.path(outputFolder, 'treatmentPatterns', i) + outputSubDir <- file.path(outputFolder, 'treatmentPatterns', targetCohorts[i,]$cohortId) if (!dir.exists(outputSubDir)) { dir.create(outputSubDir, recursive = TRUE) } diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index 3bba1c0..a948b87 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -11,7 +11,7 @@ #' @param cohortIds the cohortIds to be used form the cohort table #' @param minCellCount minimum cell count #' -#' @import dplyr TreatmentPatterns CohortGenerator CohortDiagnostics readr +#' @import dplyr TreatmentPatterns #' #' @return the drug utilisation results #' diff --git a/extras/codeToRun.R b/extras/codeToRun.R index 3d019cf..f9f983a 100644 --- a/extras/codeToRun.R +++ b/extras/codeToRun.R @@ -35,7 +35,7 @@ #Load the library library(EhdenAlopecia) -library(dplyr) + # database metadata and connection details ----- # The name/ acronym for the database databaseId <- "IPCI" From 304bbef5ee4ae76c813fd47bae1d92b549bc5353 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 11:03:22 +0100 Subject: [PATCH 16/41] fixes imports --- NAMESPACE | 13 ++++++++++--- R/runStudy.R | 3 ++- man/createCohortsCDM.Rd | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 man/createCohortsCDM.Rd diff --git a/NAMESPACE b/NAMESPACE index 7d2224f..6ddb8b5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,11 +2,18 @@ export("%>%") export(createCohorts) +export(createCohortsCDM) export(runStudy) export(runTreatmentPatterns) -import(CohortDiagnostics) -import(CohortGenerator) import(TreatmentPatterns) import(dplyr) -import(readr) +importFrom(CirceR,buildCohortQuery) +importFrom(CirceR,cohortExpressionFromJson) +importFrom(CohortDiagnostics,executeDiagnostics) +importFrom(CohortGenerator,createCohortTables) +importFrom(CohortGenerator,generateCohortSet) +importFrom(CohortGenerator,getCohortCounts) +importFrom(CohortGenerator,getCohortTableNames) importFrom(magrittr,"%>%") +importFrom(readr,read_csv) +importFrom(readr,write_csv) diff --git a/R/runStudy.R b/R/runStudy.R index 3cd7a42..c3629bc 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -11,7 +11,8 @@ #' @param databaseId a short name that can identify the database used #' @param minCellCount the minimum number of patients that can be shared for any single count in the results #' -#' @import dplyr TreatmentPatterns CohortDiagnostics readr +#' @import dplyr +#' @importFrom readr write_csv read_csv #' @importFrom CohortGenerator getCohortCounts #' @importFrom CohortDiagnostics executeDiagnostics #' @export diff --git a/man/createCohortsCDM.Rd b/man/createCohortsCDM.Rd new file mode 100644 index 0000000..02ed714 --- /dev/null +++ b/man/createCohortsCDM.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/createCohorts.R +\name{createCohortsCDM} +\alias{createCohortsCDM} +\title{Instantiate cohorts against an omop cdm instance} +\usage{ +createCohortsCDM( + cdm, + cohortTable, + type = c("cohorts"), + cdmDatabaseSchema, + cohortDatabaseSchema +) +} +\arguments{ +\item{cohortTable}{Name of the table to be created where cohorts will be stored} + +\item{type}{Which cohorts to create} + +\item{cdmDatabaseSchema}{name of the schema where the cdm is stored} + +\item{cohortDatabaseSchema}{name of a schema with write access for the creation of cohort table} + +\item{connectionDetails}{connection details generated using DatabaseConnector::createConnectionDetails()} +} +\description{ +Instantiate cohorts against an omop cdm instance +} From 67944d5633bf7d45891ffcefed63852c67cf1fa1 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 11:56:08 +0100 Subject: [PATCH 17/41] passing check --- .Rbuildignore | 6 +- .gitignore | 3 +- DESCRIPTION | 23 +- LICENSE | 201 ------------------ LICENSE.md | 194 +++++++++++++++++ NAMESPACE | 1 - R/createCohorts.R | 32 --- R/globals.R | 16 ++ R/runTreatmentPatterns.R | 10 +- extras/codeToRun.R => inst/extras/CodeToRun.R | 0 .../extras}/ExecuteUnitTests.R | 0 .../extras/badgesMarkdownCode.md | 0 .../extras}/createUnitTestData.R | 0 {extras => inst/extras}/launchShiny.R | 0 {extras => inst/extras}/package-maintenance.R | 0 man/createCohortsCDM.Rd | 28 --- man/runTreatmentPatterns.Rd | 10 +- 17 files changed, 242 insertions(+), 282 deletions(-) delete mode 100644 LICENSE create mode 100644 LICENSE.md create mode 100644 R/globals.R rename extras/codeToRun.R => inst/extras/CodeToRun.R (100%) rename {tests/testthat => inst/extras}/ExecuteUnitTests.R (100%) rename badgesMarkdownCode.md => inst/extras/badgesMarkdownCode.md (100%) rename {tests/testthat => inst/extras}/createUnitTestData.R (100%) rename {extras => inst/extras}/launchShiny.R (100%) rename {extras => inst/extras}/package-maintenance.R (100%) delete mode 100644 man/createCohortsCDM.Rd diff --git a/.Rbuildignore b/.Rbuildignore index b6ac0b4..f81b04f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,4 +3,8 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^CodeToRunSynthea\.R -^CodeToRunIPCI\.R \ No newline at end of file +^CodeToRunIPCI\.R +^results$ +^errorReportSql\.txt$ +^badgesMarkdownCode\.md$ +^LICENSE\.md$ diff --git a/.gitignore b/.gitignore index a8cfe08..8f3679d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ Results/* .DS_Store CodeToRunSynthea.R CodeToRunSnowflake.R -CodeToRunIPCI.R \ No newline at end of file +CodeToRunIPCI.R +errorReportSql.txt \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 39580b1..6baa14b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,4 +1,5 @@ Package: EhdenAlopecia +Title: Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon Version: 1.1.1 Authors@R: person("Ross", "Williams", , "r.williams@derasmusmc.nl", role = c("aut", "cre")) Description: This package creates the cohorts for this EHDEN Alopecia study study. Based on this cohort diagnostics, incidence and prevalence rates and treatment patterns are analysis are performed. @@ -9,19 +10,25 @@ RoxygenNote: 7.2.3 Depends: R (>= 3.6.1) Imports: - DBI, dplyr, - glue, - zip, magrittr, - checkmate, - log4r, - lubridate, - rlang, - readr + readr, + CirceR, + here, + CohortDiagnostics, + CohortGenerator, + TreatmentPatterns, Suggests: testthat (>= 3.0.0), rmarkdown, checkmate, + SqlRender, duckdb, + ParallelLogger, + DBI, + glue, + zip, + lubridate, + rlang, + jsonlite Config/testthat/edition: 3 diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..b62a9b5 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,194 @@ +Apache License +============== + +_Version 2.0, January 2004_ +_<>_ + +### Terms and Conditions for use, reproduction, and distribution + +#### 1. Definitions + +“License” shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +“Licensor” shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +“Legal Entity” shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, “control” means **(i)** the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the +outstanding shares, or **(iii)** beneficial ownership of such entity. + +“You” (or “Your”) shall mean an individual or Legal Entity exercising +permissions granted by this License. + +“Source” form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +“Object” form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +“Work” shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +“Derivative Works” shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +“Contribution” shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +“submitted” means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as “Not a Contribution.” + +“Contributor” shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +#### 2. Grant of Copyright License + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +#### 3. Grant of Patent License + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +#### 4. Redistribution + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +* **(a)** You must give any other recipients of the Work or Derivative Works a copy of +this License; and +* **(b)** You must cause any modified files to carry prominent notices stating that You +changed the files; and +* **(c)** You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. + +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +#### 5. Submission of Contributions + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +#### 6. Trademarks + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +#### 7. Disclaimer of Warranty + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +#### 8. Limitation of Liability + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +#### 9. Accepting Warranty or Additional Liability + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability. + +_END OF TERMS AND CONDITIONS_ + +### APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following boilerplate +notice, with the fields enclosed by brackets `[]` replaced with your own +identifying information. (Don't include the brackets!) The text should be +enclosed in the appropriate comment syntax for the file format. We also +recommend that a file or class name and description of purpose be included on +the same “printed page” as the copyright notice for easier identification within +third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NAMESPACE b/NAMESPACE index 6ddb8b5..ce85928 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,7 +2,6 @@ export("%>%") export(createCohorts) -export(createCohortsCDM) export(runStudy) export(runTreatmentPatterns) import(TreatmentPatterns) diff --git a/R/createCohorts.R b/R/createCohorts.R index 8fa9e40..4b39b74 100644 --- a/R/createCohorts.R +++ b/R/createCohorts.R @@ -59,36 +59,4 @@ createCohorts <- function(connectionDetails, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTableNames$cohortTable) return(cohortsGenerated) -} - -#' Instantiate cohorts against an omop cdm instance -#' -#' @param connectionDetails connection details generated using DatabaseConnector::createConnectionDetails() -#' @param cohortTable Name of the table to be created where cohorts will be stored -#' @param type Which cohorts to create -#' @param cdmDatabaseSchema name of the schema where the cdm is stored -#' @param cohortDatabaseSchema name of a schema with write access for the creation of cohort table -#' -#' @export -createCohortsCDM <- function(cdm, - cohortTable, - type = c("cohorts"), - cdmDatabaseSchema, - cohortDatabaseSchema){ - - alopecia_ehden <- CDMConnector::readCohortSet(system.file("cohorts", package = "EhdenAlopecia")) - - cdm <- CDMConnector::generateCohortSet(cdm, - alopecia_ehden, - name = "alopecia_ehden", - computeAttrition = TRUE, - overwrite = TRUE) - - - - # Get the cohort counts - cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTable = cohortTableNames$cohortTable) - return(cohortsGenerated) } \ No newline at end of file diff --git a/R/globals.R b/R/globals.R new file mode 100644 index 0000000..1805b4b --- /dev/null +++ b/R/globals.R @@ -0,0 +1,16 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +utils::globalVariables(c('sessionInfo', + 'cohortSubjects', + 'cohortId', + 'cohortName', + 'cohortId')) \ No newline at end of file diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index a948b87..dcecdac 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -1,12 +1,12 @@ #' Run the treatment patterns analysis -#' -#' @param connection An database connection created using DatabaseConnector::connect -#' @param cdmDatabaseSchema the schema where the cdm is located -#' @param cohortDatabaseSchema A writable location on the database. +#' +#' @param connectionDetails DatabaseConnector connection details. +#' @param cdmDatabaseSchema the schema where the cdm is located. +#' @param cohortDatabaseSchema A writable location on the database. +#' @param cohortTable Name of the main cohort table in characters. #' @param cohortsGenerated A table contianing the output of the createCohorts function, detailing the cohorts that have been instatiated #' @param outputFolder The output directory where the results should be saved #' @param tablePrefix table prefix -#' @param outcomeTableName outcome cohort table name #' @param logger logger object #' @param cohortIds the cohortIds to be used form the cohort table #' @param minCellCount minimum cell count diff --git a/extras/codeToRun.R b/inst/extras/CodeToRun.R similarity index 100% rename from extras/codeToRun.R rename to inst/extras/CodeToRun.R diff --git a/tests/testthat/ExecuteUnitTests.R b/inst/extras/ExecuteUnitTests.R similarity index 100% rename from tests/testthat/ExecuteUnitTests.R rename to inst/extras/ExecuteUnitTests.R diff --git a/badgesMarkdownCode.md b/inst/extras/badgesMarkdownCode.md similarity index 100% rename from badgesMarkdownCode.md rename to inst/extras/badgesMarkdownCode.md diff --git a/tests/testthat/createUnitTestData.R b/inst/extras/createUnitTestData.R similarity index 100% rename from tests/testthat/createUnitTestData.R rename to inst/extras/createUnitTestData.R diff --git a/extras/launchShiny.R b/inst/extras/launchShiny.R similarity index 100% rename from extras/launchShiny.R rename to inst/extras/launchShiny.R diff --git a/extras/package-maintenance.R b/inst/extras/package-maintenance.R similarity index 100% rename from extras/package-maintenance.R rename to inst/extras/package-maintenance.R diff --git a/man/createCohortsCDM.Rd b/man/createCohortsCDM.Rd deleted file mode 100644 index 02ed714..0000000 --- a/man/createCohortsCDM.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/createCohorts.R -\name{createCohortsCDM} -\alias{createCohortsCDM} -\title{Instantiate cohorts against an omop cdm instance} -\usage{ -createCohortsCDM( - cdm, - cohortTable, - type = c("cohorts"), - cdmDatabaseSchema, - cohortDatabaseSchema -) -} -\arguments{ -\item{cohortTable}{Name of the table to be created where cohorts will be stored} - -\item{type}{Which cohorts to create} - -\item{cdmDatabaseSchema}{name of the schema where the cdm is stored} - -\item{cohortDatabaseSchema}{name of a schema with write access for the creation of cohort table} - -\item{connectionDetails}{connection details generated using DatabaseConnector::createConnectionDetails()} -} -\description{ -Instantiate cohorts against an omop cdm instance -} diff --git a/man/runTreatmentPatterns.Rd b/man/runTreatmentPatterns.Rd index 42e7ce6..4df349f 100644 --- a/man/runTreatmentPatterns.Rd +++ b/man/runTreatmentPatterns.Rd @@ -18,10 +18,14 @@ runTreatmentPatterns( ) } \arguments{ -\item{cdmDatabaseSchema}{the schema where the cdm is located} +\item{connectionDetails}{DatabaseConnector connection details.} + +\item{cdmDatabaseSchema}{the schema where the cdm is located.} \item{cohortDatabaseSchema}{A writable location on the database.} +\item{cohortTable}{Name of the main cohort table in characters.} + \item{cohortsGenerated}{A table contianing the output of the createCohorts function, detailing the cohorts that have been instatiated} \item{outputFolder}{The output directory where the results should be saved} @@ -33,10 +37,6 @@ runTreatmentPatterns( \item{cohortIds}{the cohortIds to be used form the cohort table} \item{minCellCount}{minimum cell count} - -\item{connection}{An database connection created using DatabaseConnector::connect} - -\item{outcomeTableName}{outcome cohort table name} } \value{ the drug utilisation results From cec5be35e171b8a09649286913dbbd3486d616d6 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 11:57:55 +0100 Subject: [PATCH 18/41] code to run here --- inst/extras/CodeToRun.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/extras/CodeToRun.R b/inst/extras/CodeToRun.R index f9f983a..c2c6234 100644 --- a/inst/extras/CodeToRun.R +++ b/inst/extras/CodeToRun.R @@ -35,6 +35,7 @@ #Load the library library(EhdenAlopecia) +library(here) # database metadata and connection details ----- # The name/ acronym for the database @@ -75,7 +76,7 @@ cohortTable <- "alopecia_ehden" minCellCount <- 5 #specify where to save the results -outputFolder <- "results" +outputFolder <- here::here("results") #choose analysis to run From 5154824aed7ce29a669b49bf2f2dba722c4e312e Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 12:02:24 +0100 Subject: [PATCH 19/41] gha badge rmd --- .Rbuildignore | 2 + .github/.gitignore | 1 + .github/workflows/R-CMD-check.yaml | 49 +++++++++++ README.Rmd | 135 +++++++++++++++++++++++++++++ README.md | 43 +++++---- 5 files changed, 215 insertions(+), 15 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 README.Rmd diff --git a/.Rbuildignore b/.Rbuildignore index f81b04f..9affaf0 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,5 @@ ^errorReportSql\.txt$ ^badgesMarkdownCode\.md$ ^LICENSE\.md$ +^\.github$ +^README\.Rmd$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..599d78d --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main] + pull_request: + branches: [main] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..348ad5d --- /dev/null +++ b/README.Rmd @@ -0,0 +1,135 @@ +--- +output: github_document +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%", + eval = FALSE +) +``` + +# EHDEN Alopecia + + +[![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg) + + +Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon + +Study Status: Started + +- Analytics use case(s): Population-Level Estimation +- Study type: Clinical Application +- Tags: - +- Study lead: +- Study lead forums tag: +- Study start date: 1 November 2023 +- Study end date: - +- Protocol: To be added +- Publications: - +- Results explorer: - + +# Requirements + + +A database in Common Data Model version 5 in one of these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. +R version 4.0.5 +On Windows: RTools +Java +100 GB of free disk space + +# How to run +See the instructions at https://ohdsi.github.io/Hades/rSetup.html for configuring your R environment, including Java and RStudio. + +Clone the EhdenAlopecia package into your local R environment. + +Open your study package in RStudio. Use the following code to install all the dependencies: +```R +install.packages(c("DBI", + "dplyr", + "glue", + "zip", + "magrittr", + "checkmate", + "log4r", + "lubridate", + "rlang", + "readr") +) +``` + +In RStudio, select 'Build' then 'Install and Restart' to install the package. + +After succesfully installing the package. Open the extras/codeTorun.R and run the following code + +```R +#Load the library + +library(EhdenAlopecia) +# database metadata and connection details ----- +# The name/ acronym for the database +databaseId <- "" + +# Database connection details ----- +#connection details +#User specified input + + +# Details for connecting to the server: +dbms <- "" +user <- "" +pw <- "" +server <- "" +port <- "" + +connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, + server = server, + user = user, + password = pw, + port = port) + + +cdmDatabaseSchema <- "" +cohortDatabaseSchema <- "" + + +# Name of table prefix to use in the result schema for tables created during the study. +# Notes: +# - if there is an existing table in your results schema with the same names it +# will be overwritten +# - name must be lower case +cohortTable <- "alopecia_ehden" + + +# minimum counts that can be displayed according to data governance +minCellCount <- 5 + +#specify where to save the results +outputFolder <- "results" + + +#choose analysis to run +instantiateCohorts <- TRUE +runDiagnostics <- TRUE + + +### Do not edit below here + +EhdenAlopecia::runStudy( + connectionDetails = connectionDetails, + cohortTable = cohortTable, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema, + instantiateCohorts = instantiateCohorts, + runDiagnostics = runDiagnostics, + outputFolder = outputFolder, + databaseId = databaseId, + minCellCount = minCellCount +) +``` diff --git a/README.md b/README.md index 1e7d970..d533af9 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,23 @@ + + + # EHDEN Alopecia -Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon + + +\[![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg) + + +Analytic software to perform large-scale distributed analysis of +patients with Alopecia as part of the EHDEN study-athon Study Status: Started - Analytics use case(s): Population-Level Estimation - Study type: Clinical Application - Tags: - -- Study lead: -- Study lead forums tag: +- Study lead: +- Study lead forums tag: - Study start date: 1 November 2023 - Study end date: - - Protocol: To be added @@ -17,20 +26,22 @@ Analytic software to perform large-scale distributed analysis of patients with A # Requirements - -A database in Common Data Model version 5 in one of these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. -R version 4.0.5 -On Windows: RTools -Java -100 GB of free disk space +A database in Common Data Model version 5 in one of these platforms: SQL +Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, +Google BigQuery, or Microsoft APS. R version 4.0.5 On Windows: RTools +Java 100 GB of free disk space # How to run -See the instructions at https://ohdsi.github.io/Hades/rSetup.html for configuring your R environment, including Java and RStudio. + +See the instructions at for +configuring your R environment, including Java and RStudio. Clone the EhdenAlopecia package into your local R environment. -Open your study package in RStudio. Use the following code to install all the dependencies: -```R +Open your study package in RStudio. Use the following code to install +all the dependencies: + +``` r install.packages(c("DBI", "dplyr", "glue", @@ -44,11 +55,13 @@ install.packages(c("DBI", ) ``` -In RStudio, select 'Build' then 'Install and Restart' to install the package. +In RStudio, select ‘Build’ then ‘Install and Restart’ to install the +package. -After succesfully installing the package. Open the extras/codeTorun.R and run the following code +After succesfully installing the package. Open the extras/codeTorun.R +and run the following code -```R +``` r #Load the library library(EhdenAlopecia) From 449392c0405738a181e7255da23e76b78044a233 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 12:04:48 +0100 Subject: [PATCH 20/41] check develop --- .github/workflows/R-CMD-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 599d78d..745ba16 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -2,9 +2,9 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: [main] + branches: [main, develop] pull_request: - branches: [main] + branches: [main, develop] name: R-CMD-check From d424dbb2fd413e6fd9db6c1d891070aa1a39c593 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 12:14:09 +0100 Subject: [PATCH 21/41] remotes added cr, cg and cd --- DESCRIPTION | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6baa14b..f102c95 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,10 +13,7 @@ Imports: dplyr, magrittr, readr, - CirceR, here, - CohortDiagnostics, - CohortGenerator, TreatmentPatterns, Suggests: testthat (>= 3.0.0), @@ -31,4 +28,8 @@ Suggests: lubridate, rlang, jsonlite +Remotes: + ohdsi/CohortDiagnostics, + ohdsi/CirceR, + ohdsi/CohortGenerator Config/testthat/edition: 3 From f42979bbd0f4144e48a02fe45071c90c00243632 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 12:56:54 +0100 Subject: [PATCH 22/41] description remotes correction --- DESCRIPTION | 3 +++ R/runStudy.R | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f102c95..6a3374b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,6 +15,9 @@ Imports: readr, here, TreatmentPatterns, + CohortDiagnostics, + CirceR, + CohortGenerator Suggests: testthat (>= 3.0.0), rmarkdown, diff --git a/R/runStudy.R b/R/runStudy.R index c3629bc..e5f6fdb 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -70,7 +70,7 @@ runStudy <- function(connectionDetails, targetCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% filter(cohortId <= 100) treatmentCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% - filter(cohortId > 100) + filter(between(cohortId, 100, 114)) for (i in seq(1:length(targetCohorts$cohortId))) { outputSubDir <- file.path(outputFolder, 'treatmentPatterns', targetCohorts[i,]$cohortId) if (!dir.exists(outputSubDir)) { From ee503ac6732ce821efda15317f75e6d9010f0d79 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 13:09:25 +0100 Subject: [PATCH 23/41] fixing badge --- README.Rmd | 4 ++-- README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.Rmd b/README.Rmd index 348ad5d..f772074 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,10 +17,10 @@ knitr::opts_chunk$set( # EHDEN Alopecia -[![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg) +[![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml) -Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon +Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon. Study Status: Started diff --git a/README.md b/README.md index d533af9..dfafa98 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ -\[![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg) +[![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml) Analytic software to perform large-scale distributed analysis of -patients with Alopecia as part of the EHDEN study-athon +patients with Alopecia as part of the EHDEN study-athon. Study Status: Started From 84b1760cd9bd002e171658213b9d1a3d6712ad20 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 13:11:48 +0100 Subject: [PATCH 24/41] cohort --- README.Rmd | 3 +-- README.md | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.Rmd b/README.Rmd index f772074..3d36e9f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -18,12 +18,11 @@ knitr::opts_chunk$set( [![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml) +Study Status: Started Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon. -Study Status: Started - - Analytics use case(s): Population-Level Estimation - Study type: Clinical Application - Tags: - diff --git a/README.md b/README.md index dfafa98..dc1bae2 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,12 @@ [![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml) +Study Status: Started Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon. -Study Status: Started - - Analytics use case(s): Population-Level Estimation - Study type: Clinical Application - Tags: - From f90f42ff2e2ee9ada7076d49f33819fb6fd42087 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 13:37:16 +0100 Subject: [PATCH 25/41] fix outputSubDir --- R/runStudy.R | 2 +- R/runTreatmentPatterns.R | 8 ++++---- inst/extras/CodeToRun.R | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/R/runStudy.R b/R/runStudy.R index e5f6fdb..c74ee43 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -85,7 +85,7 @@ runStudy <- function(connectionDetails, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, cohortsGenerated = cohortsGenerated, - outputFolder = outputSubDir, + outputSubDir = outputSubDir, cohortIds = cohortIds, minCellCount = minCellCount) diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index dcecdac..580dc2c 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -5,7 +5,7 @@ #' @param cohortDatabaseSchema A writable location on the database. #' @param cohortTable Name of the main cohort table in characters. #' @param cohortsGenerated A table contianing the output of the createCohorts function, detailing the cohorts that have been instatiated -#' @param outputFolder The output directory where the results should be saved +#' @param outputSubDir The output directory where the results should be saved #' @param tablePrefix table prefix #' @param logger logger object #' @param cohortIds the cohortIds to be used form the cohort table @@ -21,7 +21,7 @@ runTreatmentPatterns <- function(connectionDetails, cohortDatabaseSchema, cohortTable, cohortsGenerated, - outputFolder, + outputSubDir, tablePrefix = NULL, logger = NULL, cohortIds, @@ -46,7 +46,7 @@ runTreatmentPatterns <- function(connectionDetails, pathways <- TreatmentPatterns::executeTreatmentPatterns( cohorts = cohorts, cohortTableName = cohortTable, - outputPath = outputFolder, + outputPath = outputSubDir, connectionDetails = connectionDetails, cdmSchema = cdmDatabaseSchema, resultSchema = cohortDatabaseSchema, @@ -67,7 +67,7 @@ runTreatmentPatterns <- function(connectionDetails, #export results TreatmentPatterns::export( andromeda = pathways, - outputPath = here::here(outputFolder), + outputPath = outputSubDir, ageWindow = c(2,6,11,17,65,150), minFreq = minCellCount, archiveName = NULL diff --git a/inst/extras/CodeToRun.R b/inst/extras/CodeToRun.R index c2c6234..56dc177 100644 --- a/inst/extras/CodeToRun.R +++ b/inst/extras/CodeToRun.R @@ -82,7 +82,6 @@ outputFolder <- here::here("results") #choose analysis to run instantiateCohorts <- TRUE runDiagnostics <- FALSE -instantiateTreatmentCohorts <- FALSE runPatternAnalysis <- TRUE ### Do not edit below here From 7bc1a948b78d6050f98ad871d1a30bf5f1c6f9b7 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 13:42:47 +0100 Subject: [PATCH 26/41] execute Treatment not segmented --- R/runTreatmentPatterns.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index 580dc2c..6fb8884 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -43,7 +43,7 @@ runTreatmentPatterns <- function(connectionDetails, ) # Compute pathways - pathways <- TreatmentPatterns::executeTreatmentPatterns( + TreatmentPatterns::executeTreatmentPatterns( cohorts = cohorts, cohortTableName = cohortTable, outputPath = outputSubDir, @@ -65,11 +65,11 @@ runTreatmentPatterns <- function(connectionDetails, addNoPaths = TRUE ) #export results - TreatmentPatterns::export( - andromeda = pathways, - outputPath = outputSubDir, - ageWindow = c(2,6,11,17,65,150), - minFreq = minCellCount, - archiveName = NULL - ) + # TreatmentPatterns::export( + # andromeda = pathways, + # outputPath = outputSubDir, + # ageWindow = c(2,6,11,17,65,150), + # minFreq = minCellCount, + # archiveName = NULL + # ) } From 853223a8d9a81517675dc2d08478dbb95f1d9ff2 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 15:38:42 +0100 Subject: [PATCH 27/41] suggested here fix --- DESCRIPTION | 4 ++-- R/runTreatmentPatterns.R | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6a3374b..6e91764 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,13 +13,13 @@ Imports: dplyr, magrittr, readr, - here, TreatmentPatterns, CohortDiagnostics, CirceR, CohortGenerator Suggests: - testthat (>= 3.0.0), + testthat (>= 3.0.0 + here, rmarkdown, checkmate, SqlRender, diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R index 6fb8884..0589752 100644 --- a/R/runTreatmentPatterns.R +++ b/R/runTreatmentPatterns.R @@ -64,12 +64,4 @@ runTreatmentPatterns <- function(connectionDetails, minFreq = minCellCount, addNoPaths = TRUE ) - #export results - # TreatmentPatterns::export( - # andromeda = pathways, - # outputPath = outputSubDir, - # ageWindow = c(2,6,11,17,65,150), - # minFreq = minCellCount, - # archiveName = NULL - # ) } From 65ce596a4aa5a26e92877631243dc27b3a7c6f43 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 15:43:30 +0100 Subject: [PATCH 28/41] Description fix treatpatt version and testthat parenth --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6e91764..149f21f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,12 +13,12 @@ Imports: dplyr, magrittr, readr, - TreatmentPatterns, + TreatmentPatterns (>= 2.6.0), CohortDiagnostics, CirceR, CohortGenerator Suggests: - testthat (>= 3.0.0 + testthat (>= 3.0.0) here, rmarkdown, checkmate, From 6d5a1b6d2f9e0dfc37b772753295cf952c4520b3 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 15:50:47 +0100 Subject: [PATCH 29/41] version spec testthat --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 149f21f..76e296c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ Imports: CirceR, CohortGenerator Suggests: - testthat (>= 3.0.0) + testthat (>= 3.0.0), here, rmarkdown, checkmate, From 527c3942ac65e0cb795d65784ff37e638efdbe3a Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 15:55:13 +0100 Subject: [PATCH 30/41] same page outputFolder --- man/runTreatmentPatterns.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/runTreatmentPatterns.Rd b/man/runTreatmentPatterns.Rd index 4df349f..adb77eb 100644 --- a/man/runTreatmentPatterns.Rd +++ b/man/runTreatmentPatterns.Rd @@ -10,7 +10,7 @@ runTreatmentPatterns( cohortDatabaseSchema, cohortTable, cohortsGenerated, - outputFolder, + outputSubDir, tablePrefix = NULL, logger = NULL, cohortIds, @@ -28,7 +28,7 @@ runTreatmentPatterns( \item{cohortsGenerated}{A table contianing the output of the createCohorts function, detailing the cohorts that have been instatiated} -\item{outputFolder}{The output directory where the results should be saved} +\item{outputSubDir}{The output directory where the results should be saved} \item{tablePrefix}{table prefix} From 93e48fce3d8764be2e009b74dc097d13693503e6 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 16:04:31 +0100 Subject: [PATCH 31/41] only ubuntu release --- .github/workflows/R-CMD-check.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 745ba16..dcceb0b 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -20,10 +20,7 @@ jobs: config: - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} - - {os: ubuntu-latest, r: 'oldrel-1'} - env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes From 901ed3b0c9a05f37308dac4db189e0149abd8fbe Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 16:15:48 +0100 Subject: [PATCH 32/41] old release github --- .github/workflows/R-CMD-check.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index dcceb0b..f53156d 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -21,6 +21,8 @@ jobs: - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes From f72fa33d6e7e34016edb826af0a236963444c23b Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 16:28:14 +0100 Subject: [PATCH 33/41] update readme --- .github/workflows/R-CMD-check.yaml | 1 - README.Rmd | 37 ++++++++++++++------------- README.md | 40 ++++++++++++++++-------------- inst/extras/CodeToRun.R | 6 ++--- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index f53156d..1f04c8c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -21,7 +21,6 @@ jobs: - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'release'} - - {os: ubuntu-latest, r: 'oldrel-1'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.Rmd b/README.Rmd index 3d36e9f..278ee10 100644 --- a/README.Rmd +++ b/README.Rmd @@ -44,11 +44,11 @@ Java 100 GB of free disk space # How to run -See the instructions at https://ohdsi.github.io/Hades/rSetup.html for configuring your R environment, including Java and RStudio. +1. See the instructions at https://ohdsi.github.io/Hades/rSetup.html for configuring your R environment, including Java and RStudio. -Clone the EhdenAlopecia package into your local R environment. +2. Clone the EhdenAlopecia package into your local R environment. -Open your study package in RStudio. Use the following code to install all the dependencies: +3. Open your study package in RStudio. Use the following code to install all the dependencies: ```R install.packages(c("DBI", "dplyr", @@ -71,31 +71,33 @@ After succesfully installing the package. Open the extras/codeTorun.R and run th #Load the library library(EhdenAlopecia) +library(here) + # database metadata and connection details ----- # The name/ acronym for the database -databaseId <- "" +databaseId <- "..." # Database connection details ----- #connection details #User specified input - # Details for connecting to the server: -dbms <- "" -user <- "" -pw <- "" -server <- "" -port <- "" +dbms <- Sys.getenv("dbms") +user <- Sys.getenv("user") +password <- Sys.getenv("password") +server <- Sys.getenv("host") +port <- Sys.getenv +connectionString <- Sys.getenv("connectionString") connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, - server = server, + connectionString = connectionString, user = user, - password = pw, + password = password, port = port) -cdmDatabaseSchema <- "" -cohortDatabaseSchema <- "" +cdmDatabaseSchema <- "..." +cohortDatabaseSchema <- "..." # Name of table prefix to use in the result schema for tables created during the study. @@ -110,16 +112,15 @@ cohortTable <- "alopecia_ehden" minCellCount <- 5 #specify where to save the results -outputFolder <- "results" +outputFolder <- here::here("results") #choose analysis to run instantiateCohorts <- TRUE runDiagnostics <- TRUE - +runPatternAnalysis <- TRUE ### Do not edit below here - EhdenAlopecia::runStudy( connectionDetails = connectionDetails, cohortTable = cohortTable, @@ -127,8 +128,10 @@ EhdenAlopecia::runStudy( cohortDatabaseSchema = cohortDatabaseSchema, instantiateCohorts = instantiateCohorts, runDiagnostics = runDiagnostics, + runPatternAnalysis = runPatternAnalysis, outputFolder = outputFolder, databaseId = databaseId, minCellCount = minCellCount ) + ``` diff --git a/README.md b/README.md index dc1bae2..2748d13 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,13 @@ Java 100 GB of free disk space # How to run -See the instructions at for -configuring your R environment, including Java and RStudio. +1. See the instructions at + for configuring your R environment, including Java and RStudio. -Clone the EhdenAlopecia package into your local R environment. +2. Clone the EhdenAlopecia package into your local R environment. -Open your study package in RStudio. Use the following code to install -all the dependencies: +3. Open your study package in RStudio. Use the following code to + install all the dependencies: ``` r install.packages(c("DBI", @@ -64,31 +64,33 @@ and run the following code #Load the library library(EhdenAlopecia) +library(here) + # database metadata and connection details ----- # The name/ acronym for the database -databaseId <- "" +databaseId <- "..." # Database connection details ----- #connection details #User specified input - # Details for connecting to the server: -dbms <- "" -user <- "" -pw <- "" -server <- "" -port <- "" +dbms <- Sys.getenv("dbms") +user <- Sys.getenv("user") +password <- Sys.getenv("password") +server <- Sys.getenv("host") +port <- Sys.getenv +connectionString <- Sys.getenv("connectionString") connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, - server = server, + connectionString = connectionString, user = user, - password = pw, + password = password, port = port) -cdmDatabaseSchema <- "" -cohortDatabaseSchema <- "" +cdmDatabaseSchema <- "..." +cohortDatabaseSchema <- "..." # Name of table prefix to use in the result schema for tables created during the study. @@ -103,16 +105,15 @@ cohortTable <- "alopecia_ehden" minCellCount <- 5 #specify where to save the results -outputFolder <- "results" +outputFolder <- here::here("results") #choose analysis to run instantiateCohorts <- TRUE runDiagnostics <- TRUE - +runPatternAnalysis <- TRUE ### Do not edit below here - EhdenAlopecia::runStudy( connectionDetails = connectionDetails, cohortTable = cohortTable, @@ -120,6 +121,7 @@ EhdenAlopecia::runStudy( cohortDatabaseSchema = cohortDatabaseSchema, instantiateCohorts = instantiateCohorts, runDiagnostics = runDiagnostics, + runPatternAnalysis = runPatternAnalysis, outputFolder = outputFolder, databaseId = databaseId, minCellCount = minCellCount diff --git a/inst/extras/CodeToRun.R b/inst/extras/CodeToRun.R index 56dc177..edec970 100644 --- a/inst/extras/CodeToRun.R +++ b/inst/extras/CodeToRun.R @@ -39,7 +39,7 @@ library(here) # database metadata and connection details ----- # The name/ acronym for the database -databaseId <- "IPCI" +databaseId <- "..." # Database connection details ----- #connection details @@ -60,8 +60,8 @@ connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, port = port) -cdmDatabaseSchema <- "cdm" -cohortDatabaseSchema <- "cbarboza" +cdmDatabaseSchema <- "..." +cohortDatabaseSchema <- "..." # Name of table prefix to use in the result schema for tables created during the study. From 438afeb4dba6c5a86e70853c1917d9b2377e92dc Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 16:37:15 +0100 Subject: [PATCH 34/41] last update readme --- README.Rmd | 44 +++++++++++++++++++++++++++++++------------- README.md | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/README.Rmd b/README.Rmd index 278ee10..198383e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -36,7 +36,6 @@ Analytic software to perform large-scale distributed analysis of patients with A # Requirements - A database in Common Data Model version 5 in one of these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. R version 4.0.5 On Windows: RTools @@ -44,28 +43,47 @@ Java 100 GB of free disk space # How to run + 1. See the instructions at https://ohdsi.github.io/Hades/rSetup.html for configuring your R environment, including Java and RStudio. 2. Clone the EhdenAlopecia package into your local R environment. 3. Open your study package in RStudio. Use the following code to install all the dependencies: + ```R -install.packages(c("DBI", - "dplyr", - "glue", - "zip", - "magrittr", - "checkmate", - "log4r", - "lubridate", - "rlang", - "readr") -) + +install.packages(c("TreatmentPatterns", + "DBI", + "dplyr", + "glue", + "zip", + "magrittr", + "checkmate", + "lubridate", + "rlang", + "readr", + "here", + "rmarkdown", + "checkmate", + "SqlRender", + "duckdb", + "ParallelLogger", + "DBI", + "glue", + "zip", + "lubridate", + "rlang", + "jsonlite")) + +remotes::install_github(c("ohdsi/CirceR", + "ohdsi/CohortGenerator", + "ohdsi/CohortDiagnostics")) + ``` In RStudio, select 'Build' then 'Install and Restart' to install the package. -After succesfully installing the package. Open the extras/codeTorun.R and run the following code +After succesfully installing the package. Open the extras/CodeTorun.R and run the following code: ```R #Load the library diff --git a/README.md b/README.md index 2748d13..d387072 100644 --- a/README.md +++ b/README.md @@ -41,24 +41,41 @@ Java 100 GB of free disk space install all the dependencies: ``` r -install.packages(c("DBI", - "dplyr", - "glue", - "zip", - "magrittr", - "checkmate", - "log4r", - "lubridate", - "rlang", - "readr") -) + +install.packages(c("TreatmentPatterns", + "DBI", + "dplyr", + "glue", + "zip", + "magrittr", + "checkmate", + "lubridate", + "rlang", + "readr", + "here", + "rmarkdown", + "checkmate", + "SqlRender", + "duckdb", + "ParallelLogger", + "DBI", + "glue", + "zip", + "lubridate", + "rlang", + "jsonlite")) + +remotes::install_github(c("ohdsi/CirceR", + "ohdsi/CohortGenerator", + "ohdsi/CohortDiagnostics")) + ``` In RStudio, select ‘Build’ then ‘Install and Restart’ to install the package. -After succesfully installing the package. Open the extras/codeTorun.R -and run the following code +After succesfully installing the package. Open the extras/CodeTorun.R +and run the following code: ``` r #Load the library From 27b5eef7f5e49ee2e6eaf8b11dd5b05c57d5d417 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 16:38:46 +0100 Subject: [PATCH 35/41] commit readme --- README.Rmd | 2 +- README.knit.md | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 README.knit.md diff --git a/README.Rmd b/README.Rmd index 198383e..6e4eb4a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -104,7 +104,7 @@ dbms <- Sys.getenv("dbms") user <- Sys.getenv("user") password <- Sys.getenv("password") server <- Sys.getenv("host") -port <- Sys.getenv +port <- Sys.getenv("port") connectionString <- Sys.getenv("connectionString") connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, diff --git a/README.knit.md b/README.knit.md new file mode 100644 index 0000000..5121ffb --- /dev/null +++ b/README.knit.md @@ -0,0 +1,147 @@ +--- +output: github_document +--- + + + + + +# EHDEN Alopecia + + +[![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml) +Study Status: Started + + +Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon. + +- Analytics use case(s): Population-Level Estimation +- Study type: Clinical Application +- Tags: - +- Study lead: +- Study lead forums tag: +- Study start date: 1 November 2023 +- Study end date: - +- Protocol: To be added +- Publications: - +- Results explorer: - + +# Requirements + +A database in Common Data Model version 5 in one of these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. +R version 4.0.5 +On Windows: RTools +Java +100 GB of free disk space + +# How to run + +1. See the instructions at https://ohdsi.github.io/Hades/rSetup.html for configuring your R environment, including Java and RStudio. + +2. Clone the EhdenAlopecia package into your local R environment. + +3. Open your study package in RStudio. Use the following code to install all the dependencies: + +```R + +install.packages(c("TreatmentPatterns", + "DBI", + "dplyr", + "glue", + "zip", + "magrittr", + "checkmate", + "lubridate", + "rlang", + "readr", + "here", + "rmarkdown", + "checkmate", + "SqlRender", + "duckdb", + "ParallelLogger", + "DBI", + "glue", + "zip", + "lubridate", + "rlang", + "jsonlite")) + +remotes::install_github(c("ohdsi/CirceR", + "ohdsi/CohortGenerator", + "ohdsi/CohortDiagnostics")) + +``` + +In RStudio, select 'Build' then 'Install and Restart' to install the package. + +After succesfully installing the package. Open the extras/CodeTorun.R and run the following code: + +```R +#Load the library + +library(EhdenAlopecia) +library(here) + +# database metadata and connection details ----- +# The name/ acronym for the database +databaseId <- "..." + +# Database connection details ----- +#connection details +#User specified input + +# Details for connecting to the server: +dbms <- Sys.getenv("dbms") +user <- Sys.getenv("user") +password <- Sys.getenv("password") +server <- Sys.getenv("host") +port <- Sys.getenv("port") +connectionString <- Sys.getenv("connectionString") + +connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, + connectionString = connectionString, + user = user, + password = password, + port = port) + + +cdmDatabaseSchema <- "..." +cohortDatabaseSchema <- "..." + + +# Name of table prefix to use in the result schema for tables created during the study. +# Notes: +# - if there is an existing table in your results schema with the same names it +# will be overwritten +# - name must be lower case +cohortTable <- "alopecia_ehden" + + +# minimum counts that can be displayed according to data governance +minCellCount <- 5 + +#specify where to save the results +outputFolder <- here::here("results") + + +#choose analysis to run +instantiateCohorts <- TRUE +runDiagnostics <- TRUE +runPatternAnalysis <- TRUE + +### Do not edit below here +EhdenAlopecia::runStudy( + connectionDetails = connectionDetails, + cohortTable = cohortTable, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema, + instantiateCohorts = instantiateCohorts, + runDiagnostics = runDiagnostics, + runPatternAnalysis = runPatternAnalysis, + outputFolder = outputFolder, + databaseId = databaseId, + minCellCount = minCellCount +) + +``` diff --git a/README.md b/README.md index d387072..6c928aa 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ dbms <- Sys.getenv("dbms") user <- Sys.getenv("user") password <- Sys.getenv("password") server <- Sys.getenv("host") -port <- Sys.getenv +port <- Sys.getenv("port") connectionString <- Sys.getenv("connectionString") connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, From 6d796b684f8892e0eb723ab736dc7d3c1e4cb13b Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 16:39:06 +0100 Subject: [PATCH 36/41] delete old readme md --- README.knit.md | 147 ------------------------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 README.knit.md diff --git a/README.knit.md b/README.knit.md deleted file mode 100644 index 5121ffb..0000000 --- a/README.knit.md +++ /dev/null @@ -1,147 +0,0 @@ ---- -output: github_document ---- - - - - - -# EHDEN Alopecia - - -[![R-CMD-check](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ohdsi-studies/EhdenAlopecia/actions/workflows/R-CMD-check.yaml) -Study Status: Started - - -Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon. - -- Analytics use case(s): Population-Level Estimation -- Study type: Clinical Application -- Tags: - -- Study lead: -- Study lead forums tag: -- Study start date: 1 November 2023 -- Study end date: - -- Protocol: To be added -- Publications: - -- Results explorer: - - -# Requirements - -A database in Common Data Model version 5 in one of these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. -R version 4.0.5 -On Windows: RTools -Java -100 GB of free disk space - -# How to run - -1. See the instructions at https://ohdsi.github.io/Hades/rSetup.html for configuring your R environment, including Java and RStudio. - -2. Clone the EhdenAlopecia package into your local R environment. - -3. Open your study package in RStudio. Use the following code to install all the dependencies: - -```R - -install.packages(c("TreatmentPatterns", - "DBI", - "dplyr", - "glue", - "zip", - "magrittr", - "checkmate", - "lubridate", - "rlang", - "readr", - "here", - "rmarkdown", - "checkmate", - "SqlRender", - "duckdb", - "ParallelLogger", - "DBI", - "glue", - "zip", - "lubridate", - "rlang", - "jsonlite")) - -remotes::install_github(c("ohdsi/CirceR", - "ohdsi/CohortGenerator", - "ohdsi/CohortDiagnostics")) - -``` - -In RStudio, select 'Build' then 'Install and Restart' to install the package. - -After succesfully installing the package. Open the extras/CodeTorun.R and run the following code: - -```R -#Load the library - -library(EhdenAlopecia) -library(here) - -# database metadata and connection details ----- -# The name/ acronym for the database -databaseId <- "..." - -# Database connection details ----- -#connection details -#User specified input - -# Details for connecting to the server: -dbms <- Sys.getenv("dbms") -user <- Sys.getenv("user") -password <- Sys.getenv("password") -server <- Sys.getenv("host") -port <- Sys.getenv("port") -connectionString <- Sys.getenv("connectionString") - -connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms, - connectionString = connectionString, - user = user, - password = password, - port = port) - - -cdmDatabaseSchema <- "..." -cohortDatabaseSchema <- "..." - - -# Name of table prefix to use in the result schema for tables created during the study. -# Notes: -# - if there is an existing table in your results schema with the same names it -# will be overwritten -# - name must be lower case -cohortTable <- "alopecia_ehden" - - -# minimum counts that can be displayed according to data governance -minCellCount <- 5 - -#specify where to save the results -outputFolder <- here::here("results") - - -#choose analysis to run -instantiateCohorts <- TRUE -runDiagnostics <- TRUE -runPatternAnalysis <- TRUE - -### Do not edit below here -EhdenAlopecia::runStudy( - connectionDetails = connectionDetails, - cohortTable = cohortTable, - cdmDatabaseSchema = cdmDatabaseSchema, - cohortDatabaseSchema = cohortDatabaseSchema, - instantiateCohorts = instantiateCohorts, - runDiagnostics = runDiagnostics, - runPatternAnalysis = runPatternAnalysis, - outputFolder = outputFolder, - databaseId = databaseId, - minCellCount = minCellCount -) - -``` From b3feed6e264ea073a7dc6c5bfe4e7dec84c42cee Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 16:41:19 +0100 Subject: [PATCH 37/41] event cohorts change --- R/runStudy.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/runStudy.R b/R/runStudy.R index c74ee43..2bb31df 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -69,7 +69,7 @@ runStudy <- function(connectionDetails, # Target and treatment cohorts sections targetCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% filter(cohortId <= 100) - treatmentCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% + eventCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% filter(between(cohortId, 100, 114)) for (i in seq(1:length(targetCohorts$cohortId))) { outputSubDir <- file.path(outputFolder, 'treatmentPatterns', targetCohorts[i,]$cohortId) @@ -78,7 +78,7 @@ runStudy <- function(connectionDetails, } # TreatmentPathways for each target cohort with treatments cohortsGenerated <- targetCohorts[i,] %>% - dplyr::bind_rows(treatmentCohorts) + dplyr::bind_rows(eventCohorts) cohortIds <- cohortsGenerated$cohortId runTreatmentPatterns(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, From 1471fce9153953d65be75aaa17d1f28e2ededde7 Mon Sep 17 00:00:00 2001 From: "Ross D. Williams" <34747165+rossdwilliams@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:34:59 +0100 Subject: [PATCH 38/41] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c928aa..1f3c408 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ patients with Alopecia as part of the EHDEN study-athon. # Requirements -A database in Common Data Model version 5 in one of these platforms: SQL +A database mapped to the OMOP Common Data Model version 5 in one of these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. R version 4.0.5 On Windows: RTools Java 100 GB of free disk space From 100787e3a52a5fb54af1c5b7669ca3a6f6597f53 Mon Sep 17 00:00:00 2001 From: "Ross D. Williams" <34747165+rossdwilliams@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:36:07 +0100 Subject: [PATCH 39/41] Update CodeToRun.R --- inst/extras/CodeToRun.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/extras/CodeToRun.R b/inst/extras/CodeToRun.R index edec970..1f4a079 100644 --- a/inst/extras/CodeToRun.R +++ b/inst/extras/CodeToRun.R @@ -80,9 +80,9 @@ outputFolder <- here::here("results") #choose analysis to run -instantiateCohorts <- TRUE +instantiateCohorts <- FALSE runDiagnostics <- FALSE -runPatternAnalysis <- TRUE +runPatternAnalysis <- FALSE ### Do not edit below here EhdenAlopecia::runStudy( From 1c77103516b862d9324f827c4c7d9d7137e531d6 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 17:42:51 +0100 Subject: [PATCH 40/41] codeToRun --- README.Rmd | 2 +- README.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.Rmd b/README.Rmd index 6e4eb4a..1d9321f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -83,7 +83,7 @@ remotes::install_github(c("ohdsi/CirceR", In RStudio, select 'Build' then 'Install and Restart' to install the package. -After succesfully installing the package. Open the extras/CodeTorun.R and run the following code: +After succesfully installing the package. Open the [inst/extras/CodeTorun.R](https://raw.githubusercontent.com/ohdsi-studies/EhdenAlopecia/main/inst/extras/CodeToRun.R) and run the following code: ```R #Load the library diff --git a/README.md b/README.md index 6c928aa..75bfdc2 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,8 @@ remotes::install_github(c("ohdsi/CirceR", In RStudio, select ‘Build’ then ‘Install and Restart’ to install the package. -After succesfully installing the package. Open the extras/CodeTorun.R +After succesfully installing the package. Open the +[inst/extras/CodeTorun.R](https://raw.githubusercontent.com/ohdsi-studies/EhdenAlopecia/main/inst/extras/CodeToRun.R) and run the following code: ``` r From 71033760cc5fcac6562851e70a4e6ce7ca675a6a Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Mon, 20 Nov 2023 17:46:53 +0100 Subject: [PATCH 41/41] readme update --- README.Rmd | 8 ++++---- README.md | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.Rmd b/README.Rmd index 1d9321f..d57adb5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -36,7 +36,7 @@ Analytic software to perform large-scale distributed analysis of patients with A # Requirements -A database in Common Data Model version 5 in one of these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. +A database mapped to the OMOP Common Data Model version 5 in one of these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. R version 4.0.5 On Windows: RTools Java @@ -134,9 +134,9 @@ outputFolder <- here::here("results") #choose analysis to run -instantiateCohorts <- TRUE -runDiagnostics <- TRUE -runPatternAnalysis <- TRUE +instantiateCohorts <- FALSE +runDiagnostics <- FALSE +runPatternAnalysis <- FALSE ### Do not edit below here EhdenAlopecia::runStudy( diff --git a/README.md b/README.md index 656fe22..891d3f4 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ patients with Alopecia as part of the EHDEN study-athon. # Requirements -A database mapped to the OMOP Common Data Model version 5 in one of these platforms: SQL -Server, Oracle, PostgreSQL, IBM Netezza, Apache Impala, Amazon RedShift, -Google BigQuery, or Microsoft APS. R version 4.0.5 On Windows: RTools -Java 100 GB of free disk space +A database mapped to the OMOP Common Data Model version 5 in one of +these platforms: SQL Server, Oracle, PostgreSQL, IBM Netezza, Apache +Impala, Amazon RedShift, Google BigQuery, or Microsoft APS. R version +4.0.5 On Windows: RTools Java 100 GB of free disk space # How to run @@ -127,9 +127,9 @@ outputFolder <- here::here("results") #choose analysis to run -instantiateCohorts <- TRUE -runDiagnostics <- TRUE -runPatternAnalysis <- TRUE +instantiateCohorts <- FALSE +runDiagnostics <- FALSE +runPatternAnalysis <- FALSE ### Do not edit below here EhdenAlopecia::runStudy(