forked from MIT-LCP/mimic-omop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_etl.sql
178 lines (166 loc) · 2.95 KB
/
check_etl.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
-- -----------------------------------------------------------------------------
-- File created - January-13-2018
-- ----------------------------------------------------------------------------
-- --------------------------------------------------
-- Need to install pgTAP
-- http://pgtap.org/
-- --------------------------------------------------
BEGIN;
SELECT plan ( 8 );
SELECT results_eq
(
'
SELECT COUNT(distinct person_id), COUNT(distinct visit_occurrence_id)
FROM omop.condition_occurrence
WHERE condition_type_concept_id != 42894222;
'
,
'
SELECT COUNT(distinct subject_id), COUNT(distinct hadm_id)
FROM diagnoses_icd
WHERE icd9_code IS NOT NULL;
'
,
'CONDITION OCCURRENCE -- check ICD diagnoses row count matches'
);
SELECT results_eq
(
'
WITH tmp as
(
SELECT distinct on (visit_occurrence_id) *
FROM omop.condition_occurrence
WHERE condition_type_concept_id = 42894222
)
SELECT condition_source_value::text, COUNT(1)
FROM tmp
GROUP BY 1
ORDER BY 2, 1;
'
,
'
SELECT diagnosis::text, COUNT(1)
FROM admissions
GROUP BY 1
ORDER BY 2, 1;
'
,
'CONDITION OCCURRENCE -- diagnosis in admission same'
);
SELECT results_eq
(
'
with tmp as
(
SELECT distinct on (visit_occurrence_id) *
FROM omop.condition_occurrence
WHERE condition_type_concept_id = 42894222
)
SELECT condition_source_value::text, COUNT(1)
FROM tmp
GROUP BY 1
ORDER BY 2, 1;
'
,
'
SELECT diagnosis::text, COUNT(1)
FROM admissions
GROUP BY 1
ORDER BY 2, 1
'
,
'CONDITION OCCURRENCE -- distrib diagnosis the same'
);
SELECT results_eq
(
'
SELECT COUNT(1)::INTEGER
FROM omop.condition_occurrence
WHERE condition_source_concept_id = 0;
'
,
'
SELECT 0::INTEGER;
'
,
'CONDITION OCCURRENCE -- there is source concept in measurement not described'
);
SELECT results_eq
(
'
SELECT COUNT(1)::INTEGER
FROM
(
SELECT COUNT(1)::INTEGER
FROM omop.condition_occurrence
GROUP BY condition_occurrence_id
having COUNT(1) > 1
) as t;
'
,
'
SELECT 0::INTEGER;
'
,
'CONDITION OCCURRENCE -- primary key checker'
);
SELECT results_eq
(
'
SELECT COUNT(1)::INTEGER
FROM omop.condition_occurrence
LEFT JOIN omop.concept ON condition_concept_id = concept_id
WHERE condition_concept_id != 0
AND standard_concept != ''S'';
'
,
'
SELECT 0::INTEGER;
'
,
'CONDITION OCCURRENCE -- standard concept checker'
);
SELECT results_eq
(
'
WITH tmp AS
(
SELECT visit_detail_id, visit_occurrence_id
, CASE
WHEN condition_end_datetime < condition_start_datetime
THEN 1
ELSE 0 END AS abnormal
FROM omop.condition_occurrence
)
SELECT sum(abnormal)::INTEGER FROM tmp;
'
,
'
SELECT 0::INTEGER;
'
,
'CONDITION OCCURRENCE -- start_datetime should be > end_datetime'
);
SELECT results_eq
(
'
WITH tmp AS
(
SELECT visit_detail_id, visit_occurrence_id
, CASE
WHEN condition_end_date < condition_start_date
THEN 1
ELSE 0 END AS abnormal
FROM omop.condition_occurrence
)
SELECT sum(abnormal)::INTEGER FROM tmp;
'
,
'
SELECT 0::INTEGER;
'
,
'CONDITION OCCURRENCE -- start_date should be > end_date'
);
SELECT * FROM finish();
ROLLBACK;