forked from MIT-LCP/mimic-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo-data.sql
74 lines (62 loc) · 2.77 KB
/
echo-data.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
-- This code extracts structured data from echocardiographies
-- You can join it to the text notes using ROW_ID
-- Just note that ROW_ID will differ across versions of MIMIC-III.
DROP MATERIALIZED VIEW IF EXISTS ECHODATA CASCADE;
CREATE MATERIALIZED VIEW ECHODATA AS
select ROW_ID
, subject_id, hadm_id
, chartdate
-- charttime is always null for echoes..
-- however, the time is available in the echo text, e.g.:
-- , substring(ne.text, 'Date/Time: [\[\]0-9*-]+ at ([0-9:]+)') as TIMESTAMP
-- we can therefore impute it and re-create charttime
, cast(to_timestamp( (to_char( chartdate, 'DD-MM-YYYY' ) || substring(ne.text, 'Date/Time: [\[\]0-9*-]+ at ([0-9:]+)')),
'DD-MM-YYYYHH24:MI') as timestamp without time zone)
as charttime
-- explanation of below substring:
-- 'Indication: ' - matched verbatim
-- (.*?) - match any character
-- \n - the end of the line
-- substring only returns the item in ()s
-- note: the '?' makes it non-greedy. if you exclude it, it matches until it reaches the *last* \n
, substring(ne.text, 'Indication: (.*?)\n') as Indication
-- sometimes numeric values contain de-id text, e.g. [** Numeric Identifier **]
-- this removes that text
, case
when substring(ne.text, 'Height: \(in\) (.*?)\n') like '%*%'
then null
else cast(substring(ne.text, 'Height: \(in\) (.*?)\n') as numeric)
end as Height
, case
when substring(ne.text, 'Weight \(lb\): (.*?)\n') like '%*%'
then null
else cast(substring(ne.text, 'Weight \(lb\): (.*?)\n') as numeric)
end as Weight
, case
when substring(ne.text, 'BSA \(m2\): (.*?) m2\n') like '%*%'
then null
else cast(substring(ne.text, 'BSA \(m2\): (.*?) m2\n') as numeric)
end as BSA -- ends in 'm2'
, substring(ne.text, 'BP \(mm Hg\): (.*?)\n') as BP -- Sys/Dias
, case
when substring(ne.text, 'BP \(mm Hg\): ([0-9]+)/[0-9]+?\n') like '%*%'
then null
else cast(substring(ne.text, 'BP \(mm Hg\): ([0-9]+)/[0-9]+?\n') as numeric)
end as BPSys -- first part of fraction
, case
when substring(ne.text, 'BP \(mm Hg\): [0-9]+/([0-9]+?)\n') like '%*%'
then null
else cast(substring(ne.text, 'BP \(mm Hg\): [0-9]+/([0-9]+?)\n') as numeric)
end as BPDias -- second part of fraction
, case
when substring(ne.text, 'HR \(bpm\): ([0-9]+?)\n') like '%*%'
then null
else cast(substring(ne.text, 'HR \(bpm\): ([0-9]+?)\n') as numeric)
end as HR
, substring(ne.text, 'Status: (.*?)\n') as Status
, substring(ne.text, 'Test: (.*?)\n') as Test
, substring(ne.text, 'Doppler: (.*?)\n') as Doppler
, substring(ne.text, 'Contrast: (.*?)\n') as Contrast
, substring(ne.text, 'Technical Quality: (.*?)\n') as TechnicalQuality
from noteevents ne
where category = 'Echo';