fix: reliable cloud sync and connection pooling for Render live dashboard
This commit is contained in:
@@ -522,14 +522,12 @@ async def process_vitals(vitals):
|
||||
if value is not None:
|
||||
active_fields.append(field)
|
||||
|
||||
# Update cache & record timestamps
|
||||
# Update cache & record timestamps for present values
|
||||
for field in active_fields:
|
||||
val = getattr(vitals, field, None)
|
||||
setattr(cached, field, val)
|
||||
if val is not None:
|
||||
setattr(cached, field, val)
|
||||
device_field_timestamps[device_id][field] = now
|
||||
else:
|
||||
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
|
||||
@@ -659,10 +657,39 @@ async def _persist_and_forward_bg(vitals, should_persist):
|
||||
patient.patient_type = vitals.patient_type
|
||||
if vitals.device_id:
|
||||
patient.device_id = vitals.device_id
|
||||
if patient:
|
||||
if not vitals.patient_id or vitals.patient_id == "UNKNOWN":
|
||||
vitals.patient_id = patient.mrn or patient.patient_id
|
||||
if not vitals.patient_name or vitals.patient_name == "Unknown":
|
||||
vitals.patient_name = patient.name
|
||||
if not vitals.patient_gender and patient.gender:
|
||||
vitals.patient_gender = patient.gender
|
||||
if not vitals.patient_dob and patient.dob:
|
||||
vitals.patient_dob = patient.dob
|
||||
if not vitals.bed_id and patient.bed_id:
|
||||
vitals.bed_id = patient.bed_id
|
||||
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,
|
||||
patient_id=vitals.patient_id or (patient.mrn if patient else "UNKNOWN"),
|
||||
timestamp=vitals.timestamp,
|
||||
heart_rate=vitals.heart_rate,
|
||||
spo2=vitals.spo2,
|
||||
|
||||
Reference in New Issue
Block a user