-
Notifications
You must be signed in to change notification settings - Fork 47
/
check_etl.sql
103 lines (93 loc) · 2.21 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
-- -----------------------------------------------------------------------------
-- File created - January-8-2018
-- ----------------------------------------------------------------------------
-- --------------------------------------------------
-- Need to install pgTAP
-- http://pgtap.org/
-- --------------------------------------------------
BEGIN;
SELECT plan(5);
-- procedureevents_mv --
SELECT results_eq
(
'
SELECT count (*), count(distinct person_id), count(distinct visit_occurrence_id)
FROM omop.procedure_occurrence
WHERE procedure_type_concept_id = 38000275 ;
'
,
'
SELECT count(*), count(distinct subject_id), count(distinct hadm_id)
FROM procedureevents_mv
WHERE cancelreason = 0;
'
,'PROCEDURE_OCCURRENCE -- check all procedureevents_mv rows inserted'
);
SELECT results_eq
(
'
SELECT procedure_source_value::text as label, count(1)
from omop.procedure_occurrence
WHERE procedure_type_concept_id = 38000275
GROUP BY procedure_source_value ORDER BY 2,1 desc;
'
,
'
SELECT label::text, count(1)
from procedureevents_mv
JOIN d_items using (itemid)
WHERE cancelreason = 0
GROUP BY 1 ORDER BY 2,1 desc;
'
,'PROCEDURE_OCCURRENCE -- check label is consistent with source_value'
);
-- cptevents --
SELECT results_eq
(
'
SELECT count (*), count(distinct person_id), count(distinct visit_occurrence_id)
from omop.procedure_occurrence
WHERE procedure_type_concept_id = 257 ;
'
,
'
SELECT count(*), count(distinct subject_id), count(distinct hadm_id)
FROM cptevents;
'
,'PROCEDURE_OCCURRENCE -- check all CPT code rows inserted'
);
SELECT results_eq
(
'
SELECT count(1)
FROM omop.procedure_occurrence
WHERE procedure_type_concept_id = 257
GROUP BY procedure_source_value
ORDER BY count(1) DESC;
'
,
'
SELECT count(1)
FROM cptevents
GROUP BY subsectionheader
ORDER BY count(*) DESC;
'
,'PROCEDURE_OCCURRENCE -- check CPT subsections mapped correctly'
);
-- procedures_icd --
SELECT results_eq
(
'
SELECT count(*), count(distinct subject_id), count(distinct hadm_id)
FROM procedures_icd;
'
,
'
SELECT count (*), count(distinct person_id), count(distinct visit_occurrence_id)
FROM omop.procedure_occurrence
WHERE procedure_type_concept_id = 38003622 ;
'
,'PROCEDURE_OCCURRENCE -- check ICD procedure rows inserted'
);
SELECT * FROM finish();
ROLLBACK;