diff --git a/DESCRIPTION b/DESCRIPTION index dcd02dfa..bb6d8257 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: PhenotypeLibrary Type: Package Title: The OHDSI Phenotype Library -Version: 3.35.0 -Date: 2025-03-29 +Version: 3.36.0 +Date: 2025-04-02 Author: Gowtham Rao [aut, cre] Maintainer: Gowtham Rao Description: A repository to store the content of the OHDSI Phenotype library. diff --git a/NEWS.md b/NEWS.md index 32281ee6..c5c23802 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,52 @@ +PhenotypeLibrary 3.36.0 +====================== +Accepted Cohorts: No cohorts were accepted in this release. + +New Cohorts: 42 were added. + + 1387: [P] Methadone + 1388: [P] Methadone Treatment Program Enrollment + 1389: [P] Naltrexone + 1390: [P] Naltrexone Maintenance Therapy + 1391: [P] Opioid Agonists + 1392: [P] Opioid Antagonists + 1393: [P] Medication-Assisted Treatment + 1394: [P] Nicotine Replacement Therapy + 1395: [P] OTC Nicotine Replacement + 1396: [P] Varenicline + 1397: [P] Pain Management + 1398: [P] Terminal Palliative Care + 1399: [P] Alcohol Misuse Counseling + 1400: [P] Smoking Cessation Counseling + 1401: [P] Psychotherapy + 1402: [P] Group Therapy + 1403: [P] Family Psychotherapy + 1404: [P] Behavioral Therapies + 1405: [P] 12-Step Facilitation Behavioral Therapy + 1406: [P] Harm Reduction Interventions + 1407: [P] Specialty Addiction Treatment + 1408: [P] Alcohol Use Screening + 1409: [P] Screening for substance abuse + 1410: [P] Use of Substance Use Screening Tools + 1411: [P] Laboratory Toxicology Tests + 1412: [P] Naloxone Dispensing + 1413: [P] Screening, Brief Intervention, and Referral to Treatment (SBIRT) + 1415: [P] Impaired Control + 1416: [P] Neglect of Roles or Social Impairment + 1417: [P] Risky Use + 1418: [P] Tolerance + 1419: [P] Pattern of Use Causing Harm or Distress + 1420: [P] Medical Conditions Mimicking Intoxication + 1421: [P] Hypoglycemic disorder + 1422: [P] Stroke events + 1423: [P] Single Acute Intoxication + 1424: [P] Opioid Acute intoxication + 1425: [P] Alcohol Acute intoxication + 1426: [P] Psychoactive Substances + 1427: [P] Acamprosate, all exposures + 1428: [P] Disulfiram, all exposures + 1429: [P] Buprenorphine, all exposures + PhenotypeLibrary 3.35.0 ====================== Accepted Cohorts: No cohorts were accepted in this release. diff --git a/docs/404.html b/docs/404.html index 708dc1c0..25a77701 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 diff --git a/docs/articles/CohortDefinitionSubmissionRequirements.html b/docs/articles/CohortDefinitionSubmissionRequirements.html index a4229bd8..69655fde 100644 --- a/docs/articles/CohortDefinitionSubmissionRequirements.html +++ b/docs/articles/CohortDefinitionSubmissionRequirements.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -120,7 +120,7 @@

Cohort Definition Submission Requirements

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/CohortDefinitionSubmissionRequirements.Rmd diff --git a/docs/articles/CohortDefinitionsInOhdsiPhenotypeLibrary.html b/docs/articles/CohortDefinitionsInOhdsiPhenotypeLibrary.html index 3e8ffce7..1da35eab 100644 --- a/docs/articles/CohortDefinitionsInOhdsiPhenotypeLibrary.html +++ b/docs/articles/CohortDefinitionsInOhdsiPhenotypeLibrary.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -123,7 +123,7 @@

Cohort Definitions in OHDSI Phenotype

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/CohortDefinitionsInOhdsiPhenotypeLibrary.Rmd @@ -151,7 +151,7 @@

2025-03-29

}); });
- + @@ -123,7 +123,7 @@

Concept Set Definitions in OHDSI Phenotype

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/ConceptSetDefinitionsInOhdsiPhenotypeLibrary.Rmd @@ -133,7 +133,7 @@

2025-03-29

- + @@ -121,7 +121,7 @@

Guidance on writing clinical description for

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/GuidanceOnClinicalDescriptionForConditionPhenotypes.Rmd diff --git a/docs/articles/GuidanceOnCohortDefinitionSetRObject.html b/docs/articles/GuidanceOnCohortDefinitionSetRObject.html index 4cfc270d..d0981e9b 100644 --- a/docs/articles/GuidanceOnCohortDefinitionSetRObject.html +++ b/docs/articles/GuidanceOnCohortDefinitionSetRObject.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -120,7 +120,7 @@

Guidance on Cohort Definition Set R Object

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/GuidanceOnCohortDefinitionSetRObject.Rmd diff --git a/docs/articles/GuidanceOnLiteratureReview.html b/docs/articles/GuidanceOnLiteratureReview.html index a8186a6e..efb8f4d5 100644 --- a/docs/articles/GuidanceOnLiteratureReview.html +++ b/docs/articles/GuidanceOnLiteratureReview.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -120,7 +120,7 @@

Guidance on literature review

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/GuidanceOnLiteratureReview.Rmd diff --git a/docs/articles/GuidanceOnPerformingPeerReview.html b/docs/articles/GuidanceOnPerformingPeerReview.html index a36322db..7bfc37ea 100644 --- a/docs/articles/GuidanceOnPerformingPeerReview.html +++ b/docs/articles/GuidanceOnPerformingPeerReview.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -120,7 +120,7 @@

Guidance on performing peer review

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/GuidanceOnPerformingPeerReview.Rmd diff --git a/docs/articles/GuidanceOnWritingAnEvaluationReport.html b/docs/articles/GuidanceOnWritingAnEvaluationReport.html index 4bbfc4e2..3d74cfcb 100644 --- a/docs/articles/GuidanceOnWritingAnEvaluationReport.html +++ b/docs/articles/GuidanceOnWritingAnEvaluationReport.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -120,7 +120,7 @@

Guidance on writing an evaluation report

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/GuidanceOnWritingAnEvaluationReport.Rmd diff --git a/docs/articles/GuidanceOnWritingCohortDefinitionLogicDescription.html b/docs/articles/GuidanceOnWritingCohortDefinitionLogicDescription.html index 4da83f30..5042870f 100644 --- a/docs/articles/GuidanceOnWritingCohortDefinitionLogicDescription.html +++ b/docs/articles/GuidanceOnWritingCohortDefinitionLogicDescription.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -121,7 +121,7 @@

Guidance on writing Cohort Definition Logic

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/GuidanceOnWritingCohortDefinitionLogicDescription.Rmd diff --git a/docs/articles/HowToUsePhenotypeLibraryRPackage.html b/docs/articles/HowToUsePhenotypeLibraryRPackage.html index 2a262e9f..779169b6 100644 --- a/docs/articles/HowToUsePhenotypeLibraryRPackage.html +++ b/docs/articles/HowToUsePhenotypeLibraryRPackage.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -120,7 +120,7 @@

How to Use PhenotypeLibrary R Package

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/HowToUsePhenotypeLibraryRPackage.Rmd @@ -150,7 +150,7 @@

Retrieval
 PhenotypeLibrary::getPhenotypeLog()
-
#> # A tibble: 661 × 88
+
#> # A tibble: 703 × 88
 #>    cohortId cohortName        cohortNameAtlas cohortNameFormatted cohortNameLong
 #>       <dbl> <chr>             <chr>           <chr>               <chr>         
 #>  1        3 Cough or Sputum   [P] Cough or S… Cough or Sputum     Cough or Sput…
@@ -163,7 +163,7 @@ 

Retrieval#> 8 10 Nausea or Vomiti… [P] Nausea or … Nausea or Vomiting Nausea or Vom… #> 9 11 Malaise and or f… [P] Malaise an… Malaise and or fat… Malaise and o… #> 10 12 Rhinitis or comm… [P] Rhinitis o… Rhinitis or common… Rhinitis or c… -#> # ℹ 651 more rows +#> # ℹ 693 more rows #> # ℹ 83 more variables: librarian <chr>, status <chr>, addedVersion <chr>, #> # logicDescription <chr>, hashTag <chr>, isCirceJson <dbl>, #> # contributors <chr>, contributorOrcIds <chr>, diff --git a/docs/articles/ReservedWordsWithSpecialMeaningToPhenotypers.html b/docs/articles/ReservedWordsWithSpecialMeaningToPhenotypers.html index 9926fbea..96a6d02f 100644 --- a/docs/articles/ReservedWordsWithSpecialMeaningToPhenotypers.html +++ b/docs/articles/ReservedWordsWithSpecialMeaningToPhenotypers.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -121,7 +121,7 @@

Reserved Words With Special Meaning To

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/ReservedWordsWithSpecialMeaningToPhenotypers.Rmd diff --git a/docs/articles/SubmittedCohortDefinitions.html b/docs/articles/SubmittedCohortDefinitions.html index 43d0c9a7..9a6cfbdc 100644 --- a/docs/articles/SubmittedCohortDefinitions.html +++ b/docs/articles/SubmittedCohortDefinitions.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -120,7 +120,7 @@

Submitted Cohort Definitions

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/SubmittedCohortDefinitions.Rmd diff --git a/docs/articles/ValidityChecksForCohortDefinitions.html b/docs/articles/ValidityChecksForCohortDefinitions.html index 2d339b01..511ac13d 100644 --- a/docs/articles/ValidityChecksForCohortDefinitions.html +++ b/docs/articles/ValidityChecksForCohortDefinitions.html @@ -32,7 +32,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -120,7 +120,7 @@

Validity checks for Cohort Definitions

Gowtham A. Rao

-

2025-03-29

+

2025-04-02

Source: vignettes/ValidityChecksForCohortDefinitions.Rmd diff --git a/docs/articles/index.html b/docs/articles/index.html index 0b4b0bba..2740effa 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 diff --git a/docs/authors.html b/docs/authors.html index 22df6006..c04d0a84 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -112,13 +112,13 @@

Citation

Rao G (2025). PhenotypeLibrary: The OHDSI Phenotype Library. -R package version 3.35.0, https://github.com/OHDSI/PhenotypeLibrary, https://ohdsi.github.io/PhenotypeLibrary/. +R package version 3.36.0, https://github.com/OHDSI/PhenotypeLibrary, https://ohdsi.github.io/PhenotypeLibrary/.

@Manual{,
   title = {PhenotypeLibrary: The OHDSI Phenotype Library},
   author = {Gowtham Rao},
   year = {2025},
-  note = {R package version 3.35.0, https://github.com/OHDSI/PhenotypeLibrary},
+  note = {R package version 3.36.0, https://github.com/OHDSI/PhenotypeLibrary},
   url = {https://ohdsi.github.io/PhenotypeLibrary/},
 }
diff --git a/docs/index.html b/docs/index.html index bb5fad99..93113601 100644 --- a/docs/index.html +++ b/docs/index.html @@ -33,7 +33,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 diff --git a/docs/news/index.html b/docs/news/index.html index 0bc9ece3..4987fb78 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -96,68 +96,115 @@

Changelog

Source: NEWS.md +
+ +

Accepted Cohorts: No cohorts were accepted in this release.

+

New Cohorts: 42 were added.

+
1387: [P] Methadone
+1388: [P] Methadone Treatment Program Enrollment
+1389: [P] Naltrexone
+1390: [P] Naltrexone Maintenance Therapy
+1391: [P] Opioid Agonists
+1392: [P] Opioid Antagonists
+1393: [P] Medication-Assisted Treatment
+1394: [P] Nicotine Replacement Therapy
+1395: [P] OTC Nicotine Replacement
+1396: [P] Varenicline
+1397: [P] Pain Management
+1398: [P] Terminal Palliative Care
+1399: [P] Alcohol Misuse Counseling
+1400: [P] Smoking Cessation Counseling
+1401: [P] Psychotherapy
+1402: [P] Group Therapy
+1403: [P] Family Psychotherapy
+1404: [P] Behavioral Therapies
+1405: [P] 12-Step Facilitation Behavioral Therapy
+1406: [P] Harm Reduction Interventions
+1407: [P] Specialty Addiction Treatment
+1408: [P] Alcohol Use Screening
+1409: [P] Screening for substance abuse
+1410: [P] Use of Substance Use Screening Tools
+1411: [P] Laboratory Toxicology Tests
+1412: [P] Naloxone Dispensing
+1413: [P] Screening, Brief Intervention, and Referral to Treatment (SBIRT)
+1415: [P] Impaired Control
+1416: [P] Neglect of Roles or Social Impairment
+1417: [P] Risky Use
+1418: [P] Tolerance
+1419: [P] Pattern of Use Causing Harm or Distress
+1420: [P] Medical Conditions Mimicking Intoxication
+1421: [P] Hypoglycemic disorder
+1422: [P] Stroke events
+1423: [P] Single Acute Intoxication
+1424: [P] Opioid Acute intoxication
+1425: [P] Alcohol Acute intoxication
+1426: [P] Psychoactive Substances
+1427: [P] Acamprosate, all exposures
+1428: [P] Disulfiram, all exposures
+1429: [P] Buprenorphine, all exposures
+

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 58 were added.

-
1318: [P] NSCLC solitary primary rx naive
-1329: [P] Death due to substance overdose (post mortem)
-1330: [P] Acute Overdose (or “Acute Toxicity”) by substances with abuse potential
-1331: [P] Opioid overdose - treatment drugs
-1332: [P] Alcohol poisoning (acute severe intoxication)
-1333: [P] Advanced liver disease
-1334: [P] Liver cirrhosis from alcohol
-1336: [P] Infective Endocarditis
-1337: [P] Human immunodeficiency virus infection earliest occurrence
-1338: [P] Binge Eating Disorder
-1339: [P] Bulimia Nervosa
-1340: [P] Anorexia Nervosa
-1341: [P] Eating Disorders
-1342: [P] Narcissistic personality disorder
-1343: [P] Antisocial Personality Disorder
-1344: [P] Borderline Personality Disorder
-1345: [P] Personality Disorders
-1346: [P] Attention-Deficit Hyperactivity Disorder
-1347: [P] Posttraumatic Stress Disorder
-1348: [P] Obsessive Compulsive Disorder
-1349: [P] Anxiety Disorder
-1350: [P] Primary Psychiatric Disorders
-1351: [P] Gambling Disorder
-1352: [P] Behavioral Addictions
-1353: [P] Tobacco and Nicotine User
-1354: [P] Tobacco and Nicotine Use Disorder - procedure
-1355: [P] Measurements for Opioid Use Disorder
-1356: [P] Opioid Use Disorder - treatment procedure or drug
-1357: [P] Measurements for Cannabis Use Disorder
-1358: [P] Alcohol Withdrawal - procedure
-1359: [P] Alcohol withdrawal
-1360: [P] Alcohol withdrawal - condition
-1361: [P] Alcohol detoxification
-1362: [P] Alcohol poisoning
-1363: [P] Psychosis caused by ethanol - condition
-1364: [P] Alcohol Intoxication - condition
-1365: [P] Heroin use disorder - condition
-1366: [P] Fentanyl use disorder
-1367: [P] Stimulant Use Disorder
-1368: [P] Cocaine Use Disorder
-1369: [P] Methamphetamine use disorder
-1370: [P] Sedative Hypnotic Anxiolytic Use Disorder
-1371: [P] Benzodiazepines use disorder
-1372: [P] Barbiturates use disorder
-1373: [P] Inhalant Use Disorder
-1374: [P] Tobacco and Nicotine Use Disorder - condition
-1375: [P] Tobacco and Nicotine Toxicity
-1376: [P] Infectious Diseases (HIV, Hepatitis B, Hepatitis C)
-1377: [P] Substance Use Disorder in Remission
-1378: [P] Controlled Medication Use
-1379: [P] Physical Dependence from Legitimate Therapy
-1380: [P] Prescription Drug Misuse
-1381: [P] Cravings
-1382: [P] Compulsions
-1383: [P] Mental or Moral Distress
-1384: [P] Any Distress (Physical or Mental)
-1385: [P] Withdrawal of substances with abuse potential
-1386: [P] Withdrawal Seizures
+
1318: [P] NSCLC solitary primary rx naive
+1329: [P] Death due to substance overdose (post mortem)
+1330: [P] Acute Overdose (or “Acute Toxicity”) by substances with abuse potential
+1331: [P] Opioid overdose - treatment drugs
+1332: [P] Alcohol poisoning (acute severe intoxication)
+1333: [P] Advanced liver disease
+1334: [P] Liver cirrhosis from alcohol
+1336: [P] Infective Endocarditis
+1337: [P] Human immunodeficiency virus infection earliest occurrence
+1338: [P] Binge Eating Disorder
+1339: [P] Bulimia Nervosa
+1340: [P] Anorexia Nervosa
+1341: [P] Eating Disorders
+1342: [P] Narcissistic personality disorder
+1343: [P] Antisocial Personality Disorder
+1344: [P] Borderline Personality Disorder
+1345: [P] Personality Disorders
+1346: [P] Attention-Deficit Hyperactivity Disorder
+1347: [P] Posttraumatic Stress Disorder
+1348: [P] Obsessive Compulsive Disorder
+1349: [P] Anxiety Disorder
+1350: [P] Primary Psychiatric Disorders
+1351: [P] Gambling Disorder
+1352: [P] Behavioral Addictions
+1353: [P] Tobacco and Nicotine User
+1354: [P] Tobacco and Nicotine Use Disorder - procedure
+1355: [P] Measurements for Opioid Use Disorder
+1356: [P] Opioid Use Disorder - treatment procedure or drug
+1357: [P] Measurements for Cannabis Use Disorder
+1358: [P] Alcohol Withdrawal - procedure
+1359: [P] Alcohol withdrawal
+1360: [P] Alcohol withdrawal - condition
+1361: [P] Alcohol detoxification
+1362: [P] Alcohol poisoning
+1363: [P] Psychosis caused by ethanol - condition
+1364: [P] Alcohol Intoxication - condition
+1365: [P] Heroin use disorder - condition
+1366: [P] Fentanyl use disorder
+1367: [P] Stimulant Use Disorder
+1368: [P] Cocaine Use Disorder
+1369: [P] Methamphetamine use disorder
+1370: [P] Sedative Hypnotic Anxiolytic Use Disorder
+1371: [P] Benzodiazepines use disorder
+1372: [P] Barbiturates use disorder
+1373: [P] Inhalant Use Disorder
+1374: [P] Tobacco and Nicotine Use Disorder - condition
+1375: [P] Tobacco and Nicotine Toxicity
+1376: [P] Infectious Diseases (HIV, Hepatitis B, Hepatitis C)
+1377: [P] Substance Use Disorder in Remission
+1378: [P] Controlled Medication Use
+1379: [P] Physical Dependence from Legitimate Therapy
+1380: [P] Prescription Drug Misuse
+1381: [P] Cravings
+1382: [P] Compulsions
+1383: [P] Mental or Moral Distress
+1384: [P] Any Distress (Physical or Mental)
+1385: [P] Withdrawal of substances with abuse potential
+1386: [P] Withdrawal Seizures
@@ -175,69 +222,69 @@

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 2 were added.

-
1316: Acquired Neutropenia or unspecified leukopenia (21Pe, 365Era)
-1317: [P] Reyes syndrome
+
1316: Acquired Neutropenia or unspecified leukopenia (21Pe, 365Era)
+1317: [P] Reyes syndrome

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 56 were added.

-
1217: [P] Platinum based chemotherapy regimens
-1244: [P] Non Platinum chemotherapy regimen
-1261: [P] Acute Typical Pneumonia
-1262: [P] Asthma or Chronic obstructive pulmonary disease (COPD)
-1263: [P] Chronic obstructive pulmonary disease (COPD) without asthma
-1264: [P] Pneumonitis and lung infections
-1265: [P] Pulmonary hypertension associated with lung diseases and or hypoxia (WHO Group 3)
-1266: [P] Non-small cell lung cancer (NSCLC) for first time using ICD0
-1267: [P] Lung cancer using ICD0
-1268: [P] Lung Resection, adults, inpt stay, no ED, post op new Afib
-1269: [P] Pulmonary fibrosis
-1270: [P] History of Bladder cancer
-1271: [P] Chronic obstructive pulmonary disease (COPD)
-1272: [P] Chronic Interstitial lung disease (ILD)
-1273: [P] Lung Nodule
-1274: [P] Lung Nodule - solitary
-1275: [P] Lung Nodule - multiple
-1276: [P] Lung Mass (not acute, necrotic, atlectatic, abscess, fibrosis)
-1277: [P] Lung Lesion (not acute, necrotic, atlectatic, abscess, fibrosis)
-1278: [P] Non Small Cell Lung Cancer (Stage 3)
-1279: [P] Non Small Cell Lung Cancer
-1280: [P] Small Cell Lung Cancer
-1281: [P] Primary Lung Cancer
-1282: [P] Hoarseness
-1283: [P] Bone Pain
-1284: [P] Weight loss
-1285: [P] Acute bronchitis
-1286: [P] Non Small Cell Lung Cancer (Stage 3) without second diagnosis
-1287: [P] Intestinal obstruction - colorectal specific
-1288: [P] Intraabdominal abscess - narrow for colorectal cancer
-1289: [P] Major Non Cardiac Surgery, adults
-1290: [P] Abdominal Aortic Aneurysm repair, adults
-1291: [P] Lower Extremity Bypass, adults
-1292: [P] Carotid Endarterectomy, adults
-1293: [P] Lung Resection, adults
-1294: [P] Esophagectomy, adults
-1295: [P] Pancreatectomy, adults
-1296: [P] Colectomy, adults
-1297: [P] Cystectomy, adults
-1298: [P] Nephrectomy, adults
-1299: [P] Coronary Artery Bypass Graft, adults
-1300: [P] Cardiac Valve Surgery, adults
-1301: [P] Acute Urinary tract infections UTI events
-1303: [P] Acute Heart failure from legend
-1304: [P] Major Non Cardiac Surgery, adults, post op new Afib
-1305: [P] AAA repair, adults, post op new Afib
-1306: [P] Lower Extremity Bypass, adults, post op new Afib
-1307: [P] Carotid Endarterectomy, adults, post op new Afib
-1308: [P] Lung Resection, adults, post op new Afib
-1309: [P] Esophagectomy, adults, post op new Afib
-1310: [P] Pancreatectomy, adults, post op new Afib
-1311: [P] Colectomy, adults, post op new Afib
-1312: [P] Cystectomy, adults, post op new Afib
-1313: [P] Nephrectomy, adults, post op new Afib
-1314: [P] Coronary Artery Bypass Graft, adults, post op new Afib
-1315: [P] Cardiac Valve Surgery, adults, post op new Afib
+
1217: [P] Platinum based chemotherapy regimens
+1244: [P] Non Platinum chemotherapy regimen
+1261: [P] Acute Typical Pneumonia
+1262: [P] Asthma or Chronic obstructive pulmonary disease (COPD)
+1263: [P] Chronic obstructive pulmonary disease (COPD) without asthma
+1264: [P] Pneumonitis and lung infections
+1265: [P] Pulmonary hypertension associated with lung diseases and or hypoxia (WHO Group 3)
+1266: [P] Non-small cell lung cancer (NSCLC) for first time using ICD0
+1267: [P] Lung cancer using ICD0
+1268: [P] Lung Resection, adults, inpt stay, no ED, post op new Afib
+1269: [P] Pulmonary fibrosis
+1270: [P] History of Bladder cancer
+1271: [P] Chronic obstructive pulmonary disease (COPD)
+1272: [P] Chronic Interstitial lung disease (ILD)
+1273: [P] Lung Nodule
+1274: [P] Lung Nodule - solitary
+1275: [P] Lung Nodule - multiple
+1276: [P] Lung Mass (not acute, necrotic, atlectatic, abscess, fibrosis)
+1277: [P] Lung Lesion (not acute, necrotic, atlectatic, abscess, fibrosis)
+1278: [P] Non Small Cell Lung Cancer (Stage 3)
+1279: [P] Non Small Cell Lung Cancer
+1280: [P] Small Cell Lung Cancer
+1281: [P] Primary Lung Cancer
+1282: [P] Hoarseness
+1283: [P] Bone Pain
+1284: [P] Weight loss
+1285: [P] Acute bronchitis
+1286: [P] Non Small Cell Lung Cancer (Stage 3) without second diagnosis
+1287: [P] Intestinal obstruction - colorectal specific
+1288: [P] Intraabdominal abscess - narrow for colorectal cancer
+1289: [P] Major Non Cardiac Surgery, adults
+1290: [P] Abdominal Aortic Aneurysm repair, adults
+1291: [P] Lower Extremity Bypass, adults
+1292: [P] Carotid Endarterectomy, adults
+1293: [P] Lung Resection, adults
+1294: [P] Esophagectomy, adults
+1295: [P] Pancreatectomy, adults
+1296: [P] Colectomy, adults
+1297: [P] Cystectomy, adults
+1298: [P] Nephrectomy, adults
+1299: [P] Coronary Artery Bypass Graft, adults
+1300: [P] Cardiac Valve Surgery, adults
+1301: [P] Acute Urinary tract infections UTI events
+1303: [P] Acute Heart failure from legend
+1304: [P] Major Non Cardiac Surgery, adults, post op new Afib
+1305: [P] AAA repair, adults, post op new Afib
+1306: [P] Lower Extremity Bypass, adults, post op new Afib
+1307: [P] Carotid Endarterectomy, adults, post op new Afib
+1308: [P] Lung Resection, adults, post op new Afib
+1309: [P] Esophagectomy, adults, post op new Afib
+1310: [P] Pancreatectomy, adults, post op new Afib
+1311: [P] Colectomy, adults, post op new Afib
+1312: [P] Cystectomy, adults, post op new Afib
+1313: [P] Nephrectomy, adults, post op new Afib
+1314: [P] Coronary Artery Bypass Graft, adults, post op new Afib
+1315: [P] Cardiac Valve Surgery, adults, post op new Afib

Note: The following cohorts were accidentally deleted and we restored with new id.

@@ -325,7 +372,7 @@

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 1 were added.

-
1232: [P] Non Small Cell Lung Cancer (Stage 3) without second diagnosis
+
1232: [P] Non Small Cell Lung Cancer (Stage 3) without second diagnosis
@@ -336,24 +383,24 @@

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 8 were added.

-
1223: [P] Birdshot chorioretinitis
-1224: [P] CMV Anterior Uveitis (sensitivity analysis)
-1225: [P] VZV Anterior Uveitis (SUN)
-1226: [P] VZV Anterior Uveitis (SUN) sensitive
-1227: [P] HSV Anterior Uveitis (SUN)
-1228: [P] HSV Anterior Uveitis (SUN) sensitive
-1229: [P] Behcet Uveitis (SUN)
-1231: [P] Sickle Cell Crisis
+
1223: [P] Birdshot chorioretinitis
+1224: [P] CMV Anterior Uveitis (sensitivity analysis)
+1225: [P] VZV Anterior Uveitis (SUN)
+1226: [P] VZV Anterior Uveitis (SUN) sensitive
+1227: [P] HSV Anterior Uveitis (SUN)
+1228: [P] HSV Anterior Uveitis (SUN) sensitive
+1229: [P] Behcet Uveitis (SUN)
+1231: [P] Sickle Cell Crisis

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 5 were added.

-
1218: [P] Acute bronchitis
-1219: [P] Hyperlipidemia
-1220: [P] Hypoparathyroidism
-1221: [P] Osteoporosis
-1222: [P] Viral hepatitis type A
+
1218: [P] Acute bronchitis
+1219: [P] Hyperlipidemia
+1220: [P] Hypoparathyroidism
+1221: [P] Osteoporosis
+1222: [P] Viral hepatitis type A
@@ -363,24 +410,24 @@

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 18 were added.

-
1117: [P] Pulmonary fibrosis
-1118: [P] History of Bladder cancer
-1119: [P] Chronic obstructive pulmonary disease (COPD)
-1120: [P] Chronic Interstitial lung disease (ILD)
-1128: [P] Lung Nodule
-1129: [P] Lung Nodule - solitary
-1130: [P] Lung Nodule - multiple
-1131: [P] Lung Mass (not acute, necrotic, atlectatic, abscess, fibrosis)
-1132: [P] Lung Lesion (not acute, necrotic, atlectatic, abscess, fibrosis)
-1133: [P] Non Small Cell Lung Cancer as lung cancer without small cell
-1134: [P] Lung Cancer (primary maliganancy)
-1135: [P] Small Cell Lung Cancer
-1136: [P] Non Small Cell Lung Cancer
-1137: [P] Hoarseness
-1138: [P] Bone Pain
-1139: [P] Weight loss
-1216: [P] Primary Lung Cancer, 2nd dx 365 d after, excl SCLC signs all d before 1y after
-1217: [P] Primary Lung Cancer, excl SCLC signs all d before 1y after
+
1117: [P] Pulmonary fibrosis
+1118: [P] History of Bladder cancer
+1119: [P] Chronic obstructive pulmonary disease (COPD)
+1120: [P] Chronic Interstitial lung disease (ILD)
+1128: [P] Lung Nodule
+1129: [P] Lung Nodule - solitary
+1130: [P] Lung Nodule - multiple
+1131: [P] Lung Mass (not acute, necrotic, atlectatic, abscess, fibrosis)
+1132: [P] Lung Lesion (not acute, necrotic, atlectatic, abscess, fibrosis)
+1133: [P] Non Small Cell Lung Cancer as lung cancer without small cell
+1134: [P] Lung Cancer (primary maliganancy)
+1135: [P] Small Cell Lung Cancer
+1136: [P] Non Small Cell Lung Cancer
+1137: [P] Hoarseness
+1138: [P] Bone Pain
+1139: [P] Weight loss
+1216: [P] Primary Lung Cancer, 2nd dx 365 d after, excl SCLC signs all d before 1y after
+1217: [P] Primary Lung Cancer, excl SCLC signs all d before 1y after
@@ -391,421 +438,421 @@

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 64 were added. These Cohorts are part of the prediction study and contributed by Jenna Reps

-
1152: Deep Vein Thrombosis DVT 10
-1153: Seizure 10
-1154: Heart failure 10
-1155: Non-hemorrhagic Stroke 10
-1156: Hemorrhagic stroke 10
-1157: peripheral vascular disease 10
-1158: Aspirin 10
-1159: Angina 10
-1160: Atrial Fibrillation 10
-1161: Major depressive disorder with NO occurrence of certain psychiatric disorder 10
-1162: Coronary artery disease (CAD) 10
-1163: Acute Kidney Injury 10
-1164: Asthma 10
-1165: Alcoholism 10
-1166: Smoking 10
-1167: sleep apnea 10
-1168: skin ulcer 10
-1169: Chronic hepatitis 10
-1170: hyperlipidemia 10
-1171: hypothyroidism 10
-1172: Heart valve disorder 10
-1173: Low back pain 10
-1174: neuropathy 10
-1175: Psychotic disorder 10
-1176: Sepsis 10
-1177: Acute Respiratory failure 10
-1178: Gastroesophageal reflux disease 10
-1179: obesity 10
-1180: Inflammatory Bowel Disease 10
-1181: STEROIDS 10
-1182: Opioids 10
-1183: ANTIEPILEPTICS 10
-1184: Osteoarthritis 10
-1185: Osteoporosis 10
-1186: Urinary tract infectious 10
-1187: acetaminophen exposure 10
-1188: Anemia 10
-1189: Anxiety 10
-1190: HORMONAL CONTRACEPTIVES 10
-1191: Chronic kidney disease or end stage renal disease 10
-1192: Chronic obstructive pulmonary disease (COPD) 10
-1193: Type 1 diabetes and no prior specific nonT1DM diabetes 10
-1194: Type 2 Diabetes Mellitus with no type 1 or secondary DM 10
-1195: Dyspnea 10
-1196: Edema 10
-1197: Acute gastrointestinal bleeding 10
-1198: Hypertension 10
-1199: Pneumonia 10
-1200: Rheumatoid Arthritis 10
-1201: Antibiotics Aminoglycosides 10
-1202: Antibiotics Carbapenems 10
-1203: Antibiotics Cephalosporins 10
-1204: Antibiotics Fluoroquinolones 10
-1205: Antibiotics Glycopeptides and lipoglycopeptides 10
-1206: Antibiotics Macrolides 10
-1207: Antibiotics Monobactams 10
-1208: Antibiotics Oxazolidinones 10
-1209: Antibiotics Penicillins 10
-1210: Antibiotics Polypeptides 10
-1211: Antibiotics Rifamycins 10
-1212: Antibiotics Sulfonamides 10
-1213: Antibiotics Streptogramins 10
-1214: Antibiotics Tetracyclines 10
-1215: Any cancer (excl. prostate cancer and benign cancer) 10
+
1152: Deep Vein Thrombosis DVT 10
+1153: Seizure 10
+1154: Heart failure 10
+1155: Non-hemorrhagic Stroke 10
+1156: Hemorrhagic stroke 10
+1157: peripheral vascular disease 10
+1158: Aspirin 10
+1159: Angina 10
+1160: Atrial Fibrillation 10
+1161: Major depressive disorder with NO occurrence of certain psychiatric disorder 10
+1162: Coronary artery disease (CAD) 10
+1163: Acute Kidney Injury 10
+1164: Asthma 10
+1165: Alcoholism 10
+1166: Smoking 10
+1167: sleep apnea 10
+1168: skin ulcer 10
+1169: Chronic hepatitis 10
+1170: hyperlipidemia 10
+1171: hypothyroidism 10
+1172: Heart valve disorder 10
+1173: Low back pain 10
+1174: neuropathy 10
+1175: Psychotic disorder 10
+1176: Sepsis 10
+1177: Acute Respiratory failure 10
+1178: Gastroesophageal reflux disease 10
+1179: obesity 10
+1180: Inflammatory Bowel Disease 10
+1181: STEROIDS 10
+1182: Opioids 10
+1183: ANTIEPILEPTICS 10
+1184: Osteoarthritis 10
+1185: Osteoporosis 10
+1186: Urinary tract infectious 10
+1187: acetaminophen exposure 10
+1188: Anemia 10
+1189: Anxiety 10
+1190: HORMONAL CONTRACEPTIVES 10
+1191: Chronic kidney disease or end stage renal disease 10
+1192: Chronic obstructive pulmonary disease (COPD) 10
+1193: Type 1 diabetes and no prior specific nonT1DM diabetes 10
+1194: Type 2 Diabetes Mellitus with no type 1 or secondary DM 10
+1195: Dyspnea 10
+1196: Edema 10
+1197: Acute gastrointestinal bleeding 10
+1198: Hypertension 10
+1199: Pneumonia 10
+1200: Rheumatoid Arthritis 10
+1201: Antibiotics Aminoglycosides 10
+1202: Antibiotics Carbapenems 10
+1203: Antibiotics Cephalosporins 10
+1204: Antibiotics Fluoroquinolones 10
+1205: Antibiotics Glycopeptides and lipoglycopeptides 10
+1206: Antibiotics Macrolides 10
+1207: Antibiotics Monobactams 10
+1208: Antibiotics Oxazolidinones 10
+1209: Antibiotics Penicillins 10
+1210: Antibiotics Polypeptides 10
+1211: Antibiotics Rifamycins 10
+1212: Antibiotics Sulfonamides 10
+1213: Antibiotics Streptogramins 10
+1214: Antibiotics Tetracyclines 10
+1215: Any cancer (excl. prostate cancer and benign cancer) 10

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 2 were added.

-
1150: Emergency room only or Emergency room and inpatient visits (0Pe, 0Era)
-1151: [P] Autism
+
1150: Emergency room only or Emergency room and inpatient visits (0Pe, 0Era)
+1151: [P] Autism

Following cohorts were hidden: 325 were added. To retrieve use PhenotypeLibrary::getPhenotypeLog(showHidden = TRUE).

-
2: [W] COVID-19 diagnosis or SARS-CoV-2 test (1pos)
-15: [P][R] Exposure to viral disease 
-16: [W] Exposure to SARS-Cov 2 and coronavirus
-17: [P][R] Exposure to SARS-CoV-2 
-18: [P][R] Multisystem inflammatory syndrome (MIS) 
-22: [W] SARS-CoV-2 testing
-29: [W] Autoimmune condition (FP)
-35: [W] Chronic kidney disease (FP)
-39: [W] End stage renal disease (FP)
-41: [W] Chronic kidney disease broad (FP)
-42: [W] End stage renal disease broad (FP)
-44: [P][R] COVID-19 
-45: [W] COVID-19 diagnosis with SARS-Cov-2 test (-3d to 3d)
-46: [W] COVID-19 diagnosis and SARS-CoV-2 test (1pos) within 3d
-47: [W] COVID-19 diagnosis and SARS-CoV-2 test (1pos) (0neg) within 3d
-48: [W] COVID-19 diagnosis and SARS-CoV-2 test (0pos upto 3d, 1neg within 3d)
-51: [W] SARS-CoV-2 test positive result
-52: [W] SARS-CoV-2 test negative result
-53: [W] SARS-CoV-2 test positive or negative result - keep persons with positive
-57: [P][R] Bleeding 
-59: [W] COVID-19 diagnosis with no SARS-CoV-2 test
-60: [W] SARS-CoV-2 test positive and negative result
-62: [P][R] Seizure related finding 
-65: [W] Acute pancreatitis with inpatient admission
-66: [W] Acute renal failure with inpatient admission
-67: [W] Hepatic failure with inpatient admission
-68: [W] Heart failure with inpatient admission
-69: [W] Angioedema with inpatient admission
-86: [W] SARS-CoV-2 test positive or negative result
-87: [W] SARS-CoV-2 test
-100: [P][R] Alzheimer's disease
-189: [P][R] Right upper quadrant pain 
-190: [P][R] Swollen abdomen 
-226: [P][R] Drug reaction with eosinophilia and systemic symptoms 
-231: [P][R] Erythema multiforme 
-238: [P][R] Optic neuritis 
-241: [P][R] Urticaria 
-327: [P][R] Pharyngitis 
-330: [P][R] Abdominal bloating 
-339: [P][R] Low blood pressure 
-342: [P][R] Urinary incontinence
-348: [P][R] Blood in urine 
-350: [P][R] Hemoptysis
-352: [P][R] Inflamed tonsils 
-353: [P][R] Conjunctivitis 
-357: [P][R] Pulmonary edema 
-361: [P][R] Restless legs 
-363: [P][R] Joint stiffness 
-364: [P][R] Sleep disorder 
-368: [P][R] Sinusitis 
-369: [P][R] Allergic condition 
-374: [P][R] Drug dependence 
-376: [P][R] Bleeding skin 
-377: [P][R] Petechiae 
-378: [P][R] Purpuric disorder 
-380: [P][R] Jaundice 
-384: [P][R] Contact dermatitis 
-385: [P][R] Intertrigo 
-386: [P][R] Seborrheic dermatitis 
-387: [P][R] Photodermatitis 
-388: [P][R] Peripheral neuritis 
-396: [P][R] Osteoarthritis 
-397: [P][R] Hyperplasia of prostate 
-399: [P][R] Urolithiasis 
-400: [P][R] Malignant tumor of prostate 
-406: [P][R] Intellectual disability 
-407: [P][R] Hemorrhoids 
-415: [P][R] Erythema of skin 
-444: [P][R] Neck pain
-445: [P][R] Hypoglycemia
-446: [P][R] Eosinophilic esophagitis
-447: [P][R] Esophagitis
-448: [P][R] Dysphagia
-449: [P][R] Nausea
-450: [P][R] Constipation
-451: [P][R] Myasthenia gravis
-452: [P][R] Joint pain
-453: [P][R] Osteoarthritis
-454: [P][R] Dermatomyositis
-455: [P][R] Fetal growth restriction
-456: [P][R] Osteoporosis
-457: [P][R] Rheumatoid arthritis
-458: [P][R] Ulcerative colitis
-459: [P][R] Urinary tract infectious disease
-460: [P][R] Psoriasis with arthropathy
-461: [P][R] Erythema multiforme
-462: [P][R] Lichen planus
-463: [P][R] Sepsis
-464: [P][R] Myelofibrosis
-465: [P][R] Thyroiditis
-466: [P][R] Atopic dermatitis
-467: [P][R] Systemic sclerosis
-468: [P][R] Pityriasis rubra pilaris
-469: [P][R] Jaundice
-470: [P][R] Chronic lymphoid leukemia, disease
-471: [P][R] Vitiligo
-472: [P][R] Myelodysplastic syndrome (clinical)
-473: [P][R] Acute transverse myelitis
-474: [P][R] Pemphigoid
-475: [P][R] Psoriasis
-476: [P][R] Acute myeloid leukemia, disease
-477: [P][R] Hypothyroidism
-478: [P][R] Malignant melanoma of skin
-479: [P][R] Chilblains
-480: [P][R] Alopecia areata
-481: [P][R] Renal failure syndrome
-482: [P][R] Gastrointestinal hemorrhage
-483: [P][R] Biliary cirrhosis
-484: [P][R] End-stage renal disease
-485: [P][R] Low back pain
-486: [P][R] Premature rupture of membranes
-487: [P][R] Celiac disease
-488: [P][R] Diarrhea
-489: [P][R] Acute renal failure syndrome
-490: [P][R] Viral hepatitis C
-491: [P][R] Malignant tumor of urinary bladder
-492: [P][R] Cardiogenic shock
-493: [P][R] Malignant tumor of cervix
-494: [P][R] Primary malignant neoplasm of kidney
-495: [P][R] Acute pancreatitis
-496: [P][R] Abdominal pain
-497: [P][R] Autoimmune hepatitis
-498: [P][R] Toxic shock syndrome
-499: [P][R] Type 1 diabetes mellitus
-500: [P][R] Gastritis
-501: [P][R] Crohn's disease
-502: [P][R] Kidney stone
-503: [P][R] Type 2 diabetes mellitus
-504: [P][R] Sj?gren's syndrome
-505: [P][R] Cough
-506: [P][R] Chronic obstructive lung disease
-507: [P][R] Pneumonia
-508: [P][R] Allergic rhinitis
-509: [P][R] Systemic lupus erythematosus
-510: [P][R] Acute myocardial infarction
-511: [P][R] Dyspnea
-512: [P][R] Thromboangiitis obliterans
-513: [P][R] Atrial fibrillation
-514: [P][R] Granulomatosis with polyangiitis
-515: [P][R] Sleep apnea
-516: [P][R] Thrombotic microangiopathy
-517: [P][R] Acute febrile mucocutaneous lymph node syndrome
-518: [P][R] Myocarditis
-519: [P][R] Heart failure
-520: [P][R] Hypertensive disorder
-521: [P][R] Asthma
-522: [P][R] Coronary arteriosclerosis
-523: [P][R] Arteriosclerotic vascular disease
-524: [P][R] Migraine
-525: [P][R] Gastroesophageal reflux disease
-526: [P][R] Orthostatic hypotension
-527: [P][R] Acute respiratory failure
-528: [P][R] Polyarteritis nodosa
-529: [P][R] Cardiac arrest
-530: [P][R] Peripheral vascular disease
-531: [P][R] Angina pectoris
-532: [P][R] Heart disease
-533: [P][R] Otitis media
-534: [P][R] Transient cerebral ischemia
-535: [P][R] Acute disseminated encephalomyelitis
-536: [P][R] Age related macular degeneration
-537: [P][R] Sensorineural hearing loss
-538: [P][R] Paralytic syndrome
-539: [P][R] Multiple sclerosis
-540: [P][R] Optic neuritis
-541: [P][R] Idiopathic peripheral neuropathy
-542: [P][R] Cerebral hemorrhage
-543: [P][R] Seizure
-544: [P][R] Encephalitis
-545: [P][R] Headache
-546: [P][R] Retinal detachment
-547: [P][R] Retinal disorder
-549: [P][R] Epilepsy
-550: [P][R] Chronic inflammatory demyelinating polyradiculoneuropathy
-551: [P][R] Microcephaly
-552: [P][R] Parkinson's disease
-553: [P][R] Cerebrovascular accident
-554: [P][R] Cerebrovascular disease
-555: [P][R] Blood coagulation disorder
-556: [P][R] Amyloidosis
-557: [P][R] Angioedema
-558: [P][R] Hyperlipidemia
-559: [P][R] Thrombocytopenic disorder
-560: [P][R] Pancytopenia
-561: [P][R] Myasthenic syndrome due to another disorder
-562: [P][R] Edema
-563: [P][R] Obesity
-564: [P][R] Hidradenitis
-565: [P][R] Tuberculosis
-566: [P][R] Kaposi's sarcoma (clinical)
-567: [P][R] B-cell lymphoma (clinical)
-568: [P][R] Hyperkalemia
-569: [P][R] Systemic inflammatory response syndrome
-570: [P][R] Leukopenia
-571: [P][R] Schizophrenia
-572: [P][R] Psychotic disorder
-573: [P][R] Chronic pain
-574: [P][R] Narcolepsy
-575: [P][R] Behcet's syndrome
-576: [P][R] Bipolar disorder
-577: [P][R] Posttraumatic stress disorder
-578: [P][R] Insomnia
-579: [P][R] Ankylosing spondylitis
-580: [P][R] Respiratory syncytial virus infection
-581: [P][R] Multiple myeloma
-582: [P][R] Bleeding
-583: [P][R] Glaucoma
-584: [P][R] Fever
-585: [P][R] Hypokalemia
-586: [P][R] Opioid dependence
-587: [P][R] Opioid abuse
-588: [P][R] Attention deficit hyperactivity disorder
-589: [P][R] Pre-eclampsia
-590: [P][R] Human immunodeficiency virus infection
-591: [P][R] Autism spectrum disorder
-592: [P][R] Anemia
-593: [P][R] Paralysis
-594: [P][R] Depressive disorder
-595: [P][R] Pulmonary embolism
-596: [P][R] Gout
-597: [P][R] Takayasu's disease
-598: [P][R] Methicillin resistant Staphylococcus aureus infection
-599: [P][R] Anaphylaxis
-600: [P][R] Open-angle glaucoma
-601: [P][R] Vomiting
-602: [P][R] Anxiety
-603: [P][R] Human papilloma virus infection
-604: [P][R] Cranial nerve disorder
-605: [P][R] Muscle pain
-606: [P][R] Stillbirth
-607: [P][R] Malignant tumor of stomach
-608: [P][R] Malignant neoplastic disease
-609: [P][R] Cerebral infarction
-610: [P][R] Eclampsia
-611: [P][R] Diabetic ketoacidosis
-612: [P][R] Acute tubular necrosis
-613: [P][R] Tachycardia
-614: [P][R] Venous thrombosis
-615: [P][R] Herpes simplex
-616: [P][R] Acute arthritis
-617: [P][R] Monoclonal gammopathy (clinical)
-618: [P][R] Pulmonary arterial hypertension
-619: [P][R] Gestational diabetes mellitus
-620: [P][R] Uveitis
-621: [P][R] Renal impairment
-622: [P][R] Non-Hodgkin's lymphoma (clinical)
-623: [P][R] Motor neuropathy with multiple conduction block
-624: [P][R] Primary sclerosing cholangitis
-625: [P][R] Pustular psoriasis
-626: [P][R] Cirrhosis of liver
-627: [P][R] Miscarriage
-628: [P][R] Fisher's syndrome
-629: [P][R] Inflammatory bowel disease
-630: [P][R] Facial palsy
-631: [P][R] Livebirth
-632: [P][R] Antiphospholipid syndrome
-633: [P][R] Waldenstr?m macroglobulinemia
-634: [P][R] Immunoglobulin A vasculitis
-635: [P][R] Ventricular tachycardia
-636: [P][R] Malignant tumor of breast
-637: [P][R] Peripheral ischemia
-638: [P][R] Neoplasm of thyroid gland
-639: [P][R] Deep venous thrombosis
-640: [P][R] Vasculitis
-641: [P][R] Pericarditis
-642: [P][R] Immune reconstitution syndrome
-643: [P][R] Follicular non-Hodgkin's lymphoma
-644: [P][R] Malignant tumor of prostate
-645: [P][R] Guillain-Barr? syndrome
-646: [P][R] Bradycardia
-647: [P][R] Retinopathy due to diabetes mellitus
-648: [P][R] Malignant tumor of colon
-649: [P][R] Malignant tumor of esophagus
-650: [P][R] Malignant tumor of ovary
-651: [P][R] Dementia
-652: [P][R] Vasculitis of the skin
-653: [P][R] Loss of sense of smell
-654: [P][R] Ischemic heart disease
-655: [P][R] Aseptic meningitis
-656: [P][R] Fatigue
-657: [P][R] Paresthesia
-658: [P][R] Hepatic failure
-659: [P][R] Malignant neoplasm of liver
-660: [P][R] Juvenile rheumatoid arthritis
-661: [P][R] Respiratory failure
-662: [P][R] Diverticulitis of large intestine
-663: [P][R] Influenza
-664: [P][R] Malaise
-665: [P][R] Suicidal thoughts
-666: [P][R] Type B viral hepatitis
-667: [P][R] Guttate psoriasis
-668: [P][R] SLE glomerulonephritis syndrome
-669: [P][R] Schizoaffective disorder
-670: [P][R] Temporal arteritis
-671: [P][R] Pregnant
-672: [P][R] Sense of smell impaired
-673: [P][R] Primary malignant neoplasm of respiratory tract
-674: [P][R] Degeneration of retina
-675: [P][R] Pulmonary hypertension
-676: [P][R] Necrosis of artery
-677: [P][R] Preterm labor with preterm delivery
-678: [P][R] COVID-19
-679: [P][R] Takotsubo cardiomyopathy
-680: [P][R] Mantle cell lymphoma
-681: [P][R] Malignant neoplasm of anorectum
-682: [P][R] Marginal zone lymphoma
-683: [P][R] Antineutrophil cytoplasmic antibody positive vasculitis
-684: [P][R] Sensory disorder of smell and/or taste
-685: [P][R] Cardiac arrhythmia
-686: [P][R] Fracture of bone of hip region
-687: [P][R] Chronic kidney disease
-688: [P][R] Death
-689: [P][R] Newborn death
-690: [P][R] Suicide
-695: [P][R] Optic nerve glioma
-696: [P][R] Neurofibromatosis type 2
-697: [P][R] Neurofibromatosis type 1
-698: [P][R] Neurofibromatosis syndrome
-699: [P][R] Major Depressive Disorder
-701: [P][R] Ascites
-709: [P][R] Chronic liver disease
-711: [P][R] Transplanted liver present
-714: [P][R] Endometriosis (clinical)
-794: [W] Hemorrhage of digestive system
+
2: [W] COVID-19 diagnosis or SARS-CoV-2 test (1pos)
+15: [P][R] Exposure to viral disease 
+16: [W] Exposure to SARS-Cov 2 and coronavirus
+17: [P][R] Exposure to SARS-CoV-2 
+18: [P][R] Multisystem inflammatory syndrome (MIS) 
+22: [W] SARS-CoV-2 testing
+29: [W] Autoimmune condition (FP)
+35: [W] Chronic kidney disease (FP)
+39: [W] End stage renal disease (FP)
+41: [W] Chronic kidney disease broad (FP)
+42: [W] End stage renal disease broad (FP)
+44: [P][R] COVID-19 
+45: [W] COVID-19 diagnosis with SARS-Cov-2 test (-3d to 3d)
+46: [W] COVID-19 diagnosis and SARS-CoV-2 test (1pos) within 3d
+47: [W] COVID-19 diagnosis and SARS-CoV-2 test (1pos) (0neg) within 3d
+48: [W] COVID-19 diagnosis and SARS-CoV-2 test (0pos upto 3d, 1neg within 3d)
+51: [W] SARS-CoV-2 test positive result
+52: [W] SARS-CoV-2 test negative result
+53: [W] SARS-CoV-2 test positive or negative result - keep persons with positive
+57: [P][R] Bleeding 
+59: [W] COVID-19 diagnosis with no SARS-CoV-2 test
+60: [W] SARS-CoV-2 test positive and negative result
+62: [P][R] Seizure related finding 
+65: [W] Acute pancreatitis with inpatient admission
+66: [W] Acute renal failure with inpatient admission
+67: [W] Hepatic failure with inpatient admission
+68: [W] Heart failure with inpatient admission
+69: [W] Angioedema with inpatient admission
+86: [W] SARS-CoV-2 test positive or negative result
+87: [W] SARS-CoV-2 test
+100: [P][R] Alzheimer's disease
+189: [P][R] Right upper quadrant pain 
+190: [P][R] Swollen abdomen 
+226: [P][R] Drug reaction with eosinophilia and systemic symptoms 
+231: [P][R] Erythema multiforme 
+238: [P][R] Optic neuritis 
+241: [P][R] Urticaria 
+327: [P][R] Pharyngitis 
+330: [P][R] Abdominal bloating 
+339: [P][R] Low blood pressure 
+342: [P][R] Urinary incontinence
+348: [P][R] Blood in urine 
+350: [P][R] Hemoptysis
+352: [P][R] Inflamed tonsils 
+353: [P][R] Conjunctivitis 
+357: [P][R] Pulmonary edema 
+361: [P][R] Restless legs 
+363: [P][R] Joint stiffness 
+364: [P][R] Sleep disorder 
+368: [P][R] Sinusitis 
+369: [P][R] Allergic condition 
+374: [P][R] Drug dependence 
+376: [P][R] Bleeding skin 
+377: [P][R] Petechiae 
+378: [P][R] Purpuric disorder 
+380: [P][R] Jaundice 
+384: [P][R] Contact dermatitis 
+385: [P][R] Intertrigo 
+386: [P][R] Seborrheic dermatitis 
+387: [P][R] Photodermatitis 
+388: [P][R] Peripheral neuritis 
+396: [P][R] Osteoarthritis 
+397: [P][R] Hyperplasia of prostate 
+399: [P][R] Urolithiasis 
+400: [P][R] Malignant tumor of prostate 
+406: [P][R] Intellectual disability 
+407: [P][R] Hemorrhoids 
+415: [P][R] Erythema of skin 
+444: [P][R] Neck pain
+445: [P][R] Hypoglycemia
+446: [P][R] Eosinophilic esophagitis
+447: [P][R] Esophagitis
+448: [P][R] Dysphagia
+449: [P][R] Nausea
+450: [P][R] Constipation
+451: [P][R] Myasthenia gravis
+452: [P][R] Joint pain
+453: [P][R] Osteoarthritis
+454: [P][R] Dermatomyositis
+455: [P][R] Fetal growth restriction
+456: [P][R] Osteoporosis
+457: [P][R] Rheumatoid arthritis
+458: [P][R] Ulcerative colitis
+459: [P][R] Urinary tract infectious disease
+460: [P][R] Psoriasis with arthropathy
+461: [P][R] Erythema multiforme
+462: [P][R] Lichen planus
+463: [P][R] Sepsis
+464: [P][R] Myelofibrosis
+465: [P][R] Thyroiditis
+466: [P][R] Atopic dermatitis
+467: [P][R] Systemic sclerosis
+468: [P][R] Pityriasis rubra pilaris
+469: [P][R] Jaundice
+470: [P][R] Chronic lymphoid leukemia, disease
+471: [P][R] Vitiligo
+472: [P][R] Myelodysplastic syndrome (clinical)
+473: [P][R] Acute transverse myelitis
+474: [P][R] Pemphigoid
+475: [P][R] Psoriasis
+476: [P][R] Acute myeloid leukemia, disease
+477: [P][R] Hypothyroidism
+478: [P][R] Malignant melanoma of skin
+479: [P][R] Chilblains
+480: [P][R] Alopecia areata
+481: [P][R] Renal failure syndrome
+482: [P][R] Gastrointestinal hemorrhage
+483: [P][R] Biliary cirrhosis
+484: [P][R] End-stage renal disease
+485: [P][R] Low back pain
+486: [P][R] Premature rupture of membranes
+487: [P][R] Celiac disease
+488: [P][R] Diarrhea
+489: [P][R] Acute renal failure syndrome
+490: [P][R] Viral hepatitis C
+491: [P][R] Malignant tumor of urinary bladder
+492: [P][R] Cardiogenic shock
+493: [P][R] Malignant tumor of cervix
+494: [P][R] Primary malignant neoplasm of kidney
+495: [P][R] Acute pancreatitis
+496: [P][R] Abdominal pain
+497: [P][R] Autoimmune hepatitis
+498: [P][R] Toxic shock syndrome
+499: [P][R] Type 1 diabetes mellitus
+500: [P][R] Gastritis
+501: [P][R] Crohn's disease
+502: [P][R] Kidney stone
+503: [P][R] Type 2 diabetes mellitus
+504: [P][R] Sj?gren's syndrome
+505: [P][R] Cough
+506: [P][R] Chronic obstructive lung disease
+507: [P][R] Pneumonia
+508: [P][R] Allergic rhinitis
+509: [P][R] Systemic lupus erythematosus
+510: [P][R] Acute myocardial infarction
+511: [P][R] Dyspnea
+512: [P][R] Thromboangiitis obliterans
+513: [P][R] Atrial fibrillation
+514: [P][R] Granulomatosis with polyangiitis
+515: [P][R] Sleep apnea
+516: [P][R] Thrombotic microangiopathy
+517: [P][R] Acute febrile mucocutaneous lymph node syndrome
+518: [P][R] Myocarditis
+519: [P][R] Heart failure
+520: [P][R] Hypertensive disorder
+521: [P][R] Asthma
+522: [P][R] Coronary arteriosclerosis
+523: [P][R] Arteriosclerotic vascular disease
+524: [P][R] Migraine
+525: [P][R] Gastroesophageal reflux disease
+526: [P][R] Orthostatic hypotension
+527: [P][R] Acute respiratory failure
+528: [P][R] Polyarteritis nodosa
+529: [P][R] Cardiac arrest
+530: [P][R] Peripheral vascular disease
+531: [P][R] Angina pectoris
+532: [P][R] Heart disease
+533: [P][R] Otitis media
+534: [P][R] Transient cerebral ischemia
+535: [P][R] Acute disseminated encephalomyelitis
+536: [P][R] Age related macular degeneration
+537: [P][R] Sensorineural hearing loss
+538: [P][R] Paralytic syndrome
+539: [P][R] Multiple sclerosis
+540: [P][R] Optic neuritis
+541: [P][R] Idiopathic peripheral neuropathy
+542: [P][R] Cerebral hemorrhage
+543: [P][R] Seizure
+544: [P][R] Encephalitis
+545: [P][R] Headache
+546: [P][R] Retinal detachment
+547: [P][R] Retinal disorder
+549: [P][R] Epilepsy
+550: [P][R] Chronic inflammatory demyelinating polyradiculoneuropathy
+551: [P][R] Microcephaly
+552: [P][R] Parkinson's disease
+553: [P][R] Cerebrovascular accident
+554: [P][R] Cerebrovascular disease
+555: [P][R] Blood coagulation disorder
+556: [P][R] Amyloidosis
+557: [P][R] Angioedema
+558: [P][R] Hyperlipidemia
+559: [P][R] Thrombocytopenic disorder
+560: [P][R] Pancytopenia
+561: [P][R] Myasthenic syndrome due to another disorder
+562: [P][R] Edema
+563: [P][R] Obesity
+564: [P][R] Hidradenitis
+565: [P][R] Tuberculosis
+566: [P][R] Kaposi's sarcoma (clinical)
+567: [P][R] B-cell lymphoma (clinical)
+568: [P][R] Hyperkalemia
+569: [P][R] Systemic inflammatory response syndrome
+570: [P][R] Leukopenia
+571: [P][R] Schizophrenia
+572: [P][R] Psychotic disorder
+573: [P][R] Chronic pain
+574: [P][R] Narcolepsy
+575: [P][R] Behcet's syndrome
+576: [P][R] Bipolar disorder
+577: [P][R] Posttraumatic stress disorder
+578: [P][R] Insomnia
+579: [P][R] Ankylosing spondylitis
+580: [P][R] Respiratory syncytial virus infection
+581: [P][R] Multiple myeloma
+582: [P][R] Bleeding
+583: [P][R] Glaucoma
+584: [P][R] Fever
+585: [P][R] Hypokalemia
+586: [P][R] Opioid dependence
+587: [P][R] Opioid abuse
+588: [P][R] Attention deficit hyperactivity disorder
+589: [P][R] Pre-eclampsia
+590: [P][R] Human immunodeficiency virus infection
+591: [P][R] Autism spectrum disorder
+592: [P][R] Anemia
+593: [P][R] Paralysis
+594: [P][R] Depressive disorder
+595: [P][R] Pulmonary embolism
+596: [P][R] Gout
+597: [P][R] Takayasu's disease
+598: [P][R] Methicillin resistant Staphylococcus aureus infection
+599: [P][R] Anaphylaxis
+600: [P][R] Open-angle glaucoma
+601: [P][R] Vomiting
+602: [P][R] Anxiety
+603: [P][R] Human papilloma virus infection
+604: [P][R] Cranial nerve disorder
+605: [P][R] Muscle pain
+606: [P][R] Stillbirth
+607: [P][R] Malignant tumor of stomach
+608: [P][R] Malignant neoplastic disease
+609: [P][R] Cerebral infarction
+610: [P][R] Eclampsia
+611: [P][R] Diabetic ketoacidosis
+612: [P][R] Acute tubular necrosis
+613: [P][R] Tachycardia
+614: [P][R] Venous thrombosis
+615: [P][R] Herpes simplex
+616: [P][R] Acute arthritis
+617: [P][R] Monoclonal gammopathy (clinical)
+618: [P][R] Pulmonary arterial hypertension
+619: [P][R] Gestational diabetes mellitus
+620: [P][R] Uveitis
+621: [P][R] Renal impairment
+622: [P][R] Non-Hodgkin's lymphoma (clinical)
+623: [P][R] Motor neuropathy with multiple conduction block
+624: [P][R] Primary sclerosing cholangitis
+625: [P][R] Pustular psoriasis
+626: [P][R] Cirrhosis of liver
+627: [P][R] Miscarriage
+628: [P][R] Fisher's syndrome
+629: [P][R] Inflammatory bowel disease
+630: [P][R] Facial palsy
+631: [P][R] Livebirth
+632: [P][R] Antiphospholipid syndrome
+633: [P][R] Waldenstr?m macroglobulinemia
+634: [P][R] Immunoglobulin A vasculitis
+635: [P][R] Ventricular tachycardia
+636: [P][R] Malignant tumor of breast
+637: [P][R] Peripheral ischemia
+638: [P][R] Neoplasm of thyroid gland
+639: [P][R] Deep venous thrombosis
+640: [P][R] Vasculitis
+641: [P][R] Pericarditis
+642: [P][R] Immune reconstitution syndrome
+643: [P][R] Follicular non-Hodgkin's lymphoma
+644: [P][R] Malignant tumor of prostate
+645: [P][R] Guillain-Barr? syndrome
+646: [P][R] Bradycardia
+647: [P][R] Retinopathy due to diabetes mellitus
+648: [P][R] Malignant tumor of colon
+649: [P][R] Malignant tumor of esophagus
+650: [P][R] Malignant tumor of ovary
+651: [P][R] Dementia
+652: [P][R] Vasculitis of the skin
+653: [P][R] Loss of sense of smell
+654: [P][R] Ischemic heart disease
+655: [P][R] Aseptic meningitis
+656: [P][R] Fatigue
+657: [P][R] Paresthesia
+658: [P][R] Hepatic failure
+659: [P][R] Malignant neoplasm of liver
+660: [P][R] Juvenile rheumatoid arthritis
+661: [P][R] Respiratory failure
+662: [P][R] Diverticulitis of large intestine
+663: [P][R] Influenza
+664: [P][R] Malaise
+665: [P][R] Suicidal thoughts
+666: [P][R] Type B viral hepatitis
+667: [P][R] Guttate psoriasis
+668: [P][R] SLE glomerulonephritis syndrome
+669: [P][R] Schizoaffective disorder
+670: [P][R] Temporal arteritis
+671: [P][R] Pregnant
+672: [P][R] Sense of smell impaired
+673: [P][R] Primary malignant neoplasm of respiratory tract
+674: [P][R] Degeneration of retina
+675: [P][R] Pulmonary hypertension
+676: [P][R] Necrosis of artery
+677: [P][R] Preterm labor with preterm delivery
+678: [P][R] COVID-19
+679: [P][R] Takotsubo cardiomyopathy
+680: [P][R] Mantle cell lymphoma
+681: [P][R] Malignant neoplasm of anorectum
+682: [P][R] Marginal zone lymphoma
+683: [P][R] Antineutrophil cytoplasmic antibody positive vasculitis
+684: [P][R] Sensory disorder of smell and/or taste
+685: [P][R] Cardiac arrhythmia
+686: [P][R] Fracture of bone of hip region
+687: [P][R] Chronic kidney disease
+688: [P][R] Death
+689: [P][R] Newborn death
+690: [P][R] Suicide
+695: [P][R] Optic nerve glioma
+696: [P][R] Neurofibromatosis type 2
+697: [P][R] Neurofibromatosis type 1
+698: [P][R] Neurofibromatosis syndrome
+699: [P][R] Major Depressive Disorder
+701: [P][R] Ascites
+709: [P][R] Chronic liver disease
+711: [P][R] Transplanted liver present
+714: [P][R] Endometriosis (clinical)
+794: [W] Hemorrhage of digestive system

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 14 were added.

-
1093: [P] Abdominal Aoritc Aneurysm repair - post op new Afib (any)
-1094: [P] Lower Extremity Bypass - post op new Afib (any)
-1095: [P] Carotid Endarterectomy - post op new Afib (any)
-1096: [P] Lung Resection - post op new Afib (any)
-1097: [P] Esophagectomy - post op new Afib (any)
-1098: [P] Pancreatectomy - post op new Afib (any)
-1099: [P] Colectomy - post op new Afib (any)
-1100: [P] Cystectomy - post op new Afib (any)
-1101: [P] Nephrectomy - post op new Afib (any)
-1102: [P] Coronary Artery Bypass Graft Surgery - post op new Afib (any)
-1103: [P] Aortic or Mitral Valve Repair or Replacement - post op new Afib (any)
-1104: [P] RBC Transfusion (adult relevant, no auto 1yr clean window)
-1105: [P] Clostridium difficile - first episode
-1106: [P] Non-Emergent Major Non Cardiac Surgery no prior Opioid
+
1093: [P] Abdominal Aoritc Aneurysm repair - post op new Afib (any)
+1094: [P] Lower Extremity Bypass - post op new Afib (any)
+1095: [P] Carotid Endarterectomy - post op new Afib (any)
+1096: [P] Lung Resection - post op new Afib (any)
+1097: [P] Esophagectomy - post op new Afib (any)
+1098: [P] Pancreatectomy - post op new Afib (any)
+1099: [P] Colectomy - post op new Afib (any)
+1100: [P] Cystectomy - post op new Afib (any)
+1101: [P] Nephrectomy - post op new Afib (any)
+1102: [P] Coronary Artery Bypass Graft Surgery - post op new Afib (any)
+1103: [P] Aortic or Mitral Valve Repair or Replacement - post op new Afib (any)
+1104: [P] RBC Transfusion (adult relevant, no auto 1yr clean window)
+1105: [P] Clostridium difficile - first episode
+1106: [P] Non-Emergent Major Non Cardiac Surgery no prior Opioid
@@ -833,343 +880,343 @@

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 20 were added.

-
1072: [P] CMV Anterior Uveitis
-1073: [P] Serious Infection, opportunistic infections and other infections of interest event
-1074: [P] Serious Infection
-1075: [P] FDA AESI Narcolepsy
-1076: [P] FDA AESI Anaphylaxis
-1077: [P] FDA AESI Anaphylaxis v2
-1078: [P] FDA AESI Bells Palsy
-1079: [P] FDA AESI Encephalomyelitis
-1080: [P] FDA AESI Guillain Barre Syndrome
-1081: [P] FDA AESI Acute Myocardial Infarction
-1082: [P] FDA AESI Myocarditis Pericarditis
-1083: [P] FDA AESI Immune Thrombocytopenia (ITP)
-1084: [P] FDA AESI Disseminated Intravascular Coagulation
-1085: [P] FDA AESI Appendicitis
-1086: [P] FDA AESI Transverse Myelitis
-1087: [P] FDA AESI Hemorrhagic Stroke
-1088: [P] FDA AESI Deep Vein Thrombosis (DVT)
-1089: [P] FDA AESI Non-hemorrhagic Stroke
-1090: [P] FDA AESI Pulmonary Embolism
-1091: [P] FDA AESI Thrombosis with Thrombocytopenia (TWT)
+
1072: [P] CMV Anterior Uveitis
+1073: [P] Serious Infection, opportunistic infections and other infections of interest event
+1074: [P] Serious Infection
+1075: [P] FDA AESI Narcolepsy
+1076: [P] FDA AESI Anaphylaxis
+1077: [P] FDA AESI Anaphylaxis v2
+1078: [P] FDA AESI Bells Palsy
+1079: [P] FDA AESI Encephalomyelitis
+1080: [P] FDA AESI Guillain Barre Syndrome
+1081: [P] FDA AESI Acute Myocardial Infarction
+1082: [P] FDA AESI Myocarditis Pericarditis
+1083: [P] FDA AESI Immune Thrombocytopenia (ITP)
+1084: [P] FDA AESI Disseminated Intravascular Coagulation
+1085: [P] FDA AESI Appendicitis
+1086: [P] FDA AESI Transverse Myelitis
+1087: [P] FDA AESI Hemorrhagic Stroke
+1088: [P] FDA AESI Deep Vein Thrombosis (DVT)
+1089: [P] FDA AESI Non-hemorrhagic Stroke
+1090: [P] FDA AESI Pulmonary Embolism
+1091: [P] FDA AESI Thrombosis with Thrombocytopenia (TWT)

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 37 were added.

-
1035: [P] New users of Thiazide diuretics
-1036: [P] New users of Beta blockers
-1037: [P] New users of SGLT2 inhibitor
-1038: [P] New users of GLP-1 receptor antagonists
-1039: [P] New users of DPP-4 inhibitors
-1040: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors
-1041: [P] New users of JAK inhibitors
-1042: [P] New users of IL-23 inhibitors
-1043: [P] New users of Fluoroquinolone systemic
-1044: [P] New users of Cephalosporin systemetic
-1045: [P] New users of Trimethoprim systemetic
-1046: [P] New users of Thiazide diuretics nested in essential hypertension
-1047: [P] New users of dihydropyridine calcium channel blockers nested in essential hypertension
-1048: [P] New users of dihydropyridine calcium channel blockers
-1049: [P] New users of Beta blockers nested in essential hypertension
-1050: [P] New users of Beta blockers nested in Left Heart Failure
-1051: [P] New users of SGLT2 inhibitor nested in Left Heart Failure
-1052: [P] New users of Beta blockers nested in Acute Myocardial Infarction
-1053: [P] New users of GLP-1 receptor antagonists nested in Type 2 diabetes mellitus
-1054: [P] New users of SGLT2 inhibitor nested in Type 2 diabetes mellitus
-1055: [P] New users of DPP-4 inhibitors nested in Type 2 diabetes mellitus
-1056: [P] New users of GLP-1 receptor antagonists nested in obesity
-1057: [P] New users of IL-23 inhibitors nested in Plaque psoriasis
-1058: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Plaque psoriasis
-1059: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Psoriatic Arthritis
-1060: [P] New users of Fluoroquinolone systemic nested in Urinary Tract Infection
-1061: [P] New users of Cephalosporin systemetic nested in Urinary Tract Infection
-1062: [P] New users of Trimethoprim systemetic nested in Urinary Tract Infection
-1063: [P] New users of Fluoroquinolone systemic nested in Acute Typical Pneumonia
-1064: [P] New users of Cephalosporin systemetic nested in Acute Typical Pneumonia
-1065: [P] New users of Trimethoprim systemetic nested in Acute Typical Pneumonia
-1066: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Rheumatoid arthritis
-1067: [P] New users of JAK inhibitors nested in Ulcerative colitis
-1068: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Ulcerative colitis
-1069: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Crohns disease
-1070: [P] New users of JAK inhibitors nested in Rheumatoid arthritis
-1071: [P] persons at risk at start of year 2012-2022 with 365d prior observation
+
1035: [P] New users of Thiazide diuretics
+1036: [P] New users of Beta blockers
+1037: [P] New users of SGLT2 inhibitor
+1038: [P] New users of GLP-1 receptor antagonists
+1039: [P] New users of DPP-4 inhibitors
+1040: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors
+1041: [P] New users of JAK inhibitors
+1042: [P] New users of IL-23 inhibitors
+1043: [P] New users of Fluoroquinolone systemic
+1044: [P] New users of Cephalosporin systemetic
+1045: [P] New users of Trimethoprim systemetic
+1046: [P] New users of Thiazide diuretics nested in essential hypertension
+1047: [P] New users of dihydropyridine calcium channel blockers nested in essential hypertension
+1048: [P] New users of dihydropyridine calcium channel blockers
+1049: [P] New users of Beta blockers nested in essential hypertension
+1050: [P] New users of Beta blockers nested in Left Heart Failure
+1051: [P] New users of SGLT2 inhibitor nested in Left Heart Failure
+1052: [P] New users of Beta blockers nested in Acute Myocardial Infarction
+1053: [P] New users of GLP-1 receptor antagonists nested in Type 2 diabetes mellitus
+1054: [P] New users of SGLT2 inhibitor nested in Type 2 diabetes mellitus
+1055: [P] New users of DPP-4 inhibitors nested in Type 2 diabetes mellitus
+1056: [P] New users of GLP-1 receptor antagonists nested in obesity
+1057: [P] New users of IL-23 inhibitors nested in Plaque psoriasis
+1058: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Plaque psoriasis
+1059: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Psoriatic Arthritis
+1060: [P] New users of Fluoroquinolone systemic nested in Urinary Tract Infection
+1061: [P] New users of Cephalosporin systemetic nested in Urinary Tract Infection
+1062: [P] New users of Trimethoprim systemetic nested in Urinary Tract Infection
+1063: [P] New users of Fluoroquinolone systemic nested in Acute Typical Pneumonia
+1064: [P] New users of Cephalosporin systemetic nested in Acute Typical Pneumonia
+1065: [P] New users of Trimethoprim systemetic nested in Acute Typical Pneumonia
+1066: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Rheumatoid arthritis
+1067: [P] New users of JAK inhibitors nested in Ulcerative colitis
+1068: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Ulcerative colitis
+1069: [P] New users of Tumor Necrosis Factor alpha (TNFa) inhibitors nested in Crohns disease
+1070: [P] New users of JAK inhibitors nested in Rheumatoid arthritis
+1071: [P] persons at risk at start of year 2012-2022 with 365d prior observation

This release includes the bulk of the cohorts submitted to the OHDSI PhenotypeLibrary in the month of September 2023, as part of the push for HowOften.

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 252 were added.

-
311: [P] Parasomnia
-742: [P] Parasomnia or Sleep dysfunction with arousal disturbance
-743: [P] Diabetic ketoacidosis IP-ER (SNOMED concept)
-744: [P] Pulmonary Hypertension
-745: [P] Inflammatory Bowel Disease
-746: [P] Chronic Thromboembolic Pulmonary Hypertension
-747: [P] Pulmonary Arterial Hypertension
-748: [P] Psoriatic arthritis
-749: [P] Plaque Psoriasis
-750: [P] Pulmonary hypertension associated with left heart disease (WHO Group 2)
-751: [P] Pulmonary hypertension associated with lung diseases and or hypoxia (WHO Group 3)
-752: [P] Firearm Accidents (FA)
-753: [P] Motor Vehicle Accidents (MVA)
-754: [P] Down Syndrome
-755: [P] Non-infectious uveitis and iridocyclitis
-756: [P] Cystic Fibrosis
-757: [P] Concomitant TNF - alpha Inhibitors and IL23 Inhibitors - GE 30D overlap
-759: [P] Concomitant TNF - alpha Inhibitors and IL12_23 Inhibitors - GE 30D overlap
-760: [P] Concomitant IL 23 Inhibitors and IL12_23 Inhibitors - GE 30D overlap
-761: [P] Pulmonary arterial hypertension with Prior Left Heart or Vice Versa
-762: [P] Endothelin receptor antagonists
-763: [P] Phosphodiesterase 5 inhibitors and guanylate cyclase stimulators
-764: [P] Prostacyclin analogues and prostacyclin receptor agonists
-765: [P] Earliest event of Left Heart Failure
-766: [P] Earliest event of Right Heart Failure
-767: [P] Earliest event of Sarcoidosis
-768: [P] Earliest event of Sickle Cell Anemia
-769: [P] Scleroderma, first occurrence
-770: [P] Essential Hypertension, first occurrence
-771: [P] Pulmonary Hypertension (Group 2 Left heart disease, encompassing)
-772: [P] Pulmonary Hypertension (Group 3 Chronic lung disease, encompassing)
-773: [P] Congenital Heart Disease
-774: [P] Portal Hypertension, first occurrence
-775: [P] First Inflammatory Bowel Disease
-776: [P] Antisynthetase syndrome
-777: [P] Mixed connective tissue disease
-778: [P] Undifferentiated connective tissue disease
-779: [P] Overlap syndrome
-780: [P] Raynaud?s disease or Raynaud's phenomenon
-781: [P] Antiphospholipid syndrome
-782: [P] CTEPH Prevalent (with Echo or RHC) with 2nd dx code 31-365 days after first dx
-783: [P] Pulmonary endarterectomy
-784: [P] Balloon Pulmonary Angioplasty
-785: [P] Skin Burns
-786: [P] Non-small cell lung cancer (NSCLC)
-787: [P] Lung cancer
-788: [P] Breast cancer
-789: [P] Glioblastoma multiforme (GBM)
-790: [P] Colorectal Cancer
-791: [P] Multiple Myeloma
-792: [P] Metastatic Hormone-Sensitive Prostate Cancer Synchronous
-793: [P] Metastatic Hormone-Sensitive Prostate Cancer Metachronus
-794: COPY OF [P][R] Bleeding
-795: [P] Antineoplastic drugs against colorectal cancer
-796: [P] Potential curative surgery for colorectal cancer
-797: [P] Radiotherapy against colorectal cancer
-798: [P] Primary adenocarcinoma of the colon or rectum
-802: [P] Acute Respiratory Failure 2
-803: [P] Fascial dehiscence and evisceration
-804: [P] Anastomotic leak or dehiscence
-805: [P] Intestinal obstruction (broad)
-806: [P] Intraabdominal abscess
-807: [P] Perioperative aspiration
-808: [P] Postoperative hemorrhage
-809: [P] Surgical wound infection (narrow)
-810: [P] Distant metastasis following colorectal cancer (wide)
-811: [P] Local recurrence after colorectal cancer
-812: [P] Primary adenocarcinoma of the colon or rectum, MSI-H or dMMR, no surgery or oncological treatment
-813: [P] Primary adenocarcinoma of the colon or rectum treated with potentially curative surgery
-814: [P] Primary adenocarcinoma of the colon or rectum, no curative intended surgery and oncological treatment
-817: [P] Primary adenocarcinoma of the colon or rectum, no curative intended surgery and oncological treatment2
-818: [P] Primary adenocarcinoma of the colon or rectum, MSI-L, MSI-indeterminate, MSS or pMMR
-819: [P] Primary adenocarcinoma of the colon or rectum, MSI-L, MSI-indeterminate, MSS or pMMR, treated with curative intended surgery
-820: [P] Primary adenocarcinoma of the colon or rectum, MSI-L, MSI-indeterminate, MSS or pMMR, oncological treatment, no curative surgery
-821: [P] Primary adenocarcinoma of the colon or rectum, MSI-L, MSI-indeterminate, MSS or pMMR, no surgery or oncological treatment
-822: [P] Primary adenocarcinoma of colon or rectum, MSI-H or dMMR, surgical treatment
-823: [P] Primary adenocarcinoma of colon or rectum, MSI-H or dMMR, oncological treatment no surgery
-824: [P] Primary adenocarcinoma of colon or rectum,  MSI-H or dMMR
-825: [P] Primary adenocarcinoma of colon
-826: [P] Primary adenocarcinoma of colon, no surgery or oncological treatment
-827: [P] Primary adenocarcinoma of colon surgical treatment
-828: [P] Primary adenocarcinoma of colon oncological treatment, no surgery
-829: [P] Primary adenocarcinoma of colon, MSI-L, MSI-indeterminate, MSS or pMMR
-830: [P] Primary adenocarcinoma of colon, MSI-L, MSI-indeterminate, MSS or pMMR, surgically treated
-831: [P] Primary adenocarcinoma of colon MSI-L, MSI-indeterminate, MSS or pMMR, oncological treatment, no surgery
-832: [P] Primary adenocarcinoma of colon MSI-L, MSI-indeterminate, MSS or pMMR, no surgery or oncological treatment
-833: [P] Primary adenocarcinoma of colon MSI-H or dMMR
-834: [P] Primary adenocarcinoma of colon MSI-H or dMMR, surgical treatment
-835: [P] Primary adenocarcinoma of colon MSI-H or dMMR, oncological treatment, no surgery
-836: [P] Primary adenocarcinoma of colon MSI-H or dMMR, no surgery or oncological treatment
-837: [P] Primary adenocarcinoma of rectum
-838: [P] Primary adenocarcinoma of rectum MSI-H or dMMR
-839: [P] Primary adenocarcinoma of rectum, MSI-H or dMMR, no surgery or oncological treatment
-840: [P] Primary adenocarcinoma of rectum MSI-H or dMMR, oncological treatment, no surgery
-841: [P] Primary adenocarcinoma of rectum, MSI-H or dMMR, surgical treatment
-842: [P] Primary adenocarcinoma of rectum, MSI-L, MSI-indeterminate, MSS or pMMR
-843: [P] Primary adenocarcinoma of rectum MSI-L, MSI-indeterminate, MSS or pMMR, oncological treatment,  no surgery
-844: [P] Primary adenocarcinoma of rectum MSI-L, MSI-indeterminate, MSS or pMMR, no surgery and no oncological treatment
-845: [P] Primary adenocarcinoma of rectum MSI-L, MSI-indeterminate, MSS or pMMR, treated with potentially curative surgery
-846: [P] Primary adenocarcinoma of rectum oncological treatment, no surgery
-847: [P] Primary adenocarcinoma of rectum surgical treatment
-848: [P] Primary adenocarcinoma of rectum, no surgery or oncological treatment
-850: [P] Intestinal obstruction (broad 2)
-851: [P] Intraabdominal obstruction (broad)
-852: [P] Surgical wound infection (broad)
-854: [P] Distant metastasis following colorectal cancer (medium)
-855: [P] Distant metastasis following colorectal cancer (narrow)
-856: [P] Earliest event of Migraine, including history of migraine
-857: [P] Earliest event of Migraine
-858: [P] Earliest event of Rheumatoid Arthritis
-859: [P] Earliest event of Crohns disease
-860: [P] Earliest event of Ulcerative colitis
-861: [P] Earliest event of Urinary tract infections (UTI)
-862: [P] Earliest event of Alzheimer's disease derived from Imfeld, 2
-863: [P] Cognitive impairment, incident
-864: [P] Earliest event of Dementia
-865: [P] Non-Emergent Major Non Cardiac Surgery
-866: [P] AAA repair
-867: [P] Lower Extremity Bypass
-868: [P] Carotid Endarterectomy
-869: [P] Lung Resection
-870: [P] Esophagectomy
-871: [P] Pancreatectomy
-872: [P] Colectomy
-873: [P] Cystectomy
-874: [P] Nephrectomy
-875: [P] Coronary Artery Bypass Graft Surgery
-876: [P] Aortic or Mitral Valve Repair or Replacement
-877: [P] Non-Emergent MNCS (age 18 or greater), post op Afib (parox)
-878: [P] Non-Emergent MNCS (age 18 or greater), post op Afib (any)
-879: Cxxx Endometriosis indexed on procedure with two or more diagnosis among females 15 to 49
-881: [P] Acute myocardial infarction
-882: [P] Decreased libido
-884: [P] Diarrhea2
-888: [P] Gastrointestinal bleeding
-889: [P] Hyponatremia
-890: [P] Hypotension
-891: [P] Nausea
-892: [P] Stroke
-893: [P] Vertigo
-894: [P] Abdominal pain
-895: [P] Abnormal weight gain
-896: [P] Abnormal weight loss
-898: [P] Acute renal failure
-899: [P] All-cause mortality
-900: [P] Anaphylactoid reaction
-901: [P] Anemia
-907: [P] All-cause mortality2
-910: [P] Anaphylactoid reaction2
-913: [P] Anemia2
-916: [P] Angioedema2
-917: [P] Anxiety
-918: [P] Bradycardia
-919: [P] Cardiac arrhythmia
-920: [P] Cardiovascular disease
-921: [P] Cardiovascular-related mortality
-922: [P] Chest pain or angina
-923: [P] Kidney disease
-924: [P] Coronary heart disease
-925: [P] Cough
-927: [P] Dementia2
-928: [P] Depression2
-929: [P] Edema2
-930: [P] End stage renal disease2
-931: [P] Fall2
-932: [P] Gout2
-933: [P] Headache2
-934: [P] Heart failure2
-935: [P] Hemorrhagic stroke2
-936: [P] Hepatic failure2
-937: [P] Hospitalization with heart failure2
-938: [P] Hospitalization with heart failure
-939: [P] Hospitalization with preinfarction syndrome
-940: [P] Hyperkalemia
-941: [P] Hypokalemia
-942: [P] Hypomagnesemia
-943: [P] Impotence
-944: [P] Ischemic stroke
-945: [P] Malignant neoplasm
-946: [P] Measured renal dysfunction
-947: [P] Neutropenia or agranulocytosis
-948: [P] Rash
-950: [P] Rhabdomyolysis2
-953: [P] Sudden cardiac death
-954: [P] Syncope
-955: [P] Thrombocytopenia
-956: [P] Transient ischemic attack
-957: [P] Type 2 diabetes mellitus
-958: [P] Syncope3
-959: [P] Thrombocytopenia3
-960: [P] Transient ischemic attack3
-961: [P] Type 2 diabetes mellitus3
-963: [P] Vomiting
-964: [P] Chronic kidney disease
-965: [P] 3-point MACE
-967: [P] 4-point MACE
-969: [P] Acute myocardial infarction2
-970: [P] 4-point MACE2
-975: [P] Acute renal failure2
-976: [P] Glycemic control2
-979: [P] Hospitalization with heart failure3
-980: [P] Revascularization
-982: [P] Stroke2
-983: [P] Sudden cardiac death2
-984: [P] Abnormal weight gain2
-985: [P] Abnormal weight loss2
-986: [P] Acute pancreatitis2
-988: [P] All-cause mortality3
-989: [P] Bladder cancer3
-990: [P] Bone fracture3
-991: [P] Breast cancer3
-992: [P] Diabetic ketoacidosis3
-993: [P] Diarrhea3
-994: [P] Genitourinary infection3
-995: [P] Hyperkalemia3
-996: [P] Hypoglycemia3
-997: [P] Hypotension3
-998: [P] Joint pain3
-999: [P] Lower extremity amputation3
-1000: [P] Nausea3
-1001: [P] Peripheral edema3
-1002: [P] Photosensitivity3
-1003: [P] Renal cancer3
-1004: [P] Thyroid tumor3
-1005: [P] Venous thromboembolism3
-1006: [P] Vomiting3
-1007: [P] Earliest event of Epilepsy
-1009: [P] Earliest event of Treatment resistant depression (TRD)
-1010: [P] Earliest event of Chronic Graft Versus Host Disease (GVHD)
-1011: [P] Earliest event of Marginal zone lymphoma
-1012: [P] Earliest event of Waldenstrom macroglobulinemia
-1013: [P] Earliest event of Ankylosing Spondylitis
-1015: [P] Earliest event of Pulmonary arterial hypertension (PAH)2
-1016: [P] Earliest event of Polyarticular juvenile idiopathic arthritis (JIA)
-1017: [P] Earliest event of Neonatal Thrombocytopenia (NT), less than 1 year old
-1018: [P] Earliest event of Warm Autoimmune Hemolytic Anemia (wAIHA), occurring on or after October 2020
-1019: [P] All events of Hemolytic Disease Fetus and Newborn (HDFN), RhD type, with a pregnancy episode
-1020: [P] Earliest event of Major depressive disorder, with NO occurrence of certain psychiatric disorder
-1021: [P] Earliest event of Myasthenia Gravis, inpatient, 2nd diagnosis or treatment, age gte 18
-1022: [P] Earliest event of Depressive and Sleep Disorder
-1023: [P] Earliest Event of Depressive Disorder with Suicidal Ideation or Attempt Prevalent
-1024: [P] Earliest Event of Depressive Disorder with Anhedonia
-1025: [P] First event of Attention-deficit hyperactivity (ADHD) disorder or procedure
-1026: [P] Earliest Event of Multiple Sclerosis
-1027: [P] Earliest event of Chronic Leukocytic Leukemia
-1028: [P] Earliest event of Urothelial carcinoma
-1029: [P] Earliest event of Mantle Cell Lymphoma
-1030: [P] Earliest event of Prostate cancer, among adult males
-1031: [P] Earliest event of Coronary artery disease (CAD)
-1032: [P] Earliest event of Type 2 Diabetes Mellitus (DM), with no type 1 or secondary DM
-1033: [P] Earliest event of Human Immunodeficiency Virus I (HIV), with treatment, lab or 2nd diagnosis
-1034: [P] All events of Respiratory syncytial virus infection, with 30 days washout
+
311: [P] Parasomnia
+742: [P] Parasomnia or Sleep dysfunction with arousal disturbance
+743: [P] Diabetic ketoacidosis IP-ER (SNOMED concept)
+744: [P] Pulmonary Hypertension
+745: [P] Inflammatory Bowel Disease
+746: [P] Chronic Thromboembolic Pulmonary Hypertension
+747: [P] Pulmonary Arterial Hypertension
+748: [P] Psoriatic arthritis
+749: [P] Plaque Psoriasis
+750: [P] Pulmonary hypertension associated with left heart disease (WHO Group 2)
+751: [P] Pulmonary hypertension associated with lung diseases and or hypoxia (WHO Group 3)
+752: [P] Firearm Accidents (FA)
+753: [P] Motor Vehicle Accidents (MVA)
+754: [P] Down Syndrome
+755: [P] Non-infectious uveitis and iridocyclitis
+756: [P] Cystic Fibrosis
+757: [P] Concomitant TNF - alpha Inhibitors and IL23 Inhibitors - GE 30D overlap
+759: [P] Concomitant TNF - alpha Inhibitors and IL12_23 Inhibitors - GE 30D overlap
+760: [P] Concomitant IL 23 Inhibitors and IL12_23 Inhibitors - GE 30D overlap
+761: [P] Pulmonary arterial hypertension with Prior Left Heart or Vice Versa
+762: [P] Endothelin receptor antagonists
+763: [P] Phosphodiesterase 5 inhibitors and guanylate cyclase stimulators
+764: [P] Prostacyclin analogues and prostacyclin receptor agonists
+765: [P] Earliest event of Left Heart Failure
+766: [P] Earliest event of Right Heart Failure
+767: [P] Earliest event of Sarcoidosis
+768: [P] Earliest event of Sickle Cell Anemia
+769: [P] Scleroderma, first occurrence
+770: [P] Essential Hypertension, first occurrence
+771: [P] Pulmonary Hypertension (Group 2 Left heart disease, encompassing)
+772: [P] Pulmonary Hypertension (Group 3 Chronic lung disease, encompassing)
+773: [P] Congenital Heart Disease
+774: [P] Portal Hypertension, first occurrence
+775: [P] First Inflammatory Bowel Disease
+776: [P] Antisynthetase syndrome
+777: [P] Mixed connective tissue disease
+778: [P] Undifferentiated connective tissue disease
+779: [P] Overlap syndrome
+780: [P] Raynaud?s disease or Raynaud's phenomenon
+781: [P] Antiphospholipid syndrome
+782: [P] CTEPH Prevalent (with Echo or RHC) with 2nd dx code 31-365 days after first dx
+783: [P] Pulmonary endarterectomy
+784: [P] Balloon Pulmonary Angioplasty
+785: [P] Skin Burns
+786: [P] Non-small cell lung cancer (NSCLC)
+787: [P] Lung cancer
+788: [P] Breast cancer
+789: [P] Glioblastoma multiforme (GBM)
+790: [P] Colorectal Cancer
+791: [P] Multiple Myeloma
+792: [P] Metastatic Hormone-Sensitive Prostate Cancer Synchronous
+793: [P] Metastatic Hormone-Sensitive Prostate Cancer Metachronus
+794: COPY OF [P][R] Bleeding
+795: [P] Antineoplastic drugs against colorectal cancer
+796: [P] Potential curative surgery for colorectal cancer
+797: [P] Radiotherapy against colorectal cancer
+798: [P] Primary adenocarcinoma of the colon or rectum
+802: [P] Acute Respiratory Failure 2
+803: [P] Fascial dehiscence and evisceration
+804: [P] Anastomotic leak or dehiscence
+805: [P] Intestinal obstruction (broad)
+806: [P] Intraabdominal abscess
+807: [P] Perioperative aspiration
+808: [P] Postoperative hemorrhage
+809: [P] Surgical wound infection (narrow)
+810: [P] Distant metastasis following colorectal cancer (wide)
+811: [P] Local recurrence after colorectal cancer
+812: [P] Primary adenocarcinoma of the colon or rectum, MSI-H or dMMR, no surgery or oncological treatment
+813: [P] Primary adenocarcinoma of the colon or rectum treated with potentially curative surgery
+814: [P] Primary adenocarcinoma of the colon or rectum, no curative intended surgery and oncological treatment
+817: [P] Primary adenocarcinoma of the colon or rectum, no curative intended surgery and oncological treatment2
+818: [P] Primary adenocarcinoma of the colon or rectum, MSI-L, MSI-indeterminate, MSS or pMMR
+819: [P] Primary adenocarcinoma of the colon or rectum, MSI-L, MSI-indeterminate, MSS or pMMR, treated with curative intended surgery
+820: [P] Primary adenocarcinoma of the colon or rectum, MSI-L, MSI-indeterminate, MSS or pMMR, oncological treatment, no curative surgery
+821: [P] Primary adenocarcinoma of the colon or rectum, MSI-L, MSI-indeterminate, MSS or pMMR, no surgery or oncological treatment
+822: [P] Primary adenocarcinoma of colon or rectum, MSI-H or dMMR, surgical treatment
+823: [P] Primary adenocarcinoma of colon or rectum, MSI-H or dMMR, oncological treatment no surgery
+824: [P] Primary adenocarcinoma of colon or rectum,  MSI-H or dMMR
+825: [P] Primary adenocarcinoma of colon
+826: [P] Primary adenocarcinoma of colon, no surgery or oncological treatment
+827: [P] Primary adenocarcinoma of colon surgical treatment
+828: [P] Primary adenocarcinoma of colon oncological treatment, no surgery
+829: [P] Primary adenocarcinoma of colon, MSI-L, MSI-indeterminate, MSS or pMMR
+830: [P] Primary adenocarcinoma of colon, MSI-L, MSI-indeterminate, MSS or pMMR, surgically treated
+831: [P] Primary adenocarcinoma of colon MSI-L, MSI-indeterminate, MSS or pMMR, oncological treatment, no surgery
+832: [P] Primary adenocarcinoma of colon MSI-L, MSI-indeterminate, MSS or pMMR, no surgery or oncological treatment
+833: [P] Primary adenocarcinoma of colon MSI-H or dMMR
+834: [P] Primary adenocarcinoma of colon MSI-H or dMMR, surgical treatment
+835: [P] Primary adenocarcinoma of colon MSI-H or dMMR, oncological treatment, no surgery
+836: [P] Primary adenocarcinoma of colon MSI-H or dMMR, no surgery or oncological treatment
+837: [P] Primary adenocarcinoma of rectum
+838: [P] Primary adenocarcinoma of rectum MSI-H or dMMR
+839: [P] Primary adenocarcinoma of rectum, MSI-H or dMMR, no surgery or oncological treatment
+840: [P] Primary adenocarcinoma of rectum MSI-H or dMMR, oncological treatment, no surgery
+841: [P] Primary adenocarcinoma of rectum, MSI-H or dMMR, surgical treatment
+842: [P] Primary adenocarcinoma of rectum, MSI-L, MSI-indeterminate, MSS or pMMR
+843: [P] Primary adenocarcinoma of rectum MSI-L, MSI-indeterminate, MSS or pMMR, oncological treatment,  no surgery
+844: [P] Primary adenocarcinoma of rectum MSI-L, MSI-indeterminate, MSS or pMMR, no surgery and no oncological treatment
+845: [P] Primary adenocarcinoma of rectum MSI-L, MSI-indeterminate, MSS or pMMR, treated with potentially curative surgery
+846: [P] Primary adenocarcinoma of rectum oncological treatment, no surgery
+847: [P] Primary adenocarcinoma of rectum surgical treatment
+848: [P] Primary adenocarcinoma of rectum, no surgery or oncological treatment
+850: [P] Intestinal obstruction (broad 2)
+851: [P] Intraabdominal obstruction (broad)
+852: [P] Surgical wound infection (broad)
+854: [P] Distant metastasis following colorectal cancer (medium)
+855: [P] Distant metastasis following colorectal cancer (narrow)
+856: [P] Earliest event of Migraine, including history of migraine
+857: [P] Earliest event of Migraine
+858: [P] Earliest event of Rheumatoid Arthritis
+859: [P] Earliest event of Crohns disease
+860: [P] Earliest event of Ulcerative colitis
+861: [P] Earliest event of Urinary tract infections (UTI)
+862: [P] Earliest event of Alzheimer's disease derived from Imfeld, 2
+863: [P] Cognitive impairment, incident
+864: [P] Earliest event of Dementia
+865: [P] Non-Emergent Major Non Cardiac Surgery
+866: [P] AAA repair
+867: [P] Lower Extremity Bypass
+868: [P] Carotid Endarterectomy
+869: [P] Lung Resection
+870: [P] Esophagectomy
+871: [P] Pancreatectomy
+872: [P] Colectomy
+873: [P] Cystectomy
+874: [P] Nephrectomy
+875: [P] Coronary Artery Bypass Graft Surgery
+876: [P] Aortic or Mitral Valve Repair or Replacement
+877: [P] Non-Emergent MNCS (age 18 or greater), post op Afib (parox)
+878: [P] Non-Emergent MNCS (age 18 or greater), post op Afib (any)
+879: Cxxx Endometriosis indexed on procedure with two or more diagnosis among females 15 to 49
+881: [P] Acute myocardial infarction
+882: [P] Decreased libido
+884: [P] Diarrhea2
+888: [P] Gastrointestinal bleeding
+889: [P] Hyponatremia
+890: [P] Hypotension
+891: [P] Nausea
+892: [P] Stroke
+893: [P] Vertigo
+894: [P] Abdominal pain
+895: [P] Abnormal weight gain
+896: [P] Abnormal weight loss
+898: [P] Acute renal failure
+899: [P] All-cause mortality
+900: [P] Anaphylactoid reaction
+901: [P] Anemia
+907: [P] All-cause mortality2
+910: [P] Anaphylactoid reaction2
+913: [P] Anemia2
+916: [P] Angioedema2
+917: [P] Anxiety
+918: [P] Bradycardia
+919: [P] Cardiac arrhythmia
+920: [P] Cardiovascular disease
+921: [P] Cardiovascular-related mortality
+922: [P] Chest pain or angina
+923: [P] Kidney disease
+924: [P] Coronary heart disease
+925: [P] Cough
+927: [P] Dementia2
+928: [P] Depression2
+929: [P] Edema2
+930: [P] End stage renal disease2
+931: [P] Fall2
+932: [P] Gout2
+933: [P] Headache2
+934: [P] Heart failure2
+935: [P] Hemorrhagic stroke2
+936: [P] Hepatic failure2
+937: [P] Hospitalization with heart failure2
+938: [P] Hospitalization with heart failure
+939: [P] Hospitalization with preinfarction syndrome
+940: [P] Hyperkalemia
+941: [P] Hypokalemia
+942: [P] Hypomagnesemia
+943: [P] Impotence
+944: [P] Ischemic stroke
+945: [P] Malignant neoplasm
+946: [P] Measured renal dysfunction
+947: [P] Neutropenia or agranulocytosis
+948: [P] Rash
+950: [P] Rhabdomyolysis2
+953: [P] Sudden cardiac death
+954: [P] Syncope
+955: [P] Thrombocytopenia
+956: [P] Transient ischemic attack
+957: [P] Type 2 diabetes mellitus
+958: [P] Syncope3
+959: [P] Thrombocytopenia3
+960: [P] Transient ischemic attack3
+961: [P] Type 2 diabetes mellitus3
+963: [P] Vomiting
+964: [P] Chronic kidney disease
+965: [P] 3-point MACE
+967: [P] 4-point MACE
+969: [P] Acute myocardial infarction2
+970: [P] 4-point MACE2
+975: [P] Acute renal failure2
+976: [P] Glycemic control2
+979: [P] Hospitalization with heart failure3
+980: [P] Revascularization
+982: [P] Stroke2
+983: [P] Sudden cardiac death2
+984: [P] Abnormal weight gain2
+985: [P] Abnormal weight loss2
+986: [P] Acute pancreatitis2
+988: [P] All-cause mortality3
+989: [P] Bladder cancer3
+990: [P] Bone fracture3
+991: [P] Breast cancer3
+992: [P] Diabetic ketoacidosis3
+993: [P] Diarrhea3
+994: [P] Genitourinary infection3
+995: [P] Hyperkalemia3
+996: [P] Hypoglycemia3
+997: [P] Hypotension3
+998: [P] Joint pain3
+999: [P] Lower extremity amputation3
+1000: [P] Nausea3
+1001: [P] Peripheral edema3
+1002: [P] Photosensitivity3
+1003: [P] Renal cancer3
+1004: [P] Thyroid tumor3
+1005: [P] Venous thromboembolism3
+1006: [P] Vomiting3
+1007: [P] Earliest event of Epilepsy
+1009: [P] Earliest event of Treatment resistant depression (TRD)
+1010: [P] Earliest event of Chronic Graft Versus Host Disease (GVHD)
+1011: [P] Earliest event of Marginal zone lymphoma
+1012: [P] Earliest event of Waldenstrom macroglobulinemia
+1013: [P] Earliest event of Ankylosing Spondylitis
+1015: [P] Earliest event of Pulmonary arterial hypertension (PAH)2
+1016: [P] Earliest event of Polyarticular juvenile idiopathic arthritis (JIA)
+1017: [P] Earliest event of Neonatal Thrombocytopenia (NT), less than 1 year old
+1018: [P] Earliest event of Warm Autoimmune Hemolytic Anemia (wAIHA), occurring on or after October 2020
+1019: [P] All events of Hemolytic Disease Fetus and Newborn (HDFN), RhD type, with a pregnancy episode
+1020: [P] Earliest event of Major depressive disorder, with NO occurrence of certain psychiatric disorder
+1021: [P] Earliest event of Myasthenia Gravis, inpatient, 2nd diagnosis or treatment, age gte 18
+1022: [P] Earliest event of Depressive and Sleep Disorder
+1023: [P] Earliest Event of Depressive Disorder with Suicidal Ideation or Attempt Prevalent
+1024: [P] Earliest Event of Depressive Disorder with Anhedonia
+1025: [P] First event of Attention-deficit hyperactivity (ADHD) disorder or procedure
+1026: [P] Earliest Event of Multiple Sclerosis
+1027: [P] Earliest event of Chronic Leukocytic Leukemia
+1028: [P] Earliest event of Urothelial carcinoma
+1029: [P] Earliest event of Mantle Cell Lymphoma
+1030: [P] Earliest event of Prostate cancer, among adult males
+1031: [P] Earliest event of Coronary artery disease (CAD)
+1032: [P] Earliest event of Type 2 Diabetes Mellitus (DM), with no type 1 or secondary DM
+1033: [P] Earliest event of Human Immunodeficiency Virus I (HIV), with treatment, lab or 2nd diagnosis
+1034: [P] All events of Respiratory syncytial virus infection, with 30 days washout

This release is a clean up of files and cohorts before adding cohorts from HowOften. getPhenotypeLog() now gives additional information about a cohort. These are programmatically derived from Circe model compatible cohort json.

-
censorWindowStartDate   censorWindowEndDate collapseSettingsType    
-collapseEraPad  exitStrategy    exitDateOffSetField exitDateOffSet  
-numberOfInclusionRules  qualifyingLimitType primaryCriteriaLimit    
-numberOfCohortEntryEvents   numberOfDomainsInEntryEvents    
-domainsInEntryEvents    continousObservationWindowPrior 
-continousObservationWindowPost  numberOfConceptSets 
-demographicCriteria demographicCriteriaAge  demographicCriteriaGender   
-useOfObservationPeriodInclusionRule restrictedByVisit   
-domainConditionOccurrence   domainMeasurement   domainObservation   
-domainVisitOccurrence   domainDeath domainDrugExposure  
-criteriaAgePrimaryCriteria  domainDeviceExposure    
-domainProcedureOccurrence   criteriaAgeInclusionRules   
-criteriaGenderPrimaryCriteria   criteriaGenderInclusionRules
+
censorWindowStartDate   censorWindowEndDate collapseSettingsType    
+collapseEraPad  exitStrategy    exitDateOffSetField exitDateOffSet  
+numberOfInclusionRules  qualifyingLimitType primaryCriteriaLimit    
+numberOfCohortEntryEvents   numberOfDomainsInEntryEvents    
+domainsInEntryEvents    continousObservationWindowPrior 
+continousObservationWindowPost  numberOfConceptSets 
+demographicCriteria demographicCriteriaAge  demographicCriteriaGender   
+useOfObservationPeriodInclusionRule restrictedByVisit   
+domainConditionOccurrence   domainMeasurement   domainObservation   
+domainVisitOccurrence   domainDeath domainDrugExposure  
+criteriaAgePrimaryCriteria  domainDeviceExposure    
+domainProcedureOccurrence   criteriaAgeInclusionRules   
+criteriaGenderPrimaryCriteria   criteriaGenderInclusionRules

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: No new cohorts were added in this release.

@@ -1181,45 +1228,45 @@

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 39 were added.

-
701: [P][R] Ascites
-702: [P] Alanine aminotransferase (ALT) elevated
-703: [P] Aspartate aminotransferase (AST) elevated
-705: [P] Total Bilirubin elevated
-706: [P] Prothrombin time (PT) elevated
-707: Inpatient Hospitalization (0Pe, 1Era)
-708: [P] International normalized ratio (INR) elevated
-709: [P][R] Chronic liver disease
-710: [P] Cirrhosis of liver or its sequela
-711: [P][R] Transplanted liver present
-712: [P] Viral hepatitis including history of
-713: [P] Alcoholic hepatitis or alcohol liver disorder
-714: [P][R] Endometriosis (clinical)
-715: [P] Hepatic fibrosis
-716: [P] Acute Hepatic Injury
-717: [P] Portal hypertension or esophageal varices
-719: [P] Acute Hepatic Injury or jaundice while inpatient with no cooccurring certain liver disease
-720: [P] Aplastic Anemia
-721: [P] Sudden New Onset Blindness
-722: [P] Endometriosis indexed on procedure with two or more diagnosis among females 15 to 49
-723: [P] First Acute Hepatic Failure with no known severe liver disease
-724: [P] First Acute Hepatic Failure with no known liver disease
-725: [P] All events of Acute Kidney Injury (AKI), with a washout period of 30 days
-726: [P] All events of Anaphylaxis, Mini-Sentinel
-727: [P] All events of Angioedema, with a washout period of 180 days
-728: [P] Autoimmune hemolytic anemia events not including evans syndrome
-729: [P] Autoimmune hepatitis, with a washout period of 365 days
-730: [P] Acute pancreatitis, indexed on visit with NO chronic or hereditary pancreatitis
-731: [P] Sudden Hearing Loss, No congenital anomaly or middle or inner ear conditions
-732: [P] Severe Cutaneous Adverse Reaction (SCAR = SJS+TEN+DRESS) with clean window
-733: [P] Drug Rash with Eosinophilia and Systemic Symptoms (DRESS) with clean window
-734: [P] Drug Rash with Eosinophilia and Systemic Symptoms (DRESS)
-735: [P] Acute Liver Injury indexed on diagnosis or symptoms with no chronic hepatic failure
-736: [P] Acute Liver Injury NO viral, alcoholic, chronic hepatic failure
-737: [P] Neutropenic Fever, Inpatient or ER, indexed on fever or Infection, 90 days era
-738: [P] Autoimmune hemolytic anemia
-739: [P] All events of Isolated Immune Thrombocytopenia (ITP), with a washout period of 365 days
-740: [P] Earliest event of Pulmonary arterial hypertension (PAH)
-741: [P] Earliest event of Thrombotic microangiopathy (TMA) or Microangiopathic hemolytic anemia (MAHA)
+
701: [P][R] Ascites
+702: [P] Alanine aminotransferase (ALT) elevated
+703: [P] Aspartate aminotransferase (AST) elevated
+705: [P] Total Bilirubin elevated
+706: [P] Prothrombin time (PT) elevated
+707: Inpatient Hospitalization (0Pe, 1Era)
+708: [P] International normalized ratio (INR) elevated
+709: [P][R] Chronic liver disease
+710: [P] Cirrhosis of liver or its sequela
+711: [P][R] Transplanted liver present
+712: [P] Viral hepatitis including history of
+713: [P] Alcoholic hepatitis or alcohol liver disorder
+714: [P][R] Endometriosis (clinical)
+715: [P] Hepatic fibrosis
+716: [P] Acute Hepatic Injury
+717: [P] Portal hypertension or esophageal varices
+719: [P] Acute Hepatic Injury or jaundice while inpatient with no cooccurring certain liver disease
+720: [P] Aplastic Anemia
+721: [P] Sudden New Onset Blindness
+722: [P] Endometriosis indexed on procedure with two or more diagnosis among females 15 to 49
+723: [P] First Acute Hepatic Failure with no known severe liver disease
+724: [P] First Acute Hepatic Failure with no known liver disease
+725: [P] All events of Acute Kidney Injury (AKI), with a washout period of 30 days
+726: [P] All events of Anaphylaxis, Mini-Sentinel
+727: [P] All events of Angioedema, with a washout period of 180 days
+728: [P] Autoimmune hemolytic anemia events not including evans syndrome
+729: [P] Autoimmune hepatitis, with a washout period of 365 days
+730: [P] Acute pancreatitis, indexed on visit with NO chronic or hereditary pancreatitis
+731: [P] Sudden Hearing Loss, No congenital anomaly or middle or inner ear conditions
+732: [P] Severe Cutaneous Adverse Reaction (SCAR = SJS+TEN+DRESS) with clean window
+733: [P] Drug Rash with Eosinophilia and Systemic Symptoms (DRESS) with clean window
+734: [P] Drug Rash with Eosinophilia and Systemic Symptoms (DRESS)
+735: [P] Acute Liver Injury indexed on diagnosis or symptoms with no chronic hepatic failure
+736: [P] Acute Liver Injury NO viral, alcoholic, chronic hepatic failure
+737: [P] Neutropenic Fever, Inpatient or ER, indexed on fever or Infection, 90 days era
+738: [P] Autoimmune hemolytic anemia
+739: [P] All events of Isolated Immune Thrombocytopenia (ITP), with a washout period of 365 days
+740: [P] Earliest event of Pulmonary arterial hypertension (PAH)
+741: [P] Earliest event of Thrombotic microangiopathy (TMA) or Microangiopathic hemolytic anemia (MAHA)
@@ -1231,706 +1278,706 @@

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 7 were added.

-
410: [P] Acute Urinary tract infections UTI (1Pe, 30Era)
-411: [P] Sepsis or Septic Shock (1Pe, 7Era)
-412: Transverse myelitis indexed on diagnosis (1Ps, 0Era, 365W)
-414: [P] Acute Skin Eruption symptoms (1Pe, 7Era)
-415: [P] Skin Erythema (1Pe, 7Era)
-416: [P] Skin Rash (1Pe, 7Era)
-417: [P] Acute gastrointestinal bleeding events (7Pe, 30Era)
+
410: [P] Acute Urinary tract infections UTI (1Pe, 30Era)
+411: [P] Sepsis or Septic Shock (1Pe, 7Era)
+412: Transverse myelitis indexed on diagnosis (1Ps, 0Era, 365W)
+414: [P] Acute Skin Eruption symptoms (1Pe, 7Era)
+415: [P] Skin Erythema (1Pe, 7Era)
+416: [P] Skin Rash (1Pe, 7Era)
+417: [P] Acute gastrointestinal bleeding events (7Pe, 30Era)

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 44 were added.

-
363: [P] Joint Stiffness (3Pe, 7Era)
-364: [P] Sleep disorder (3Pe, 7Era)
-365: [P] Dysuria (3Pe, 7Era)
-366: [P] Streptococcal throat infection (14Pe, 30Era)
-367: [P] Allergic Rhinitis (14Pe, 30Era)
-368: [P] Sinusitis (7Pe, 30Era)
-369: [P] Allergic condition (14Pe, 30Era)
-370: [P] Allergic disorder (14Pe, 30Era)
-371: [P] Claudication Pain (365Pe, 365Era)
-372: [P] Otitis media (3Pe, 30Era)
-373: [P] Iron deficiency Anemia (365Pe, 365Era)
-374: [P] Drug Dependence Disorder (30Pe, 365Era)
-375: [P] Gall stone disorder (30Pe, 365Era)
-376: [P] Skin Bleeding (1Pe, 7Era)
-377: [P] Skin Petechiae (1Pe, 7Era)
-378: [P] Skin Purpura (1Pe, 7Era)
-379: [P] Ecchymosis (1Pe, 7Era)
-380: [P] Jaundice (1Pe, 7Era)
-381: [P] Skin Itching  (1Pe, 7Era)
-382: [P] Prurititc Rash (1Pe, 7Era)
-383: [P] Eczematous Atopic Dermatitis and non hyperkeratotic dermatosis (1Pe, 365Era)
-384: [P] Contact Dermatitis (14Pe, 60Era)
-385: [P] Intertrigo (14Pe, 60Era)
-386: [P] Seborrheic dermatitis (14Pe, 60Era)
-387: [P] Photodermatitis (14Pe, 60Era)
-388: [P] Peripheral Neuritis (FP)
-389: [P] Peripheral Neuropathy or Neuritits (FP)
-391: [P] Hearing Loss (30Pe, 365Era)
-392: [P] Otalgia or Otitis (3Pe, 30Era)
-393: [P] Low Back Pain or Injury (3Pe, 7Era)
-394: [P] Gastroesophageal reflux disease (365Pe, 365Era)
-395: [P] Dysmenorrhea (90Pe, 365Era)
-396: [P] Osteoarthritis (FP)
-397: [P] Benign Prostatic Hyperplasia (FP)
-398: [P] Bladder Outflow Obstruction (0Pe, 180Era)
-399: [P] Kidney Stone (1Pe, 30Era)
-400: [P] Prostate Cancer among adult males (FP)
-401: [P] Uterine Fibroids (FP)
-402: [P] Ventilatory assist for respiratory findings with Acute Respiratory Failure (0Pe, 0Era)
-403: [P] Acute Respiratory Failure in inpatient or Emergency room (0Pe, 0Era)
-404: [P] Ventricular Tachycardia, in an Inpatient or Emergency room setting (1Pe, 7Era)
-405: [P] Atrial Fibrillation or Flutter (1Pe, 365Era)
-406: [P] Intellectual Disability (FP)
-407: [P] Hemorrhoids (1Pe, 30Era)
+
363: [P] Joint Stiffness (3Pe, 7Era)
+364: [P] Sleep disorder (3Pe, 7Era)
+365: [P] Dysuria (3Pe, 7Era)
+366: [P] Streptococcal throat infection (14Pe, 30Era)
+367: [P] Allergic Rhinitis (14Pe, 30Era)
+368: [P] Sinusitis (7Pe, 30Era)
+369: [P] Allergic condition (14Pe, 30Era)
+370: [P] Allergic disorder (14Pe, 30Era)
+371: [P] Claudication Pain (365Pe, 365Era)
+372: [P] Otitis media (3Pe, 30Era)
+373: [P] Iron deficiency Anemia (365Pe, 365Era)
+374: [P] Drug Dependence Disorder (30Pe, 365Era)
+375: [P] Gall stone disorder (30Pe, 365Era)
+376: [P] Skin Bleeding (1Pe, 7Era)
+377: [P] Skin Petechiae (1Pe, 7Era)
+378: [P] Skin Purpura (1Pe, 7Era)
+379: [P] Ecchymosis (1Pe, 7Era)
+380: [P] Jaundice (1Pe, 7Era)
+381: [P] Skin Itching  (1Pe, 7Era)
+382: [P] Prurititc Rash (1Pe, 7Era)
+383: [P] Eczematous Atopic Dermatitis and non hyperkeratotic dermatosis (1Pe, 365Era)
+384: [P] Contact Dermatitis (14Pe, 60Era)
+385: [P] Intertrigo (14Pe, 60Era)
+386: [P] Seborrheic dermatitis (14Pe, 60Era)
+387: [P] Photodermatitis (14Pe, 60Era)
+388: [P] Peripheral Neuritis (FP)
+389: [P] Peripheral Neuropathy or Neuritits (FP)
+391: [P] Hearing Loss (30Pe, 365Era)
+392: [P] Otalgia or Otitis (3Pe, 30Era)
+393: [P] Low Back Pain or Injury (3Pe, 7Era)
+394: [P] Gastroesophageal reflux disease (365Pe, 365Era)
+395: [P] Dysmenorrhea (90Pe, 365Era)
+396: [P] Osteoarthritis (FP)
+397: [P] Benign Prostatic Hyperplasia (FP)
+398: [P] Bladder Outflow Obstruction (0Pe, 180Era)
+399: [P] Kidney Stone (1Pe, 30Era)
+400: [P] Prostate Cancer among adult males (FP)
+401: [P] Uterine Fibroids (FP)
+402: [P] Ventilatory assist for respiratory findings with Acute Respiratory Failure (0Pe, 0Era)
+403: [P] Acute Respiratory Failure in inpatient or Emergency room (0Pe, 0Era)
+404: [P] Ventricular Tachycardia, in an Inpatient or Emergency room setting (1Pe, 7Era)
+405: [P] Atrial Fibrillation or Flutter (1Pe, 365Era)
+406: [P] Intellectual Disability (FP)
+407: [P] Hemorrhoids (1Pe, 30Era)

Accepted Cohorts: 5 cohorts were accepted in this release.

-
304: Neurofibromatosis type 1 (FP)
-305: Neurofibromatosis type 1 without Type 2 (FP)
-306: Optical pathway glioma and neurofibromatosis (FP)
-307: Optical pathway glioma or non malignant neoplasm of optic nerve w neurofibromatosis (FP)
-308: Optical pathway glioma with MRI imaging and ophthalmology visits Neurofibromatosis (FP)
+
304: Neurofibromatosis type 1 (FP)
+305: Neurofibromatosis type 1 without Type 2 (FP)
+306: Optical pathway glioma and neurofibromatosis (FP)
+307: Optical pathway glioma or non malignant neoplasm of optic nerve w neurofibromatosis (FP)
+308: Optical pathway glioma with MRI imaging and ophthalmology visits Neurofibromatosis (FP)

New Cohorts: 7 were added.

-
361: [P] Restless Leg Syndrome (FP)
-362: [P] Acute Kidney Injury AKI (7Pe, 30W)
+
361: [P] Restless Leg Syndrome (FP)
+362: [P] Acute Kidney Injury AKI (7Pe, 30W)

Accepted Cohorts: No cohorts were accepted in this release.

New Cohorts: 13 were added.

-
348: [P] Hematuria (7Pe, 30Era)
-349: [P] Lower gastrointestinal bleeding events (7Pe, 30Era)
-350: [P] Hemoptysis (7Pe, 30Era)
-351: [P] Nasal Polyp (365Pe, 365Era)
-352: [P] Inflamed Tonsil (7Pe, 30Era)
-353: [P] Conjunctivitis (3Pe, 7Era)
-354: [P] Nasal Congestion or Rhinitis or Common Cold (3Pe, 7Era)
-355: [P] Laryngitis (3Pe, 7Era)
-356: [P] Epistaxis (3Pe, 7Era)
-357: [P] Pulmonary Edema (3Pe, 30Era)
-358: [P] Acute Respiratory Failure among persons with no chronic respiratory failure (3Pe, 30Era)
-359: [P] Acute Respiratory Failure (3Pe, 30Era)
-360: [P] Pleural Effusion (3Pe, 30Era)
+
348: [P] Hematuria (7Pe, 30Era)
+349: [P] Lower gastrointestinal bleeding events (7Pe, 30Era)
+350: [P] Hemoptysis (7Pe, 30Era)
+351: [P] Nasal Polyp (365Pe, 365Era)
+352: [P] Inflamed Tonsil (7Pe, 30Era)
+353: [P] Conjunctivitis (3Pe, 7Era)
+354: [P] Nasal Congestion or Rhinitis or Common Cold (3Pe, 7Era)
+355: [P] Laryngitis (3Pe, 7Era)
+356: [P] Epistaxis (3Pe, 7Era)
+357: [P] Pulmonary Edema (3Pe, 30Era)
+358: [P] Acute Respiratory Failure among persons with no chronic respiratory failure (3Pe, 30Era)
+359: [P] Acute Respiratory Failure (3Pe, 30Era)
+360: [P] Pleural Effusion (3Pe, 30Era)

Accepted Cohorts: 2 were accepted. 234: Appendicitis (1Pe, 180Era) 213: Acquired Neutropenia or unspecified leukopenia (21Pe, 365Era)

New Cohorts: 9 were added.

-
339: [P] Hypotension (1Pe, 3Era)
-340: [P] Hives, Erythema, Eruption, Urticaria (1Pe, 7Era)
-341: [P] Loss of mentation including coma, loss of consciousness, altered consciousness (1Pe, 3Era)
-342: [P] Urinary Incontinence (1Pe, 3Era)
-343: [P] Fecal Incontinence (1Pe, 3Era)
-344: [P] Doctors office or clinic visit without other overlapping visits (0Pe, 0Era)
-345: [P] Doctors office or clinic visit (0Pe, 0Era)
-346: [P] Non urgent outpatient visit without overlapping inpatient or emergency visit (0Pe, 0Era)
-347: [P] Ambulance utilization (0Pe, 0Era)
+
339: [P] Hypotension (1Pe, 3Era)
+340: [P] Hives, Erythema, Eruption, Urticaria (1Pe, 7Era)
+341: [P] Loss of mentation including coma, loss of consciousness, altered consciousness (1Pe, 3Era)
+342: [P] Urinary Incontinence (1Pe, 3Era)
+343: [P] Fecal Incontinence (1Pe, 3Era)
+344: [P] Doctors office or clinic visit without other overlapping visits (0Pe, 0Era)
+345: [P] Doctors office or clinic visit (0Pe, 0Era)
+346: [P] Non urgent outpatient visit without overlapping inpatient or emergency visit (0Pe, 0Era)
+347: [P] Ambulance utilization (0Pe, 0Era)

Accepted Cohorts: The following cohorts were added

-
119: Systemic lupus erythematosus indexed on signs, symptoms, treatment or diagnosis (FP)
-296: Transverse myelitis or symptoms indexed on symptoms or diagnosis (180Pe, 180Era)
+
119: Systemic lupus erythematosus indexed on signs, symptoms, treatment or diagnosis (FP)
+296: Transverse myelitis or symptoms indexed on symptoms or diagnosis (180Pe, 180Era)

New Cohorts: 17 were added.

-
142: [P] Earliest event of ST elevated myocardial infarction (7P, 1E)
-192: [P] Skin or mucosal bleeding events (1Pe, 7Era)
-298: [P] Urinary bleed events in persons without renal glomerular disease (30Pe, 7Era)
-299: [P] Acute gastrointestinal bleeding events (7Pe, 30Era)
-300: [P] Heavy menstrual bleeding (menorrhagia) events (60Pe, 180Era)
-318: [P] All events of Acute Hepatic Failure in persons without chronic hepatic failure (90Pe, 365Era)
-324: [P] Pain (3Pe, 7Era)
-325: [P] Inpatient Hospitalization By Site of care or type of service (0Pe, 1Era)
-327: [P] Pharyngitis (3Pe, 7Era)
-328: [P] Wheezing (3Pe, 30Era)
-329: [P] Pneumonitis and lung infections (14Pe, 30Era)
-330: [P] Abdominal Bloating (1Pe, 7Era)
-331: [P] Encephalopathy (1Pe, 14Era)
-332: [P] Pain or ache that is Chronic (3Pe, 180Era)
-333: [P] Alcohol Use Disorder (365Pe, 365Era)
-334: [P] Asthma (FP)
-335: [P] Anxiety or Fear (3Pe, 30Era)
+
142: [P] Earliest event of ST elevated myocardial infarction (7P, 1E)
+192: [P] Skin or mucosal bleeding events (1Pe, 7Era)
+298: [P] Urinary bleed events in persons without renal glomerular disease (30Pe, 7Era)
+299: [P] Acute gastrointestinal bleeding events (7Pe, 30Era)
+300: [P] Heavy menstrual bleeding (menorrhagia) events (60Pe, 180Era)
+318: [P] All events of Acute Hepatic Failure in persons without chronic hepatic failure (90Pe, 365Era)
+324: [P] Pain (3Pe, 7Era)
+325: [P] Inpatient Hospitalization By Site of care or type of service (0Pe, 1Era)
+327: [P] Pharyngitis (3Pe, 7Era)
+328: [P] Wheezing (3Pe, 30Era)
+329: [P] Pneumonitis and lung infections (14Pe, 30Era)
+330: [P] Abdominal Bloating (1Pe, 7Era)
+331: [P] Encephalopathy (1Pe, 14Era)
+332: [P] Pain or ache that is Chronic (3Pe, 180Era)
+333: [P] Alcohol Use Disorder (365Pe, 365Era)
+334: [P] Asthma (FP)
+335: [P] Anxiety or Fear (3Pe, 30Era)

Deprecated Cohorts: No new cohorts were added in this release.

New Cohorts: 19 were added.

-
134: [P] Persons with Attention Deficit Hyperactivity Disorder (FP)
-278: [P] Pain that is Non Chronic, Non Generalized (3Pe, 7Era)
-279: [P] Low Back Pain (30Pe, 180Era)
-280: [P] Abdominal Pain (3Pe, 7Era)
-281: [P] Epigastric Pain (3Pe, 7Era)
-282: [P] Joint Pain (3Pe, 30Era)
-283: [P] Prostatitis (180Pe, 365Era)
-284: [P] Myocarditis or Pericarditis (30Pe, 90Era)
-285: [P] Myocarditis or Pericarditis Not due to infections (30Pe, 90Era)
-287: [P] Transverse myelitis includes Myelitis Unspecified and neuromyelitis optica (90Pe, 365Era)
-288: [P] Type 2 Diabetes Mellitus indexed on diagnosis, treatment or lab results (FP)
-289: [P] Presence Of Cardiac Arrhythmia (3Pe, 60Era)
-290: [P] Thyroiditis indexed on diagnosis or treatment without (FP)
-291: [P] Gynecomastia, indexed on diagnosis, procedure or symptoms (FP)
-292: [P] Hepatic Failure (365Pe, 365Era)
-293: [P] Acute Hepatic Injury with no chronic hepatic failure (180Pe, 180Era)
-294: [P] Acute Hepatic Injury with no pre-existing liver disease (180Pe, 180Era)
-295: [P] Acute Hepatic Failure in persons with no pre-existing liver disease (365Pe, 365Era)
-296: Transverse myelitis or symptoms indexed on symptoms or diagnosis (180Pe, 180Era)
+
134: [P] Persons with Attention Deficit Hyperactivity Disorder (FP)
+278: [P] Pain that is Non Chronic, Non Generalized (3Pe, 7Era)
+279: [P] Low Back Pain (30Pe, 180Era)
+280: [P] Abdominal Pain (3Pe, 7Era)
+281: [P] Epigastric Pain (3Pe, 7Era)
+282: [P] Joint Pain (3Pe, 30Era)
+283: [P] Prostatitis (180Pe, 365Era)
+284: [P] Myocarditis or Pericarditis (30Pe, 90Era)
+285: [P] Myocarditis or Pericarditis Not due to infections (30Pe, 90Era)
+287: [P] Transverse myelitis includes Myelitis Unspecified and neuromyelitis optica (90Pe, 365Era)
+288: [P] Type 2 Diabetes Mellitus indexed on diagnosis, treatment or lab results (FP)
+289: [P] Presence Of Cardiac Arrhythmia (3Pe, 60Era)
+290: [P] Thyroiditis indexed on diagnosis or treatment without (FP)
+291: [P] Gynecomastia, indexed on diagnosis, procedure or symptoms (FP)
+292: [P] Hepatic Failure (365Pe, 365Era)
+293: [P] Acute Hepatic Injury with no chronic hepatic failure (180Pe, 180Era)
+294: [P] Acute Hepatic Injury with no pre-existing liver disease (180Pe, 180Era)
+295: [P] Acute Hepatic Failure in persons with no pre-existing liver disease (365Pe, 365Era)
+296: Transverse myelitis or symptoms indexed on symptoms or diagnosis (180Pe, 180Era)

Deprecated Cohorts: No new cohorts were added in this release.

Accepted Cohorts: The following cohorts were added

-
269: Acute Kidney Injury AKI (7Pe, 30W)
+
269: Acute Kidney Injury AKI (7Pe, 30W)

Discussed https://forums.ohdsi.org/t/phenotype-phebruary-day-29-acute-kidney-injury/16067 and peer reviewed by Azza Shoaibi and accepted after modifications. See recording dated August 12th 2022

New Cohorts: 2 were added.

-
276: [P] Sudden Vision Loss (1Pe, 0Era, 365W)
-277: [P] Sudden Hearing Loss (1Pe, 0Era, 365W)
+
276: [P] Sudden Vision Loss (1Pe, 0Era, 365W)
+277: [P] Sudden Hearing Loss (1Pe, 0Era, 365W)

Deprecated Cohorts: No new cohorts were added in this release.

Accepted Cohorts: The following cohorts were added

-
63: Transverse myelitis or symptoms (1Ps, 0Era, 365W)
+
63: Transverse myelitis or symptoms (1Ps, 0Era, 365W)

Deprecated Cohorts: No new cohorts were added in this release.

Modified Cohorts: several symptom and sign based cohorts were updated to support discussion https://forums.ohdsi.org/t/phenotype-submission-symptoms-and-signs/17895

New Cohorts: 2 were added.

-
270: [P] Hemolytic Anemia (7Pe, 0Era, 365W)
-271: [P] Hemolytic Anemia Intra corpuscular (FP)
+
270: [P] Hemolytic Anemia (7Pe, 0Era, 365W)
+271: [P] Hemolytic Anemia Intra corpuscular (FP)

Deprecated Cohorts: No new cohorts were added in this release.

Modified Cohorts: 0 were modified.

New Cohorts: 11 were added.

-
258: [P] Anaphylaxis or Anaphylactic shock events (1Pe, 0Era, 30W)
-259: [P] Anaphylaxis all cause (1Pe, 0Era, 30W)
-260: [P] ST elevated myocardial infarction with inpatient admission (7Pe, 180Era)
-261: [P] Non ST elevated myocardial infarction with inpatient admission (7Pe, 180Era)
-262: [P] Unstable Angina with inpatient admission (7Pe, 180Era)
-263: [P] Unstable Angina OR NSTEMI with inpatient admission (7Pe, 180Era)
-264: [P] Acute Hepatic Failure in persons with liver disease (90Pe, 180W)
-265: [P] Drug Induced Acute Hepatic Failure (90Pe, 180W)
-267: [P] Acute Kidney Injury AKI, in persons with chronic kidney disease (7Pe, 30W)
-268: [P] Acute Kidney Injury AKI, in persons with NO chronic kidney disease (7Pe, 30W)
-269: [P] Acute Kidney Injury (AKI) (7Pe, 30W)
+
258: [P] Anaphylaxis or Anaphylactic shock events (1Pe, 0Era, 30W)
+259: [P] Anaphylaxis all cause (1Pe, 0Era, 30W)
+260: [P] ST elevated myocardial infarction with inpatient admission (7Pe, 180Era)
+261: [P] Non ST elevated myocardial infarction with inpatient admission (7Pe, 180Era)
+262: [P] Unstable Angina with inpatient admission (7Pe, 180Era)
+263: [P] Unstable Angina OR NSTEMI with inpatient admission (7Pe, 180Era)
+264: [P] Acute Hepatic Failure in persons with liver disease (90Pe, 180W)
+265: [P] Drug Induced Acute Hepatic Failure (90Pe, 180W)
+267: [P] Acute Kidney Injury AKI, in persons with chronic kidney disease (7Pe, 30W)
+268: [P] Acute Kidney Injury AKI, in persons with NO chronic kidney disease (7Pe, 30W)
+269: [P] Acute Kidney Injury (AKI) (7Pe, 30W)

Deprecated Cohorts: No new cohorts were added in this release.

Modified Cohorts: 3 were modified.

-
71: [P] Acute myocardial infarction with inpatient admission (7Pe, 180Era)
-221: [P] Anaphylaxis Non Environmental exposure related (1Pe, 0Era, 30W)
-234: [P] Appendicitis (1Pe, 0Era, 365W)
+
71: [P] Acute myocardial infarction with inpatient admission (7Pe, 180Era)
+221: [P] Anaphylaxis Non Environmental exposure related (1Pe, 0Era, 30W)
+234: [P] Appendicitis (1Pe, 0Era, 365W)

Accepted Cohort: 3 cohorts were accepted. cohortId 23, 24 and 25 were considered accepted to the OHDSI Phenotype Library. This cohort is deemed validated as it represents a convention and thus do not need to go through peer review process.

-
23: Inpatient Hospitalization (1Pe, 0Era)
-24: Emergency room visits (0Pe, 0Era)
-25: All cause mortality
+
23: Inpatient Hospitalization (1Pe, 0Era)
+24: Emergency room visits (0Pe, 0Era)
+25: All cause mortality

New Cohorts: 8 were added.

-
100: [P] Alzheimer's disease
-119: [P] Systemic lupus erythematosus (FP)
-251: [P] Acute pancreatitis (7Pe, 0Era, 365W)
-253: [P] Drug Induced Acute pancreatitis (7Pe, 365W)
-254: [P] Drug Resistant Epilepsy
-255: [P] Alzheimer's disease (based on Imfeld, 2013)
-256: [P] Facial Palsy lower motor neuron including Bells Palsy (180Pe, 0Era, 183W)
-257: [P] Emergency room visits or code (0Pe, 0Era)
+
100: [P] Alzheimer's disease
+119: [P] Systemic lupus erythematosus (FP)
+251: [P] Acute pancreatitis (7Pe, 0Era, 365W)
+253: [P] Drug Induced Acute pancreatitis (7Pe, 365W)
+254: [P] Drug Resistant Epilepsy
+255: [P] Alzheimer's disease (based on Imfeld, 2013)
+256: [P] Facial Palsy lower motor neuron including Bells Palsy (180Pe, 0Era, 183W)
+257: [P] Emergency room visits or code (0Pe, 0Era)

Deprecated Cohorts: No cohorts were added in this release.

Modified Cohorts: 136 were modified. Several cohorts were changed from [P] to [W] i.e. were withdrawn from peer review consideration. Some of the cohorts in [P] pending peer review status were modified by the contributor. The changes includes cohort name changes and cohort specification changes. No accepted cohorts were modified.

-
2: [W] COVID-19 diagnosis or SARS-CoV-2 test (1pos) (3Ps, 7Era)
-3: [P] Cough (3Ps, 30Era)
-4: [P] Diarrhea (7Ps, 30Era)
-5: [P] Dyspnea (14Pe, 30Era)
-6: [P] Fever (3Pe, 30Era)
-7: [P] Headache, Migraine or related Neurologic pain (7Pe, 30Era)
-8: [P] Anosmia OR Hyposmia OR Dysgeusia (7Ps, 180Era)
-9: [P] Sore throat (7Pe, 30Era)
-10: [P] Nausea or Vomiting (3Pe, 30Era)
-11: [P] Malaise or fatigue (3P, 30Era)
-12: [P] Rhinitis or common cold (7P, 30Era)
-13: [P] Myalgia (not explained by injury, ischemia or systemic inflammation) (3Pe, 30Era)
-14: [P] Myalgia (3Pe, 30Era)
-15: [W] Exposure to Viral Disease (7Pe, 30Era)
-16: [W] Exposure to SARS-Cov 2 and coronavirus (7Pe, 30Era)
-17: [W] Exposure to SARS-Cov 2 (7Pe, 30Era)
-18: [P] Multiple Inflammatory Syndrome (30Pe, 30Era)
-19: [P] Acute Typical Pneumonia (14Pe, 30Era)
-20: [P] Bronchitis (14Pe, 90Era)
-21: [P] Acute respiratory distress syndrome (ARDS) or Acute Respiratory Failure (3Pe, 30Era)
-22: [W] SARS-CoV-2 testing (1Ps, 0Era)
-26: [P] Asthma or Chronic obstructive pulmonary disease (COPD) (FP)
-27: [P] Asthma without COPD (FP)
-28: [P] Chronic obstructive pulmonary disease (COPD) without asthma (FP)
-29: [W] Autoimmune condition (FP)
-30: [P] Tuberculosis (FP)
-31: [P] Malignant neoplasm excluding non-melanoma skin cancer (FP)
-32: [P] Obesity (FP)
-33: [P] Dementia (FP)
-34: [P] Hypertensive disorder or hypertensive complications (FP)
-35: [W] Chronic kidney disease (FP)
-36: [P] Human immunodeficiency virus (not HIV2) infection (FP)
-37: [P] Hepatitis C (FP)
-38: [P] Heart disease (FP)
-39: [W] End stage renal disease (FP)
-40: [P] Diabetes Mellitus Type 2 (FP)
-41: [W] Chronic kidney disease broad (FP)
-42: [W] End stage renal disease broad (FP)
-43: [P] Respiratory or pulmonary tuberculosis (FP)
-44: [W] COVID-19 diagnosis (3Pe, 7Era)
-45: [W] COVID-19 diagnosis with SARS-Cov-2 test (-3d to 3d) (3Pe, 21Era)
-46: [W] COVID-19 diagnosis and SARS-CoV-2 test (1pos) within 3d (3Pe, 21Era)
-47: [W] COVID-19 diagnosis and SARS-CoV-2 test (1pos) (0neg) within 3d (3Pe, 21Era)
-48: [W] COVID-19 diagnosis and SARS-CoV-2 test (0pos upto 3d, 1neg within 3d) (3Pe, 7Era)
-51: [W] SARS-CoV-2 test positive result (0Ps, 0Era)
-52: [W] SARS-CoV-2 test negative result (0Ps, 0Era)
-53: [W] SARS-CoV-2 test positive or negative result - keep persons with positive (0Ps, 0Era)
-54: [P] Febrile seizure (1Pe, 0Era, 42W)
-55: [W] COVID-19 diagnosis or SARS-CoV-2 test (1pos) (3Ps, 21Era)
-56: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (0 neg -3d to 3d) (3Ps, 21Era)
-57: [P] Bleeding (1Pe, 0Era, 30W)
-58: [W] SARS-CoV-2 test positive result (3Ps, 21Era)
-59: [W] COVID-19 diagnosis with no SARS-CoV-2 test (3Ps, 21Era)
-60: [W] SARS-CoV-2 test positive and negative result (0Ps, 0Era)
-61: [P] Bradycardia or heart block with inpatient admission (1Pe, 30Era)
-62: [P] Generalized Seizure (1Pe, 0Era, 42W)
-63: [P] Transverse myelitis or symptoms (1Ps, 0Era, 365W)
-64: [W] Flu-like symptoms fever, cough, malaise, fatigue, dyspnea, myalgia (3P, 30Era)
-65: [W] Acute pancreatitis with inpatient admission (3Pe, 30Era)
-66: [W] Acute renal failure with inpatient admission (3Pe, 30Era)
-67: [W] Hepatic failure with inpatient admission (3Pe, 30Era)
-68: [W] Heart failure with inpatient admission (3Pe, 30Era)
-69: [W] Angioedema with inpatient admission (7Ps, 30Era)
-70: [P] Stroke (ischemic or hemorrhagic) with inpatient admission (7Ps, 30Era)
-71: [P] Acute myocardial infarction with inpatient admission (7Ps, 180Era)
-72: [P] Influenza diagnosis or positive test result (7Pe, 90Era)
-73: [W] Pregnancy (270P, 0Era)
-74: [P] Hemorrhagic stroke (intracerebral bleeding) with inpatient admission (7Ps, 180Era)
-75: [P] Ischemic stroke with inpatient admission (7Ps, 180Era)
-76: [P] Transient ischemic attack with inpatient admission (7Ps, 30Era)
-77: [P] Gastrointestinal bleeding with inpatient admission (7Ps, 30Era)
-78: [P] Cardiac arrhythmia with inpatient admission (1Pe, 30Era)
-79: [P] Dialysis with inpatient admission (1Ps, 7Era)
-80: [P] Extracorporeal Membrane Oxygenation with inpatient admission (1Pe, 30Era)
-81: [P] Cesarean section (7Pe, 180Era)
-82: [P] Intensive services during hospitalization (1Ps, 30Era)
-84: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (1pos or 0 neg 0d to 3d) (3Ps, 180Era)
-85: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (1pos or 0 neg 0d to 3d) (3Ps, 21Era)
-86: [W] SARS-CoV-2 test positive or negative result (0Ps, 0Era)
-87: [W] SARS-CoV-2 test (1Ps, 0Era)
-95: [P] Delirium (FP)
-123: [W] First event of Suicide attempt, including injuries and poisonings with undetermined, 365 days
-189: [P] Right Upper Quadrant Pain (Pe1, 0Era, 14W)
-190: [P] Abdominal Distension (Pe1, 0Era, 14W)
-191: [P] Fatigue, Malaise, Lethargy, Anorexia (Pe1, 0Era, 14W)
-192: [P] Nausea or Vomiting (Pe1, 0Era, 7W)
-193: [P] Jaundice or Itching (Pe1, 0Era, 14W)
-194: [P] Encephalopathy or its presentations (Pe1, 0Era, 30W)
-195: [P] Urothelial bladder cancer (FP)
-197: [P] Coronary Artery Disease from vessel disease to ischemic injury (FP)
-205: [W] Acute pancreatitis (7Pe, 0Era, 365W)
-206: [W] Drug Induced Acute pancreatitis (7Pe, 365W)
-207: [P] Acquired Pure Red Cell Aplasia
-208: [P] Neutropenic Fever (3Pe, 30Era)
-209: [P] Hemolytic Anemia, Extra corpuscular Acquired - G6PD deficiency excluded (7Pe, 0Era, 365W)
-210: [P] Hemolytic Anemia, Extra corpuscular Acquired (7Pe, 0Era, 365W)
-211: [P] Pancytopenia, Acquired
-213: [P] Acquired Neutropenia or unspecified leukopenia (21Pe, 365Era)
-214: [P] Acquired Isolated Neutropenia or unspecified leukopenia (21Pe, 365Era)
-215: [P] Isolated Immune Thrombocytopenia (180Pe, 365Era)
-216: [P] Isolated Immune Thrombocytopenia in absence of common thrombocytopenia causes (180Pe, 365Era)
-217: [P] Thrombotic microangiopathy (TMA) or Microangiopathic hemolytic anemia (MAHA)
-218: [P] Rhabdomyolysis (3Pe, 0Era, 180W)
-219: [P] Sudden Cardiac arrest or cardiac death
-220: [P] Angioedema (3Pe, 0Era, 180W)
-221: [P] Anaphylaxis Non Environmental exposure related (1Pe, 0Era, 180W)
-222: [P] Stevens-Johnson syndrome, toxic epidermal necrolysis spectrum
-223: [P] Posterior reversible encephalopathy syndrome PRES (FP)
-224: [P] Long QT Syndrome or QT prolonged (Acquired)
-225: [P] Drug-induced Lupus (180Pe, 0Era, 365W)
-226: [P] Drug Rash with Eosinophilia and Systemic Symptoms DRESS (1Pe, 0Era, 365W)
-227: [P] Severe Cutaneous Adverse Reaction SCAR (SJS+TEN+DRESS+EM) (3Pe, 0Era, 365W)
-228: [P] Severe Cutaneous Adverse Reaction SCAR (SJS+TEN+DRESS) (3Pe, 0Era, 365W)
-229: [P] Progressive multifocal leukoencephalopathy
-230: [P] Autoimmune hepatitis (1Pe, 0Era, 365W)
-231: [P] Erythema multiforme (3Pe, 0Era, 365W)
-232: [P] Paresthesia (3Pe, 0Era, 365W)
-233: [P] Hemorrhagic stroke (1Pe, 0Era, 180W)
-234: [P] Appendicitis (1Pe, 0Era, 365W)
-235: [P] Guillain Barre syndrome (180Pe, FP)
-236: [P] Idiopathic Peripheral Neuropathy (1Pe, 0Era, 365W)
-237: [P] Kawasaki disease (1Pe, 0Era, 365W)
-238: [P] Optic Neuritis (7Pe, 0Era, 365W)
-239: [P] Narcolepsy events (1Pe, 0Era, 365W)
-240: [P] Muscle weakness or monoplegia (1Pe, 0Era, 365W)
-241: [P] Urticaria (1Pe, 0Era, 30W)
-243: [P] Tinnitus (1Pe, 0Era, 365W)
-244: [P] Dizziness (1Pe, 0Era, 180W)
-245: [P] Hepatic Thrombosis (90Pe, 0Era)
-246: [P] Portal vein thrombosis (90Pe, 0Era)
-247: [P] Deep Vein Thrombosis DVT (90Pe, 0Era)
-248: [P] Disseminated intravascular coagulation DIC (1Pe, 0Era, 365W)
-249: [P] Ischemic (Non-hemorrhagic) Stroke (1Pe, 0Era, 365W)
-
-
- -

New Cohorts: 43 were added. 205: [P] Acute pancreatitis (7Pe, 0Era, 365W) 206: [P] Drug Induced Acute pancreatitis (7Pe, 365W) 207: [P] Acquired Pure Red Cell Aplasia 208: [P] Neutropenic Fever (3Pe, 30Era) 209: [P] Hemolytic Anemia, Extra corpuscular Acquired - G6PD deficiency excluded (7Pe, 0Era, 365W) 210: [P] Hemolytic Anemia, Extra corpuscular Acquired (7Pe, 0Era, 365W) 211: [P] Pancytopenia, Acquired 213: [P] Acquired Neutropenia or unspecified leukopenia (21Pe, 365Era) 214: [P] Acquired Isolated Neutropenia or unspecified leukopenia (21Pe, 365Era) 215: [P] Isolated Immune Thrombocytopenia (180Pe, 365Era) 216: [P] Isolated Immune Thrombocytopenia in absence of common thrombocytopenia causes (180Pe, 365Era) 217: [P] Thrombotic microangiopathy or Microangiopathic hemolytic anemia 218: [P] Rhabdomyolysis (3Pe, 0Era, 180W) 219: [P] Sudden Cardiac arrest or cardiac death 220: [P] Angioedema (3Pe, 0Era, 180W) 221: [P] Anaphylaxis Non Environmental exposure related (1Pe, 0Era, 180W) 222: [P] Stevens-Johnson syndrome, toxic epidermal necrolysis spectrum 223: [P] Posterior reversible encephalopathy syndrome (PRES) 224: [P] Long QT Syndrome or QT prolonged (Acquired) 225: [P] Drug-induced Lupus (7Pe, 0Era, 365W) 226: [P] Drug Rash with Eosinophilia and Systemic Symptoms DRESS (1Pe, 0Era, 365W) 227: [P] Severe Cutaneous Adverse Reaction SCAR (SJS+TEN+DRESS+EM) (3Pe, 0Era, 365W) 228: [P] Severe Cutaneous Adverse Reaction SCAR (SJS+TEN+DRESS) (3Pe, 0Era, 365W) 229: [P] Progressive multifocal leukoencephalopathy 230: [P] Autoimmune hepatitis (1Pe, 0Era, 365W) 231: [P] Erythema multiforme (3Pe, 0Era, 365W) 232: [P] Paresthesia (3Pe, 0Era, 365W) 233: [P] Hemorrhagic stroke (1Pe, 0Era, 180W) 234: [P] Appendicitis (1Pe, 0Era, 365W) 235: [P] Guillain Barre syndrome (1Pe, 0Era, 365W) 236: [P] Idiopathic Peripheral Neuropathy (1Pe, 0Era, 365W) 237: [P] Kawasaki disease (1Pe, 0Era, 365W) 238: [P] Optic Neuritis (7Pe, 0Era, 365W) 239: [P] Narcolepsy events (1Pe, 0Era, 365W) 240: [P] Muscle weakness or monoplegia (1Pe, 0Era, 365W) 241: [P] Urticaria (1Pe, 0Era, 365W) 243: [P] Tinnitus (1Pe, 0Era, 365W) 244: [P] Dizziness (1Pe, 0Era, 365W) 245: [P] Hepatic Thrombosis (1Pe, 0Era, 365W) 246: [P] Portal vein thrombosis (1Pe, 0Era, 365W) 247: [P] Deep Vein Thrombosis DVT (1Pe, 0Era, 365W) 248: [P] Disseminated intravascular coagulation DIC (1Pe, 0Era, 365W) 249: [P] Ischemic (Non-hemorrhagic) Stroke (1Pe, 0Era, 365W) Deprecated Cohorts: No new cohorts were added in this release. Modified Cohorts: No cohorts were modified in this release.

-
-
- -

New Cohorts: No new cohorts were added in this release.

-

Modified Cohorts: 85 were modified. These are only name modifications. These cohorts have not undergone Peer review process. They are not considered accepted. However, because of grandfathered status (i.e. these cohorts existed in Phenotype Library prior to version 3.0, results for these cohorts are computed as part of PhenotypeLibraryDiagnostics study package - unless withdrawn). The Cohort JSON specifications were not changed.

-
2: [P] COVID-19 diagnosis or SARS-CoV-2 test (1pos) (3Ps, 7Era)
+
2: [W] COVID-19 diagnosis or SARS-CoV-2 test (1pos) (3Ps, 7Era)
 3: [P] Cough (3Ps, 30Era)
 4: [P] Diarrhea (7Ps, 30Era)
 5: [P] Dyspnea (14Pe, 30Era)
 6: [P] Fever (3Pe, 30Era)
-7: [P]Headache, Migraine, Neurologic pain (7Pe, 30Era)
+7: [P] Headache, Migraine or related Neurologic pain (7Pe, 30Era)
 8: [P] Anosmia OR Hyposmia OR Dysgeusia (7Ps, 180Era)
 9: [P] Sore throat (7Pe, 30Era)
 10: [P] Nausea or Vomiting (3Pe, 30Era)
 11: [P] Malaise or fatigue (3P, 30Era)
 12: [P] Rhinitis or common cold (7P, 30Era)
-13: [P] Myalgia (not including secondary causes) (3Pe, 30Era)
+13: [P] Myalgia (not explained by injury, ischemia or systemic inflammation) (3Pe, 30Era)
 14: [P] Myalgia (3Pe, 30Era)
-15: [P] Exposure to Viral Disease (7Pe, 30Era)
-16: [P] Exposure to SARS-Cov 2 and coronavirus (7Pe, 30Era)
-17: [P] Exposure to SARS-Cov 2 (7Pe, 30Era)
+15: [W] Exposure to Viral Disease (7Pe, 30Era)
+16: [W] Exposure to SARS-Cov 2 and coronavirus (7Pe, 30Era)
+17: [W] Exposure to SARS-Cov 2 (7Pe, 30Era)
 18: [P] Multiple Inflammatory Syndrome (30Pe, 30Era)
-19: [P] Pneumonia (14Pe, 30Era)
+19: [P] Acute Typical Pneumonia (14Pe, 30Era)
 20: [P] Bronchitis (14Pe, 90Era)
 21: [P] Acute respiratory distress syndrome (ARDS) or Acute Respiratory Failure (3Pe, 30Era)
-22: [P] SARS-CoV-2 testing (1Ps, 0Era)
-23: [P] Hospitalization (1Pe, 30Era)
-24: [P] Emergency room visits (0Pe, 0Era)
-25: [P] All cause mortality
-26: [P] Asthma or Chronic obstructive pulmonary disease (COPD) (FP)
-27: [P] Asthma without COPD (FP)
-28: [P] Chronic obstructive pulmonary disease (COPD) without asthma (FP)
-30: [P] Tuberculosis (FP)
-31: [P] Malignant neoplasm excluding non-melanoma skin cancer (FP)
-32: [P] Obesity (FP)
-33: [P] Dementia (FP)
-34: [P] Hypertension (FP)
-36: [P] Human immunodeficiency virus infection (FP)
-37: [P] Hepatitis C (FP)
-38: [P] Heart disease (FP)
+22: [W] SARS-CoV-2 testing (1Ps, 0Era)
+26: [P] Asthma or Chronic obstructive pulmonary disease (COPD) (FP)
+27: [P] Asthma without COPD (FP)
+28: [P] Chronic obstructive pulmonary disease (COPD) without asthma (FP)
+29: [W] Autoimmune condition (FP)
+30: [P] Tuberculosis (FP)
+31: [P] Malignant neoplasm excluding non-melanoma skin cancer (FP)
+32: [P] Obesity (FP)
+33: [P] Dementia (FP)
+34: [P] Hypertensive disorder or hypertensive complications (FP)
+35: [W] Chronic kidney disease (FP)
+36: [P] Human immunodeficiency virus (not HIV2) infection (FP)
+37: [P] Hepatitis C (FP)
+38: [P] Heart disease (FP)
+39: [W] End stage renal disease (FP)
 40: [P] Diabetes Mellitus Type 2 (FP)
-43: [P] Tuberculosis broad (FP)
-45: [P] COVID-19 diagnosis with SARS-Cov-2 test (-3d to 3d) (3Pe, 21Era)
-46: [P] COVID-19 diagnosis and SARS-CoV-2 test (1pos) within 3d (3Pe, 21Era)
-47: [P] COVID-19 diagnosis and SARS-CoV-2 test (1pos) (0neg) within 3d (3Pe, 21Era)
-48: [P] COVID-19 diagnosis and SARS-CoV-2 test (0pos upto 3d, 1neg within 3d) (3Pe, 7Era)
-51: [P] SARS-CoV-2 test positive result (0Ps, 0Era)
-52: [P] SARS-CoV-2 test negative result (0Ps, 0Era)
-53: [P] SARS-CoV-2 test positive or negative result - keep persons with positive (0Ps, 0Era)
-54: [P] Febrile seizure (1Ps, 0Era)
-55: [P] COVID-19 diagnosis or SARS-CoV-2 test (1pos) (3Ps, 21Era)
-56: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (0 neg -3d to 3d) (3Ps, 21Era)
-57: [P] Bleeding (1Ps, 30Era)
-58: [P] SARS-CoV-2 test positive result (3Ps, 21Era)
-59: [P] COVID-19 diagnosis with no SARS-CoV-2 test (3Ps, 21Era)
-60: [P] SARS-CoV-2 test positive and negative result (0Ps, 0Era)
-61: [P] Bradycardia or heart block with inpatient admission (1Pe, 30Era)
-62: [P] Generalized Seizure (1Ps, 0Era)
-63: [P] Transverse myelitis (or symptoms with transverse myelitis) 365dWO (1Ps, 0Era)
-64: [P] Flu-like symptoms (3P, 30Era)
-65: [P] Acute pancreatitis with inpatient admission (3Pe, 30Era)
-66: [P] Acute renal failure with inpatient admission (3Pe, 30Era)
-67: [P] Hepatic failure with inpatient admission (3Pe, 30Era)
-68: [P] Heart failure with inpatient admission (3Pe, 30Era)
-69: [P] Angioedema with inpatient admission (7Ps, 30Era)
-70: [P] Stroke (ischemic or hemorrhagic) with inpatient admission (7Ps, 30Era)
-71: [P] Acute myocardial infarction with inpatient admission (7Ps, 180Era)
-72: [P] Influenza (narrow) (7Pe, 90Era)
-74: [P] Hemorrhagic stroke (intracerebral bleeding) with inpatient admission (7Ps, 180Era)
-75: [P] Ischemic stroke with inpatient admission (7Ps, 180Era)
-76: [P] Transient ischemic attack with inpatient admission (7Ps, 30Era)
-77: [P] Gastrointestinal bleeding with inpatient admission (7Ps, 30Era)
-78: [P] Cardiac arrhythmia with inpatient admission (1Pe, 30Era)
-79: [P] Dialysis with inpatient admission (1Ps, 7Era)
-80: [P] Extracorporeal Membrane Oxygenation with inpatient admission (1Ps, 30Era)
-81: [P] Cesarean section (7Pe, 180Era)
-82: [P] Intensive services during hospitalization (1Ps, 30Era)
-84: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (1pos or 0 neg 0d to 3d) (3Ps, 180Era)
-85: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (1pos or 0 neg 0d to 3d) (3Ps, 21Era)
-86: [P] SARS-CoV-2 test positive or negative result (0Ps, 0Era)
-87: [P] SARS-CoV-2 test (1Ps, 0Era)
-95: [P] Delirium (FP)
-189: [P] Right Upper Quadrant Pain (Pe1, 3Era)
-190: [P] Abdominal Distension (Pe1, 7Era)
-191: [P] Fatigue, Malaise, Lethargy, Anorexia (Pe1, 1Era)
-192: [P] Nausea or Vomiting (Pe1, 7Era)
-193: [P] Jaundice or Itching (Pe1, 7Era)
-194: [P] Encephalopathy or its presentations (Pe1, 7Era)
-195: [P] Urothelial bladder cancer (FP)
-197: [P] Coronary Artery Disease from vessel disease to ischemic injury (FP)
+41: [W] Chronic kidney disease broad (FP) +42: [W] End stage renal disease broad (FP) +43: [P] Respiratory or pulmonary tuberculosis (FP) +44: [W] COVID-19 diagnosis (3Pe, 7Era) +45: [W] COVID-19 diagnosis with SARS-Cov-2 test (-3d to 3d) (3Pe, 21Era) +46: [W] COVID-19 diagnosis and SARS-CoV-2 test (1pos) within 3d (3Pe, 21Era) +47: [W] COVID-19 diagnosis and SARS-CoV-2 test (1pos) (0neg) within 3d (3Pe, 21Era) +48: [W] COVID-19 diagnosis and SARS-CoV-2 test (0pos upto 3d, 1neg within 3d) (3Pe, 7Era) +51: [W] SARS-CoV-2 test positive result (0Ps, 0Era) +52: [W] SARS-CoV-2 test negative result (0Ps, 0Era) +53: [W] SARS-CoV-2 test positive or negative result - keep persons with positive (0Ps, 0Era) +54: [P] Febrile seizure (1Pe, 0Era, 42W) +55: [W] COVID-19 diagnosis or SARS-CoV-2 test (1pos) (3Ps, 21Era) +56: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (0 neg -3d to 3d) (3Ps, 21Era) +57: [P] Bleeding (1Pe, 0Era, 30W) +58: [W] SARS-CoV-2 test positive result (3Ps, 21Era) +59: [W] COVID-19 diagnosis with no SARS-CoV-2 test (3Ps, 21Era) +60: [W] SARS-CoV-2 test positive and negative result (0Ps, 0Era) +61: [P] Bradycardia or heart block with inpatient admission (1Pe, 30Era) +62: [P] Generalized Seizure (1Pe, 0Era, 42W) +63: [P] Transverse myelitis or symptoms (1Ps, 0Era, 365W) +64: [W] Flu-like symptoms fever, cough, malaise, fatigue, dyspnea, myalgia (3P, 30Era) +65: [W] Acute pancreatitis with inpatient admission (3Pe, 30Era) +66: [W] Acute renal failure with inpatient admission (3Pe, 30Era) +67: [W] Hepatic failure with inpatient admission (3Pe, 30Era) +68: [W] Heart failure with inpatient admission (3Pe, 30Era) +69: [W] Angioedema with inpatient admission (7Ps, 30Era) +70: [P] Stroke (ischemic or hemorrhagic) with inpatient admission (7Ps, 30Era) +71: [P] Acute myocardial infarction with inpatient admission (7Ps, 180Era) +72: [P] Influenza diagnosis or positive test result (7Pe, 90Era) +73: [W] Pregnancy (270P, 0Era) +74: [P] Hemorrhagic stroke (intracerebral bleeding) with inpatient admission (7Ps, 180Era) +75: [P] Ischemic stroke with inpatient admission (7Ps, 180Era) +76: [P] Transient ischemic attack with inpatient admission (7Ps, 30Era) +77: [P] Gastrointestinal bleeding with inpatient admission (7Ps, 30Era) +78: [P] Cardiac arrhythmia with inpatient admission (1Pe, 30Era) +79: [P] Dialysis with inpatient admission (1Ps, 7Era) +80: [P] Extracorporeal Membrane Oxygenation with inpatient admission (1Pe, 30Era) +81: [P] Cesarean section (7Pe, 180Era) +82: [P] Intensive services during hospitalization (1Ps, 30Era) +84: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (1pos or 0 neg 0d to 3d) (3Ps, 180Era) +85: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (1pos or 0 neg 0d to 3d) (3Ps, 21Era) +86: [W] SARS-CoV-2 test positive or negative result (0Ps, 0Era) +87: [W] SARS-CoV-2 test (1Ps, 0Era) +95: [P] Delirium (FP) +123: [W] First event of Suicide attempt, including injuries and poisonings with undetermined, 365 days +189: [P] Right Upper Quadrant Pain (Pe1, 0Era, 14W) +190: [P] Abdominal Distension (Pe1, 0Era, 14W) +191: [P] Fatigue, Malaise, Lethargy, Anorexia (Pe1, 0Era, 14W) +192: [P] Nausea or Vomiting (Pe1, 0Era, 7W) +193: [P] Jaundice or Itching (Pe1, 0Era, 14W) +194: [P] Encephalopathy or its presentations (Pe1, 0Era, 30W) +195: [P] Urothelial bladder cancer (FP) +197: [P] Coronary Artery Disease from vessel disease to ischemic injury (FP) +205: [W] Acute pancreatitis (7Pe, 0Era, 365W) +206: [W] Drug Induced Acute pancreatitis (7Pe, 365W) +207: [P] Acquired Pure Red Cell Aplasia +208: [P] Neutropenic Fever (3Pe, 30Era) +209: [P] Hemolytic Anemia, Extra corpuscular Acquired - G6PD deficiency excluded (7Pe, 0Era, 365W) +210: [P] Hemolytic Anemia, Extra corpuscular Acquired (7Pe, 0Era, 365W) +211: [P] Pancytopenia, Acquired +213: [P] Acquired Neutropenia or unspecified leukopenia (21Pe, 365Era) +214: [P] Acquired Isolated Neutropenia or unspecified leukopenia (21Pe, 365Era) +215: [P] Isolated Immune Thrombocytopenia (180Pe, 365Era) +216: [P] Isolated Immune Thrombocytopenia in absence of common thrombocytopenia causes (180Pe, 365Era) +217: [P] Thrombotic microangiopathy (TMA) or Microangiopathic hemolytic anemia (MAHA) +218: [P] Rhabdomyolysis (3Pe, 0Era, 180W) +219: [P] Sudden Cardiac arrest or cardiac death +220: [P] Angioedema (3Pe, 0Era, 180W) +221: [P] Anaphylaxis Non Environmental exposure related (1Pe, 0Era, 180W) +222: [P] Stevens-Johnson syndrome, toxic epidermal necrolysis spectrum +223: [P] Posterior reversible encephalopathy syndrome PRES (FP) +224: [P] Long QT Syndrome or QT prolonged (Acquired) +225: [P] Drug-induced Lupus (180Pe, 0Era, 365W) +226: [P] Drug Rash with Eosinophilia and Systemic Symptoms DRESS (1Pe, 0Era, 365W) +227: [P] Severe Cutaneous Adverse Reaction SCAR (SJS+TEN+DRESS+EM) (3Pe, 0Era, 365W) +228: [P] Severe Cutaneous Adverse Reaction SCAR (SJS+TEN+DRESS) (3Pe, 0Era, 365W) +229: [P] Progressive multifocal leukoencephalopathy +230: [P] Autoimmune hepatitis (1Pe, 0Era, 365W) +231: [P] Erythema multiforme (3Pe, 0Era, 365W) +232: [P] Paresthesia (3Pe, 0Era, 365W) +233: [P] Hemorrhagic stroke (1Pe, 0Era, 180W) +234: [P] Appendicitis (1Pe, 0Era, 365W) +235: [P] Guillain Barre syndrome (180Pe, FP) +236: [P] Idiopathic Peripheral Neuropathy (1Pe, 0Era, 365W) +237: [P] Kawasaki disease (1Pe, 0Era, 365W) +238: [P] Optic Neuritis (7Pe, 0Era, 365W) +239: [P] Narcolepsy events (1Pe, 0Era, 365W) +240: [P] Muscle weakness or monoplegia (1Pe, 0Era, 365W) +241: [P] Urticaria (1Pe, 0Era, 30W) +243: [P] Tinnitus (1Pe, 0Era, 365W) +244: [P] Dizziness (1Pe, 0Era, 180W) +245: [P] Hepatic Thrombosis (90Pe, 0Era) +246: [P] Portal vein thrombosis (90Pe, 0Era) +247: [P] Deep Vein Thrombosis DVT (90Pe, 0Era) +248: [P] Disseminated intravascular coagulation DIC (1Pe, 0Era, 365W) +249: [P] Ischemic (Non-hemorrhagic) Stroke (1Pe, 0Era, 365W)
+
+
+ +

New Cohorts: 43 were added. 205: [P] Acute pancreatitis (7Pe, 0Era, 365W) 206: [P] Drug Induced Acute pancreatitis (7Pe, 365W) 207: [P] Acquired Pure Red Cell Aplasia 208: [P] Neutropenic Fever (3Pe, 30Era) 209: [P] Hemolytic Anemia, Extra corpuscular Acquired - G6PD deficiency excluded (7Pe, 0Era, 365W) 210: [P] Hemolytic Anemia, Extra corpuscular Acquired (7Pe, 0Era, 365W) 211: [P] Pancytopenia, Acquired 213: [P] Acquired Neutropenia or unspecified leukopenia (21Pe, 365Era) 214: [P] Acquired Isolated Neutropenia or unspecified leukopenia (21Pe, 365Era) 215: [P] Isolated Immune Thrombocytopenia (180Pe, 365Era) 216: [P] Isolated Immune Thrombocytopenia in absence of common thrombocytopenia causes (180Pe, 365Era) 217: [P] Thrombotic microangiopathy or Microangiopathic hemolytic anemia 218: [P] Rhabdomyolysis (3Pe, 0Era, 180W) 219: [P] Sudden Cardiac arrest or cardiac death 220: [P] Angioedema (3Pe, 0Era, 180W) 221: [P] Anaphylaxis Non Environmental exposure related (1Pe, 0Era, 180W) 222: [P] Stevens-Johnson syndrome, toxic epidermal necrolysis spectrum 223: [P] Posterior reversible encephalopathy syndrome (PRES) 224: [P] Long QT Syndrome or QT prolonged (Acquired) 225: [P] Drug-induced Lupus (7Pe, 0Era, 365W) 226: [P] Drug Rash with Eosinophilia and Systemic Symptoms DRESS (1Pe, 0Era, 365W) 227: [P] Severe Cutaneous Adverse Reaction SCAR (SJS+TEN+DRESS+EM) (3Pe, 0Era, 365W) 228: [P] Severe Cutaneous Adverse Reaction SCAR (SJS+TEN+DRESS) (3Pe, 0Era, 365W) 229: [P] Progressive multifocal leukoencephalopathy 230: [P] Autoimmune hepatitis (1Pe, 0Era, 365W) 231: [P] Erythema multiforme (3Pe, 0Era, 365W) 232: [P] Paresthesia (3Pe, 0Era, 365W) 233: [P] Hemorrhagic stroke (1Pe, 0Era, 180W) 234: [P] Appendicitis (1Pe, 0Era, 365W) 235: [P] Guillain Barre syndrome (1Pe, 0Era, 365W) 236: [P] Idiopathic Peripheral Neuropathy (1Pe, 0Era, 365W) 237: [P] Kawasaki disease (1Pe, 0Era, 365W) 238: [P] Optic Neuritis (7Pe, 0Era, 365W) 239: [P] Narcolepsy events (1Pe, 0Era, 365W) 240: [P] Muscle weakness or monoplegia (1Pe, 0Era, 365W) 241: [P] Urticaria (1Pe, 0Era, 365W) 243: [P] Tinnitus (1Pe, 0Era, 365W) 244: [P] Dizziness (1Pe, 0Era, 365W) 245: [P] Hepatic Thrombosis (1Pe, 0Era, 365W) 246: [P] Portal vein thrombosis (1Pe, 0Era, 365W) 247: [P] Deep Vein Thrombosis DVT (1Pe, 0Era, 365W) 248: [P] Disseminated intravascular coagulation DIC (1Pe, 0Era, 365W) 249: [P] Ischemic (Non-hemorrhagic) Stroke (1Pe, 0Era, 365W) Deprecated Cohorts: No new cohorts were added in this release. Modified Cohorts: No cohorts were modified in this release.

+
+
+ +

New Cohorts: No new cohorts were added in this release.

+

Modified Cohorts: 85 were modified. These are only name modifications. These cohorts have not undergone Peer review process. They are not considered accepted. However, because of grandfathered status (i.e. these cohorts existed in Phenotype Library prior to version 3.0, results for these cohorts are computed as part of PhenotypeLibraryDiagnostics study package - unless withdrawn). The Cohort JSON specifications were not changed.

+
2: [P] COVID-19 diagnosis or SARS-CoV-2 test (1pos) (3Ps, 7Era)
+3: [P] Cough (3Ps, 30Era)
+4: [P] Diarrhea (7Ps, 30Era)
+5: [P] Dyspnea (14Pe, 30Era)
+6: [P] Fever (3Pe, 30Era)
+7: [P]Headache, Migraine, Neurologic pain (7Pe, 30Era)
+8: [P] Anosmia OR Hyposmia OR Dysgeusia (7Ps, 180Era)
+9: [P] Sore throat (7Pe, 30Era)
+10: [P] Nausea or Vomiting (3Pe, 30Era)
+11: [P] Malaise or fatigue (3P, 30Era)
+12: [P] Rhinitis or common cold (7P, 30Era)
+13: [P] Myalgia (not including secondary causes) (3Pe, 30Era)
+14: [P] Myalgia (3Pe, 30Era)
+15: [P] Exposure to Viral Disease (7Pe, 30Era)
+16: [P] Exposure to SARS-Cov 2 and coronavirus (7Pe, 30Era)
+17: [P] Exposure to SARS-Cov 2 (7Pe, 30Era)
+18: [P] Multiple Inflammatory Syndrome (30Pe, 30Era)
+19: [P] Pneumonia (14Pe, 30Era)
+20: [P] Bronchitis (14Pe, 90Era)
+21: [P] Acute respiratory distress syndrome (ARDS) or Acute Respiratory Failure (3Pe, 30Era)
+22: [P] SARS-CoV-2 testing (1Ps, 0Era)
+23: [P] Hospitalization (1Pe, 30Era)
+24: [P] Emergency room visits (0Pe, 0Era)
+25: [P] All cause mortality
+26: [P] Asthma or Chronic obstructive pulmonary disease (COPD) (FP)
+27: [P] Asthma without COPD (FP)
+28: [P] Chronic obstructive pulmonary disease (COPD) without asthma (FP)
+30: [P] Tuberculosis (FP)
+31: [P] Malignant neoplasm excluding non-melanoma skin cancer (FP)
+32: [P] Obesity (FP)
+33: [P] Dementia (FP)
+34: [P] Hypertension (FP)
+36: [P] Human immunodeficiency virus infection (FP)
+37: [P] Hepatitis C (FP)
+38: [P] Heart disease (FP)
+40: [P] Diabetes Mellitus Type 2 (FP)
+43: [P] Tuberculosis broad (FP)
+45: [P] COVID-19 diagnosis with SARS-Cov-2 test (-3d to 3d) (3Pe, 21Era)
+46: [P] COVID-19 diagnosis and SARS-CoV-2 test (1pos) within 3d (3Pe, 21Era)
+47: [P] COVID-19 diagnosis and SARS-CoV-2 test (1pos) (0neg) within 3d (3Pe, 21Era)
+48: [P] COVID-19 diagnosis and SARS-CoV-2 test (0pos upto 3d, 1neg within 3d) (3Pe, 7Era)
+51: [P] SARS-CoV-2 test positive result (0Ps, 0Era)
+52: [P] SARS-CoV-2 test negative result (0Ps, 0Era)
+53: [P] SARS-CoV-2 test positive or negative result - keep persons with positive (0Ps, 0Era)
+54: [P] Febrile seizure (1Ps, 0Era)
+55: [P] COVID-19 diagnosis or SARS-CoV-2 test (1pos) (3Ps, 21Era)
+56: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (0 neg -3d to 3d) (3Ps, 21Era)
+57: [P] Bleeding (1Ps, 30Era)
+58: [P] SARS-CoV-2 test positive result (3Ps, 21Era)
+59: [P] COVID-19 diagnosis with no SARS-CoV-2 test (3Ps, 21Era)
+60: [P] SARS-CoV-2 test positive and negative result (0Ps, 0Era)
+61: [P] Bradycardia or heart block with inpatient admission (1Pe, 30Era)
+62: [P] Generalized Seizure (1Ps, 0Era)
+63: [P] Transverse myelitis (or symptoms with transverse myelitis) 365dWO (1Ps, 0Era)
+64: [P] Flu-like symptoms (3P, 30Era)
+65: [P] Acute pancreatitis with inpatient admission (3Pe, 30Era)
+66: [P] Acute renal failure with inpatient admission (3Pe, 30Era)
+67: [P] Hepatic failure with inpatient admission (3Pe, 30Era)
+68: [P] Heart failure with inpatient admission (3Pe, 30Era)
+69: [P] Angioedema with inpatient admission (7Ps, 30Era)
+70: [P] Stroke (ischemic or hemorrhagic) with inpatient admission (7Ps, 30Era)
+71: [P] Acute myocardial infarction with inpatient admission (7Ps, 180Era)
+72: [P] Influenza (narrow) (7Pe, 90Era)
+74: [P] Hemorrhagic stroke (intracerebral bleeding) with inpatient admission (7Ps, 180Era)
+75: [P] Ischemic stroke with inpatient admission (7Ps, 180Era)
+76: [P] Transient ischemic attack with inpatient admission (7Ps, 30Era)
+77: [P] Gastrointestinal bleeding with inpatient admission (7Ps, 30Era)
+78: [P] Cardiac arrhythmia with inpatient admission (1Pe, 30Era)
+79: [P] Dialysis with inpatient admission (1Ps, 7Era)
+80: [P] Extracorporeal Membrane Oxygenation with inpatient admission (1Ps, 30Era)
+81: [P] Cesarean section (7Pe, 180Era)
+82: [P] Intensive services during hospitalization (1Ps, 30Era)
+84: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (1pos or 0 neg 0d to 3d) (3Ps, 180Era)
+85: [P] SARS-CoV-2 test (1pos) or COVID-19 diagnosis with (1pos or 0 neg 0d to 3d) (3Ps, 21Era)
+86: [P] SARS-CoV-2 test positive or negative result (0Ps, 0Era)
+87: [P] SARS-CoV-2 test (1Ps, 0Era)
+95: [P] Delirium (FP)
+189: [P] Right Upper Quadrant Pain (Pe1, 3Era)
+190: [P] Abdominal Distension (Pe1, 7Era)
+191: [P] Fatigue, Malaise, Lethargy, Anorexia (Pe1, 1Era)
+192: [P] Nausea or Vomiting (Pe1, 7Era)
+193: [P] Jaundice or Itching (Pe1, 7Era)
+194: [P] Encephalopathy or its presentations (Pe1, 7Era)
+195: [P] Urothelial bladder cancer (FP)
+197: [P] Coronary Artery Disease from vessel disease to ischemic injury (FP)

Withdrawn Cohorts: 13 were withdrawn prior to peer review. These cohorts have not undergone Peer review process. They are not considered accepted. It has been withdrawn prior to peer review. The Cohort JSON specifications were not changed. 29: [W] Autoimmune condition (FP) 35: [W] Chronic kidney disease (FP) 39: [W] End stage renal disease (FP) 41: [W] Chronic kidney disease broad (FP) 42: [W] End stage renal disease broad (FP) 44: [W] COVID-19 diagnosis (3Pe, 7Era) 73: [W] Pregnancy (270P, 0Era) 123: [W] First event of Suicide attempt, including injuries and poisonings with undetermined, 365 days 196: [W] Rheumatoid arthritis (FP) 198: [W] Crohns disease (FP) 199: [W] Major Depressive Disorder (FP) 200: [W] Plaque psoriasis (FP) 201: [W] Ulcerative colitis (FP)

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index ce065e5f..523bc476 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -15,4 +15,4 @@ articles: ReservedWordsWithSpecialMeaningToPhenotypers: ReservedWordsWithSpecialMeaningToPhenotypers.html SubmittedCohortDefinitions: SubmittedCohortDefinitions.html ValidityChecksForCohortDefinitions: ValidityChecksForCohortDefinitions.html -last_built: 2025-03-29T11:07Z +last_built: 2025-04-02T23:46Z diff --git a/docs/reference/PhenotypeLibrary-package.html b/docs/reference/PhenotypeLibrary-package.html index 8a0fd8dc..de71cd3b 100644 --- a/docs/reference/PhenotypeLibrary-package.html +++ b/docs/reference/PhenotypeLibrary-package.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0
diff --git a/docs/reference/getPhenotypeLog.html b/docs/reference/getPhenotypeLog.html index e5d1545f..0a5c94cc 100644 --- a/docs/reference/getPhenotypeLog.html +++ b/docs/reference/getPhenotypeLog.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 diff --git a/docs/reference/getPlCohortDefinitionSet.html b/docs/reference/getPlCohortDefinitionSet.html index fae8b0cc..b2f8c6c0 100644 --- a/docs/reference/getPlCohortDefinitionSet.html +++ b/docs/reference/getPlCohortDefinitionSet.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 diff --git a/docs/reference/getPlConceptDefinitionSet.html b/docs/reference/getPlConceptDefinitionSet.html index 3f5801e9..6367cba5 100644 --- a/docs/reference/getPlConceptDefinitionSet.html +++ b/docs/reference/getPlConceptDefinitionSet.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 diff --git a/docs/reference/index.html b/docs/reference/index.html index 3dd50371..aff7377d 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 diff --git a/docs/reference/listPhenotypes.html b/docs/reference/listPhenotypes.html index 178c7a2e..61a03759 100644 --- a/docs/reference/listPhenotypes.html +++ b/docs/reference/listPhenotypes.html @@ -17,7 +17,7 @@ PhenotypeLibrary - 3.35.0 + 3.36.0 @@ -115,7 +115,7 @@

Value

Examples

listPhenotypes()
 #> Warning: listPhenotypes is deprecated. use getPhenotypeLog
-#> # A tibble: 661 × 88
+#> # A tibble: 703 × 88
 #>    cohortId cohortName        cohortNameAtlas cohortNameFormatted cohortNameLong
 #>       <dbl> <chr>             <chr>           <chr>               <chr>         
 #>  1        3 Cough or Sputum   [P] Cough or S… Cough or Sputum     Cough or Sput…
@@ -128,7 +128,7 @@ 

Examples

#> 8 10 Nausea or Vomiti… [P] Nausea or … Nausea or Vomiting Nausea or Vom… #> 9 11 Malaise and or f… [P] Malaise an… Malaise and or fat… Malaise and o… #> 10 12 Rhinitis or comm… [P] Rhinitis o… Rhinitis or common… Rhinitis or c… -#> # ℹ 651 more rows +#> # ℹ 693 more rows #> # ℹ 83 more variables: librarian <chr>, status <chr>, addedVersion <chr>, #> # logicDescription <chr>, hashTag <chr>, isCirceJson <dbl>, #> # contributors <chr>, contributorOrcIds <chr>, diff --git a/inst/Cohorts.csv b/inst/Cohorts.csv index 59bb5cc1..836b7545 100644 --- a/inst/Cohorts.csv +++ b/inst/Cohorts.csv @@ -1001,7 +1001,7 @@ 1317,"[P] Reyes syndrome","Reyes syndrome","Reyes syndrome","rao@ohdsi.org","Pending peer review","","First occurrence of Reyes syndrome","#Disease, #DME",1,"'Gowtham A. Rao', 'Azza Shoaibi'","'0000-0002-4949-7236', '0000-0002-6976-2594'","'OHDSI'","","","375241","","2024-09-11","2024-09-26",,"",,0,,,"ERA","0","end of continuous observation",,,0,"First",FALSE,"All","First",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,,,,,,,,,,, 1318,"[P] NSCLC solitary primary rx naive","NSCLC solitary primary rx naive","Solitary Primary Non Small Cell Lung Cancer - treatment naive","rao@ohdsi.org","Pending peer review","","First occurrence of Solitary Primary Non Small Cell Lung Cancer - treatment naive","#Oncology, #LungCancer",1,"Gowtham A. Rao","'0000-0002-4949-7236'","'OHDSI'","","","4311499","","2024-12-06","2025-03-28",,"",,0,,,"ERA","0","end of continuous observation",,,43,"First",TRUE,"First","First",1,1,"ConditionOccurrence",365,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,,,,,,,,,,, 1329,"[P] Death due to substance overdose (post mortem)","Death due to substance overdose (post mortem)","Death due to substance overdose","rao@ohdsi.org","Pending peer review","","first event of death with measurement of overdose within 7 days of death to account for reporting date discrepancy","#Death",1,"Gowtham A. Rao","'0000-0002-4949-7236'","'OHDSI'","","","4306655","","2025-03-28","2025-03-28",,"",,0,,,"ERA","0","fixed duration relative to initial event","StartDate",0,1,"First",FALSE,"All","First",2,2,"Death, Observation",0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,,1,,,,,,,, -1330,"[P] Acute Overdose (or “Acute Toxicity”) by substances with abuse potential","Acute Overdose (or “Acute Toxicity”) by substances with abuse potential","Acute Overdose (or “Acute Toxicity”) by substances with abuse potential","rao@ohdsi.org","Pending peer review","","Acute Overdose (or “Acute Toxicity”) by substances with abuse potential events","#SubstanceUseDisorder, #MentalHealth",1,"'Gowtham A. Rao', 'Azza Shoaibi'","'0000-0002-4949-7236', '0000-0002-6976-2594'","'OHDSI'","","","602985","","2025-03-28","2025-03-28",,"",,0,,,"ERA","1","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1330,"[P] Acute Overdose (or “Acute Toxicity”) by substances with abuse potential","Acute Overdose (or “Acute Toxicity”) by substances with abuse potential","Acute Overdose (or Acute Toxicity) by substances with abuse potential","rao@ohdsi.org","Pending peer review","","Acute Overdose (or Acute Toxicity) by substances with abuse potential events","#SubstanceUseDisorder, #MentalHealth",1,"'Gowtham A. Rao', 'Azza Shoaibi'","'0000-0002-4949-7236', '0000-0002-6976-2594'","'OHDSI'","","","602985","","2025-03-28","2025-03-31",,"",,0,,,"ERA","1","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, 1331,"[P] Opioid overdose - treatment drugs","Opioid overdose - treatment drugs","Opioid overdose - treatment drugs","rao@ohdsi.org","Pending peer review","","Opioid overdose - treatment drugs","#SubstanceUseDisorder, #MentalHealth",1,"'Gowtham A. Rao', 'Azza Shoaibi'","'0000-0002-4949-7236', '0000-0002-6976-2594'","'OHDSI'","","","21604816","","2025-03-28","2025-03-28",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,0,30,0, 1332,"[P] Alcohol poisoning (acute severe intoxication)","Alcohol poisoning (acute severe intoxication)","Alcohol poisoning (acute severe intoxication)","rao@ohdsi.org","Pending peer review","","All events of Alcohol poisoning (acute severe intoxication)","#SubstanceUseDisorder, #MentalHealth",1,"'Gowtham A. Rao', 'Azza Shoaibi'","'0000-0002-4949-7236', '0000-0002-6976-2594'","'OHDSI'","","","602985","","2025-03-28","2025-03-28",,"",,0,,,"ERA","1","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, 1333,"[P] Advanced liver disease","Advanced liver disease","Advanced Liver Disease","rao@ohdsi.org","Pending peer review","","earliest event of Advanced Liver Disease. Persons exit on end of observation period","#Condition",1,"Gowtham A. Rao","'0000-0002-4949-7236'","'OHDSI'","","","45769564","","2025-03-28","2025-03-28",,"",,0,,,"ERA","0","end of continuous observation",,,0,"First",FALSE,"All","First",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,,,,,, @@ -1057,3 +1057,45 @@ 1384,"[P] Any Distress (Physical or Mental)","Any Distress (Physical or Mental)","[P] Any Distress (Physical or Mental)","rao@ohdsi.org","Pending peer review","","All events of [P] Any Distress (Physical or Mental)","#Disease",1,"Gowtham A. Rao","'0000-0002-4949-7236'","'OHDSI'","","","37162280","","2025-03-29","2025-03-29",,"",,0,,,"ERA","365","fixed duration relative to initial event","EndDate",7,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, 1385,"[P] Withdrawal of substances with abuse potential","Withdrawal of substances with abuse potential","[P] Withdrawal of substances with abuse potential","rao@ohdsi.org","Pending peer review","","All events of [P] Withdrawal of substances with abuse potential","#Disease",1,"Gowtham A. Rao","'0000-0002-4949-7236'","'OHDSI'","","","37162280","","2025-03-29","2025-03-29",,"",,0,,,"ERA","365","fixed duration relative to initial event","EndDate",3,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, 1386,"[P] Withdrawal Seizures","Withdrawal Seizures","[P] Withdrawal Seizures","rao@ohdsi.org","Pending peer review","","All events of [P] Withdrawal Seizures","#Disease",1,"Gowtham A. Rao","'0000-0002-4949-7236'","'OHDSI'","","","37162280","","2025-03-29","2025-03-29",,"",,0,,,"ERA","365","fixed duration relative to initial event","EndDate",3,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1387,"[P] Methadone","Methadone","[P] Methadone","rao@ohdsi.org","Pending peer review","","[P] Methadone","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,0,90, +1388,"[P] Methadone Treatment Program Enrollment","Methadone Treatment Program Enrollment","[P] Methadone Treatment Program Enrollment","rao@ohdsi.org","Pending peer review","","[P] Methadone Treatment Program Enrollment","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","90","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",2,2,"ProcedureOccurrence, VisitOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,1,,,,1,,,,, +1389,"[P] Naltrexone","Naltrexone","[P] Naltrexone","rao@ohdsi.org","Pending peer review","","[P] Naltrexone","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,0,90, +1390,"[P] Naltrexone Maintenance Therapy","Naltrexone Maintenance Therapy","[P] Naltrexone Maintenance Therapy","rao@ohdsi.org","Pending peer review","","[P] Naltrexone Maintenance Therapy","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","180","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,1,,,,, +1391,"[P] Opioid Agonists","Opioid Agonists","[P] Opioid Agonists","rao@ohdsi.org","Pending peer review","","[P] Opioid Agonists","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,0,90, +1392,"[P] Opioid Antagonists","Opioid Antagonists","[P] Opioid Antagonists","rao@ohdsi.org","Pending peer review","","[P] Opioid Antagonists","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,0,90, +1393,"[P] Medication-Assisted Treatment","Medication-Assisted Treatment","[P] Medication-Assisted Treatment","rao@ohdsi.org","Pending peer review","","[P] Medication-Assisted Treatment","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","90","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",2,2,"Observation, ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,1,,,,, +1394,"[P] Nicotine Replacement Therapy","Nicotine Replacement Therapy","[P] Nicotine Replacement Therapy","rao@ohdsi.org","Pending peer review","","[P] Nicotine Replacement Therapy","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,0,90, +1395,"[P] OTC Nicotine Replacement","OTC Nicotine Replacement","[P] OTC Nicotine Replacement","rao@ohdsi.org","Pending peer review","","[P] OTC Nicotine Replacement","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,0,90, +1396,"[P] Varenicline","Varenicline","[P] Varenicline","rao@ohdsi.org","Pending peer review","","[P] Varenicline","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,0,90, +1397,"[P] Pain Management","Pain Management","[P] Pain Management","rao@ohdsi.org","Pending peer review","","[P] Pain Management","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","180","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,1,,,,, +1398,"[P] Terminal Palliative Care","Terminal Palliative Care","[P] Terminal Palliative Care","rao@ohdsi.org","Pending peer review","","[P] Terminal Palliative Care","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","30","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",2,2,"Observation, ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,1,,,,, +1399,"[P] Alcohol Misuse Counseling","Alcohol Misuse Counseling","[P] Alcohol Misuse Counseling","rao@ohdsi.org","Pending peer review","","[P] Alcohol Misuse Counseling","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","90","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,1,,,,, +1400,"[P] Smoking Cessation Counseling","Smoking Cessation Counseling","[P] Smoking Cessation Counseling","rao@ohdsi.org","Pending peer review","","[P] Smoking Cessation Counseling","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","180","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,1,,,,, +1401,"[P] Psychotherapy","Psychotherapy","[P] Psychotherapy","rao@ohdsi.org","Pending peer review","","[P] Psychotherapy","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","30","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",2,2,"Observation, ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,1,,,,, +1402,"[P] Group Therapy","Group Therapy","[P] Group Therapy","rao@ohdsi.org","Pending peer review","","[P] Group Therapy","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","30","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",2,2,"Observation, ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,1,,,,, +1403,"[P] Family Psychotherapy","Family Psychotherapy","[P] Family Psychotherapy","rao@ohdsi.org","Pending peer review","","[P] Family Psychotherapy","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","90","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,1,,,,, +1404,"[P] Behavioral Therapies","Behavioral Therapies","[P] Behavioral Therapies","rao@ohdsi.org","Pending peer review","","[P] Behavioral Therapies","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","365","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,1,,,,, +1405,"[P] 12-Step Facilitation Behavioral Therapy","12-Step Facilitation Behavioral Therapy","[P] 12-Step Facilitation Behavioral Therapy","rao@ohdsi.org","Pending peer review","","[P] 12-Step Facilitation Behavioral Therapy","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","365","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,1,,,,, +1406,"[P] Harm Reduction Interventions","Harm Reduction Interventions","[P] Harm Reduction Interventions","rao@ohdsi.org","Pending peer review","","[P] Harm Reduction Interventions","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","365","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",2,2,"Observation, ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,1,,,,, +1407,"[P] Specialty Addiction Treatment","Specialty Addiction Treatment","[P] Specialty Addiction Treatment","rao@ohdsi.org","Pending peer review","","[P] Specialty Addiction Treatment","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","30","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",2,2,"ProcedureOccurrence, VisitOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,1,,,,1,,,,, +1408,"[P] Alcohol Use Screening","Alcohol Use Screening","[P] Alcohol Use Screening","rao@ohdsi.org","Pending peer review","","[P] Alcohol Use Screening","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","1","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",2,2,"Measurement, Observation",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,,,,,, +1409,"[P] Screening for substance abuse","Screening for substance abuse","[P] Screening for substance abuse","rao@ohdsi.org","Pending peer review","","[P] Screening for substance abuse","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","1","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"Measurement",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1410,"[P] Use of Substance Use Screening Tools","Use of Substance Use Screening Tools","[P] Use of Substance Use Screening Tools","rao@ohdsi.org","Pending peer review","","[P] Use of Substance Use Screening Tools","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","1","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",3,3,"Measurement, Observation, ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,1,,,,, +1411,"[P] Laboratory Toxicology Tests","Laboratory Toxicology Tests","[P] Laboratory Toxicology Tests","rao@ohdsi.org","Pending peer review","","[P] Laboratory Toxicology Tests","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","1","fixed duration relative to initial event","EndDate",0,0,"All",FALSE,"All","All",1,1,"Measurement",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1412,"[P] Naloxone Dispensing","Naloxone Dispensing","[P] Naloxone Dispensing","rao@ohdsi.org","Pending peer review","","[P] Naloxone Dispensing","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,1,1, +1413,"[P] Screening, Brief Intervention, and Referral to Treatment (SBIRT)","Screening, Brief Intervention, and Referral to Treatment (SBIRT)","[P] Screening, Brief Intervention, and Referral to Treatment (SBIRT)","rao@ohdsi.org","Pending peer review","","[P] Screening, Brief Intervention, and Referral to Treatment (SBIRT)","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",2,2,"Observation, ProcedureOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,1,,,,, +1415,"[P] Impaired Control","Impaired Control","[P] Impaired Control","rao@ohdsi.org","Pending peer review","","[P] Impaired Control","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","fixed duration relative to initial event","EndDate",180,0,"All",FALSE,"All","All",2,2,"ConditionOccurrence, Observation",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,,,,,, +1416,"[P] Neglect of Roles or Social Impairment","Neglect of Roles or Social Impairment","[P] Neglect of Roles or Social Impairment","rao@ohdsi.org","Pending peer review","","[P] Neglect of Roles or Social Impairment","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","fixed duration relative to initial event","EndDate",14,0,"All",FALSE,"All","All",1,1,"Observation",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,,,,,, +1417,"[P] Risky Use","Risky Use","[P] Risky Use","rao@ohdsi.org","Pending peer review","","[P] Risky Use","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","30","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",1,1,"Observation",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,,,,,, +1418,"[P] Tolerance","Tolerance","[P] Tolerance","rao@ohdsi.org","Pending peer review","","[P] Tolerance","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","fixed duration relative to initial event","EndDate",90,0,"All",FALSE,"All","All",1,1,"Observation",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,,,,,, +1419,"[P] Pattern of Use Causing Harm or Distress","Pattern of Use Causing Harm or Distress","[P] Pattern of Use Causing Harm or Distress","rao@ohdsi.org","Pending peer review","","[P] Pattern of Use Causing Harm or Distress","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","fixed duration relative to initial event","EndDate",30,0,"All",FALSE,"All","All",2,2,"ConditionOccurrence, Observation",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,,,,,, +1420,"[P] Medical Conditions Mimicking Intoxication","Medical Conditions Mimicking Intoxication","[P] Medical Conditions Mimicking Intoxication","rao@ohdsi.org","Pending peer review","","[P] Medical Conditions Mimicking Intoxication","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","30","fixed duration relative to initial event","EndDate",14,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1421,"[P] Hypoglycemic disorder","Hypoglycemic disorder","[P] Hypoglycemic disorder","rao@ohdsi.org","Pending peer review","","[P] Hypoglycemic disorder","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","7","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1422,"[P] Stroke events","Stroke events","[P] Stroke events","rao@ohdsi.org","Pending peer review","","[P] Stroke events","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","30","fixed duration relative to initial event","EndDate",7,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1423,"[P] Single Acute Intoxication","Single Acute Intoxication","[P] Single Acute Intoxication","rao@ohdsi.org","Pending peer review","","[P] Single Acute Intoxication","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","7","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1424,"[P] Opioid Acute intoxication","Opioid Acute intoxication","[P] Opioid Acute intoxication","rao@ohdsi.org","Pending peer review","","[P] Opioid Acute intoxication","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","7","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",2,2,"ConditionOccurrence, DrugExposure",0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,,,, +1425,"[P] Alcohol Acute intoxication","Alcohol Acute intoxication","[P] Alcohol Acute intoxication","rao@ohdsi.org","Pending peer review","","[P] Alcohol Acute intoxication","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","7","fixed duration relative to initial event","EndDate",1,0,"All",FALSE,"All","All",1,1,"ConditionOccurrence",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,,,,,,,, +1426,"[P] Psychoactive Substances","Psychoactive Substances","[P] Psychoactive Substances","rao@ohdsi.org","Pending peer review","","[P] Psychoactive Substances","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","180","fixed duration relative to initial event","EndDate",7,0,"All",FALSE,"All","All",2,2,"ConditionOccurrence, Observation",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,,,,,,,,,, +1427,"[P] Acamprosate, all exposures","Acamprosate, all exposures","[P] Acamprosate, all exposures","rao@ohdsi.org","Pending peer review","","[P] Acamprosate, all exposures","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,0,1,30, +1428,"[P] Disulfiram, all exposures","Disulfiram, all exposures","[P] Disulfiram, all exposures","rao@ohdsi.org","Pending peer review","","[P] Disulfiram, all exposures","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,0,1,30, +1429,"[P] Buprenorphine, all exposures","Buprenorphine, all exposures","[P] Buprenorphine, all exposures","rao@ohdsi.org","Pending peer review","","[P] Buprenorphine, all exposures","",1,"Gowtham A. Rao","0000-0002-4949-7236","","","","","","2025-04-02","2025-04-02",,"",,0,,,"ERA","0","end of continuous drug exposure",,,0,"All",FALSE,"All","All",1,1,"DrugExposure",0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,,,,1,,,,1,0,30, diff --git a/inst/ConceptSetsInCohortDefinition.RDS b/inst/ConceptSetsInCohortDefinition.RDS index ed50f7f0..eaee8318 100644 Binary files a/inst/ConceptSetsInCohortDefinition.RDS and b/inst/ConceptSetsInCohortDefinition.RDS differ diff --git a/inst/OrcidLog.csv b/inst/OrcidLog.csv index ba1d329a..a174464b 100644 --- a/inst/OrcidLog.csv +++ b/inst/OrcidLog.csv @@ -15,7 +15,7 @@ "0000-0002-2970-0778","Jenna","Reps","",64,0 "0000-0002-4243-155X","Asieh","Golozar","",8,0 "0000-0002-4449-8598","Jessica","Shantha","",7,0 -"0000-0002-4949-7236","Gowtham","Rao","",611,15 +"0000-0002-4949-7236","Gowtham","Rao","",653,15 "0000-0002-6662-5850","Rupesh","Agrawal","",7,0 "0000-0002-6976-2594","Azza","Shoaibi","",84,0 "0000-0002-9612-5697","Brian","Toy","",8,0 diff --git a/inst/cohorts/1330.json b/inst/cohorts/1330.json index b8540117..e54dd6e9 100644 --- a/inst/cohorts/1330.json +++ b/inst/cohorts/1330.json @@ -20,7 +20,7 @@ "ConceptSets" : [ { "id" : 0, - "name" : "Acute Overdose (or “Acute Toxicity”) by substances with abuse potential", + "name" : "Acute Overdose (or Acute Toxicity) by substances with abuse potential", "expression" : { "items" : [ { diff --git a/inst/cohorts/1387.json b/inst/cohorts/1387.json new file mode 100644 index 00000000..461a6d09 --- /dev/null +++ b/inst/cohorts/1387.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "Methadone", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1103640, + "CONCEPT_NAME" : "methadone", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "6813", + "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" : 1, + "GapDays" : 0, + "Offset" : 90 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1388.json b/inst/cohorts/1388.json new file mode 100644 index 00000000..6752ccac --- /dev/null +++ b/inst/cohorts/1388.json @@ -0,0 +1,72 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "VisitOccurrence" : { + "CodesetId" : 2, + "VisitTypeExclude" : false + } + }, + { + "ProcedureOccurrence" : { + "CodesetId" : 2, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 2, + "name" : "methadone treatment program enrollment", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 38004241, + "CONCEPT_NAME" : "Ambulatory Methadone Clinic", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "261QM2800X", + "DOMAIN_ID" : "Visit", + "VOCABULARY_ID" : "NUCC", + "CONCEPT_CLASS_ID" : "Visit" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 90 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1389.json b/inst/cohorts/1389.json new file mode 100644 index 00000000..b2459e57 --- /dev/null +++ b/inst/cohorts/1389.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "naltrexone", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 21604824, + "CONCEPT_NAME" : "naltrexone; oral", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N07BB04", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 5th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 1, + "GapDays" : 0, + "Offset" : 90 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1390.json b/inst/cohorts/1390.json new file mode 100644 index 00000000..581ea075 --- /dev/null +++ b/inst/cohorts/1390.json @@ -0,0 +1,66 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 2, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 2, + "name" : "naltrexone maintenance therapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 44804691, + "CONCEPT_NAME" : "Drug addiction maintenance therapy - naltrexone", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "768691000000103", + "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" : 180 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1391.json b/inst/cohorts/1391.json new file mode 100644 index 00000000..e50c7bb7 --- /dev/null +++ b/inst/cohorts/1391.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "opioid agonists", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 21604825, + "CONCEPT_NAME" : "Drugs used in opioid dependence", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N07BC", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 4th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 1, + "GapDays" : 0, + "Offset" : 90 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1392.json b/inst/cohorts/1392.json new file mode 100644 index 00000000..8284affb --- /dev/null +++ b/inst/cohorts/1392.json @@ -0,0 +1,118 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "opioid antagonists", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1114220, + "CONCEPT_NAME" : "naloxone", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "7242", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1714319, + "CONCEPT_NAME" : "naltrexone", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "7243", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19014158, + "CONCEPT_NAME" : "nalmefene", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "31479", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 909841, + "CONCEPT_NAME" : "methylnaltrexone", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "29899", + "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" : 1, + "GapDays" : 0, + "Offset" : 90 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1393.json b/inst/cohorts/1393.json new file mode 100644 index 00000000..2eb69e63 --- /dev/null +++ b/inst/cohorts/1393.json @@ -0,0 +1,242 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 1, + "ProcedureTypeExclude" : false + } + }, + { + "Observation" : { + "CodesetId" : 1, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "medication-assisted treatment", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40217336, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (implant insertion); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medi...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2070", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217335, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (implant removal); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medica...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2071", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217334, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (implant insertion and removal); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the servic...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2072", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217338, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (oral); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-enrolled...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2068", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217337, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (injectable); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-en...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2069", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217333, + "CONCEPT_NAME" : "Medication assisted treatment, naltrexone; weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-enrolled opioid tr...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2073", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217339, + "CONCEPT_NAME" : "Medication assisted treatment, methadone; weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing, if performed (provision of the services by a medicare-enrolled opioid tr...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2067", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217332, + "CONCEPT_NAME" : "Medication assisted treatment, weekly bundle not including the drug, including substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-enrolled opioid treatment program)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2074", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217331, + "CONCEPT_NAME" : "Medication assisted treatment, medication not otherwise specified; weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing, if performed (provision of the services by a me...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2075", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217326, + "CONCEPT_NAME" : "Each additional 30 minutes of counseling in a week of medication assisted treatment, (provision of the services by a medicare-enrolled opioid treatment program); list separately in addition to code for primary procedure", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2080", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217332, + "CONCEPT_NAME" : "Medication assisted treatment, weekly bundle not including the drug, including substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-enrolled opioid treatment program)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2074", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 90 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1394.json b/inst/cohorts/1394.json new file mode 100644 index 00000000..bb10b02f --- /dev/null +++ b/inst/cohorts/1394.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "nicotine replacement therapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 21604818, + "CONCEPT_NAME" : "nicotine; chewing gum, inhalant, nasal, sublingual, transdermal", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N07BA01", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 5th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 1, + "GapDays" : 0, + "Offset" : 90 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1395.json b/inst/cohorts/1395.json new file mode 100644 index 00000000..0961b24b --- /dev/null +++ b/inst/cohorts/1395.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "OTC nicotine replacement", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 21604818, + "CONCEPT_NAME" : "nicotine; chewing gum, inhalant, nasal, sublingual, transdermal", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N07BA01", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 5th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "CustomEra" : { + "DrugCodesetId" : 1, + "GapDays" : 0, + "Offset" : 90 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1396.json b/inst/cohorts/1396.json new file mode 100644 index 00000000..35a3026c --- /dev/null +++ b/inst/cohorts/1396.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "varenicline", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 780442, + "CONCEPT_NAME" : "varenicline", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "591622", + "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" : 1, + "GapDays" : 0, + "Offset" : 90 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1397.json b/inst/cohorts/1397.json new file mode 100644 index 00000000..48e32195 --- /dev/null +++ b/inst/cohorts/1397.json @@ -0,0 +1,66 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "pain management", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4083171, + "CONCEPT_NAME" : "Pain management", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "278414003", + "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" : 180 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1398.json b/inst/cohorts/1398.json new file mode 100644 index 00000000..ee2c9554 --- /dev/null +++ b/inst/cohorts/1398.json @@ -0,0 +1,123 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + }, + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "terminal palliative care", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4082728, + "CONCEPT_NAME" : "Terminal care", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "182964004", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4176643, + "CONCEPT_NAME" : "Palliative procedure", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "362964009", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2514512, + "CONCEPT_NAME" : "Supervision of a hospice patient (patient not present) requiring complex and multidisciplinary care modalities involving regular development and/or revision of care plans by that individual, review of subsequent reports of patient status, review of relate", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99377", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2514513, + "CONCEPT_NAME" : "Supervision of a hospice patient (patient not present) requiring complex and multidisciplinary care modalities involving regular development and/or revision of care plans by that individual, review of subsequent reports of patient status, review of relate", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99378", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 30 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1399.json b/inst/cohorts/1399.json new file mode 100644 index 00000000..acb9d3af --- /dev/null +++ b/inst/cohorts/1399.json @@ -0,0 +1,66 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "alcohol misuse counseling", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4211325, + "CONCEPT_NAME" : "Alcohol consumption counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "413473000", + "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" : 90 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1400.json b/inst/cohorts/1400.json new file mode 100644 index 00000000..5999262a --- /dev/null +++ b/inst/cohorts/1400.json @@ -0,0 +1,66 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "smoking cessation counseling", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 46272634, + "CONCEPT_NAME" : "Counseling about tobacco use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "711028002", + "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" : 180 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1401.json b/inst/cohorts/1401.json new file mode 100644 index 00000000..4eec0add --- /dev/null +++ b/inst/cohorts/1401.json @@ -0,0 +1,412 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + }, + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "psychotherapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 2795873, + "CONCEPT_NAME" : "Substance Abuse Treatment, Group Counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "HZ4", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "ICD10PCS", + "CONCEPT_CLASS_ID" : "ICD10PCS Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2795886, + "CONCEPT_NAME" : "Substance Abuse Treatment, Individual Psychotherapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "HZ5", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "ICD10PCS", + "CONCEPT_CLASS_ID" : "ICD10PCS Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4297063, + "CONCEPT_NAME" : "Substance use therapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "385989002", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4210149, + "CONCEPT_NAME" : "Substance abuse counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "313071005", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4043203, + "CONCEPT_NAME" : "Psychosocial intervention strategy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228558003", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1552629, + "CONCEPT_NAME" : "Group psychotherapy service for diagnosis, evaluation, or treatment of a mental health or substance use disorder provided remotely by hospital staff who are licensed to provide mental health services under applicable state law(s), when the patient is i...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "C7903", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4327941, + "CONCEPT_NAME" : "Psychotherapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "75516001", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2795900, + "CONCEPT_NAME" : "Substance Abuse Treatment, Family Counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "HZ6", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "ICD10PCS", + "CONCEPT_CLASS_ID" : "ICD10PCS Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37155220, + "CONCEPT_NAME" : "Adolescent-focused psychotherapy for anorexia nervosa", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1833251000000107", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40664776, + "CONCEPT_NAME" : "Annual, face-to-face intensive behavioral therapy for cardiovascular disease, individual, 15 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0446", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4084199, + "CONCEPT_NAME" : "Antiphobic therapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "183399002", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4079606, + "CONCEPT_NAME" : "Aversion therapy - somatic ill", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "183389007", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4296253, + "CONCEPT_NAME" : "Dementia management", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "386257007", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4117916, + "CONCEPT_NAME" : "Family, systemic, couple and sex therapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "302245002", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3657567, + "CONCEPT_NAME" : "MANTRA - Maudsley Model of Anorexia Nervosa Treatment for Adults", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1323471000000102", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4272803, + "CONCEPT_NAME" : "Sexual psychotherapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "63386006", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44811077, + "CONCEPT_NAME" : "Behavioural parent training", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "882381000000106", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209052, + "CONCEPT_NAME" : "CBT-ED - Cognitive behavioural therapy for eating disorders", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111811000000109", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37155031, + "CONCEPT_NAME" : "Cognitive behavioural therapy for bipolar disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1771581000000100", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37154898, + "CONCEPT_NAME" : "Cognitive behavioural therapy for personality disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "149451000000104", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4079611, + "CONCEPT_NAME" : "Conscious blood pressure control", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "183413003", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 30 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1402.json b/inst/cohorts/1402.json new file mode 100644 index 00000000..93033f8d --- /dev/null +++ b/inst/cohorts/1402.json @@ -0,0 +1,140 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + }, + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "group therapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 2795873, + "CONCEPT_NAME" : "Substance Abuse Treatment, Group Counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "HZ4", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "ICD10PCS", + "CONCEPT_CLASS_ID" : "ICD10PCS Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4079501, + "CONCEPT_NAME" : "Aversion therapy - alcoholism", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "183388004", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1552629, + "CONCEPT_NAME" : "Group psychotherapy service for diagnosis, evaluation, or treatment of a mental health or substance use disorder provided remotely by hospital staff who are licensed to provide mental health services under applicable state law(s), when the patient is i...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "C7903", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2213548, + "CONCEPT_NAME" : "Group psychotherapy (other than of a multiple-family group)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "90853", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4296166, + "CONCEPT_NAME" : "Group psychotherapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "76168009", + "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" : 30 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1403.json b/inst/cohorts/1403.json new file mode 100644 index 00000000..442ea603 --- /dev/null +++ b/inst/cohorts/1403.json @@ -0,0 +1,117 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "family psychotherapy", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4297063, + "CONCEPT_NAME" : "Substance use therapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "385989002", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4210149, + "CONCEPT_NAME" : "Substance abuse counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "313071005", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2795900, + "CONCEPT_NAME" : "Substance Abuse Treatment, Family Counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "HZ6", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "ICD10PCS", + "CONCEPT_CLASS_ID" : "ICD10PCS Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4028920, + "CONCEPT_NAME" : "Family psychotherapy procedure", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "108313002", + "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" : 90 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1404.json b/inst/cohorts/1404.json new file mode 100644 index 00000000..2f084587 --- /dev/null +++ b/inst/cohorts/1404.json @@ -0,0 +1,134 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "behavioral therapies", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 44811077, + "CONCEPT_NAME" : "Behavioural parent training", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "882381000000106", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209052, + "CONCEPT_NAME" : "CBT-ED - Cognitive behavioural therapy for eating disorders", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111811000000109", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37155031, + "CONCEPT_NAME" : "Cognitive behavioural therapy for bipolar disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1771581000000100", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37154898, + "CONCEPT_NAME" : "Cognitive behavioural therapy for personality disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "149451000000104", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4040976, + "CONCEPT_NAME" : "Behavioral therapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "166001", + "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" : 365 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1405.json b/inst/cohorts/1405.json new file mode 100644 index 00000000..cdbac0f3 --- /dev/null +++ b/inst/cohorts/1405.json @@ -0,0 +1,134 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "12-step facilitation", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 44811077, + "CONCEPT_NAME" : "Behavioural parent training", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "882381000000106", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209052, + "CONCEPT_NAME" : "CBT-ED - Cognitive behavioural therapy for eating disorders", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111811000000109", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37155031, + "CONCEPT_NAME" : "Cognitive behavioural therapy for bipolar disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1771581000000100", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37154898, + "CONCEPT_NAME" : "Cognitive behavioural therapy for personality disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "149451000000104", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4040976, + "CONCEPT_NAME" : "Behavioral therapy", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "166001", + "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" : 365 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1406.json b/inst/cohorts/1406.json new file mode 100644 index 00000000..34485d27 --- /dev/null +++ b/inst/cohorts/1406.json @@ -0,0 +1,514 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + }, + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "harm reduction interventions", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 44792681, + "CONCEPT_NAME" : "Needle and syringe exchange", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "344671000000100", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44809825, + "CONCEPT_NAME" : "Provision of information about needle and syringe exchange scheme", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "865261000000102", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209005, + "CONCEPT_NAME" : "Provision of information about psychoactive substance use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111281000000101", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209000, + "CONCEPT_NAME" : "Provision of information about alcohol use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111231000000100", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4174714, + "CONCEPT_NAME" : "Substance use education", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "425014005", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46272515, + "CONCEPT_NAME" : "Education about substance abuse", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "710893009", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4135675, + "CONCEPT_NAME" : "Alcohol disorder monitoring", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "413130000", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44791051, + "CONCEPT_NAME" : "Drug abuse monitoring", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "247781000000105", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4243827, + "CONCEPT_NAME" : "Drug addiction counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "60112009", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4175010, + "CONCEPT_NAME" : "Referral to drug addiction rehabilitation service", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "4266003", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3661916, + "CONCEPT_NAME" : "Provision of information about sedative use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1239281000000105", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209004, + "CONCEPT_NAME" : "Provision of information about opioid use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111271000000103", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209003, + "CONCEPT_NAME" : "Provision of information about tranquilliser use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111261000000105", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209002, + "CONCEPT_NAME" : "Provision of information about stimulant use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111251000000107", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37209001, + "CONCEPT_NAME" : "Provision of information about cannabis use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1111241000000109", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217334, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (implant insertion and removal); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the servic...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2072", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217326, + "CONCEPT_NAME" : "Each additional 30 minutes of counseling in a week of medication assisted treatment, (provision of the services by a medicare-enrolled opioid treatment program); list separately in addition to code for primary procedure", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2080", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217331, + "CONCEPT_NAME" : "Medication assisted treatment, medication not otherwise specified; weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing, if performed (provision of the services by a me...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2075", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217332, + "CONCEPT_NAME" : "Medication assisted treatment, weekly bundle not including the drug, including substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-enrolled opioid treatment program)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2074", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217333, + "CONCEPT_NAME" : "Medication assisted treatment, naltrexone; weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-enrolled opioid tr...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2073", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217335, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (implant removal); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medica...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2071", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217336, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (implant insertion); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medi...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2070", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217337, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (injectable); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-en...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2069", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217338, + "CONCEPT_NAME" : "Medication assisted treatment, buprenorphine (oral); weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing if performed (provision of the services by a medicare-enrolled...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2068", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40217339, + "CONCEPT_NAME" : "Medication assisted treatment, methadone; weekly bundle including dispensing and/or administration, substance use counseling, individual and group therapy, and toxicology testing, if performed (provision of the services by a medicare-enrolled opioid tr...", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2067", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44804161, + "CONCEPT_NAME" : "Supervised consumption of medication", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "710131000000108", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4273851, + "CONCEPT_NAME" : "Infection prevention education", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "63994009", + "DOMAIN_ID" : "Observation", + "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" : 365 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1407.json b/inst/cohorts/1407.json new file mode 100644 index 00000000..ebb79ce7 --- /dev/null +++ b/inst/cohorts/1407.json @@ -0,0 +1,123 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "VisitOccurrence" : { + "CodesetId" : 0, + "VisitTypeExclude" : false + } + }, + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "specialty addiction treatment", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 38004257, + "CONCEPT_NAME" : "Ambulatory Substance Use Disorder Rehabilitation Clinic / Center", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "261QR0405X", + "DOMAIN_ID" : "Visit", + "VOCABULARY_ID" : "NUCC", + "CONCEPT_CLASS_ID" : "Visit" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 38004274, + "CONCEPT_NAME" : "Substance Use Disorder Rehabilitation Hospital Unit", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "276400000X", + "DOMAIN_ID" : "Visit", + "VOCABULARY_ID" : "NUCC", + "CONCEPT_CLASS_ID" : "Visit" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 8974, + "CONCEPT_NAME" : "Non-residential Substance Abuse Treatment Facility", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "57", + "DOMAIN_ID" : "Visit", + "VOCABULARY_ID" : "CMS Place of Service", + "CONCEPT_CLASS_ID" : "Visit" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 8957, + "CONCEPT_NAME" : "Residential Substance Abuse Treatment Facility", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "55", + "DOMAIN_ID" : "Visit", + "VOCABULARY_ID" : "CMS Place of Service", + "CONCEPT_CLASS_ID" : "Visit" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 30 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1408.json b/inst/cohorts/1408.json new file mode 100644 index 00000000..18727654 --- /dev/null +++ b/inst/cohorts/1408.json @@ -0,0 +1,174 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + }, + { + "Measurement" : { + "CodesetId" : 0, + "MeasurementTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "alcohol use screening", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 2514536, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) abuse structured screening (eg, AUDIT, DAST), and brief intervention (SBI) services; 15 to 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99408", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 915726, + "CONCEPT_NAME" : "Patient identified as an unhealthy alcohol user when screened for unhealthy alcohol use using a systematic screening method and received brief counseling", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G9621", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4062656, + "CONCEPT_NAME" : "Alcohol consumption screening", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "171208001", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2514537, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) abuse structured screening (eg, AUDIT, DAST), and brief intervention (SBI) services; greater than 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99409", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 801323, + "CONCEPT_NAME" : "Patient screened for unhealthy alcohol use using a systematic screening method and not identified as an unhealthy alcohol user", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2197", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 801324, + "CONCEPT_NAME" : "Patient identified as an unhealthy alcohol user when screened for unhealthy alcohol use using a systematic screening method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G2196", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 915727, + "CONCEPT_NAME" : "Patient not identified as an unhealthy alcohol user when screened for unhealthy alcohol use using a systematic screening method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G9622", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 1 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1409.json b/inst/cohorts/1409.json new file mode 100644 index 00000000..4ae124e8 --- /dev/null +++ b/inst/cohorts/1409.json @@ -0,0 +1,66 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Measurement" : { + "CodesetId" : 0, + "MeasurementTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "preventive screening for substance use", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4158091, + "CONCEPT_NAME" : "Screening for substance abuse", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "370854007", + "DOMAIN_ID" : "Measurement", + "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" : 1 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1410.json b/inst/cohorts/1410.json new file mode 100644 index 00000000..cef88fe9 --- /dev/null +++ b/inst/cohorts/1410.json @@ -0,0 +1,622 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Measurement" : { + "CodesetId" : 0, + "MeasurementTypeExclude" : false + } + }, + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + }, + { + "ProcedureOccurrence" : { + "CodesetId" : 0, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "use of substance use screening tools", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 37208717, + "CONCEPT_NAME" : "Adapted ASSIST-Lite (Alcohol, Smoking and Substance Involvement Screening Test Lite) - Opioid total score", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1108251000000100", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37310702, + "CONCEPT_NAME" : "CRAFFT (Car, Relax, Alone, Forget, Family/Friends, Trouble) interview version 2.1", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "153601000000102", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4169338, + "CONCEPT_NAME" : "Severity of opiate dependence questionnaire", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273800005", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4157230, + "CONCEPT_NAME" : "Alcohol use disorders identification test", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273265007", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4159408, + "CONCEPT_NAME" : "Alcohol dependence scale", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273264006", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37208713, + "CONCEPT_NAME" : "Adapted ASSIST-Lite (Alcohol, Smoking and Substance Involvement Screening Test Lite) - Alcohol total score", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1108211000000104", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4159696, + "CONCEPT_NAME" : "Fagerstrom test for nicotine dependence", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273453005", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4165123, + "CONCEPT_NAME" : "Michigan alcoholism screening test", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273608000", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4158756, + "CONCEPT_NAME" : "Short alcohol dependence data", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273802002", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44792141, + "CONCEPT_NAME" : "Alcohol use disorder identification test consumption questionnaire", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "335811000000106", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 42536965, + "CONCEPT_NAME" : "CRAFFT Screening Test", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "736042002", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3655567, + "CONCEPT_NAME" : "Opioid Risk Tool", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "866023006", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46234680, + "CONCEPT_NAME" : "Alcohol Use Disorder Identification Test - Consumption [AUDIT-C]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "72109-2", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Survey" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4159568, + "CONCEPT_NAME" : "Drug abuse screening test", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273426006", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46234681, + "CONCEPT_NAME" : "Alcohol Use Disorder Identification Test [AUDIT]", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "72110-0", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Survey" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 42536966, + "CONCEPT_NAME" : "CRAFFT Screening Test version 2.0", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "736043007", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3657588, + "CONCEPT_NAME" : "Adapted ASSIST-Lite (Alcohol, Smoking and Substance Involvement Screening Test Lite) - Other psychoactive substance score", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1323791000000108", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37208715, + "CONCEPT_NAME" : "Adapted ASSIST-Lite (Alcohol, Smoking and Substance Involvement Screening Test Lite) - Stimulant total score", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1108231000000107", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37208712, + "CONCEPT_NAME" : "Adapted ASSIST-Lite (Alcohol, Smoking and Substance Involvement Screening Test Lite) - Tobacco total score", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1108201000000101", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37208716, + "CONCEPT_NAME" : "Adapted ASSIST-Lite (Alcohol, Smoking and Substance Involvement Screening Test Lite) - Sedative total score", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1108241000000103", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4164813, + "CONCEPT_NAME" : "Cage questionnaire", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273347006", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4167760, + "CONCEPT_NAME" : "Drinking problem scale", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273425005", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37208714, + "CONCEPT_NAME" : "Adapted ASSIST-Lite (Alcohol, Smoking and Substance Involvement Screening Test Lite) - Cannabis total score", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1108221000000105", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37208560, + "CONCEPT_NAME" : "Adapted ASSIST-Lite (Alcohol, Smoking and Substance Involvement Screening Test Lite)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1106631000000106", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44792142, + "CONCEPT_NAME" : "Alcohol use disorder identification test Piccinelli consumption questionnaire", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "335841000000107", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36674484, + "CONCEPT_NAME" : "Alcohol Use Disorders Identification Test for Primary Care score", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "774089008", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4165448, + "CONCEPT_NAME" : "Severity of alcohol dependence questionnaire", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "273799006", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2514536, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) abuse structured screening (eg, AUDIT, DAST), and brief intervention (SBI) services; 15 to 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99408", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2514537, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) abuse structured screening (eg, AUDIT, DAST), and brief intervention (SBI) services; greater than 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99409", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2617464, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) misuse structured assessment (e.g., audit, dast), and brief intervention 15 to 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0396", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2617465, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) misuse structured assessment (e.g., audit, dast), and intervention, greater than 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0397", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40664833, + "CONCEPT_NAME" : "Annual alcohol misuse screening, 5 to 15 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0442", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40664725, + "CONCEPT_NAME" : "Brief face-to-face behavioral counseling for alcohol misuse, 15 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0443", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 1 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1411.json b/inst/cohorts/1411.json new file mode 100644 index 00000000..ed541c4a --- /dev/null +++ b/inst/cohorts/1411.json @@ -0,0 +1,2123 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Measurement" : { + "CodesetId" : 0, + "MeasurementTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "laboratory toxicology tests", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40772940, + "CONCEPT_NAME" : "Psychiatric drugs", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP31449-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37078900, + "CONCEPT_NAME" : "Nicotine | Gastric fluid | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP387885-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3032575, + "CONCEPT_NAME" : "Barbiturates/Creatinine [Mass Ratio] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "41468-0", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4326820, + "CONCEPT_NAME" : "Ethanol measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "430837008", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3026040, + "CONCEPT_NAME" : "Para hydroxyamphetamine [Mass] of Dose", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "4375-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40481408, + "CONCEPT_NAME" : "Measurement of opiate agonist", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "442007007", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21494866, + "CONCEPT_NAME" : "Amitriptyline and Nortriptyline panel - Gastric fluid", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "81207-3", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3028841, + "CONCEPT_NAME" : "Benzodiazepine metabolites [Presence] in Urine by Screen method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "42235-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3015906, + "CONCEPT_NAME" : "Levoamphetamine/Amphetamines.total in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "31016-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40655173, + "CONCEPT_NAME" : "Nicotine|Moment in time|Serum or Plasma", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LG47379-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40766846, + "CONCEPT_NAME" : "PENTobarbital/Creatinine [Mass Ratio] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "64132-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37049368, + "CONCEPT_NAME" : "Valproate Free | Serum or Plasma | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP390872-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37071236, + "CONCEPT_NAME" : "Drugs of abuse 7 and Alcohol and Tricyclics panel | Urine | Drug and Toxicology Panels", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP392064-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21494867, + "CONCEPT_NAME" : "Amitriptyline and Nortriptyline panel - Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "81208-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4280954, + "CONCEPT_NAME" : "Cannabinoids measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "66689000", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4096080, + "CONCEPT_NAME" : "Haloperidol measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "25104002", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43533688, + "CONCEPT_NAME" : "Barbiturates panel - Saliva (oral fluid) by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73663-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46257673, + "CONCEPT_NAME" : "Antidepressants, tricyclic and other cyclicals", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1022251", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4 Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1247077, + "CONCEPT_NAME" : "Benzodiazepine in urine by confirmatory technique", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "364681000119104", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43533687, + "CONCEPT_NAME" : "Benzodiazepines panel - Saliva (oral fluid) by Screen method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73662-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4255267, + "CONCEPT_NAME" : "Drug of abuse, quantitative screen, includes amphetamines, barbiturates, benzodiazepines, cannabinoids, cocaine, methadone, methaqualone, opiates, phencyclidines and propoxyphene", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "40823001", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43533448, + "CONCEPT_NAME" : "Amphetamine induced platelet IgG Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73425-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37062255, + "CONCEPT_NAME" : "Valproate | Serum or Plasma | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP390867-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37045698, + "CONCEPT_NAME" : "Valproate | Urine | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP390868-0", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43534383, + "CONCEPT_NAME" : "PHENobarbital induced platelet IgG Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73209-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3022432, + "CONCEPT_NAME" : "Barbiturates confirm method [Identifier] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19278-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4021313, + "CONCEPT_NAME" : "Barbiturates measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "105079003", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3034429, + "CONCEPT_NAME" : "Barbiturates screen method [Identifier] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19277-3", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21492624, + "CONCEPT_NAME" : "Primidone and PHENobarbital trough panel - Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "78436-3", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43533447, + "CONCEPT_NAME" : "Amphetamine induced platelet IgM Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73424-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40655612, + "CONCEPT_NAME" : "Valproate|Moment in time|Serum or Plasma", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LG49789-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3045233, + "CONCEPT_NAME" : "Primidone+PHENobarbital [Moles/volume] in Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "34365-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46284938, + "CONCEPT_NAME" : "Serum pentobarbital concentration measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "958101000000104", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4006367, + "CONCEPT_NAME" : "Allobarbital measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "121436007", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4104671, + "CONCEPT_NAME" : "Cocaine measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "29142004", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43534240, + "CONCEPT_NAME" : "Amitriptyline induced neutrophil IgG Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73066-3", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40771543, + "CONCEPT_NAME" : "Amphetamines panel - Meconium by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "69021-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3034963, + "CONCEPT_NAME" : "Benzodiazepines/Creatinine [Mass Ratio] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "41467-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37169494, + "CONCEPT_NAME" : "Amphetamine mass concentration in serum", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "16031000237109", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1001641, + "CONCEPT_NAME" : "Benzodiazepines panel [Presence] - Urine by Screen method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "94117-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3001241, + "CONCEPT_NAME" : "Benzodiazepines tested for in Urine by Screen method Narrative", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19280-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40766847, + "CONCEPT_NAME" : "PHENobarbital/Creatinine [Mass Ratio] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "64133-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37169917, + "CONCEPT_NAME" : "Amphetamine mass concentration in oral fluid", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "15511000237104", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37024054, + "CONCEPT_NAME" : "Valproate.free/Valproate.total | Serum or Plasma | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP390873-0", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43533556, + "CONCEPT_NAME" : "Amitriptyline induced platelet IgM Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73533-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3042517, + "CONCEPT_NAME" : "Benzodiazepines panel - Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "53745-6", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37041970, + "CONCEPT_NAME" : "Valproate induced platelet IgM | Serum or Plasma | Serology - non-micro", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP403326-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40655546, + "CONCEPT_NAME" : "Tricyclic antidepressants|Moment in time|Serum or Plasma", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LG46403-8", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3013169, + "CONCEPT_NAME" : "Benzodiazepines confirm method [Identifier] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19286-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4324133, + "CONCEPT_NAME" : "Valproic acid measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "71466003", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44806422, + "CONCEPT_NAME" : "Opiate screening test", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "791821000000106", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 42529009, + "CONCEPT_NAME" : "Brallobarbital [Mass/volume] in Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "82873-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43534382, + "CONCEPT_NAME" : "PHENobarbital induced platelet IgM Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73208-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4269834, + "CONCEPT_NAME" : "Finding of serum phenobarbital level", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "365742004", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3006476, + "CONCEPT_NAME" : "PHENobarbital Free [Mass/volume] in Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3951-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4221377, + "CONCEPT_NAME" : "Toxicology screen, sedatives", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "40167001", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40771548, + "CONCEPT_NAME" : "Opiates panel - Meconium by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "69026-3", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43533555, + "CONCEPT_NAME" : "Amitriptyline induced platelet IgG Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73532-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3034789, + "CONCEPT_NAME" : "Benzodiazepines positive [Identifier] in Urine by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19282-3", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3033472, + "CONCEPT_NAME" : "Benzodiazepines positive [Identifier] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3387-8", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37039135, + "CONCEPT_NAME" : "Valproate induced platelet IgG | Serum or Plasma | Serology - non-micro", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP403325-6", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4260399, + "CONCEPT_NAME" : "Tricyclic antidepressant measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "44787002", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40766849, + "CONCEPT_NAME" : "Secobarbital/Creatinine [Mass Ratio] of Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "64135-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4211848, + "CONCEPT_NAME" : "Benzodiazepine measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "574005", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1616297, + "CONCEPT_NAME" : "Mephobarbital and PHENobarbital panel - Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "97183-8", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37025133, + "CONCEPT_NAME" : "Nornicotine | Urine | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP387902-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3013362, + "CONCEPT_NAME" : "Benzodiazepines tested for in Urine by Screen method Nominal", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19279-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37169029, + "CONCEPT_NAME" : "Amphetamine mass concentration in plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "14371000237103", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36713684, + "CONCEPT_NAME" : "Clinical Institute Withdrawal Assessment for Benzodiazepines scale", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "718619009", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Staging / Scales" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37173225, + "CONCEPT_NAME" : "Barbiturate mass concentration in fluid", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "5811000237103", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37077798, + "CONCEPT_NAME" : "Valproate Free | Saliva | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP390871-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3004555, + "CONCEPT_NAME" : "Barbiturate screen present [Identifier] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3374-6", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4273557, + "CONCEPT_NAME" : "Amphetamine measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "63817004", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40656638, + "CONCEPT_NAME" : "Nicotine|Any Property|Any Time|Any System|Any Method", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LG37562-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3037571, + "CONCEPT_NAME" : "Benzodiazepines negative [Identifier] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3385-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44806443, + "CONCEPT_NAME" : "Tricyclic drug screening test", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "792061000000101", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37060400, + "CONCEPT_NAME" : "Nicotine | Meconium | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP387887-5", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43534147, + "CONCEPT_NAME" : "PHENobarbital induced neutrophil IgM Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "72973-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40655611, + "CONCEPT_NAME" : "Valproate.free|Moment in time|Serum or Plasma", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LG47174-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3019270, + "CONCEPT_NAME" : "Barbiturate screen absent [Identifier] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3372-0", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3000684, + "CONCEPT_NAME" : "Barbiturates positive [Identifier] in Urine by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19274-0", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44812145, + "CONCEPT_NAME" : "Urine benzodiazepine screening test", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "911081000000106", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37046785, + "CONCEPT_NAME" : "Valproate.bound/Valproate.total | Serum or Plasma | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP390869-8", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37022969, + "CONCEPT_NAME" : "Valproate | Body fluid | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP390866-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43534239, + "CONCEPT_NAME" : "Amitriptyline induced neutrophil IgM Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "73065-5", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3015840, + "CONCEPT_NAME" : "Allyl-sec-butyl-barbiturate [Mass/volume] in Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "12490-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3021426, + "CONCEPT_NAME" : "Barbiturates present [Identifier] in Serum or Plasma by Screen method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "21091-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3009354, + "CONCEPT_NAME" : "Benzodiazepines screen method [Identifier] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19285-6", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37048890, + "CONCEPT_NAME" : "Nicotine | XXX | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP387890-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3002874, + "CONCEPT_NAME" : "Barbiturates tested for in Urine by Screen method Narrative", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19272-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1175388, + "CONCEPT_NAME" : "Benzodiazepines panel - Urine by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "90890-5", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37027040, + "CONCEPT_NAME" : "Valproate.free and Valproate panel | Serum or Plasma | Drug and Toxicology Panels", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP392133-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1988963, + "CONCEPT_NAME" : "Designer benzodiazepines [Presence] in Urine by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99262-8", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3043690, + "CONCEPT_NAME" : "Dextromethamphetamine/Levomethamphetamine [Mass Ratio] in Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "32643-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43534148, + "CONCEPT_NAME" : "PHENobarbital induced neutrophil IgG Ab [Presence] in Serum or Plasma by Flow cytometry (FC)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "72974-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46257559, + "CONCEPT_NAME" : "Sedative hypnotics (non-benzodiazepines)", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "80368", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3032544, + "CONCEPT_NAME" : "Amitriptyline and Nortriptyline panel - Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "43106-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3003644, + "CONCEPT_NAME" : "Primidone+PHENobarbital [Mass/volume] in Serum or Plasma", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "10547-8", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37043740, + "CONCEPT_NAME" : "Nicotine | Urine | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP387889-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3000074, + "CONCEPT_NAME" : "Barbiturates tested for in Urine by Screen method Nominal", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "19271-6", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4021452, + "CONCEPT_NAME" : "Clozapine measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "105140007", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21494870, + "CONCEPT_NAME" : "Amitriptyline and Nortriptyline panel - Specimen", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "81211-5", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40766842, + "CONCEPT_NAME" : "Amobarbital/Creatinine [Mass Ratio] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "64128-2", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4091463, + "CONCEPT_NAME" : "Volatile substance screening", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "252170002", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3039447, + "CONCEPT_NAME" : "Barbiturates.other [Mass/volume] in Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "53735-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37073815, + "CONCEPT_NAME" : "Nicotine and Metabolites panel | Urine | Drug and Toxicology Panels", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP392108-9", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37169036, + "CONCEPT_NAME" : "Benzodiazepine mass concentration in urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "14421000237108", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40772939, + "CONCEPT_NAME" : "Controlled substances and drugs of abuse", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP31448-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4021450, + "CONCEPT_NAME" : "Chlorprothixene measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "105125005", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40655174, + "CONCEPT_NAME" : "Nicotine|Moment in time|Urine", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LG47377-3", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37032910, + "CONCEPT_NAME" : "Nicotine and Cotinine panel | Serum or Plasma | Drug and Toxicology Panels", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP392107-1", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1616954, + "CONCEPT_NAME" : "Amphetamines panel - Urine by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "97161-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40653859, + "CONCEPT_NAME" : "Tricyclic antidepressants|Presence or Threshold|Moment in time|Any Urine specimen", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LG590-6", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Group" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3050636, + "CONCEPT_NAME" : "Barbiturates panel - Urine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "53746-4", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4203316, + "CONCEPT_NAME" : "Nicotine measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "5338000", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37077184, + "CONCEPT_NAME" : "Valproate.protein bound | Serum or Plasma | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP390870-6", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4020273, + "CONCEPT_NAME" : "Hydroxymethoxyphenamine measurement", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "105209006", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 43533385, + "CONCEPT_NAME" : "Barbiturates panel - Blood by Confirmatory method", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "72480-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "Lab Test" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37033562, + "CONCEPT_NAME" : "Nicotine | Hair | Drug toxicology", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP387886-7", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37155997, + "CONCEPT_NAME" : "Benzodiazepine mass concentration in oral fluid", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "13871000237108", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44806229, + "CONCEPT_NAME" : "Benzodiazepine screening test", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "800681000000104", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Procedure" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37055737, + "CONCEPT_NAME" : "Valproate induced neutrophil IgG | Serum or Plasma | Serology - non-micro", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "LP402849-6", + "DOMAIN_ID" : "Measurement", + "VOCABULARY_ID" : "LOINC", + "CONCEPT_CLASS_ID" : "LOINC Hierarchy" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 0 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 1 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1412.json b/inst/cohorts/1412.json new file mode 100644 index 00000000..6df84610 --- /dev/null +++ b/inst/cohorts/1412.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "naloxone dispensing", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1114220, + "CONCEPT_NAME" : "naloxone", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "7242", + "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" : 1, + "GapDays" : 1, + "Offset" : 1 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1413.json b/inst/cohorts/1413.json new file mode 100644 index 00000000..0afd8f77 --- /dev/null +++ b/inst/cohorts/1413.json @@ -0,0 +1,157 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Observation" : { + "CodesetId" : 1, + "ObservationTypeExclude" : false + } + }, + { + "ProcedureOccurrence" : { + "CodesetId" : 1, + "ProcedureTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "Screening, Brief Intervention, and Referral to Treatment (SBIRT)", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 2514536, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) abuse structured screening (eg, AUDIT, DAST), and brief intervention (SBI) services; 15 to 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99408", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2514537, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) abuse structured screening (eg, AUDIT, DAST), and brief intervention (SBI) services; greater than 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "99409", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "CPT4", + "CONCEPT_CLASS_ID" : "CPT4" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2617464, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) misuse structured assessment (e.g., audit, dast), and brief intervention 15 to 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0396", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 2617465, + "CONCEPT_NAME" : "Alcohol and/or substance (other than tobacco) misuse structured assessment (e.g., audit, dast), and intervention, greater than 30 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0397", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40664833, + "CONCEPT_NAME" : "Annual alcohol misuse screening, 5 to 15 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0442", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40664725, + "CONCEPT_NAME" : "Brief face-to-face behavioral counseling for alcohol misuse, 15 minutes", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "G0443", + "DOMAIN_ID" : "Procedure", + "VOCABULARY_ID" : "HCPCS", + "CONCEPT_CLASS_ID" : "HCPCS" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 1 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1415.json b/inst/cohorts/1415.json new file mode 100644 index 00000000..c3d24ea2 --- /dev/null +++ b/inst/cohorts/1415.json @@ -0,0 +1,89 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 0, + "ConditionTypeExclude" : false + } + }, + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "impaired control", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4027643, + "CONCEPT_NAME" : "Unable to control drinking", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228340008", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4215819, + "CONCEPT_NAME" : "Compulsive uncontrollable drug taking", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "416993008", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 180 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1416.json b/inst/cohorts/1416.json new file mode 100644 index 00000000..0a346472 --- /dev/null +++ b/inst/cohorts/1416.json @@ -0,0 +1,151 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "neglect of roles or social impairment", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4313342, + "CONCEPT_NAME" : "Altered behavior due to substance use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "424461008", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37164784, + "CONCEPT_NAME" : "Aggression caused by ethanol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1234773008", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37164787, + "CONCEPT_NAME" : "Disinhibition caused by ethanol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1234777009", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4042878, + "CONCEPT_NAME" : "Undue priority given to drink-related activities", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228334001", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4036418, + "CONCEPT_NAME" : "Priority of drug-related activities", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228415000", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4038713, + "CONCEPT_NAME" : "Undue priority given to drug-related activities", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228417008", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 14 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1417.json b/inst/cohorts/1417.json new file mode 100644 index 00000000..d0eec444 --- /dev/null +++ b/inst/cohorts/1417.json @@ -0,0 +1,134 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Observation" : { + "CodesetId" : 1, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "risky use", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4226563, + "CONCEPT_NAME" : "Risk control behavior: alcohol use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "405137009", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4229859, + "CONCEPT_NAME" : "Risk control behavior: drug use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "405138004", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4038703, + "CONCEPT_NAME" : "Drunk driving", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228354000", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4042885, + "CONCEPT_NAME" : "Charged with drunk driving offence", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228355004", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4027647, + "CONCEPT_NAME" : "Convicted of drunk driving", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228356003", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 1 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 30 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1418.json b/inst/cohorts/1418.json new file mode 100644 index 00000000..5478514e --- /dev/null +++ b/inst/cohorts/1418.json @@ -0,0 +1,185 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "tolerance", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4038700, + "CONCEPT_NAME" : "Tolerance to alcohol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228349009", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 45769951, + "CONCEPT_NAME" : "Opioid tolerant", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "919561000000107", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37109199, + "CONCEPT_NAME" : "Physical tolerance to opiate drug", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "22121000087104", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4038701, + "CONCEPT_NAME" : "Behavioral tolerance to alcohol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228350009", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4042884, + "CONCEPT_NAME" : "Physical tolerance to alcohol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228351008", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4038702, + "CONCEPT_NAME" : "Psychological tolerance to alcohol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228352001", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4027646, + "CONCEPT_NAME" : "Reverse tolerance to alcohol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "228353006", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37116662, + "CONCEPT_NAME" : "Opiate tolerance", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "733462007", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Observable Entity" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 90 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1419.json b/inst/cohorts/1419.json new file mode 100644 index 00000000..5ff80ccf --- /dev/null +++ b/inst/cohorts/1419.json @@ -0,0 +1,361 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + }, + { + "ConditionOccurrence" : { + "CodesetId" : 0, + "ConditionTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "pattern of use causing harm or distress", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 35610540, + "CONCEPT_NAME" : "Harmful use of opioid", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094231000000109", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610541, + "CONCEPT_NAME" : "Harmful use of sedative", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094241000000100", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610542, + "CONCEPT_NAME" : "Harmful use of barbiturate", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094251000000102", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610524, + "CONCEPT_NAME" : "Harmful use of antidepressant drug", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094071000000103", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610545, + "CONCEPT_NAME" : "Harmful use of synthetic cathinone", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094281000000108", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610537, + "CONCEPT_NAME" : "Harmful use of hallucinogen", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094201000000103", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 44788726, + "CONCEPT_NAME" : "Harmful alcohol use", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "198431000000105", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610544, + "CONCEPT_NAME" : "Harmful use of synthetic cannabinoid", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094271000000106", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37205764, + "CONCEPT_NAME" : "Harmful pattern of use of amphetamine and/or amphetamine derivative", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "785277001", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610534, + "CONCEPT_NAME" : "Harmful use of cannabis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094171000000104", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36676296, + "CONCEPT_NAME" : "Harmful use of hypnotic", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "772999000", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610533, + "CONCEPT_NAME" : "Harmful use of amphetamine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094161000000106", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36676297, + "CONCEPT_NAME" : "Harmful use of anxiolytic", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "773000004", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610532, + "CONCEPT_NAME" : "Harmful use of alcohol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094151000000108", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610538, + "CONCEPT_NAME" : "Harmful use of inhalant", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094211000000101", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610543, + "CONCEPT_NAME" : "Harmful use of stimulant", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094261000000104", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35610536, + "CONCEPT_NAME" : "Harmful use of cocaine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1094191000000100", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37110444, + "CONCEPT_NAME" : "Harmful pattern of use of nicotine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "724697004", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 30 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1420.json b/inst/cohorts/1420.json new file mode 100644 index 00000000..aa46892d --- /dev/null +++ b/inst/cohorts/1420.json @@ -0,0 +1,236 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 0, + "ConditionTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "medical conditions mimicking intoxication", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 378143, + "CONCEPT_NAME" : "Encephalitis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "45170000", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 374009, + "CONCEPT_NAME" : "Organic mental disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "111479008", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 434889, + "CONCEPT_NAME" : "Dissociative disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "44376007", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 4133611, + "CONCEPT_NAME" : "Traumatic or nontraumatic brain injury", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "127294003", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 444100, + "CONCEPT_NAME" : "Mood disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "46206005", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 442077, + "CONCEPT_NAME" : "Anxiety disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "197480006", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 439706, + "CONCEPT_NAME" : "Psychosis with origin in childhood", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "191687005", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 30361, + "CONCEPT_NAME" : "Hypoglycemic disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "237630007", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 436073, + "CONCEPT_NAME" : "Psychotic disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "69322001", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35609901, + "CONCEPT_NAME" : "Late onset substance-induced psychosis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1087461000000107", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 434900, + "CONCEPT_NAME" : "Drug-induced psychosis", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "191483003", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 14 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 30 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1421.json b/inst/cohorts/1421.json new file mode 100644 index 00000000..eae4c841 --- /dev/null +++ b/inst/cohorts/1421.json @@ -0,0 +1,66 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 0, + "ConditionTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "hypoglycemia", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 30361, + "CONCEPT_NAME" : "Hypoglycemic disorder", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "237630007", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 1 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 7 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1422.json b/inst/cohorts/1422.json new file mode 100644 index 00000000..9469858b --- /dev/null +++ b/inst/cohorts/1422.json @@ -0,0 +1,66 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 0, + "ConditionTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "stroke", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 381316, + "CONCEPT_NAME" : "Cerebrovascular accident", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "230690007", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 7 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 30 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1423.json b/inst/cohorts/1423.json new file mode 100644 index 00000000..f188eb4d --- /dev/null +++ b/inst/cohorts/1423.json @@ -0,0 +1,100 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 1, + "ConditionTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "single acute intoxication", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 607209, + "CONCEPT_NAME" : "Acute intoxication", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1149334009", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 3178217, + "CONCEPT_NAME" : "Acute lorazepam intoxication", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "31430001000004108", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "Nebraska Lexicon", + "CONCEPT_CLASS_ID" : "Clinical Finding" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 1245119, + "CONCEPT_NAME" : "Acute opioid intoxication", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1296773009", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 1 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 7 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1424.json b/inst/cohorts/1424.json new file mode 100644 index 00000000..de9a7a2f --- /dev/null +++ b/inst/cohorts/1424.json @@ -0,0 +1,216 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 1, + "ConditionTypeExclude" : false + } + }, + { + "DrugExposure" : { + "CodesetId" : 0, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "opioid overdose treatment drugs", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 40141382, + "CONCEPT_NAME" : "naloxone Prefilled Syringe", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "727348", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 35603851, + "CONCEPT_NAME" : "naloxone Nasal Spray", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1725058", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40063501, + "CONCEPT_NAME" : "naloxone Injectable Solution", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "372989", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46275783, + "CONCEPT_NAME" : "naloxone Cartridge", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1659913", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46275793, + "CONCEPT_NAME" : "naloxone Injection", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1659928", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 46275772, + "CONCEPT_NAME" : "naloxone Auto-Injector", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1659888", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug Form" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 19014158, + "CONCEPT_NAME" : "nalmefene", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "31479", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 40166388, + "CONCEPT_NAME" : "morphine / naltrexone Extended Release Oral Capsule", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "863844", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Clinical Drug Form" + }, + "isExcluded" : true, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + }, + { + "id" : 1, + "name" : "opioid overdose condition", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 606805, + "CONCEPT_NAME" : "Poisoning caused by opioid receptor agonist", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1148649003", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 1 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 7 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1425.json b/inst/cohorts/1425.json new file mode 100644 index 00000000..6af8ff4c --- /dev/null +++ b/inst/cohorts/1425.json @@ -0,0 +1,83 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 0, + "ConditionTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "alcohol acute intoxication", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 37165681, + "CONCEPT_NAME" : "Accidental poisoning by substance with alcohol structure", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1255412009", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 37208159, + "CONCEPT_NAME" : "Intentional poisoning by ethyl alcohol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "461171000124100", + "DOMAIN_ID" : "Condition", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Disorder" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 1 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 7 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1426.json b/inst/cohorts/1426.json new file mode 100644 index 00000000..ba73452e --- /dev/null +++ b/inst/cohorts/1426.json @@ -0,0 +1,429 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "ConditionOccurrence" : { + "CodesetId" : 0, + "ConditionTypeExclude" : false + } + }, + { + "Observation" : { + "CodesetId" : 0, + "ObservationTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "psychoactive substances", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 4205848, + "CONCEPT_NAME" : "Alcoholic beverage", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "53527002", + "DOMAIN_ID" : "Observation", + "VOCABULARY_ID" : "SNOMED", + "CONCEPT_CLASS_ID" : "Substance" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21603244, + "CONCEPT_NAME" : "cocaine; local oral", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "R02AD03", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 5th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36854582, + "CONCEPT_NAME" : "LYSERGIDE", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP5172198", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604752, + "CONCEPT_NAME" : "PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N06B", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 3rd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36855591, + "CONCEPT_NAME" : "2-BROMOMESCALINE", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP5173208", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604787, + "CONCEPT_NAME" : "PSYCHOLEPTICS AND PSYCHOANALEPTICS IN COMBINATION", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N06C", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 3rd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604390, + "CONCEPT_NAME" : "ANTIEPILEPTICS", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N03A", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 3rd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36859280, + "CONCEPT_NAME" : ".ALPHA.-ETHYL MESCALINE", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP5176897", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604200, + "CONCEPT_NAME" : "Opioid anesthetics", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N01AH", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 4th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36863385, + "CONCEPT_NAME" : "ISOMESCALINE", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP5181002", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604686, + "CONCEPT_NAME" : "ANTIDEPRESSANTS", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N06A", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 3rd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604247, + "CONCEPT_NAME" : "cocaine; parenteral", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N01BC01", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 5th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604489, + "CONCEPT_NAME" : "PSYCHOLEPTICS", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N05", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 2nd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36856603, + "CONCEPT_NAME" : "CYCLOPROPYLMESCALINE", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP5174219", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604198, + "CONCEPT_NAME" : "Barbiturates in combination with other drugs", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N01AG", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 4th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604254, + "CONCEPT_NAME" : "OPIOIDS", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N02A", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 3rd" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 955372, + "CONCEPT_NAME" : "ethanol", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "448", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604363, + "CONCEPT_NAME" : "cannabinoids; oral", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N02BG10", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 5th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36861112, + "CONCEPT_NAME" : "MESCALINE", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP5178729", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 36858409, + "CONCEPT_NAME" : "PHENCYCLIDINE", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "OMOP5176026", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm Extension", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : false, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 21604194, + "CONCEPT_NAME" : "Barbiturates, plain", + "STANDARD_CONCEPT" : "C", + "STANDARD_CONCEPT_CAPTION" : "Classification", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "N01AF", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "ATC", + "CONCEPT_CLASS_ID" : "ATC 4th" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + }, + { + "concept" : { + "CONCEPT_ID" : 718583, + "CONCEPT_NAME" : "nicotine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "7407", + "DOMAIN_ID" : "Drug", + "VOCABULARY_ID" : "RxNorm", + "CONCEPT_CLASS_ID" : "Ingredient" + }, + "isExcluded" : false, + "includeDescendants" : true, + "includeMapped" : false + } + ] + } + } + ], + "QualifiedLimit" : { + "Type" : "First" + }, + "ExpressionLimit" : { + "Type" : "All" + }, + "InclusionRules" : [], + "EndStrategy" : { + "DateOffset" : { + "DateField" : "EndDate", + "Offset" : 7 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 180 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1427.json b/inst/cohorts/1427.json new file mode 100644 index 00000000..182ddc06 --- /dev/null +++ b/inst/cohorts/1427.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 0, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "acamprosate", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 19043959, + "CONCEPT_NAME" : "acamprosate", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "82819", + "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" : 0, + "GapDays" : 1, + "Offset" : 30 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1428.json b/inst/cohorts/1428.json new file mode 100644 index 00000000..76412e3c --- /dev/null +++ b/inst/cohorts/1428.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 0, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 0, + "name" : "disulfiram", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 735850, + "CONCEPT_NAME" : "disulfiram", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "3554", + "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" : 0, + "GapDays" : 1, + "Offset" : 30 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/cohorts/1429.json b/inst/cohorts/1429.json new file mode 100644 index 00000000..18e0565e --- /dev/null +++ b/inst/cohorts/1429.json @@ -0,0 +1,67 @@ +{ + "cdmVersionRange" : ">=5.0.0", + "PrimaryCriteria" : { + "CriteriaList" : [ + { + "DrugExposure" : { + "CodesetId" : 1, + "DrugTypeExclude" : false + } + } + ], + "ObservationWindow" : { + "PriorDays" : 0, + "PostDays" : 0 + }, + "PrimaryCriteriaLimit" : { + "Type" : "All" + } + }, + "ConceptSets" : [ + { + "id" : 1, + "name" : "buprenorphine", + "expression" : { + "items" : [ + { + "concept" : { + "CONCEPT_ID" : 1133201, + "CONCEPT_NAME" : "buprenorphine", + "STANDARD_CONCEPT" : "S", + "STANDARD_CONCEPT_CAPTION" : "Standard", + "INVALID_REASON" : "V", + "INVALID_REASON_CAPTION" : "Valid", + "CONCEPT_CODE" : "1819", + "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" : 1, + "GapDays" : 0, + "Offset" : 30 + } + }, + "CensoringCriteria" : [], + "CollapseSettings" : { + "CollapseType" : "ERA", + "EraPad" : 0 + }, + "CensorWindow" : {} +} \ No newline at end of file diff --git a/inst/doc/HowToUsePhenotypeLibraryRPackage.pdf b/inst/doc/HowToUsePhenotypeLibraryRPackage.pdf index 2f79c998..6e37437a 100644 Binary files a/inst/doc/HowToUsePhenotypeLibraryRPackage.pdf and b/inst/doc/HowToUsePhenotypeLibraryRPackage.pdf differ diff --git a/inst/sql/sql_server/1387.sql b/inst/sql/sql_server/1387.sql new file mode 100644 index 00000000..08863ad1 --- /dev/null +++ b/inst/sql/sql_server/1387.sql @@ -0,0 +1,336 @@ +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 (1103640)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (1103640)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 0, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(0 + 90),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1388.sql b/inst/sql/sql_server/1388.sql new file mode 100644 index 00000000..90bf512a --- /dev/null +++ b/inst/sql/sql_server/1388.sql @@ -0,0 +1,301 @@ +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 (38004241)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Visit Occurrence Criteria +select C.person_id, C.visit_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select vo.person_id,vo.visit_occurrence_id,vo.visit_concept_id,vo.visit_start_date as start_date, vo.visit_end_date as end_date + FROM @cdm_database_schema.VISIT_OCCURRENCE vo +JOIN #Codesets cs on (vo.visit_concept_id = cs.concept_id and cs.codeset_id = 2) +) C + + +-- End Visit Occurrence Criteria + +UNION ALL +-- Begin Procedure Occurrence Criteria +select C.person_id, C.procedure_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 2) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 90, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,90,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1389.sql b/inst/sql/sql_server/1389.sql new file mode 100644 index 00000000..e88880e1 --- /dev/null +++ b/inst/sql/sql_server/1389.sql @@ -0,0 +1,336 @@ +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 (21604824)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (21604824)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 0, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(0 + 90),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1390.sql b/inst/sql/sql_server/1390.sql new file mode 100644 index 00000000..91ac89bc --- /dev/null +++ b/inst/sql/sql_server/1390.sql @@ -0,0 +1,292 @@ +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 (44804691)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (44804691)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 2) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 180, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,180,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1391.sql b/inst/sql/sql_server/1391.sql new file mode 100644 index 00000000..924d332e --- /dev/null +++ b/inst/sql/sql_server/1391.sql @@ -0,0 +1,336 @@ +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 (21604825)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (21604825)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 0, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(0 + 90),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1392.sql b/inst/sql/sql_server/1392.sql new file mode 100644 index 00000000..e3acaffd --- /dev/null +++ b/inst/sql/sql_server/1392.sql @@ -0,0 +1,336 @@ +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 (1114220,1714319,19014158,909841)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (1114220,1714319,19014158,909841)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 0, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(0 + 90),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1393.sql b/inst/sql/sql_server/1393.sql new file mode 100644 index 00000000..35a14b15 --- /dev/null +++ b/inst/sql/sql_server/1393.sql @@ -0,0 +1,301 @@ +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 (40217336,40217335,40217334,40217338,40217337,40217333,40217339,40217332,40217331,40217326,40217332)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- End Procedure Occurrence Criteria + +UNION ALL +-- Begin Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 90, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,90,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1394.sql b/inst/sql/sql_server/1394.sql new file mode 100644 index 00000000..b2483f09 --- /dev/null +++ b/inst/sql/sql_server/1394.sql @@ -0,0 +1,336 @@ +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 (21604818)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (21604818)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 0, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(0 + 90),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1395.sql b/inst/sql/sql_server/1395.sql new file mode 100644 index 00000000..b2483f09 --- /dev/null +++ b/inst/sql/sql_server/1395.sql @@ -0,0 +1,336 @@ +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 (21604818)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (21604818)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 0, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(0 + 90),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1396.sql b/inst/sql/sql_server/1396.sql new file mode 100644 index 00000000..08e1211a --- /dev/null +++ b/inst/sql/sql_server/1396.sql @@ -0,0 +1,336 @@ +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 (780442)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (780442)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 0, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(0 + 90),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1397.sql b/inst/sql/sql_server/1397.sql new file mode 100644 index 00000000..56525be4 --- /dev/null +++ b/inst/sql/sql_server/1397.sql @@ -0,0 +1,292 @@ +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 (4083171)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4083171)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 180, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,180,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1398.sql b/inst/sql/sql_server/1398.sql new file mode 100644 index 00000000..5718eeea --- /dev/null +++ b/inst/sql/sql_server/1398.sql @@ -0,0 +1,306 @@ +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 (4082728,4176643,2514512,2514513)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4082728,4176643)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Procedure Occurrence Criteria + +UNION ALL +-- Begin Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 30, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,30,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1399.sql b/inst/sql/sql_server/1399.sql new file mode 100644 index 00000000..7ec27bd0 --- /dev/null +++ b/inst/sql/sql_server/1399.sql @@ -0,0 +1,292 @@ +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 (4211325)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4211325)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 90, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,90,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1400.sql b/inst/sql/sql_server/1400.sql new file mode 100644 index 00000000..37400862 --- /dev/null +++ b/inst/sql/sql_server/1400.sql @@ -0,0 +1,292 @@ +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 (46272634)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (46272634)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 180, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,180,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1401.sql b/inst/sql/sql_server/1401.sql new file mode 100644 index 00000000..1c27ccfc --- /dev/null +++ b/inst/sql/sql_server/1401.sql @@ -0,0 +1,317 @@ +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 (2795873,2795886,4297063,4210149,4043203,1552629,4327941,2795900)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (2795873,2795886,4210149,4043203,4327941,2795900)) + +) I +LEFT JOIN +( + select concept_id from @vocabulary_database_schema.CONCEPT where (concept_id in (37155220,40664776,4084199,4079606,4296253,4117916,3657567,4272803,44811077,37209052,37155031,37154898,4079611)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (37155220,40664776,4084199,4079606,4296253,4117916,3657567,4272803,44811077,37209052,37155031,37154898)) + +) E ON I.concept_id = E.concept_id +WHERE E.concept_id is null +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Procedure Occurrence Criteria + +UNION ALL +-- Begin Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 30, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,30,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1402.sql b/inst/sql/sql_server/1402.sql new file mode 100644 index 00000000..040330bf --- /dev/null +++ b/inst/sql/sql_server/1402.sql @@ -0,0 +1,306 @@ +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 (2795873,4079501,1552629,2213548,4296166)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (2795873,4296166)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Procedure Occurrence Criteria + +UNION ALL +-- Begin Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 30, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,30,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1403.sql b/inst/sql/sql_server/1403.sql new file mode 100644 index 00000000..529ccfb4 --- /dev/null +++ b/inst/sql/sql_server/1403.sql @@ -0,0 +1,292 @@ +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 (4297063,4210149,2795900,4028920)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4210149,2795900,4028920)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 90, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,90,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1404.sql b/inst/sql/sql_server/1404.sql new file mode 100644 index 00000000..b910d239 --- /dev/null +++ b/inst/sql/sql_server/1404.sql @@ -0,0 +1,303 @@ +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 (4040976)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4040976)) + +) I +LEFT JOIN +( + select concept_id from @vocabulary_database_schema.CONCEPT where (concept_id in (44811077,37209052,37155031,37154898)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (44811077,37209052,37155031,37154898)) + +) E ON I.concept_id = E.concept_id +WHERE E.concept_id is null +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 365, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,365,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1405.sql b/inst/sql/sql_server/1405.sql new file mode 100644 index 00000000..b910d239 --- /dev/null +++ b/inst/sql/sql_server/1405.sql @@ -0,0 +1,303 @@ +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 (4040976)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4040976)) + +) I +LEFT JOIN +( + select concept_id from @vocabulary_database_schema.CONCEPT where (concept_id in (44811077,37209052,37155031,37154898)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (44811077,37209052,37155031,37154898)) + +) E ON I.concept_id = E.concept_id +WHERE E.concept_id is null +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 365, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,365,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1406.sql b/inst/sql/sql_server/1406.sql new file mode 100644 index 00000000..63b24967 --- /dev/null +++ b/inst/sql/sql_server/1406.sql @@ -0,0 +1,306 @@ +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 (44792681,44809825,37209005,37209000,4174714,46272515,4135675,44791051,4243827,4175010,3661916,37209004,37209003,37209002,37209001,40217334,40217326,40217331,40217332,40217333,40217335,40217336,40217337,40217338,40217339,44804161,4273851)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4174714,4135675,44791051,4243827,44804161,4273851)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Procedure Occurrence Criteria + +UNION ALL +-- Begin Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 365, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,365,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1407.sql b/inst/sql/sql_server/1407.sql new file mode 100644 index 00000000..ea5f1502 --- /dev/null +++ b/inst/sql/sql_server/1407.sql @@ -0,0 +1,306 @@ +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 (38004257,38004274,8974,8957)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (8974,8957)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Visit Occurrence Criteria +select C.person_id, C.visit_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select vo.person_id,vo.visit_occurrence_id,vo.visit_concept_id,vo.visit_start_date as start_date, vo.visit_end_date as end_date + FROM @cdm_database_schema.VISIT_OCCURRENCE vo +JOIN #Codesets cs on (vo.visit_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Visit Occurrence Criteria + +UNION ALL +-- Begin Procedure Occurrence Criteria +select C.person_id, C.procedure_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 30, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,30,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1408.sql b/inst/sql/sql_server/1408.sql new file mode 100644 index 00000000..f29429a6 --- /dev/null +++ b/inst/sql/sql_server/1408.sql @@ -0,0 +1,306 @@ +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 (2514536,915726,4062656,2514537,801323,801324,915727)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4062656)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation Criteria + +UNION ALL +-- Begin Measurement Criteria +select C.person_id, C.measurement_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select m.person_id,m.measurement_id,m.measurement_concept_id,m.visit_occurrence_id,m.value_as_number,m.range_high,m.range_low,m.measurement_date as start_date, DATEADD(day,1,m.measurement_date) as end_date + FROM @cdm_database_schema.MEASUREMENT m +JOIN #Codesets cs on (m.measurement_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Measurement 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 1, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,1,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1409.sql b/inst/sql/sql_server/1409.sql new file mode 100644 index 00000000..cf93c53b --- /dev/null +++ b/inst/sql/sql_server/1409.sql @@ -0,0 +1,292 @@ +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 (4158091)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4158091)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Measurement Criteria +select C.person_id, C.measurement_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select m.person_id,m.measurement_id,m.measurement_concept_id,m.visit_occurrence_id,m.value_as_number,m.range_high,m.range_low,m.measurement_date as start_date, DATEADD(day,1,m.measurement_date) as end_date + FROM @cdm_database_schema.MEASUREMENT m +JOIN #Codesets cs on (m.measurement_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Measurement 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 1, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,1,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1410.sql b/inst/sql/sql_server/1410.sql new file mode 100644 index 00000000..54e65af3 --- /dev/null +++ b/inst/sql/sql_server/1410.sql @@ -0,0 +1,320 @@ +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 (37208717,37310702,4169338,4157230,4159408,37208713,4159696,4165123,4158756,44792141,42536965,3655567,46234680,4159568,46234681,42536966,3657588,37208715,37208712,37208716,4164813,4167760,37208714,37208560,44792142,36674484,4165448,2514536,2514537,2617464,2617465,40664833,40664725)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4157230,4165123,36674484)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Measurement Criteria +select C.person_id, C.measurement_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select m.person_id,m.measurement_id,m.measurement_concept_id,m.visit_occurrence_id,m.value_as_number,m.range_high,m.range_low,m.measurement_date as start_date, DATEADD(day,1,m.measurement_date) as end_date + FROM @cdm_database_schema.MEASUREMENT m +JOIN #Codesets cs on (m.measurement_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Measurement Criteria + +UNION ALL +-- Begin Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation Criteria + +UNION ALL +-- Begin Procedure Occurrence Criteria +select C.person_id, C.procedure_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 0) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 1, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,1,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1411.sql b/inst/sql/sql_server/1411.sql new file mode 100644 index 00000000..1ee2bfaa --- /dev/null +++ b/inst/sql/sql_server/1411.sql @@ -0,0 +1,292 @@ +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 (40772940,37078900,3032575,4326820,3026040,40481408,21494866,3028841,3015906,40655173,40766846,37049368,37071236,21494867,4280954,4096080,43533688,46257673,1247077,43533687,4255267,43533448,37062255,37045698,43534383,3022432,4021313,3034429,21492624,43533447,40655612,3045233,46284938,4006367,4104671,43534240,40771543,3034963,37169494,1001641,3001241,40766847,37169917,37024054,43533556,3042517,37041970,40655546,3013169,4324133,44806422,42529009,43534382,4269834,3006476,4221377,40771548,43533555,3034789,3033472,37039135,4260399,40766849,4211848,1616297,37025133,3013362,37169029,36713684,37173225,37077798,3004555,4273557,40656638,3037571,44806443,37060400,43534147,40655611,3019270,3000684,44812145,37046785,37022969,43534239,3015840,3021426,3009354,37048890,3002874,1175388,37027040,1988963,3043690,43534148,46257559,3032544,3003644,37043740,3000074,4021452,21494870,40766842,4091463,3039447,37073815,37169036,40772939,4021450,40655174,37032910,1616954,40653859,3050636,4203316,37077184,4020273,43533385,37033562,37155997,44806229,37055737)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (40772940,37078900,4326820,40481408,40655173,37049368,37071236,4280954,4096080,46257673,1247077,4255267,37062255,37045698,4021313,40655612,46284938,4006367,4104671,37169494,37169917,37024054,37041970,40655546,4324133,44806422,4269834,4221377,37039135,4260399,4211848,37025133,37169029,36713684,37173225,37077798,4273557,40656638,44806443,37060400,40655611,44812145,37046785,37022969,37048890,37027040,46257559,37043740,4021452,4091463,37073815,37169036,40772939,4021450,40655174,37032910,40653859,4203316,37077184,4020273,37033562,37155997,44806229,37055737)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Measurement Criteria +select C.person_id, C.measurement_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select m.person_id,m.measurement_id,m.measurement_concept_id,m.visit_occurrence_id,m.value_as_number,m.range_high,m.range_low,m.measurement_date as start_date, DATEADD(day,1,m.measurement_date) as end_date + FROM @cdm_database_schema.MEASUREMENT m +JOIN #Codesets cs on (m.measurement_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Measurement 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 1, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,1,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1412.sql b/inst/sql/sql_server/1412.sql new file mode 100644 index 00000000..c0b5efce --- /dev/null +++ b/inst/sql/sql_server/1412.sql @@ -0,0 +1,336 @@ +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 (1114220)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (1114220)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 1, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(1 + 1),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1413.sql b/inst/sql/sql_server/1413.sql new file mode 100644 index 00000000..6e55175c --- /dev/null +++ b/inst/sql/sql_server/1413.sql @@ -0,0 +1,301 @@ +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 (2514536,2514537,2617464,2617465,40664833,40664725)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- End Observation Criteria + +UNION ALL +-- Begin Procedure Occurrence Criteria +select C.person_id, C.procedure_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select po.person_id,po.procedure_occurrence_id,po.procedure_concept_id,po.visit_occurrence_id,po.quantity,po.procedure_date as start_date, DATEADD(day,1,po.procedure_date) as end_date + FROM @cdm_database_schema.PROCEDURE_OCCURRENCE po +JOIN #Codesets cs on (po.procedure_concept_id = cs.concept_id and cs.codeset_id = 1) +) 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,1,end_date) > op_end_date then op_end_date else DATEADD(day,1,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1415.sql b/inst/sql/sql_server/1415.sql new file mode 100644 index 00000000..bc7ce428 --- /dev/null +++ b/inst/sql/sql_server/1415.sql @@ -0,0 +1,306 @@ +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 (4027643,4215819)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4027643,4215819)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Condition Occurrence Criteria + +UNION ALL +-- Begin Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,180,end_date) > op_end_date then op_end_date else DATEADD(day,180,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1416.sql b/inst/sql/sql_server/1416.sql new file mode 100644 index 00000000..20e5b9f3 --- /dev/null +++ b/inst/sql/sql_server/1416.sql @@ -0,0 +1,292 @@ +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 (4313342,37164784,37164787,4042878,4036418,4038713)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4042878,4036418,4038713)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,14,end_date) > op_end_date then op_end_date else DATEADD(day,14,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1417.sql b/inst/sql/sql_server/1417.sql new file mode 100644 index 00000000..d59a509d --- /dev/null +++ b/inst/sql/sql_server/1417.sql @@ -0,0 +1,292 @@ +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 (4226563,4229859,4038703,4042885,4027647)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4229859)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,1,end_date) > op_end_date then op_end_date else DATEADD(day,1,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 30, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,30,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1418.sql b/inst/sql/sql_server/1418.sql new file mode 100644 index 00000000..196b5456 --- /dev/null +++ b/inst/sql/sql_server/1418.sql @@ -0,0 +1,292 @@ +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 (4038700,45769951,37109199,4038701,4042884,4038702,4027646,37116662)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4038700,45769951,4038701)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,90,end_date) > op_end_date then op_end_date else DATEADD(day,90,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1419.sql b/inst/sql/sql_server/1419.sql new file mode 100644 index 00000000..9b4ccfc9 --- /dev/null +++ b/inst/sql/sql_server/1419.sql @@ -0,0 +1,306 @@ +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 (35610540,35610541,35610542,35610524,35610545,35610537,44788726,35610544,37205764,35610534,36676296,35610533,36676297,35610532,35610538,35610543,35610536,37110444)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (37205764)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation Criteria + +UNION ALL +-- Begin Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Condition 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,30,end_date) > op_end_date then op_end_date else DATEADD(day,30,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1420.sql b/inst/sql/sql_server/1420.sql new file mode 100644 index 00000000..4a314917 --- /dev/null +++ b/inst/sql/sql_server/1420.sql @@ -0,0 +1,303 @@ +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 (378143,374009,434889,4133611,444100,442077,439706,30361,436073)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (378143,374009,434889,4133611,444100,442077,439706,30361,436073)) + +) I +LEFT JOIN +( + select concept_id from @vocabulary_database_schema.CONCEPT where (concept_id in (35609901,434900)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (35609901,434900)) + +) E ON I.concept_id = E.concept_id +WHERE E.concept_id is null +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Condition 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,14,end_date) > op_end_date then op_end_date else DATEADD(day,14,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 30, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,30,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1421.sql b/inst/sql/sql_server/1421.sql new file mode 100644 index 00000000..064b15c5 --- /dev/null +++ b/inst/sql/sql_server/1421.sql @@ -0,0 +1,292 @@ +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 (30361)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (30361)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Condition 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,1,end_date) > op_end_date then op_end_date else DATEADD(day,1,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 7, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,7,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1422.sql b/inst/sql/sql_server/1422.sql new file mode 100644 index 00000000..1a9cbf57 --- /dev/null +++ b/inst/sql/sql_server/1422.sql @@ -0,0 +1,292 @@ +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 (381316)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (381316)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Condition 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,7,end_date) > op_end_date then op_end_date else DATEADD(day,7,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 30, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,30,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1423.sql b/inst/sql/sql_server/1423.sql new file mode 100644 index 00000000..fdff65a1 --- /dev/null +++ b/inst/sql/sql_server/1423.sql @@ -0,0 +1,292 @@ +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 (607209,3178217,1245119)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (607209,3178217,1245119)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- End Condition 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,1,end_date) > op_end_date then op_end_date else DATEADD(day,1,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 7, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,7,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1424.sql b/inst/sql/sql_server/1424.sql new file mode 100644 index 00000000..380fef01 --- /dev/null +++ b/inst/sql/sql_server/1424.sql @@ -0,0 +1,328 @@ +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 (40141382,35603851,40063501,46275783,46275793,46275772,19014158)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (40141382,35603851,40063501,46275783,46275793,46275772,19014158)) + +) I +LEFT JOIN +( + select concept_id from @vocabulary_database_schema.CONCEPT where (concept_id in (40166388)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (40166388)) + +) E ON I.concept_id = E.concept_id +WHERE E.concept_id is null +) C UNION ALL +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 (606805)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (606805)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- End Condition Occurrence Criteria + +UNION ALL +-- Begin Drug Exposure Criteria +select C.person_id, C.drug_exposure_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,1,end_date) > op_end_date then op_end_date else DATEADD(day,1,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 7, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,7,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1425.sql b/inst/sql/sql_server/1425.sql new file mode 100644 index 00000000..d37bd305 --- /dev/null +++ b/inst/sql/sql_server/1425.sql @@ -0,0 +1,292 @@ +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 (37165681,37208159)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (37165681,37208159)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Condition 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,1,end_date) > op_end_date then op_end_date else DATEADD(day,1,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 7, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,7,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1426.sql b/inst/sql/sql_server/1426.sql new file mode 100644 index 00000000..a97969ce --- /dev/null +++ b/inst/sql/sql_server/1426.sql @@ -0,0 +1,306 @@ +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 (4205848,21603244,36854582,21604752,36855591,21604787,21604390,36859280,21604200,36863385,21604686,21604247,21604489,36856603,21604198,21604254,955372,21604363,36861112,36858409,21604194,718583)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (4205848,21603244,21604752,21604787,21604390,21604200,21604686,21604247,21604489,21604198,21604254,955372,21604363,21604194,718583)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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 Condition Occurrence Criteria +SELECT C.person_id, C.condition_occurrence_id as event_id, C.start_date, C.end_date, + C.visit_occurrence_id, C.start_date as sort_date +FROM +( + SELECT co.person_id,co.condition_occurrence_id,co.condition_concept_id,co.visit_occurrence_id,co.condition_start_date as start_date, COALESCE(co.condition_end_date, DATEADD(day,1,co.condition_start_date)) as end_date + FROM @cdm_database_schema.CONDITION_OCCURRENCE co + JOIN #Codesets cs on (co.condition_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Condition Occurrence Criteria + +UNION ALL +-- Begin Observation Criteria +select C.person_id, C.observation_id as event_id, C.start_date, C.END_DATE, + C.visit_occurrence_id, C.start_date as sort_date +from +( + select o.person_id,o.observation_id,o.observation_concept_id,o.visit_occurrence_id,o.value_as_number,o.observation_date as start_date, DATEADD(day,1,o.observation_date) as end_date + FROM @cdm_database_schema.OBSERVATION o +JOIN #Codesets cs on (o.observation_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- End Observation 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) Results + +; + +-- date offset strategy + +select event_id, person_id, + case when DATEADD(day,7,end_date) > op_end_date then op_end_date else DATEADD(day,7,end_date) end as end_date +INTO #strategy_ends +from #included_events; + + +-- generate cohort periods into #final_cohort +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- cohort exit dates +-- End Date Strategy +SELECT event_id, person_id, end_date from #strategy_ends + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 180, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,180,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1427.sql b/inst/sql/sql_server/1427.sql new file mode 100644 index 00000000..f8dacd24 --- /dev/null +++ b/inst/sql/sql_server/1427.sql @@ -0,0 +1,336 @@ +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 (19043959)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (19043959)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 = 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 1, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(1 + 30),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1428.sql b/inst/sql/sql_server/1428.sql new file mode 100644 index 00000000..b22d5ad3 --- /dev/null +++ b/inst/sql/sql_server/1428.sql @@ -0,0 +1,336 @@ +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 (735850)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (735850)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 0) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 = 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 1, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(1 + 30),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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; diff --git a/inst/sql/sql_server/1429.sql b/inst/sql/sql_server/1429.sql new file mode 100644 index 00000000..0d2869cb --- /dev/null +++ b/inst/sql/sql_server/1429.sql @@ -0,0 +1,336 @@ +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 (1133201)) +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 + WHERE c.invalid_reason is null + and (ca.ancestor_concept_id in (1133201)) + +) I +) C; + +UPDATE STATISTICS #Codesets; + + +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 (-- 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, E.event_id) 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.start_date, C.end_date, + C.visit_occurrence_id,C.start_date as sort_date +from +( + select de.person_id,de.drug_exposure_id,de.drug_concept_id,de.visit_occurrence_id,days_supply,quantity,refills,de.drug_exposure_start_date as start_date, COALESCE(de.drug_exposure_end_date, DATEADD(day,de.days_supply,de.drug_exposure_start_date), DATEADD(day,1,de.drug_exposure_start_date)) as end_date + FROM @cdm_database_schema.DRUG_EXPOSURE de +JOIN #Codesets cs on (de.drug_concept_id = cs.concept_id and cs.codeset_id = 1) +) C + + +-- 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 +) pe + +) QE + +; + +--- Inclusion Rule Inserts + +create table #inclusion_events (inclusion_rule_id bigint, + person_id bigint, + event_id bigint +); + +select event_id, person_id, start_date, end_date, op_start_date, op_end_date +into #included_events +FROM ( + 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 +{0 != 0}?{ + -- the matching group with all bits set ( POWER(2,# of inclusion rules) - 1 = inclusion_rule_mask + WHERE (MG.inclusion_rule_mask = POWER(cast(2 as bigint),0)-1) +} +) 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 person_id, min(start_date) as era_start_date, DATEADD(day,-1 * 0, max(end_date)) as era_end_date + from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, drug_exposure_start_date as start_date, DATEADD(day,(0 + 30),DRUG_EXPOSURE_END_DATE) as end_date + FROM #drugTarget + ) DT + ) ST + ) GR + group by person_id, group_idx +) 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 +select person_id, start_date, end_date +INTO #cohort_rows +from ( -- first_ends + select F.person_id, F.start_date, F.end_date + FROM ( + select I.event_id, I.person_id, I.start_date, CE.end_date, row_number() over (partition by I.person_id, I.event_id order by CE.end_date) as ordinal + from #included_events I + join ( -- cohort_ends +-- 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 + + ) CE on I.event_id = CE.event_id and I.person_id = CE.person_id and CE.end_date >= I.start_date + ) F + WHERE F.ordinal = 1 +) FE; + + +select person_id, min(start_date) as start_date, DATEADD(day,-1 * 0, max(end_date)) as end_date +into #final_cohort +from ( + select person_id, start_date, end_date, sum(is_start) over (partition by person_id order by start_date, is_start desc rows unbounded preceding) group_idx + from ( + select person_id, start_date, end_date, + case when max(end_date) over (partition by person_id order by start_date rows between unbounded preceding and 1 preceding) >= start_date then 0 else 1 end is_start + from ( + select person_id, start_date, DATEADD(day,0,end_date) as end_date + from #cohort_rows + ) CR + ) ST +) GR +group by person_id, group_idx; + +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 +; + +{1 != 0}?{ +-- BEGIN: Censored Stats + +delete from @results_database_schema.cohort_censor_stats where cohort_definition_id = @target_cohort_id; + +-- END: Censored Stats +} +{1 != 0 & 0 != 0}?{ + +CREATE TABLE #inclusion_rules (rule_sequence int); + +-- Find the event that is the 'best match' per person. +-- the 'best match' is defined as the event that satisfies the most inclusion rules. +-- ties are solved by choosing the event that matches the earliest inclusion rule, and then earliest. + +select q.person_id, q.event_id +into #best_events +from #qualified_events Q +join ( + SELECT R.person_id, R.event_id, ROW_NUMBER() OVER (PARTITION BY R.person_id ORDER BY R.rule_count DESC,R.min_rule_id ASC, R.start_date ASC) AS rank_value + FROM ( + SELECT Q.person_id, Q.event_id, COALESCE(COUNT(DISTINCT I.inclusion_rule_id), 0) AS rule_count, COALESCE(MIN(I.inclusion_rule_id), 0) AS min_rule_id, Q.start_date + FROM #qualified_events Q + LEFT JOIN #inclusion_events I ON q.person_id = i.person_id AND q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id, Q.start_date + ) R +) ranked on Q.person_id = ranked.person_id and Q.event_id = ranked.event_id +WHERE ranked.rank_value = 1 +; + +-- modes of generation: (the same tables store the results for the different modes, identified by the mode_id column) +-- 0: all events +-- 1: best event + + +-- BEGIN: Inclusion Impact Analysis - event +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 0 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #qualified_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 0 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #qualified_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #qualified_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 0 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 0; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 0 as mode_id +FROM +(select count_big(event_id) as total from #qualified_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 0 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - event + +-- BEGIN: Inclusion Impact Analysis - person +-- calculte matching group counts +delete from @results_database_schema.cohort_inclusion_result where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_result (cohort_definition_id, inclusion_rule_mask, person_count, mode_id) +select @target_cohort_id as cohort_definition_id, inclusion_rule_mask, count_big(*) as person_count, 1 as mode_id +from +( + select Q.person_id, Q.event_id, CAST(SUM(coalesce(POWER(cast(2 as bigint), I.inclusion_rule_id), 0)) AS bigint) as inclusion_rule_mask + from #best_events Q + LEFT JOIN #inclusion_events I on q.person_id = i.person_id and q.event_id = i.event_id + GROUP BY Q.person_id, Q.event_id +) MG -- matching groups +group by inclusion_rule_mask +; + +-- calculate gain counts +delete from @results_database_schema.cohort_inclusion_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_inclusion_stats (cohort_definition_id, rule_sequence, person_count, gain_count, person_total, mode_id) +select @target_cohort_id as cohort_definition_id, ir.rule_sequence, coalesce(T.person_count, 0) as person_count, coalesce(SR.person_count, 0) gain_count, EventTotal.total, 1 as mode_id +from #inclusion_rules ir +left join +( + select i.inclusion_rule_id, count_big(i.event_id) as person_count + from #best_events Q + JOIN #inclusion_events i on Q.person_id = I.person_id and Q.event_id = i.event_id + group by i.inclusion_rule_id +) T on ir.rule_sequence = T.inclusion_rule_id +CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal +CROSS JOIN (select count_big(event_id) as total from #best_events) EventTotal +LEFT JOIN @results_database_schema.cohort_inclusion_result SR on SR.mode_id = 1 AND SR.cohort_definition_id = @target_cohort_id AND (POWER(cast(2 as bigint),RuleTotal.total_rules) - POWER(cast(2 as bigint),ir.rule_sequence) - 1) = SR.inclusion_rule_mask -- POWER(2,rule count) - POWER(2,rule sequence) - 1 is the mask for 'all except this rule' +; + +-- calculate totals +delete from @results_database_schema.cohort_summary_stats where cohort_definition_id = @target_cohort_id and mode_id = 1; +insert into @results_database_schema.cohort_summary_stats (cohort_definition_id, base_count, final_count, mode_id) +select @target_cohort_id as cohort_definition_id, PC.total as person_count, coalesce(FC.total, 0) as final_count, 1 as mode_id +FROM +(select count_big(event_id) as total from #best_events) PC, +(select sum(sr.person_count) as total + from @results_database_schema.cohort_inclusion_result sr + CROSS JOIN (select count(*) as total_rules from #inclusion_rules) RuleTotal + where sr.mode_id = 1 and sr.cohort_definition_id = @target_cohort_id and sr.inclusion_rule_mask = POWER(cast(2 as bigint),RuleTotal.total_rules)-1 +) FC +; + +-- END: Inclusion Impact Analysis - person + +TRUNCATE TABLE #best_events; +DROP TABLE #best_events; + +TRUNCATE TABLE #inclusion_rules; +DROP TABLE #inclusion_rules; +} + +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;
oldId newId