Skip to content

Commit 9d684be

Browse files
committed
Merge branch 'mimic' of https://github.com/alan-turing-institute/sqlsynthgen into mimic
2 parents 368c554 + 3a8e064 commit 9d684be

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

config_story.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,24 @@ src-stats:
8585
WHERE m.measurement_concept_id IN (21492239, 21492240)
8686
) sub
8787
GROUP BY sub.gender_concept_id;
88-
89-
88+
- name: avg_measurements_per_visit_hour
89+
query: >
90+
SELECT
91+
AVG(subquery.measurements_per_hour)::float4 AS avg_measurements_per_hour,
92+
stddev(subquery.measurements_per_hour)::float4 AS stddev_measurements_per_hour
93+
FROM
94+
(SELECT
95+
COUNT(*)/2
96+
/ (EXTRACT(EPOCH FROM (v.visit_end_datetime - v.visit_start_datetime)) / 3600.0)
97+
AS measurements_per_hour
98+
FROM mimic.measurement m
99+
JOIN mimic.visit_occurrence v ON m.visit_occurrence_id = v.visit_occurrence_id
100+
WHERE m.measurement_concept_id IN (21492239, 21492240)
101+
GROUP BY
102+
m.person_id,
103+
m.visit_occurrence_id,
104+
v.visit_start_datetime,
105+
v.visit_end_datetime) subquery;
90106
tables:
91107
person:
92108
num_rows_per_pass: 0

person_story.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,13 @@ def generate(
327327
death_row = (yield death) if death else None
328328
visit_occurrence = yield gen_visit_occurrence(person, death_row, src_stats)
329329

330+
# abs to avoid negative rates due to random normal variation
331+
avg_rate = abs(random_normal(
332+
src_stats["avg_measurements_per_visit_hour"][0]['avg_measurements_per_hour'],
333+
src_stats["avg_measurements_per_visit_hour"][0]['stddev_measurements_per_hour'] ))
334+
330335
for event in gen_blood_pressure_events(
331-
10.0,
336+
avg_rate,
332337
visit_occurrence,
333338
person,
334339
src_stats,

0 commit comments

Comments
 (0)