Last active
August 12, 2019 21:57
-
-
Save callahantiff/0d1602bbaca504b62b4495dd8cce5165 to your computer and use it in GitHub Desktop.
PheKnowVec Cohort Query: https://github.com/callahantiff/PheKnowVec/wiki/Peanut-Allergy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH all_case_inclusion_criteria_1 AS ( | |
SELECT person_id, {code_set_group} AS code_set FROM | |
(SELECT co.person_id | |
FROM | |
{database}.condition_occurrence co, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
co.condition_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
co.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT co.condition_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT de.person_id | |
FROM | |
{database}.drug_exposure de, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
de.drug_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
de.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT de.drug_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT m.person_id | |
FROM | |
{database}.measurement m, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
m.measurement_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
m.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT m.measurement_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT o.person_id | |
FROM | |
{database}.observation o, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
o.observation_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
o.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT o.observation_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT pr.person_id | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
)), | |
mx_case_inclusion_criteria_1 AS ( | |
SELECT m.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.measurement m, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
m.measurement_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 2 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY m.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT m.measurement_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_1 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 3 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_2 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 4 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_3 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 5 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_4 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 6 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
) | |
SELECT * FROM | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE1' AS cohort_type | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_1 | |
INTERSECT DISTINCT | |
(SELECT person_id, code_set FROM mx_case_inclusion_criteria_1 | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_1) | |
GROUP BY person_id, code_set, cohort_type)) | |
UNION ALL | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE2' AS cohort_type | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_1 | |
INTERSECT DISTINCT | |
(SELECT person_id, code_set FROM px_case_inclusion_criteria_2 | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_3 | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_4)) | |
GROUP BY person_id, code_set, cohort_type) | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- CODES + ALL CLINICAL DOMAINS vs. CONDITIONS ONLY | |
WITH all_case_inclusion_criteria_1 AS ( | |
SELECT person_id, {code_set_group} AS code_set FROM | |
(SELECT co.person_id | |
FROM | |
{database}.condition_occurrence co, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
co.condition_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
co.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT co.condition_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT de.person_id | |
FROM | |
{database}.drug_exposure de, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
de.drug_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
de.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT de.drug_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT m.person_id | |
FROM | |
{database}.measurement m, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
m.measurement_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
m.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT m.measurement_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT o.person_id | |
FROM | |
{database}.observation o, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
o.observation_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
o.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT o.observation_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT pr.person_id | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
)), | |
all_case_inclusion_criteria_2 AS ( | |
SELECT person_id, {code_set_group} AS code_set FROM | |
(SELECT co.person_id | |
FROM | |
{database}.condition_occurrence co, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
co.condition_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
co.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT co.condition_concept_id) >= 1 | |
)), | |
mx_case_inclusion_criteria_1 AS ( | |
SELECT m.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.measurement m, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
m.measurement_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 2 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY m.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT m.measurement_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_1 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 3 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_2 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 4 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_3 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 5 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_4 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 6 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
) | |
SELECT * FROM | |
# all clinical domains + codes | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE1' AS cohort_type, 'ALL DOMAINS' AS clinical_data_type, 'CODES' AS cohort_assignment | |
FROM ( | |
(SELECT person_id, code_set FROM all_case_inclusion_criteria_1 | |
INTERSECT DISTINCT | |
SELECT person_id, code_set FROM mx_case_inclusion_criteria_1) | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_1) | |
GROUP BY person_id, code_set, cohort_type, clinical_data_type, cohort_assignment) | |
UNION ALL | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE2' AS cohort_type, 'ALL DOMAINS' AS clinical_data_type, 'CODES' AS cohort_assignment | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_1 | |
INTERSECT DISTINCT | |
(SELECT person_id, code_set FROM px_case_inclusion_criteria_2 | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_3 | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_4)) | |
GROUP BY person_id, code_set, cohort_type, clinical_data_type, cohort_assignment) | |
UNION ALL | |
# only conditions + codes | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE1' AS cohort_type, 'CONDITIONS ONLY' AS clinical_data_type, 'CODES' AS cohort_assignment | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_2) | |
GROUP BY person_id, code_set, cohort_type, clinical_data_type, cohort_assignment) | |
UNION ALL | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE2' AS cohort_type, 'CONDITIONS ONLY' AS clinical_data_type, 'CODES' AS cohort_assignment | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_2) | |
GROUP BY person_id, code_set, cohort_type, clinical_data_type, cohort_assignment) | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- DEFINITIONS + ALL CLINICAL DOMAINS vs. CONDITIONS ONLY | |
WITH all_case_inclusion_criteria_1 AS ( | |
SELECT person_id, {code_set_group} AS code_set FROM | |
(SELECT co.person_id | |
FROM | |
{database}.condition_occurrence co, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
co.condition_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
co.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT co.condition_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT de.person_id | |
FROM | |
{database}.drug_exposure de, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
de.drug_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
de.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT de.drug_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT m.person_id | |
FROM | |
{database}.measurement m, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
m.measurement_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
m.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT m.measurement_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT o.person_id | |
FROM | |
{database}.observation o, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
o.observation_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
o.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT o.observation_concept_id) >= 1 | |
UNION DISTINCT | |
SELECT pr.person_id | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
)), | |
all_case_inclusion_criteria_2 AS ( | |
SELECT person_id, {code_set_group} AS code_set FROM | |
(SELECT co.person_id | |
FROM | |
{database}.condition_occurrence co, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
co.condition_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 1 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY | |
co.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT co.condition_concept_id) >= 1 | |
)), | |
mx_case_inclusion_criteria_1 AS ( | |
SELECT m.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.measurement m, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
m.measurement_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 2 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY m.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT m.measurement_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_1 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 3 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_2 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 4 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_3 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 5 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
), | |
px_case_inclusion_criteria_4 AS ( | |
SELECT pr.person_id, cohort.standard_code_set AS code_set | |
FROM | |
{database}.procedure_occurrence pr, | |
{database}.PEANUTALLERGY_COHORT_VARS cohort | |
WHERE | |
pr.procedure_concept_id = CAST(cohort.standard_concept_id AS int64) | |
AND cohort.phenotype_definition_number = 6 | |
AND cohort.standard_code_set = {code_set_group} | |
GROUP BY pr.person_id, cohort.standard_code_set | |
HAVING | |
COUNT(DISTINCT pr.procedure_concept_id) >= 1 | |
) | |
SELECT * FROM | |
# all clinical domains + definitions | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE1' AS cohort_type, 'ALL DOMAINS' AS clinical_data_type, 'DEFINITIONS' AS cohort_assignment | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_1 | |
INTERSECT DISTINCT | |
(SELECT person_id, code_set FROM mx_case_inclusion_criteria_1 | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_1)) | |
GROUP BY person_id, code_set, cohort_type, clinical_data_type, cohort_assignment) | |
UNION ALL | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE2' AS cohort_type, 'ALL DOMAINS' AS clinical_data_type, 'DEFINITIONS' AS cohort_assignment | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_1 | |
INTERSECT DISTINCT | |
(SELECT person_id, code_set FROM px_case_inclusion_criteria_2 | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_3 | |
UNION DISTINCT | |
SELECT person_id, code_set FROM px_case_inclusion_criteria_4)) | |
GROUP BY person_id, code_set, cohort_type, clinical_data_type, cohort_assignment) | |
UNION ALL | |
# only conditions + definitions | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE1' AS cohort_type, 'CONDITIONS ONLY' AS clinical_data_type, 'DEFINITIONS' AS cohort_assignment | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_2) | |
GROUP BY person_id, code_set, cohort_type, clinical_data_type, cohort_assignment) | |
UNION ALL | |
(SELECT person_id, code_set, 'PEANUTALLERGY_CASE_TYPE2' AS cohort_type, 'CONDITIONS ONLY' AS clinical_data_type, 'DEFINITIONS' AS cohort_assignment | |
FROM ( | |
SELECT person_id, code_set FROM all_case_inclusion_criteria_2) | |
GROUP BY person_id, code_set, cohort_type, clinical_data_type, cohort_assignment) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment