|
9 | 9 | -- --------------------------------------------------
|
10 | 10 |
|
11 | 11 | BEGIN;
|
12 |
| -SELECT plan ( 7 ); |
| 12 | +SELECT plan ( 8 ); |
13 | 13 |
|
14 | 14 | SELECT results_eq
|
15 | 15 | (
|
16 | 16 | '
|
17 |
| -SELECT count(distinct person_id), count(distinct visit_occurrence_id) |
| 17 | +SELECT COUNT(distinct person_id), COUNT(distinct visit_occurrence_id) |
18 | 18 | FROM omop.condition_occurrence
|
19 | 19 | WHERE condition_type_concept_id != 42894222;
|
20 | 20 | '
|
21 | 21 | ,
|
22 | 22 | '
|
23 |
| -SELECT count(distinct subject_id), count(distinct hadm_id) FROM diagnoses_icd where icd9_code is not null; |
24 |
| -' |
| 23 | +SELECT COUNT(distinct subject_id), COUNT(distinct hadm_id) |
| 24 | +FROM diagnoses_icd |
| 25 | +WHERE icd9_code IS NOT NULL; |
| 26 | +' |
25 | 27 | ,
|
26 |
| -'Condition_occurrence table -- nb icd' |
| 28 | +'CONDITION OCCURRENCE -- check ICD diagnoses row count matches' |
27 | 29 | );
|
28 | 30 |
|
29 | 31 | SELECT results_eq
|
30 | 32 | (
|
31 | 33 | '
|
32 |
| -WITH tmp as |
33 |
| -(SELECT distinct on (visit_occurrence_id) * from omop.condition_occurrence where condition_type_concept_id = 42894222) |
34 |
| -SELECT condition_source_value::text, count(1) |
35 |
| -FROM tmp |
36 |
| -group by condition_source_value order by count(condition_source_value) desc; |
| 34 | +WITH tmp as |
| 35 | +( |
| 36 | + SELECT distinct on (visit_occurrence_id) * |
| 37 | + FROM omop.condition_occurrence |
| 38 | + WHERE condition_type_concept_id = 42894222 |
| 39 | +) |
| 40 | +SELECT condition_source_value::text, COUNT(1) |
| 41 | +FROM tmp |
| 42 | +GROUP BY 1 |
| 43 | +ORDER BY 2, 1; |
37 | 44 | '
|
38 | 45 | ,
|
39 | 46 | '
|
40 |
| -SELECT diagnosis::text, count(1) from admissions group by diagnosis order by count(1) desc; |
41 |
| -' |
| 47 | +SELECT diagnosis::text, COUNT(1) |
| 48 | +FROM admissions |
| 49 | +GROUP BY 1 |
| 50 | +ORDER BY 2, 1; |
| 51 | +' |
42 | 52 | ,
|
43 |
| -'Condition_occurrence table -- diagnosis in admission same ' |
| 53 | +'CONDITION OCCURRENCE -- diagnosis in admission same' |
44 | 54 | );
|
45 | 55 |
|
46 | 56 | SELECT results_eq
|
47 | 57 | (
|
48 | 58 | '
|
49 |
| -with tmp as |
50 |
| -(SELECT distinct on (visit_occurrence_id) * from omop.condition_occurrence where condition_type_concept_id = 42894222) |
51 |
| -SELECT condition_source_value::text, count(1) |
52 |
| -FROM tmp |
53 |
| -group by condition_source_value order by count(condition_source_value) desc; |
| 59 | +with tmp as |
| 60 | +( |
| 61 | + SELECT distinct on (visit_occurrence_id) * |
| 62 | + FROM omop.condition_occurrence |
| 63 | + WHERE condition_type_concept_id = 42894222 |
| 64 | +) |
| 65 | +SELECT condition_source_value::text, COUNT(1) |
| 66 | +FROM tmp |
| 67 | +GROUP BY 1 |
| 68 | +ORDER BY 2, 1; |
54 | 69 | '
|
55 | 70 | ,
|
56 | 71 | '
|
57 |
| -SELECT diagnosis::text, count(1) from admissions group by 1 order by 2 desc |
58 |
| -' |
| 72 | +SELECT diagnosis::text, COUNT(1) |
| 73 | +FROM admissions |
| 74 | +GROUP BY 1 |
| 75 | +ORDER BY 2, 1 |
| 76 | +' |
59 | 77 | ,
|
60 |
| -'Condition_occurrence table -- distrib diagnosis the same' |
| 78 | +'CONDITION OCCURRENCE -- distrib diagnosis the same' |
61 | 79 | );
|
62 | 80 |
|
63 | 81 | SELECT results_eq
|
64 | 82 | (
|
65 | 83 | '
|
66 |
| -select 0::integer; |
| 84 | +SELECT COUNT(1)::INTEGER |
| 85 | +FROM omop.condition_occurrence |
| 86 | +WHERE condition_source_concept_id = 0; |
67 | 87 | '
|
68 | 88 | ,
|
69 | 89 | '
|
70 |
| -SELECT count(1)::integer |
71 |
| -FROM omop.condition_occurrence |
72 |
| -where condition_source_concept_id = 0; |
| 90 | +SELECT 0::INTEGER; |
73 | 91 | '
|
74 | 92 | ,
|
75 |
| -'Condition_occurrence table -- there is source concept in measurement not described' |
| 93 | +'CONDITION OCCURRENCE -- there is source concept in measurement not described' |
76 | 94 | );
|
77 | 95 |
|
78 | 96 | SELECT results_eq
|
79 | 97 | (
|
80 | 98 | '
|
81 |
| -select 0::integer; |
| 99 | +SELECT COUNT(1)::INTEGER |
| 100 | +FROM |
| 101 | +( |
| 102 | + SELECT COUNT(1)::INTEGER |
| 103 | + FROM omop.condition_occurrence |
| 104 | + GROUP BY condition_occurrence_id |
| 105 | + having COUNT(1) > 1 |
| 106 | +) as t; |
82 | 107 | '
|
83 | 108 | ,
|
84 | 109 | '
|
85 |
| -select count(1)::integer from ( |
86 |
| -SELECT count(1)::integer |
87 |
| -FROM omop.condition_occurrence |
88 |
| -group by condition_occurrence_id |
89 |
| -having count(1) > 1) as t; |
| 110 | +SELECT 0::INTEGER; |
90 | 111 | '
|
91 | 112 | ,
|
92 |
| -'Condition_occurrence table -- primary key checker' |
| 113 | +'CONDITION OCCURRENCE -- primary key checker' |
93 | 114 | );
|
94 | 115 |
|
95 | 116 | SELECT results_eq
|
96 | 117 | (
|
97 | 118 | '
|
98 |
| -select 0::integer; |
99 |
| -' |
100 |
| -, |
101 |
| -' |
102 |
| -SELECT count(1)::integer |
| 119 | +SELECT COUNT(1)::INTEGER |
103 | 120 | FROM omop.condition_occurrence
|
104 | 121 | LEFT JOIN omop.concept ON condition_concept_id = concept_id
|
105 |
| -WHERE |
106 |
| -condition_concept_id != 0 |
| 122 | +WHERE condition_concept_id != 0 |
107 | 123 | AND standard_concept != ''S'';
|
108 | 124 | '
|
109 | 125 | ,
|
110 |
| -'Condition_occurrence table -- standard concept checker' |
| 126 | +' |
| 127 | +SELECT 0::INTEGER; |
| 128 | +' |
| 129 | +, |
| 130 | +'CONDITION OCCURRENCE -- standard concept checker' |
111 | 131 | );
|
112 | 132 |
|
113 | 133 | SELECT results_eq
|
114 | 134 | (
|
115 | 135 | '
|
116 |
| -select 0::integer; |
117 |
| -' |
118 |
| -, |
119 |
| -' |
120 | 136 | WITH tmp AS
|
121 | 137 | (
|
122 |
| - SELECT visit_detail_id, visit_occurrence_id, CASE WHEN condition_end_datetime < condition_start_datetime THEN 1 ELSE 0 END AS abnormal |
123 |
| - FROM omop.condition_occurrence |
124 |
| -
|
| 138 | + SELECT visit_detail_id, visit_occurrence_id |
| 139 | + , CASE |
| 140 | + WHEN condition_end_datetime < condition_start_datetime |
| 141 | + THEN 1 |
| 142 | + ELSE 0 END AS abnormal |
| 143 | + FROM omop.condition_occurrence |
125 | 144 | )
|
126 |
| -SELECT max(abnormal) FROM tmp; |
| 145 | +SELECT sum(abnormal)::INTEGER FROM tmp; |
| 146 | +' |
| 147 | +, |
| 148 | +' |
| 149 | +SELECT 0::INTEGER; |
127 | 150 | '
|
128 | 151 | ,
|
129 |
| -'Condition_occurrence table -- start_datetime > end_datetime' |
| 152 | +'CONDITION OCCURRENCE -- start_datetime should be > end_datetime' |
130 | 153 | );
|
131 | 154 |
|
132 | 155 | SELECT results_eq
|
133 | 156 | (
|
134 | 157 | '
|
135 |
| -select 0::integer; |
136 |
| -' |
137 |
| -, |
138 |
| -' |
139 | 158 | WITH tmp AS
|
140 | 159 | (
|
141 |
| - SELECT visit_detail_id, visit_occurrence_id, CASE WHEN condition_end_date < condition_start_date THEN 1 ELSE 0 END AS abnormal |
142 |
| - FROM omop.condition_occurrence |
143 |
| -
|
| 160 | + SELECT visit_detail_id, visit_occurrence_id |
| 161 | + , CASE |
| 162 | + WHEN condition_end_date < condition_start_date |
| 163 | + THEN 1 |
| 164 | + ELSE 0 END AS abnormal |
| 165 | + FROM omop.condition_occurrence |
144 | 166 | )
|
145 |
| -SELECT max(abnormal) FROM tmp; |
| 167 | +SELECT sum(abnormal)::INTEGER FROM tmp; |
| 168 | +' |
| 169 | +, |
| 170 | +' |
| 171 | +SELECT 0::INTEGER; |
146 | 172 | '
|
147 | 173 | ,
|
148 |
| -'Condition_occurrence table -- start_date > end_date' |
| 174 | +'CONDITION OCCURRENCE -- start_date should be > end_date' |
149 | 175 | );
|
150 | 176 |
|
151 | 177 | SELECT * FROM finish();
|
|
0 commit comments