1
1
-- -- db: -h localhost -p 5488 -U postgres devbox
2
2
\d+ patient
3
3
-- --
4
+ select id from patient;
5
+ -- --
4
6
\c devbox
5
7
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
6
8
-- --
7
9
DROP VIEW if exists hr_view CASCADE;
8
10
DROP VIEW if exists pulse_view CASCADE;
9
11
DROP VIEW if exists resp_view CASCADE;
10
12
DROP VIEW if exists oxy_view CASCADE;
13
+ -- --
11
14
12
15
DROP table if exists observation_data;
13
16
@@ -68,6 +71,15 @@ SELECT create_hypertable('observation_data', 'ts');
68
71
SELECT add_dimension(' observation_data' , ' Patient_id' , number_partitions => 200 , if_not_exists => true);
69
72
SELECT add_dimension(' observation_data' , ' Observation_id' , number_partitions => 200 , if_not_exists => true);
70
73
74
+ -- --
75
+ \d+ observation_data
76
+ -- --
77
+
78
+ SELECT
79
+ pid ,wait_event, age(clock_timestamp(), query_start) ,query
80
+ FROM pg_stat_activity
81
+ WHERE query != ' <IDLE>' AND query NOT ILIKE ' %pg_stat_activity%' and " state" = ' active'
82
+ ORDER BY query_start nulls last;
71
83
-- --
72
84
\x
73
85
select count (* )
@@ -87,32 +99,14 @@ from observation_data;;
87
99
\x
88
100
select * from observation_data limit 1 ;
89
101
-- --
102
+ -- --
90
103
DROP VIEW if exists hr_view CASCADE;
91
104
DROP VIEW if exists pulse_view CASCADE;
92
105
DROP VIEW if exists resp_view CASCADE;
93
106
DROP VIEW if exists oxy_view CASCADE;
94
107
95
108
truncate observation_data;
96
109
-- --
97
- select patient_id, (array_agg(smooth_bpm))[1 ]
98
- from (
99
- SELECT
100
- ts,
101
- Patient_id,
102
- AVG (valueQuantity_value) OVER(
103
- PARTITION BY Patient_id
104
- ORDER BY ts
105
- ROWS BETWEEN 60 PRECEDING AND CURRENT ROW
106
- )
107
- AS smooth_bpm
108
- FROM observation_data
109
- WHERE code = ' 8867-4' -- heart rate
110
- and ts > NOW() - INTERVAL ' 1 minute'
111
- -- and smooth_bpm > 90
112
- ORDER BY ts DESC
113
- ) as avgg
114
- where avgg .smooth_bpm > 100
115
- group by patient_id;
116
110
-- --
117
111
SELECT
118
112
time_bucket(' 10s' , ts) as bucket,
@@ -141,8 +135,10 @@ FROM
141
135
observation_data
142
136
143
137
-- --
138
+ -- --------------------------------------------------------------------
144
139
DROP VIEW if exists hr_view CASCADE;
145
140
141
+
146
142
CREATE VIEW hr_view WITH
147
143
(timescaledb .continuous , timescaledb .refresh_interval = ' 30s' )
148
144
AS
@@ -197,6 +193,22 @@ WHERE code = '2708-6' -- resp
197
193
group by patient_id, time_bucket(' 10s' , ts)
198
194
HAVING AVG (valueQuantity_value) < 96
199
195
196
+ -- --
197
+ explain analyze
198
+ SELECT ts AS " time"
199
+ , valuesampleddata_data I
200
+ FROM observation_data
201
+ where code = ' 131329'
202
+ -- and ts BETWEEN (1601823599500)::timestamp AND (1601823610500)::timestamp
203
+ and ts BETWEEN ' 2020-10-04T14:59:59.500Z' AND ' 2020-10-04T15:00:10.500Z'
204
+ and patient_id = ' bfd8ecb3-06dd-8f08-7121-020a9a589602'
205
+ order by ts
206
+ -- limit 1000
207
+
208
+ -- --
209
+ create index obsdatacode on observation_data (code);
210
+ -- --
211
+ analyze observation_data;
200
212
-- --
201
213
\x
202
214
SELECT * FROM timescaledb_information .continuous_aggregate_stats ;
0 commit comments