diff --git a/.Rbuildignore b/.Rbuildignore
new file mode 100644
index 0000000..9affaf0
--- /dev/null
+++ b/.Rbuildignore
@@ -0,0 +1,12 @@
+^renv$
+^renv\.lock$
+^.*\.Rproj$
+^\.Rproj\.user$
+^CodeToRunSynthea\.R
+^CodeToRunIPCI\.R
+^results$
+^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..1f04c8c
--- /dev/null
+++ b/.github/workflows/R-CMD-check.yaml
@@ -0,0 +1,47 @@
+# 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, develop]
+ pull_request:
+ branches: [main, develop]
+
+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: 'release'}
+
+ 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/.gitignore b/.gitignore
new file mode 100644
index 0000000..8f3679d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+.Rproj.user
+.Rhistory
+.RData
+.Ruserdata
+
+errorReport*
+Results/*
+
+.DS_Store
+CodeToRunSynthea.R
+CodeToRunSnowflake.R
+CodeToRunIPCI.R
+errorReportSql.txt
\ No newline at end of file
diff --git a/DESCRIPTION b/DESCRIPTION
index 7d4b031..76e296c 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,4 +1,5 @@
-Package: EhdenAlopecia
+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,29 @@ RoxygenNote: 7.2.3
Depends:
R (>= 3.6.1)
Imports:
- DBI,
dplyr,
- glue,
- zip,
magrittr,
- checkmate,
- log4r,
- lubridate,
- rlang,
- readr
+ readr,
+ TreatmentPatterns (>= 2.6.0),
+ CohortDiagnostics,
+ CirceR,
+ CohortGenerator
Suggests:
testthat (>= 3.0.0),
+ here,
rmarkdown,
checkmate,
+ SqlRender,
duckdb,
+ ParallelLogger,
+ DBI,
+ glue,
+ zip,
+ lubridate,
+ rlang,
+ jsonlite
+Remotes:
+ ohdsi/CohortDiagnostics,
+ ohdsi/CirceR,
+ ohdsi/CohortGenerator
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 1dd48d8..ce85928 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -3,4 +3,16 @@
export("%>%")
export(createCohorts)
export(runStudy)
+export(runTreatmentPatterns)
+import(TreatmentPatterns)
+import(dplyr)
+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/createCohorts.R b/R/createCohorts.R
index 5d3a5d6..4b39b74 100644
--- a/R/createCohorts.R
+++ b/R/createCohorts.R
@@ -2,12 +2,18 @@
#'
#' @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
+#'
+#' @import dplyr
+#' @importFrom CirceR cohortExpressionFromJson buildCohortQuery
+#' @importFrom CohortGenerator getCohortTableNames createCohortTables generateCohortSet getCohortCounts
#'
#' @export
createCohorts <- function(connectionDetails,
- cohortTable,
+ cohortTable,
+ type = c("cohorts"),
cdmDatabaseSchema,
cohortDatabaseSchema){
@@ -17,21 +23,21 @@ 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))
- # 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))
}
@@ -39,8 +45,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,
@@ -52,6 +58,5 @@ createCohorts <- function(connectionDetails,
cohortCounts <- CohortGenerator::getCohortCounts(connectionDetails = connectionDetails,
cohortDatabaseSchema = cohortDatabaseSchema,
cohortTable = cohortTableNames$cohortTable)
- print(cohortCounts)
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/runStudy.R b/R/runStudy.R
index 310c539..2bb31df 100644
--- a/R/runStudy.R
+++ b/R/runStudy.R
@@ -6,10 +6,15 @@
#' @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
-#'
+#'
+#' @import dplyr
+#' @importFrom readr write_csv read_csv
+#' @importFrom CohortGenerator getCohortCounts
+#' @importFrom CohortDiagnostics executeDiagnostics
#' @export
runStudy <- function(connectionDetails,
@@ -18,27 +23,72 @@ runStudy <- function(connectionDetails,
cohortDatabaseSchema,
instantiateCohorts = FALSE,
runDiagnostics = FALSE,
+ runPatternAnalysis = FALSE,
outputFolder,
databaseId,
minCellCount) {
- if (instantiateCohorts){
- createCohorts(connectionDetails = connectionDetails,
- cohortTable = cohortTable,
- cdmDatabaseSchema = cdmDatabaseSchema,
- cohortDatabaseSchema = cohortDatabaseSchema)
+ # Create output folder
+ if (!dir.exists(outputFolder)) {
+ dir.create(outputFolder)
+ }
+
+ # Instantiate cohorts
+ 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"))
}
- if (runDiagnostics){
+ # CohortDiagnostics
+ 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
+ CohortDiagnostics::executeDiagnostics(cohortDefinitionSet = cohortDefinitionSet,
+ connectionDetails = connectionDetails,
+ cohortTable = cohortTable,
+ cohortDatabaseSchema = cohortDatabaseSchema,
+ cdmDatabaseSchema = cdmDatabaseSchema,
+ exportFolder = outputFolder,
+ databaseId = databaseId,
+ minCellCount = minCellCount
)
}
+
+ # TreatmentPatterns
+ if (runPatternAnalysis){
+ # Target and treatment cohorts sections
+ targetCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>%
+ filter(cohortId <= 100)
+ 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)
+ if (!dir.exists(outputSubDir)) {
+ dir.create(outputSubDir, recursive = TRUE)
+ }
+ # TreatmentPathways for each target cohort with treatments
+ cohortsGenerated <- targetCohorts[i,] %>%
+ dplyr::bind_rows(eventCohorts)
+ cohortIds <- cohortsGenerated$cohortId
+ runTreatmentPatterns(connectionDetails = connectionDetails,
+ cdmDatabaseSchema = cdmDatabaseSchema,
+ cohortDatabaseSchema = cohortDatabaseSchema,
+ cohortTable = cohortTable,
+ cohortsGenerated = cohortsGenerated,
+ outputSubDir = outputSubDir,
+ cohortIds = cohortIds,
+ minCellCount = minCellCount)
+
+ }
+ }
}
\ No newline at end of file
diff --git a/R/runTreatmentPatterns.R b/R/runTreatmentPatterns.R
new file mode 100644
index 0000000..0589752
--- /dev/null
+++ b/R/runTreatmentPatterns.R
@@ -0,0 +1,67 @@
+#' Run the treatment patterns analysis
+#'
+#' @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 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
+#' @param minCellCount minimum cell count
+#'
+#' @import dplyr TreatmentPatterns
+#'
+#' @return the drug utilisation results
+#'
+#' @export
+runTreatmentPatterns <- function(connectionDetails,
+ cdmDatabaseSchema,
+ cohortDatabaseSchema,
+ cohortTable,
+ cohortsGenerated,
+ outputSubDir,
+ tablePrefix = NULL,
+ logger = NULL,
+ cohortIds,
+ minCellCount = 5) {
+
+ # Select target cohort
+ targetCohorts <- cohortsGenerated %>%
+ filter(cohortName == cohortIds[1]) %>%
+ select(cohortId, cohortName)
+
+ # Select everything BUT target cohorts
+ eventCohorts <- cohortsGenerated %>%
+ filter(cohortName != cohortIds[1]) %>%
+ select(cohortId, cohortName)
+
+ cohorts <- dplyr::bind_rows(
+ targetCohorts %>% mutate(type = "target"),
+ eventCohorts %>% mutate(type = "event")
+ )
+
+ # Compute pathways
+ TreatmentPatterns::executeTreatmentPatterns(
+ cohorts = cohorts,
+ cohortTableName = cohortTable,
+ outputPath = outputSubDir,
+ 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
+ )
+}
diff --git a/README.Rmd b/README.Rmd
new file mode 100644
index 0000000..d57adb5
--- /dev/null
+++ b/README.Rmd
@@ -0,0 +1,155 @@
+---
+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)](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.
+
+- 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 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
+
+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 [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
+
+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 <- FALSE
+runDiagnostics <- FALSE
+runPatternAnalysis <- FALSE
+
+### 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 1e7d970..891d3f4 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,22 @@
+
+
+
# 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)](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.
- 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,66 +25,90 @@ 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 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
-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")
-)
+
+1. See the instructions at
+ 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.
+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
+``` r
#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("port")
+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.
@@ -91,16 +123,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
-
+instantiateCohorts <- FALSE
+runDiagnostics <- FALSE
+runPatternAnalysis <- FALSE
### Do not edit below here
-
EhdenAlopecia::runStudy(
connectionDetails = connectionDetails,
cohortTable = cohortTable,
@@ -108,6 +139,7 @@ EhdenAlopecia::runStudy(
cohortDatabaseSchema = cohortDatabaseSchema,
instantiateCohorts = instantiateCohorts,
runDiagnostics = runDiagnostics,
+ runPatternAnalysis = runPatternAnalysis,
outputFolder = outputFolder,
databaseId = databaseId,
minCellCount = minCellCount
diff --git a/extras/package-maintenance.R b/extras/package-maintenance.R
deleted file mode 100644
index d20b5cb..0000000
--- a/extras/package-maintenance.R
+++ /dev/null
@@ -1,29 +0,0 @@
-library(ROhdsiWebApi)
-baseUrl <- "https://test-atlas.ehden.eu/WebAPI"
-
-authorizeWebApi(
- baseUrl,
- authMethod = "db",
- webApiUsername = Sys.getenv('EHDEN_WEBAPI_USERNAME'),
- webApiPassword = Sys.getenv('EHDEN_WEBAPI_PASSWORD')
-)
-
-getCdmSources(baseUrl)
-
-cohortDefinitionSet <- ROhdsiWebApi::exportCohortDefinitionSet(
- baseUrl,
- c(92:97, 100)
-)
-write.csv(cohortDefinitionSet, 'inst/cohortDefinitionSet.csv')
-
-# Insert cohort definitions from ATLAS into package -----------------------
-for (cohortId in 92:97) {
- ROhdsiWebApi::insertCohortDefinitionInPackage(
- cohortId,
- name = cohortId,
- jsonFolder = "inst/cohorts",
- sqlFolder = "inst/sql/sql_server",
- baseUrl,
- generateStats = FALSE
- )
-}
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
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/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" : {}
+}
diff --git a/extras/codeToRun.R b/inst/extras/CodeToRun.R
similarity index 85%
rename from extras/codeToRun.R
rename to inst/extras/CodeToRun.R
index fe7e09e..1f4a079 100644
--- a/extras/codeToRun.R
+++ b/inst/extras/CodeToRun.R
@@ -35,31 +35,33 @@
#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.
@@ -74,16 +76,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
-
+instantiateCohorts <- FALSE
+runDiagnostics <- FALSE
+runPatternAnalysis <- FALSE
### Do not edit below here
-
EhdenAlopecia::runStudy(
connectionDetails = connectionDetails,
cohortTable = cohortTable,
@@ -91,6 +92,7 @@ EhdenAlopecia::runStudy(
cohortDatabaseSchema = cohortDatabaseSchema,
instantiateCohorts = instantiateCohorts,
runDiagnostics = runDiagnostics,
+ runPatternAnalysis = runPatternAnalysis,
outputFolder = outputFolder,
databaseId = databaseId,
minCellCount = minCellCount
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/inst/extras/launchShiny.R b/inst/extras/launchShiny.R
new file mode 100644
index 0000000..b417f8d
--- /dev/null
+++ b/inst/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, "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.
diff --git a/inst/extras/package-maintenance.R b/inst/extras/package-maintenance.R
new file mode 100644
index 0000000..eeeaf1c
--- /dev/null
+++ b/inst/extras/package-maintenance.R
@@ -0,0 +1,37 @@
+library(ROhdsiWebApi)
+baseUrl <- "https://test-atlas.ehden.eu/WebAPI"
+
+authorizeWebApi(
+ baseUrl,
+ authMethod = "db",
+ webApiUsername = Sys.getenv('EHDEN_WEBAPI_USERNAME'),
+ webApiPassword = Sys.getenv('EHDEN_WEBAPI_PASSWORD')
+)
+
+getCdmSources(baseUrl)
+
+cohortDefinitionSet <- ROhdsiWebApi::exportCohortDefinitionSet(
+ baseUrl,
+ c(92:97, 100, setdiff(101:127, 118))
+)
+write.csv(cohortDefinitionSet, 'inst/cohortDefinitionSet.csv')
+
+# Insert cohort definitions from ATLAS into package -----------------------
+for (cohortId in c(92:97, 100)) {
+ ROhdsiWebApi::insertCohortDefinitionInPackage(
+ 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)) {
+ 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/treatment_cohorts/101.json b/inst/treatment_cohorts/101.json
new file mode 100644
index 0000000..1c7ee7c
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/102.json b/inst/treatment_cohorts/102.json
new file mode 100644
index 0000000..56b59cd
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/103.json b/inst/treatment_cohorts/103.json
new file mode 100644
index 0000000..74af237
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/104.json b/inst/treatment_cohorts/104.json
new file mode 100644
index 0000000..d1ba597
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/105.json b/inst/treatment_cohorts/105.json
new file mode 100644
index 0000000..49d575e
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/106.json b/inst/treatment_cohorts/106.json
new file mode 100644
index 0000000..e43670f
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/107.json b/inst/treatment_cohorts/107.json
new file mode 100644
index 0000000..abcc582
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/108.json b/inst/treatment_cohorts/108.json
new file mode 100644
index 0000000..e40f423
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/109.json b/inst/treatment_cohorts/109.json
new file mode 100644
index 0000000..cadfbaf
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/110.json b/inst/treatment_cohorts/110.json
new file mode 100644
index 0000000..e78f4ec
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/111.json b/inst/treatment_cohorts/111.json
new file mode 100644
index 0000000..f898661
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/112.json b/inst/treatment_cohorts/112.json
new file mode 100644
index 0000000..7ebc565
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/113.json b/inst/treatment_cohorts/113.json
new file mode 100644
index 0000000..9dc9124
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/114.json b/inst/treatment_cohorts/114.json
new file mode 100644
index 0000000..3fa0850
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/115.json b/inst/treatment_cohorts/115.json
new file mode 100644
index 0000000..6cb6fdc
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/116.json b/inst/treatment_cohorts/116.json
new file mode 100644
index 0000000..9448584
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/117.json b/inst/treatment_cohorts/117.json
new file mode 100644
index 0000000..caca4ff
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/119.json b/inst/treatment_cohorts/119.json
new file mode 100644
index 0000000..4d383f8
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/120.json b/inst/treatment_cohorts/120.json
new file mode 100644
index 0000000..b2fcd09
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/121.json b/inst/treatment_cohorts/121.json
new file mode 100644
index 0000000..9a70c3d
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/122.json b/inst/treatment_cohorts/122.json
new file mode 100644
index 0000000..6b153bf
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/123.json b/inst/treatment_cohorts/123.json
new file mode 100644
index 0000000..b27a351
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/124.json b/inst/treatment_cohorts/124.json
new file mode 100644
index 0000000..8016fce
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/125.json b/inst/treatment_cohorts/125.json
new file mode 100644
index 0000000..5946683
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/126.json b/inst/treatment_cohorts/126.json
new file mode 100644
index 0000000..e0f923d
--- /dev/null
+++ b/inst/treatment_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/treatment_cohorts/127.json b/inst/treatment_cohorts/127.json
new file mode 100644
index 0000000..cc15733
--- /dev/null
+++ b/inst/treatment_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" : {}
+}
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..adb77eb
--- /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,
+ outputSubDir,
+ tablePrefix = NULL,
+ logger = NULL,
+ cohortIds,
+ minCellCount = 5
+)
+}
+\arguments{
+\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{outputSubDir}{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}
+}
+\value{
+the drug utilisation results
+}
+\description{
+Run the treatment patterns analysis
+}
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()
+
+})