-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentation.html
More file actions
416 lines (380 loc) · 16.1 KB
/
Copy pathdocumentation.html
File metadata and controls
416 lines (380 loc) · 16.1 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Documentation | MEDWEAR</title>
<link rel="stylesheet" href="style.css" />
<link rel="icon" href="favicon.svg" type="image/svg+xml" />
</head>
<body>
<header>
<a href="index.html" class="header-brand">MEDWEAR</a>
<nav>
<a href="index.html">Home</a>
<a href="about.html">About</a>
<a href="documentation.html" class="active">Documentation</a>
<a href="schemas.html">Schemas</a>
<a href="med-api.html">MED-API</a>
<a href="use-cases.html">Use Cases</a>
<a href="contribute.html">Contribute</a>
</nav>
</header>
<div class="page-banner" style="background-image: url('assets/images/hero-schemas.jpg')">
<div class="page-banner-content">
<h1>Documentation</h1>
<p>Guides for using MEDWEAR schemas and the data collection platform</p>
</div>
</div>
<div class="content-container">
<main>
<div class="quick-links" style="margin-bottom: 3em;">
<a href="#schemas" class="quick-link-card">
<h3>Data Schemas</h3>
<p>Use MEDWEAR schemas in your own application - download, validation, ROS 2 integration.</p>
</a>
<a href="#platform" class="quick-link-card">
<h3>Data Collection Platform</h3>
<p>Deploy and use the MEDWEAR data collection platform - installation, setup, authentication, API access.</p>
</a>
</div>
<!-- ══════════════════════════════════════════════════════
BLOCK 1 - DATA SCHEMAS
══════════════════════════════════════════════════════ -->
<h2 id="schemas" class="doc-block-title">Using the Data Schemas</h2>
<section>
<h2>Integration Options</h2>
<p>
MEDWEAR schemas are available in two formats. Choose based on your application:
JSON Schemas for general data storage and validation, or ROS 2 messages for
real-time streaming and robotics middleware.
</p>
<div class="pilot-grid" style="margin-top: 1.4em;">
<div class="pilot-card pilot-card--json">
<div class="pilot-card-header">
<span class="pilot-tag">Option A</span>
<h3>JSON Schemas</h3>
<p class="pilot-subtitle">Storage · validation · non-ROS applications</p>
</div>
<div class="pilot-card-body">
<h4>When to use</h4>
<p>Your application stores, validates, or processes wearable data outside a ROS environment — e.g. a web
backend, mobile app, or data pipeline.</p>
<h4>Install</h4>
<pre><code>git clone https://github.com/SCAI-Lab/ord_schemas</code></pre>
<h4>Schema structure</h4>
<p>Each schema defines a physiological signal. Minimal ECG example:</p>
<pre><code>{
"schema_id": "org.medwear.biosignal.ecg",
"version": "1.0",
"data": {
"ecg": [0.12, 0.15, 0.11],
"sample_rate": 250,
"units": "mV"
},
"metadata": {
"device_id": "device1234",
"timestamp": "2025-06-30T15:30:00Z"
}
}</code></pre>
<h4>Validate in Python</h4>
<pre><code>import json
from jsonschema import validate
with open('ecg_schema.json') as f:
schema = json.load(f)
with open('ecg_data.json') as f:
data = json.load(f)
validate(instance=data, schema=schema)
print("Data is valid.")</code></pre>
<h4>Resources</h4>
<p>
Browse schemas on the <a href="schemas.html">Schemas page</a> or download the full set from
<a href="https://github.com/SCAI-Lab/ord_schemas/tree/main/schema" target="_blank"
rel="noopener">GitHub</a>.
</p>
</div>
</div>
<div class="pilot-card pilot-card--ros">
<div class="pilot-card-header">
<span class="pilot-tag">Option B</span>
<h3>ROS 2 Messages</h3>
<p class="pilot-subtitle">Real-time streaming · robotics</p>
</div>
<div class="pilot-card-body">
<h4>When to use</h4>
<p>Your application uses ROS 2 — e.g. a healthcare robot, assistive device, or real-time signal processing
pipeline that publishes sensor data as ROS topics.</p>
<h4>Package</h4>
<p>
The <code>healthcare_msgs</code> package provides <code>.msg</code> definitions for all
MEDWEAR signal types. Debian packages are available for Humble, Jazzy, and Rolling on
amd64 and arm64. Supported signals:
</p>
<div class="signal-tags" style="margin-bottom: 0.8em;">
<span class="signal-tag">ECG</span>
<span class="signal-tag">BCG</span>
<span class="signal-tag">PPG</span>
<span class="signal-tag">EEG</span>
<span class="signal-tag">EDA</span>
<span class="signal-tag">IMU</span>
<span class="signal-tag">HR</span>
<span class="signal-tag">HRV</span>
</div>
<h4>Install via APT</h4>
<p>Replace <code>humble</code> / <code>amd64</code> / <code>jammy</code> with your distro and
architecture:</p>
<pre><code># Add GPG key
sudo curl -fsSL \
https://scai-lab.github.io/healthcare_msgs/humble-amd64/KEY.gpg \
-o /etc/apt/trusted.gpg.d/healthcare-msgs.gpg
# Add APT source
echo "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/healthcare-msgs.gpg] \
https://scai-lab.github.io/healthcare_msgs/humble-amd64 humble-jammy main" \
| sudo tee /etc/apt/sources.list.d/healthcare-msgs.list
# Install
sudo apt update && sudo apt install ros-humble-healthcare-msgs</code></pre>
<table style="margin-top: 0.6em;">
<thead>
<tr>
<th>ROS distro</th>
<th>OS</th>
<th>Architectures</th>
</tr>
</thead>
<tbody>
<tr>
<td>Humble</td>
<td>Ubuntu 22.04 Jammy</td>
<td>amd64, arm64</td>
</tr>
<tr>
<td>Jazzy</td>
<td>Ubuntu 24.04 Noble</td>
<td>amd64, arm64</td>
</tr>
<tr>
<td>Rolling</td>
<td>Ubuntu 24.10 Resolute</td>
<td>amd64, arm64</td>
</tr>
</tbody>
</table>
<h4>Resources</h4>
<p>
<a href="https://github.com/SCAI-Lab/healthcare_msgs" target="_blank" rel="noopener">View the full
package on GitHub</a>
</p>
</div>
</div>
</div>
</section>
<section>
<h2>Streaming & Conversion Tools</h2>
<p>
Command-line tools and notebooks are available to convert CSV, JSON, and raw wearable files
into MEDWEAR-compliant format. You can also use the provided libraries to stream the messages in MQTT(S), UDP,
websockets or BLE. These tools are ideal for testing, prototyping, and integrating MEDWEAR schemas into
existing workflows.
</p>
<p><a href="https://github.com/SCAI-Lab/healthcare_common" target="_blank" rel="noopener">Explore conversion
tools on GitHub</a></p>
</section>
<section>
<h2>Resources</h2>
<h3>External References</h3>
<ul>
<li><a href="https://json-schema.org/" target="_blank" rel="noopener">JSON Schema documentation</a></li>
<li><a href="http://www.openmhealth.org" target="_blank" rel="noopener">Open mHealth</a></li>
</ul>
</section>
<!-- ══════════════════════════════════════════════════════
BLOCK 2 - DATA COLLECTION PLATFORM & API
══════════════════════════════════════════════════════ -->
<h2 id="platform" class="doc-block-title">Using the MEDWEAR Data Collection Platform</h2>
<section>
<h2>Overview</h2>
<p>
MED-API is the backend service of the MEDWEAR platform - a secure REST API for ingesting,
querying, and managing wearable health data. It runs alongside MinIO, InfluxDB, PostgreSQL,
Keycloak, Dagster, Grafana, and pgAdmin as a single-server Docker stack.
For the full API reference, see the <a href="med-api.html">MED-API page</a>.
</p>
</section>
<section>
<h2>Installation</h2>
<p>Clone the MEDWEAR platform repository from GitHub:</p>
<pre><code>git clone https://github.com/SCAI-Lab/medwear
cd medwear</code></pre>
</section>
<section>
<h2>Quick Setup</h2>
<pre><code>./setup.sh</code></pre>
<p>This will automatically:</p>
<ul>
<li>Generate random secure credentials for all services (PostgreSQL, MinIO, Grafana, Keycloak, InfluxDB)</li>
<li>Create <code>.env</code> and <code>.env.medwear</code> files</li>
<li>Start all Docker services</li>
<li>Initialize InfluxDB and PostgreSQL tables</li>
<li>Save all generated credentials to <code>.credentials.txt</code></li>
</ul>
<p>After setup, view your credentials:</p>
<pre><code>cat .credentials.txt</code></pre>
<pre><code>PostgreSQL : medwear / xK7mP2qR9nL4wY8j
MinIO root : minioadmin / hT3vB6cN1mX5pQ2r
MinIO API key : medwear-api / dF8yA4kW7nJ2mR6s...
Keycloak admin : admin / hJ9nQ3vB6cN1mX5p
InfluxDB : admin / wY8jxK7mP2qR9nL4
Grafana : admin / T3vB6cN1mX5pQ2rd
pgAdmin : admin@medwear.local / F8yA4kW7nJ2mR6s</code></pre>
<p><strong>Note:</strong> Do not commit <code>.credentials.txt</code> to version control. It is already listed
in <code>.gitignore</code>.</p>
</section>
<section>
<h2>Start & Stop</h2>
<pre><code># First time or after code changes
docker compose -f docker-compose.medwear-minimal.yml build
docker compose -f docker-compose.medwear-minimal.yml up -d
# Subsequent runs (no code changes)
docker compose -f docker-compose.medwear-minimal.yml up -d</code></pre>
<p>After starting, Keycloak takes ~30 seconds to be ready.</p>
<pre><code># Restart a single service (e.g. after API code change)
docker compose -f docker-compose.medwear-minimal.yml restart med-api
# Stop all services
docker compose -f docker-compose.medwear-minimal.yml down</code></pre>
</section>
<section>
<h2>Service Access</h2>
<table>
<thead>
<tr>
<th>Service</th>
<th>URL</th>
<th>Credentials</th>
</tr>
</thead>
<tbody>
<tr>
<td>MED-API</td>
<td>https://localhost/v1/health</td>
<td>Token required</td>
</tr>
<tr>
<td>API Docs</td>
<td>https://localhost/docs</td>
<td>-</td>
</tr>
<tr>
<td>Frontend</td>
<td>https://localhost</td>
<td>Keycloak login</td>
</tr>
<tr>
<td>Keycloak</td>
<td>http://localhost:8180/admin</td>
<td>admin / see .credentials.txt</td>
</tr>
<tr>
<td>pgAdmin</td>
<td>http://localhost:5050</td>
<td>admin@medwear.com / see .credentials.txt</td>
</tr>
<tr>
<td>InfluxDB</td>
<td>http://localhost:8086</td>
<td>admin / see .credentials.txt</td>
</tr>
<tr>
<td>MinIO</td>
<td>http://localhost:9001</td>
<td>minioadmin / see .credentials.txt</td>
</tr>
<tr>
<td>Grafana</td>
<td>http://localhost:3001</td>
<td>admin / see .credentials.txt</td>
</tr>
<tr>
<td>Dagster</td>
<td>http://localhost:3000</td>
<td>-</td>
</tr>
</tbody>
</table>
<p>The MedWear platform is deployed at <code>https://172.20.83.11</code>. Frontend and API are accessible
directly. Admin services require SSH tunnel or direct server access.</p>
<details>
<summary>Remote access via SSH tunnel</summary>
<pre><code>ssh -L 443:localhost:443 \
-L 80:localhost:80 \
-L 8180:localhost:8180 \
-L 9001:localhost:9001 \
-L 8086:localhost:8086 \
-L 3001:localhost:3001 \
-L 5050:localhost:5050 \
user@your-server.com</code></pre>
</details>
</section>
<section>
<h2>Authentication</h2>
<p>All endpoints require a Keycloak JWT token.</p>
<details>
<summary>Get a token via API proxy (Recommended)</summary>
<pre><code>curl -k -X POST https://localhost/v1/data/auth/token \
-H "Content-Type: application/json" \
-d '{"username":"<user>","password":"<pass>"}'</code></pre>
</details>
<details>
<summary>Get a token directly from Keycloak (Internal/testing only)</summary>
<pre><code>curl -X POST http://localhost:8180/realms/medwear/protocol/openid-connect/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=password&client_id=med-api&client_secret=<secret>&username=<user>&password=<pass>"</code></pre>
</details>
<details>
<summary>Use the token</summary>
<pre><code>curl -k -H "Authorization: Bearer <access_token>" https://localhost/v1/me</code></pre>
</details>
<details>
<summary>Health check</summary>
<pre><code>curl -k https://localhost/v1/health</code></pre>
</details>
</section>
<section>
<h2>Testing</h2>
<pre><code>cd /path/to/repo/medwear_med_api
source venv/bin/activate
python3 scripts/test_phase3.py # Batch upload, CSV, validation
python3 scripts/test_phase4.py # Query, delete, restore, admin, multi-project
python3 scripts/test_phase5.py # Error handling: 46/46 tests</code></pre>
<details>
<summary>Quick smoke test</summary>
<pre><code># 1. Get a token
TOKEN=$(curl -sk -X POST https://localhost/v1/data/auth/token \
-H "Content-Type: application/json" \
-d '{"username":"<your-username>","password":"<your-password>"}' | jq -r .access_token)
# 2. Check health
curl -sk https://localhost/v1/health | jq .
# 3. Query recent batches
curl -sk -H "Authorization: Bearer $TOKEN" \
"https://localhost/v1/data?limit=5" | jq .</code></pre>
</details>
</section>
<section>
<h2>Backup</h2>
<p>Backs up PostgreSQL, InfluxDB, and MinIO to a compressed archive. Backups older than 30 days are deleted
automatically.</p>
<pre><code># Run manually
./scripts/backup.sh /opt/medwear_backups
# Add to crontab (daily at 2 AM)
0 2 * * * /path/to/med-api/scripts/backup.sh /opt/medwear_backups >> /var/log/medwear_backup.log 2>&1</code></pre>
</section>
</main>
</div>
<footer>
<div class="footer-logos">
<img src="assets/images/scai_logo.png" alt="SCAI Lab Logo" />
<img src="assets/images/ethz_logo.png" alt="ETH Zurich Logo" class="ethz-logo" />
</div>
<p>© 2026 ETH Zurich – MEDWEAR Project | Contact: diego.paez@scai.ethz.ch · monica.perezserrano@hest.ethz.ch</p>
</footer>
</body>
</html>