feat: real ECG/Pleth waveform streaming + clinical monitor UI redesign

- schemas.py: Add ecg_wave and pleth_wave List[int] fields to NormalizedVitals
- contec_parser.py: Extract raw 8-bit waveform samples from binary packets
  - 286/288-byte (Subtype 21): bytes[8..263] = Pleth waveform (256 samples)
  - 989-byte (Subtype 20): bytes[8..903] = ECG waveform, downsampled 4x -> 224 pts
- dashboard.html: Full clinical monitor redesign
  - Scrolling sweep waveform engine (ECG green, Pleth cyan, Resp amber)
  - Real samples fed from WebSocket ecg_wave / pleth_wave arrays
  - Synthetic fallbacks when no live data
  - Right panel: HR, SpO2, RR, NIBP, Temp with range badges
  - MRN-only verification overlay
  - Minimal-mode support for iframe embedding
This commit is contained in:
2026-07-15 13:37:14 +05:30
parent 78500c487a
commit 14f3d45e53
3 changed files with 567 additions and 1545 deletions
+21 -2
View File
@@ -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)
+4 -1
View File
@@ -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
File diff suppressed because it is too large Load Diff