forked from ohcnetwork/mock-cns-req
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform_to_ventilator.py
59 lines (50 loc) · 1.47 KB
/
transform_to_ventilator.py
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
import json
import os
input_file = os.getenv("IN", "mock_data/data.json")
output_file = os.getenv("OUT", input_file)
with open(input_file, "r") as f:
data = f.read()
data = json.loads(data)
source_map = {
"heart-rate": {
"observation_id": "PEEP",
"unit": "cmH2O",
"low-limit": "0",
"high-limit": "15",
},
"spo2": {
"observation_id": "FiO2",
},
"respiratory-rate": {
"observation_id": "R.Rate",
},
"pulse-rate": {
"observation_id": "Insp-Time",
"unit": "sec",
"low-limit": "0",
"high-limit": "5",
},
"waveform": {
"II": "P",
"Pleth": "F",
"Respiration": "V",
},
}
def transform_data():
waveform_source_map = source_map.pop("waveform")
list_of_lists_of_lists = data[:]
for list_of_lists in list_of_lists_of_lists:
for list_of_dicts in list_of_lists:
for dict_ in list_of_dicts:
map_ = source_map.get(dict_["observation_id"])
if dict_["observation_id"] == "waveform":
dict_["wave-name"] = waveform_source_map[dict_["wave-name"]]
continue
if not map_:
list_of_dicts.remove(dict_)
continue
for key, value in map_.items():
dict_[key] = value
with open(output_file, "w") as f:
f.write(json.dumps(list_of_lists_of_lists, indent=4))
transform_data()