/
manual_checks_after_generic.sql
97 lines (84 loc) · 3 KB
/
manual_checks_after_generic.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--1. Drug Standard RxNorm/RxE concepts aren't linked to the Standard Drug Ingredients
--1a. statistics
--vocabulary version v20201222:
-- 16519/1905195 = 0.867%
SELECT c.vocabulary_id, c.concept_class_id, COUNT (*)
FROM concept c
WHERE c.domain_id = 'Drug'
AND c.standard_concept = 'S'
AND c.vocabulary_id IN ('RxNorm', 'RxNorm Extension')
AND c.concept_class_id NOT IN ('Ingredient')
AND NOT EXISTS (
SELECT 1
FROM concept_ancestor ca
JOIN concept c2
ON ca.ancestor_concept_id = c2.concept_id
AND c2.concept_class_id = 'Ingredient'
AND c2.domain_id = 'Drug'
AND c2.standard_concept = 'S'
WHERE ca.descendant_concept_id = c.concept_id
)
GROUP BY 1,2
ORDER BY 1,2
;
--1b. full list
SELECT c.*
FROM concept c
WHERE c.domain_id = 'Drug'
AND c.standard_concept = 'S'
AND c.vocabulary_id IN ('RxNorm', 'RxNorm Extension')
AND c.concept_class_id NOT IN ('Ingredient')
AND NOT EXISTS (
SELECT 1
FROM concept_ancestor ca
JOIN concept c2
ON ca.ancestor_concept_id = c2.concept_id
AND c2.concept_class_id = 'Ingredient'
AND c2.domain_id = 'Drug'
AND c2.standard_concept = 'S'
WHERE ca.descendant_concept_id = c.concept_id
)
ORDER BY concept_id
;
--2. Drug Standard RxNorm/RxE concepts aren't linked to the Standard Clinical Drug Forms
--2a. statistics
--vocabulary version v20201222:
-- 30110/1651102 = 1.82%
SELECT c.vocabulary_id, c.concept_class_id, COUNT (*)
FROM concept c
WHERE c.domain_id = 'Drug'
AND c.standard_concept = 'S'
AND c.vocabulary_id IN ('RxNorm', 'RxNorm Extension')
AND c.concept_class_id NOT IN ('Ingredient', 'Branded Drug Comp', 'Clinical Drug Comp')
AND NOT EXISTS (
SELECT 1
FROM concept_ancestor ca
JOIN concept c2
ON ca.ancestor_concept_id = c2.concept_id
AND c2.concept_class_id = 'Clinical Drug Form'
AND c2.domain_id = 'Drug'
AND c2.standard_concept = 'S'
WHERE ca.descendant_concept_id = c.concept_id
)
GROUP BY 1,2
ORDER BY 1,2
;
--2b. full list
SELECT c.*
FROM concept c
WHERE c.domain_id = 'Drug'
AND c.standard_concept = 'S'
AND c.vocabulary_id IN ('RxNorm', 'RxNorm Extension')
AND c.concept_class_id NOT IN ('Ingredient', 'Branded Drug Comp', 'Clinical Drug Comp')
AND NOT EXISTS (
SELECT 1
FROM concept_ancestor ca
JOIN concept c2
ON ca.ancestor_concept_id = c2.concept_id
AND c2.concept_class_id = 'Clinical Drug Form'
AND c2.domain_id = 'Drug'
AND c2.standard_concept = 'S'
WHERE ca.descendant_concept_id = c.concept_id
)
ORDER BY concept_id
;