Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible error with DEX14: Among people who take drug A, how many take drug B at the same time? #12

Open
ablack3 opened this issue Feb 19, 2020 · 0 comments

Comments

@ablack3
Copy link

ablack3 commented Feb 19, 2020

I think that this query is incorrect.

WITH statins AS (
SELECT descendant_concept_id AS concept_id
FROM cdm.concept_ancestor
WHERE ancestor_concept_id = 1539403
), diuretics AS (
SELECT descendant_concept_id AS concept_id
FROM cdm.concept_ancestor
WHERE ancestor_concept_id = 974166
)
SELECT COUNT(DISTINCT de1.person_id) AS num_users,
COUNT(DISTINCT de2.person_id) AS also_bp
FROM cdm.drug_exposure de1
JOIN statins s
ON de1.drug_concept_id = s.concept_id
JOIN cdm.drug_exposure de2
ON de1.person_id = de2.person_id
LEFT JOIN diuretics d
ON de2.drug_concept_id = d.concept_id
AND de2.drug_exposure_start_date < de1.drug_exposure_end_date
AND de2.drug_exposure_end_date > de1.drug_exposure_start_date;

This is my proposed fix.

WITH drug_exposure1 AS (
SELECT de.person_id,
de.drug_exposure_start_date,
de.drug_exposure_end_date
FROM cdm.drug_exposure de
INNER JOIN cdm.concept_ancestor ca
ON de.drug_concept_id = ca.descendant_concept_id
WHERE ancestor_concept_id = 1539403

),
drug_exposure2 AS (
SELECT de.person_id,
de.drug_exposure_start_date,
de.drug_exposure_end_date
FROM cdm.drug_exposure de
INNER JOIN cdm.concept_ancestor ca
ON de.drug_concept_id = ca.descendant_concept_id
WHERE ancestor_concept_id = 974166
)
SELECT COUNT(DISTINCT de1.person_id) AS num_drug1_users,
COUNT(DISTINCT de2.person_id) AS also_drug2_users
FROM drug_exposure1 de1
LEFT JOIN drug_exposure2 de2
ON de1.person_id = de2.person_id
AND de2.drug_exposure_start_date < de1.drug_exposure_end_date
AND de2.drug_exposure_end_date > de1.drug_exposure_start_date;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant