Rich, Erica et al.:
Here is the query that will do the following:
- Stratify by ingredient only
- Stratify by ingredient and HOI
- Stratify by ingredient and clinical drug
- Give the full detail (all ingredients, drugs, HOI and the numbers)
and create one summary report for each of them. The numbers are:
- ct_count - clinical trial count. The details are listed for ingredients and HOIs, not for clinical drugs. The summary is provided as a total.
- case_count - care report count. Same as above.
- other_count - other mesh based count. Same as above.
- splicer_count - count in splicer. The details are listed for clinical drugs and HOIs. The summary is provided as a total.
- eb05 - ebgm confidence interval. The details are listed for ingredients and HOIs. The summary provides an average.
- ebgm - empirical Bayes geometric mean of the EARS report. Same as above.
- aers_report_count - absolute number of AERS reports. The summary is provided as a total.
Here is the query (takes a minute to run):
select
report_name,
case
when lag(ingredient_id) over (partition by ingredient_id order by report_order, clinical_drug_id, hoi_id) = ingredient_id then null
else ingredient_id
end as ingredient_id,
case
when lag(ingredient_id) over (partition by ingredient_id order by report_order, clinical_drug_id, hoi_id) = ingredient_id then null
else ingredient
end as ingredient,
case
when lag(clinical_drug_id) over (partition by ingredient_id, clinical_drug_id order by report_order, hoi_id) = clinical_drug_id then null
else clinical_drug_id
end as clinical_drug_id,
case
when lag(clinical_drug_id) over (partition by ingredient_id, clinical_drug_id order by report_order, hoi_id) = clinical_drug_id then null
else clinical_drug
end as clinical_drug,
hoi_id, hoi, ct_count, case_count, other_count, splicer_count, eb05, ebgm, aers_report_count
from (
select distinct
1 as report_order,
'Stratified by ingredient' as report_name,
dv1.drug as ingredient_id,
dv1.rxnorm_drug as ingredient,
cast(null as integer) as clinical_drug_id,
cast(null as varchar(1)) as clinical_drug,
cast(null as integer) as hoi_id,
cast(null as varchar(1)) as hoi,
sum(dv1.medline_mesh_clin_trial_count) over (partition by dv1.drug) as ct_count, -- Ingredient-based
sum(dv1.medline_mesh_case_report_count) over (partition by dv1.drug) as case_count, -- Ingredient-based
sum(dv1.medline_mesh_other_count) over (partition by dv1.drug) as other_count, -- Ingredient-based
sum(dv2.spl_splicer_count) over (partition by dv1.drug) as splicer_count, -- Drug-based
avg(dv1.aers_eb05) over (partition by dv1.drug) as eb05, -- Ingredient-based
avg(dv1.aers_ebgm) over (partition by dv1.drug) as ebgm, -- Ingredient-based
sum(dv1.aers_report_count) over (partition by dv1.drug) as aers_report_count-- Ingredient-based
from drug_hoi_evidence_view dv1, drug_hoi_evidence_view dv2, concept_ancestor ca, concept ing, concept drg
where dv1.hoi = dv2.hoi
and dv1.drug = ca.ancestor_concept_id and dv1.drug=ing.concept_id and ing.concept_class_id='Ingredient'
and dv2.drug = ca.descendant_concept_id and dv2.drug=drg.concept_id and drg.concept_class_id like '%Drug'
union
select distinct
2 as report_order,
'Stratified by ingredient and HOI' as report_name,
dv1.drug as ingredient_id,
dv1.rxnorm_drug as ingredient,
cast(null as integer) as clinical_drug_id,
cast(null as varchar(1)) as clinical_drug,
dv1.hoi as hoi_id,
dv1.snomed_hoi as hoi,
sum(dv1.medline_mesh_clin_trial_count) over (partition by dv1.drug, dv1.hoi) as ct_count, -- Ingredient-based
sum(dv1.medline_mesh_case_report_count) over (partition by dv1.drug, dv1.hoi) as case_count, -- Ingredient-based
sum(dv1.medline_mesh_other_count) over (partition by dv1.drug, dv1.hoi) as other_count, -- Ingredient-based
sum(dv2.spl_splicer_count) over (partition by dv1.drug, dv1.hoi) as splicer_count, -- Drug-based
avg(dv1.aers_eb05) over (partition by dv1.drug, dv1.hoi) as eb05, -- Ingredient-based
avg(dv1.aers_ebgm) over (partition by dv1.drug, dv1.hoi) as ebgm, -- Ingredient-based
sum(dv1.aers_report_count) over (partition by dv1.drug, dv1.hoi) as aers_report_count-- Ingredient-based
from drug_hoi_evidence_view dv1, drug_hoi_evidence_view dv2, concept_ancestor ca, concept ing, concept drg
where dv1.hoi = dv2.hoi
and dv1.drug = ca.ancestor_concept_id and dv1.drug=ing.concept_id and ing.concept_class_id='Ingredient'
and dv2.drug = ca.descendant_concept_id and dv2.drug=drg.concept_id and drg.concept_class_id like '%Drug'
union
select distinct
3 as report_order,
'Stratified by ingredient and clinical drug' as report_name,
dv1.drug as ingredient_id,
dv1.rxnorm_drug as ingredient,
dv2.drug as clinical_drug_id,
dv2.rxnorm_drug as clinical_drug,
cast(null as integer) as hoi_id,
cast(null as varchar(1)) as hoi,
sum(dv1.medline_mesh_clin_trial_count) over (partition by dv1.drug, dv2.drug) as ct_count, -- Ingredient-based
sum(dv1.medline_mesh_case_report_count) over (partition by dv1.drug, dv2.drug) as case_count, -- Ingredient-based
sum(dv1.medline_mesh_other_count) over (partition by dv1.drug, dv2.drug) as other_count, -- Ingredient-based
sum(dv2.spl_splicer_count) over (partition by dv1.drug, dv2.drug) as splicer_count, -- Drug-based
avg(dv1.aers_eb05) over (partition by dv1.drug, dv2.drug) as eb05, -- Ingredient-based
avg(dv1.aers_ebgm) over (partition by dv1.drug, dv2.drug) as ebgm, -- Ingredient-based
sum(dv1.aers_report_count) over (partition by dv1.drug, dv2.drug) as aers_report_count-- Ingredient-based
from drug_hoi_evidence_view dv1, drug_hoi_evidence_view dv2, concept_ancestor ca, concept ing, concept drg
where dv1.hoi = dv2.hoi
and dv1.drug = ca.ancestor_concept_id and dv1.drug=ing.concept_id and ing.concept_class_id='Ingredient'
and dv2.drug = ca.descendant_concept_id and dv2.drug=drg.concept_id and drg.concept_class_id like '%Drug'
union
select
4 as report_order,
'Full detail: ingredient, clinical drug, HOI' as report_name,
dv1.drug as ingredient_id,
dv1.rxnorm_drug as ingredient,
dv2.drug as clinical_drug_id,
dv2.rxnorm_drug as clinical_drug,
dv1.hoi as hoi_id,
dv1.snomed_hoi as hoi,
dv1.medline_mesh_clin_trial_count as ct_count, -- Ingredient-based
dv1.medline_mesh_case_report_count as case_count, -- Ingredient-based
dv1.medline_mesh_other_count as other_count, -- Ingredient-based
dv2.spl_splicer_count as splicer_count, -- Drug-based
dv1.aers_eb05 as eb05, -- Ingredient-based
dv1.aers_ebgm as ebgm, -- Ingredient-based
dv1.aers_report_count as aers_report_count-- Ingredient-based
from drug_hoi_evidence_view dv1, drug_hoi_evidence_view dv2, concept_ancestor ca, concept ing, concept drg
where dv1.hoi = dv2.hoi
and dv1.drug = ca.ancestor_concept_id and dv1.drug=ing.concept_id and ing.concept_class_id='Ingredient'
and dv2.drug = ca.descendant_concept_id and dv2.drug=drg.concept_id and drg.concept_class_id like '%Drug'
) d
order by d.ingredient_id, report_order, d.clinical_drug_id, d.hoi_id
limit 1000;