Strictly eliminate fake and stale vitals and enforce machine-to-MRN isolation
This commit is contained in:
@@ -528,13 +528,16 @@ async def process_vitals(vitals):
|
||||
if val is not None:
|
||||
setattr(cached, field, val)
|
||||
device_field_timestamps[device_id][field] = now
|
||||
else:
|
||||
setattr(cached, field, None)
|
||||
device_field_timestamps[device_id].pop(field, None)
|
||||
|
||||
# Clean up stale fields:
|
||||
# Live vitals (HR, SpO2, Temp, RR) have a 60-second window because monitor cycles take ~24s
|
||||
# NIBP (BP, MAP) has a 1-hour window because it is measured intermittently
|
||||
# Live vitals (HR, SpO2, Temp, RR) have a 15-second window
|
||||
# NIBP (BP, MAP) has a 15-minute window because it is measured intermittently
|
||||
for field in list(device_field_timestamps[device_id].keys()):
|
||||
last_updated = device_field_timestamps[device_id][field]
|
||||
timeout = 3600.0 if field in ("systolic_bp", "diastolic_bp", "map_bp") else 60.0
|
||||
timeout = 900.0 if field in ("systolic_bp", "diastolic_bp", "map_bp") else 15.0
|
||||
if (now - last_updated).total_seconds() > timeout:
|
||||
setattr(cached, field, None)
|
||||
device_field_timestamps[device_id].pop(field, None)
|
||||
@@ -671,22 +674,6 @@ async def _persist_and_forward_bg(vitals, should_persist):
|
||||
if not getattr(vitals, "patient_type", None) and getattr(patient, "patient_type", None):
|
||||
vitals.patient_type = patient.patient_type
|
||||
|
||||
# Backfill non-null vitals from device cache so REST forwarders always get complete vitals
|
||||
cached = device_cache.get(vitals.device_id)
|
||||
if cached:
|
||||
if vitals.heart_rate is None and cached.heart_rate is not None:
|
||||
vitals.heart_rate = cached.heart_rate
|
||||
if vitals.spo2 is None and cached.spo2 is not None:
|
||||
vitals.spo2 = cached.spo2
|
||||
if vitals.systolic_bp is None and cached.systolic_bp is not None:
|
||||
vitals.systolic_bp = cached.systolic_bp
|
||||
vitals.diastolic_bp = cached.diastolic_bp
|
||||
vitals.map_bp = cached.map_bp
|
||||
if vitals.respiratory_rate is None and cached.respiratory_rate is not None:
|
||||
vitals.respiratory_rate = cached.respiratory_rate
|
||||
if vitals.temperature is None and cached.temperature is not None:
|
||||
vitals.temperature = cached.temperature
|
||||
|
||||
reading = VitalReading(
|
||||
device_id=vitals.device_id,
|
||||
patient_id=vitals.patient_id or (patient.mrn if patient else "UNKNOWN"),
|
||||
|
||||
Reference in New Issue
Block a user