fix: timezone-aware timestamp parsing, favicon 404, and performance lag

This commit is contained in:
2026-09-18 11:40:14 +05:30
parent b35d196ba6
commit 1ebbd0e68a
2 changed files with 22 additions and 4 deletions
+1
View File
@@ -217,6 +217,7 @@ async def favicon():
# === WebSocket endpoint for live vitals === # === WebSocket endpoint for live vitals ===
@app.websocket("/ws/vitals") @app.websocket("/ws/vitals")
async def websocket_vitals(websocket: WebSocket): async def websocket_vitals(websocket: WebSocket):
+21 -4
View File
@@ -2559,6 +2559,23 @@
document.body.classList.add('minimal-mode'); document.body.classList.add('minimal-mode');
} }
// Helper: Calculate age in milliseconds robustly against UTC and local timezones
function getTimestampAgeMs(ts) {
if (!ts) return 999999999;
try {
let str = String(ts).trim();
if (!str.endsWith('Z') && !str.includes('+') && !/[-+]\d{2}:\d{2}$/.test(str)) {
str = str + 'Z';
}
const time = new Date(str).getTime();
if (isNaN(time)) return 999999999;
return Math.abs(Date.now() - time);
} catch (e) {
return 999999999;
}
}
function getTargetPatientBadge() { function getTargetPatientBadge() {
const items = []; const items = [];
if (targetMrn) items.push(`<span class="patient-mrn-badge" style="padding: 4px 10px; font-size: 12px;">📋 MRN: <strong>${targetMrn}</strong></span>`); if (targetMrn) items.push(`<span class="patient-mrn-badge" style="padding: 4px 10px; font-size: 12px;">📋 MRN: <strong>${targetMrn}</strong></span>`);
@@ -3127,7 +3144,7 @@
const now = Date.now(); const now = Date.now();
for (let i = readings.length - 1; i >= 0; i--) { for (let i = readings.length - 1; i >= 0; i--) {
const r = readings[i]; const r = readings[i];
const rAge = r.timestamp ? (now - new Date(r.timestamp).getTime()) : 9999999; const rAge = getTimestampAgeMs(r.timestamp);
if (rAge <= 25000) { if (rAge <= 25000) {
if (r.heart_rate != null) merged.heart_rate = r.heart_rate; if (r.heart_rate != null) merged.heart_rate = r.heart_rate;
if (r.spo2 != null) merged.spo2 = r.spo2; if (r.spo2 != null) merged.spo2 = r.spo2;
@@ -3220,7 +3237,7 @@
const now = Date.now(); const now = Date.now();
for (let i = readings.length - 1; i >= 0; i--) { for (let i = readings.length - 1; i >= 0; i--) {
const r = readings[i]; const r = readings[i];
const rAge = r.timestamp ? (now - new Date(r.timestamp).getTime()) : 9999999; const rAge = getTimestampAgeMs(r.timestamp);
if (rAge <= 25000) { if (rAge <= 25000) {
if (r.heart_rate != null) merged.heart_rate = r.heart_rate; if (r.heart_rate != null) merged.heart_rate = r.heart_rate;
if (r.spo2 != null) merged.spo2 = r.spo2; if (r.spo2 != null) merged.spo2 = r.spo2;
@@ -3652,7 +3669,7 @@
if (readings.length > 0) { if (readings.length > 0) {
const now = Date.now(); const now = Date.now();
readings.forEach(r => { readings.forEach(r => {
const rAge = r.timestamp ? (now - new Date(r.timestamp).getTime()) : 9999999; const rAge = getTimestampAgeMs(r.timestamp);
if (rAge > 25000) { if (rAge > 25000) {
r.heart_rate = null; r.heart_rate = null;
r.spo2 = null; r.spo2 = null;
@@ -3743,7 +3760,7 @@
const devKey = r.device_id; const devKey = r.device_id;
if (devKey && connectedDevices[devKey]) { if (devKey && connectedDevices[devKey]) {
const dev = connectedDevices[devKey]; const dev = connectedDevices[devKey];
const rAge = r.timestamp ? (now - new Date(r.timestamp).getTime()) : 9999999; const rAge = getTimestampAgeMs(r.timestamp);
if (rAge <= 25000) { if (rAge <= 25000) {
if ((dev.heart_rate === undefined || dev.heart_rate === null) && r.heart_rate != null) dev.heart_rate = r.heart_rate; if ((dev.heart_rate === undefined || dev.heart_rate === null) && r.heart_rate != null) dev.heart_rate = r.heart_rate;
if ((dev.spo2 === undefined || dev.spo2 === null) && r.spo2 != null) dev.spo2 = r.spo2; if ((dev.spo2 === undefined || dev.spo2 === null) && r.spo2 != null) dev.spo2 = r.spo2;