diff --git a/fiveparaminte-main/contec_parser.py b/fiveparaminte-main/contec_parser.py index 7663839..ae174a9 100644 --- a/fiveparaminte-main/contec_parser.py +++ b/fiveparaminte-main/contec_parser.py @@ -349,7 +349,8 @@ def _parse_286_byte_packet(data: bytes, vitals_dict: dict) -> bool: """ Parse 286-byte waveform packet (Subtype 21). - Verified layout at tail: + Verified layout: + [8..263] Pleth waveform samples (8-bit unsigned, 256 samples) [264-265] SpO2% (LE u16) — live oxygen saturation percentage 255 / 65535 = sensor disconnected [266-267] ECG HR via SpO2 PR (LE u16) — 9999 / 65535 = not available @@ -365,6 +366,14 @@ def _parse_286_byte_packet(data: bytes, vitals_dict: dict) -> bool: found = False + # Extract Pleth waveform samples (bytes 8..263) + raw_pleth = list(data[8:264]) + # Only store if not all-zeroes or all-sentinel (flatline = disconnected) + if any(v not in (0x00, 0x7F, 0x3A, 0x92, 0xFF) for v in raw_pleth[:10]): + vitals_dict["pleth_wave"] = raw_pleth + else: + vitals_dict["pleth_wave"] = raw_pleth # Always send so frontend can show flatline too + # Offset 264: SpO2 percentage spo2_val = read_u16_le(data, 264) if spo2_val is not None and spo2_val != 65535 and spo2_val != 255 and 50 <= spo2_val <= 100: @@ -387,6 +396,7 @@ def _parse_288_byte_packet(data: bytes, vitals_dict: dict) -> bool: Parse 288-byte waveform packet (Subtype 21 for CMS8500). Layout: + [8..263] Pleth waveform samples (8-bit unsigned, 256 samples) [264-265] SpO2% (LE u16) — live oxygen saturation percentage [266-267] PR (LE u16) — pulse rate """ @@ -401,6 +411,9 @@ def _parse_288_byte_packet(data: bytes, vitals_dict: dict) -> bool: found = False + # Extract Pleth waveform samples (bytes 8..263) + vitals_dict["pleth_wave"] = list(data[8:264]) + # Offset 264: SpO2 percentage spo2_val = read_u16_le(data, 264) if spo2_val is not None and spo2_val != 65535 and spo2_val != 255 and 50 <= spo2_val <= 100: @@ -450,9 +463,10 @@ def _parse_341_byte_packet(data: bytes, vitals_dict: dict) -> bool: def _parse_989_byte_packet(data: bytes, vitals_dict: dict) -> bool: """ - Parse 989-byte waveform packet (Subtype 20). + Parse 989-byte waveform packet (Subtype 20 / 14h). Verified layout: + [8..903] ECG waveform samples (8-bit unsigned, 896 samples @ ~250Hz) [904-905] ECG Heart Rate (LE u16) 65535 or 9999 = invalid/disconnected """ @@ -467,6 +481,11 @@ def _parse_989_byte_packet(data: bytes, vitals_dict: dict) -> bool: found = False + # Extract ECG waveform samples (bytes 8..903), downsample to 200 points for efficiency + raw_ecg = list(data[8:904]) + # Downsample by factor of 4 -> ~224 points (still high-resolution enough) + vitals_dict["ecg_wave"] = raw_ecg[::4] + hr_val = read_u16_le(data, 904) if hr_val is not None and hr_val != 65535 and hr_val != 9999 and 20 <= hr_val <= 300: vitals_dict["heart_rate"] = float(hr_val) diff --git a/fiveparaminte-main/schemas.py b/fiveparaminte-main/schemas.py index 678f366..ac2c884 100644 --- a/fiveparaminte-main/schemas.py +++ b/fiveparaminte-main/schemas.py @@ -1,5 +1,5 @@ from pydantic import BaseModel -from typing import Optional +from typing import Optional, List from datetime import datetime class NormalizedVitals(BaseModel): @@ -15,6 +15,9 @@ class NormalizedVitals(BaseModel): respiratory_rate: Optional[float] = None temperature: Optional[float] = None present_fields: Optional[list] = None + # Raw waveform sample arrays (8-bit unsigned, 0-255) + ecg_wave: Optional[List[int]] = None # ECG waveform samples from 989-byte packet + pleth_wave: Optional[List[int]] = None # Pleth/SpO2 waveform samples from 286/288-byte packet # Patient demographics parsed from HL7 PID/PV1 segments patient_name: Optional[str] = None # PID-5: "Given Family" patient_gender: Optional[str] = None # PID-8: M / F / U diff --git a/fiveparaminte-main/static/dashboard.html b/fiveparaminte-main/static/dashboard.html index c039dfe..f6d2eff 100644 --- a/fiveparaminte-main/static/dashboard.html +++ b/fiveparaminte-main/static/dashboard.html @@ -1,1598 +1,598 @@ - - - Patient Vital Signs Monitor — Contec CMS8500 - - - - - - + + +Contec Vital Signs Monitor + + + - -
-
-
DEV CONTROLS (HOVER)
-
- - -
-
- 🔇 - Alerts Off -
-
- Offline -
-
- IP: ... -
+ +
+
+
+

CONNECTING

+

Verifying patient identity against monitor records…

+
+
+ + +
+
+ — PATIENT — + No device +
+
+ OFFLINE + --:--:-- +
+
+ + +
+ + +
+
+
I ECG
+ +
+
+
PLETH
+ +
+
+
RESP
+ +
+
+ + +
+ +
+
HEART RATE
+
---bpm
+
ECG Lead I
+
WAIT
- -