reorganize application code into fiveparaminte-main directory structure
This commit is contained in:
@@ -2192,10 +2192,10 @@
|
||||
<div class="machine-top-bar">
|
||||
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
|
||||
<span class="machine-brand">🏥 CONTEC CMS7000PLUS</span>
|
||||
<span class="machine-pill" id="machBedPill">BED 01</span>
|
||||
<span class="machine-pill">ADULT</span>
|
||||
<span style="font-weight: 800; color: #ffffff;" id="machPatientName">SHAHIL</span>
|
||||
<span class="machine-pill" id="machMrnPill">MRN: 09091102</span>
|
||||
<span class="machine-pill" id="machBedPill">BED --</span>
|
||||
<span class="machine-pill" id="machCategoryPill">ADULT</span>
|
||||
<span style="font-weight: 800; color: #ffffff;" id="machPatientName">--</span>
|
||||
<span class="machine-pill" id="machMrnPill">MRN: --</span>
|
||||
<span style="color: #64748b; font-size: 11px;">PACE: NO</span>
|
||||
<span class="machine-alarm-normal">● TELEMETRY NORMAL</span>
|
||||
</div>
|
||||
@@ -2592,26 +2592,30 @@
|
||||
};
|
||||
if (!dev) return res;
|
||||
|
||||
const pMrn = String(dev?.mrn || dev?.patient_id || '').toLowerCase().trim();
|
||||
const pName = String(dev?.patient_name || dev?.name || '').toLowerCase().trim();
|
||||
let pMrn = String(dev?.mrn || dev?.patient_id || '').toLowerCase().trim();
|
||||
if ((!pMrn || pMrn === 'unknown') && dev?.device_id) {
|
||||
const pat = Object.values(patientRegistry).find(p => p.device_id === dev.device_id);
|
||||
if (pat) pMrn = String(pat.mrn || pat.patient_id || '').toLowerCase().trim();
|
||||
}
|
||||
let pName = String(dev?.patient_name || dev?.name || '').toLowerCase().trim();
|
||||
if ((!pName || pName === 'unknown') && dev?.device_id) {
|
||||
const pat = Object.values(patientRegistry).find(p => p.device_id === dev.device_id);
|
||||
if (pat) pName = String(pat.name || '').toLowerCase().trim();
|
||||
}
|
||||
const pDob = String(dev?.patient_dob || dev?.dob || '').toLowerCase().trim();
|
||||
const pGender = String(dev?.patient_gender || dev?.gender || '').toLowerCase().trim();
|
||||
|
||||
// 1. MRN verification
|
||||
if (targetMrn) {
|
||||
const tm = targetMrn.toLowerCase().trim();
|
||||
if (pMrn && (pMrn === tm || pMrn.includes(tm) || tm.includes(pMrn))) {
|
||||
const cleanTm = tm.replace(/^0+/, '');
|
||||
const cleanMrn = pMrn.replace(/^0+/, '');
|
||||
if (pMrn && (pMrn === tm || (cleanTm.length >= 2 && cleanTm === cleanMrn))) {
|
||||
res.mrnMatched = true;
|
||||
} else {
|
||||
const numT = parseInt(tm, 10);
|
||||
const numMrn = parseInt(pMrn, 10);
|
||||
if (!isNaN(numT) && !isNaN(numMrn) && numT === numMrn && tm.length >= 3 && pMrn.length >= 3) {
|
||||
res.mrnMatched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Name verification (supports "Shahil", "Shahil Kumar", "Kumar Shahil")
|
||||
// 2. Name verification (supports exact, partial or token-based matching)
|
||||
if (targetName) {
|
||||
const tn = targetName.toLowerCase().trim();
|
||||
const targetTokens = normalizeNameTokens(targetName);
|
||||
@@ -2645,7 +2649,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
res.allMatched = res.mrnMatched && res.nameMatched && res.dobMatched && res.genderMatched;
|
||||
// Match positively on MRN, or on Name (with DOB if supplied)
|
||||
if (targetMrn && res.mrnMatched) {
|
||||
res.allMatched = true;
|
||||
} else if (targetName && res.nameMatched && (!targetDob || res.dobMatched)) {
|
||||
res.allMatched = true;
|
||||
} else if (!targetMrn && !targetName) {
|
||||
res.allMatched = res.dobMatched && res.genderMatched;
|
||||
} else {
|
||||
res.allMatched = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -2682,6 +2695,32 @@
|
||||
bed_id: null
|
||||
};
|
||||
|
||||
function clearMachineVitals() {
|
||||
machVitals.heart_rate = null;
|
||||
machVitals.spo2 = null;
|
||||
machVitals.systolic_bp = null;
|
||||
machVitals.diastolic_bp = null;
|
||||
machVitals.map_bp = null;
|
||||
machVitals.respiratory_rate = null;
|
||||
machVitals.temperature = null;
|
||||
machVitals.temperature2 = null;
|
||||
machVitals.temperature_diff = null;
|
||||
machVitals.device_id = null;
|
||||
machVitals.patient_name = targetName || null;
|
||||
machVitals.patient_id = targetMrn || null;
|
||||
machVitals.bed_id = null;
|
||||
machVitals.patient_type = null;
|
||||
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = machVitals.patient_name ? machVitals.patient_name.toUpperCase() : '--';
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = machVitals.patient_id ? `MRN: ${machVitals.patient_id}` : 'MRN: --';
|
||||
const elBed = document.getElementById('machBedPill');
|
||||
if (elBed) elBed.textContent = machVitals.bed_id ? `BED ${machVitals.bed_id}` : 'BED --';
|
||||
|
||||
updateMachineDisplay();
|
||||
}
|
||||
|
||||
let machSweepX = 0;
|
||||
let machPrevY_ecg = null;
|
||||
let machPrevY_spo2 = null;
|
||||
@@ -2711,13 +2750,16 @@
|
||||
window.addEventListener('resize', resizeMachineCanvases);
|
||||
|
||||
if (targetMrn) {
|
||||
machVitals.patient_id = targetMrn;
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = `MRN: ${targetMrn}`;
|
||||
}
|
||||
if (targetName) {
|
||||
machVitals.patient_name = targetName;
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = targetName.toUpperCase();
|
||||
}
|
||||
updateMachineDisplay();
|
||||
|
||||
// Load real patient telemetry from DB
|
||||
fetchMachineTelemetry();
|
||||
@@ -3021,45 +3063,136 @@
|
||||
// === Load Real Machine Telemetry from Database & API ===
|
||||
async function fetchMachineTelemetry() {
|
||||
try {
|
||||
const targetId = targetMrn || targetName || '09091102';
|
||||
|
||||
// 1. Demographics from registered patient list
|
||||
const patResp = await fetch(`${API_BASE}/patients`);
|
||||
if (patResp.ok) {
|
||||
const patients = await patResp.json();
|
||||
const p = patients.find(pt =>
|
||||
(targetMrn && (pt.mrn === targetMrn || pt.patient_id === targetMrn)) ||
|
||||
(targetName && pt.name && pt.name.toLowerCase().includes(targetName.toLowerCase()))
|
||||
) || (targetMrn ? null : patients[0]);
|
||||
if (hasTargetFilter) {
|
||||
// Strict Target Patient Mode: NEVER fallback to another patient or transmitting device!
|
||||
let p = null;
|
||||
const patResp = await fetch(`${API_BASE}/patients`);
|
||||
if (patResp.ok) {
|
||||
const patients = await patResp.json();
|
||||
if (targetMrn) {
|
||||
const cleanTm = targetMrn.toLowerCase().trim().replace(/^0+/, '');
|
||||
p = patients.find(pt => {
|
||||
const m = String(pt.mrn || pt.patient_id || '').toLowerCase().trim();
|
||||
return m === targetMrn.toLowerCase().trim() || (cleanTm.length >= 2 && m.replace(/^0+/, '') === cleanTm);
|
||||
});
|
||||
} else if (targetName) {
|
||||
p = patients.find(pt => pt.name && pt.name.toLowerCase().includes(targetName.toLowerCase()));
|
||||
}
|
||||
}
|
||||
|
||||
if (p) {
|
||||
machVitals.patient_name = p.name || targetName || 'SHAHIL';
|
||||
machVitals.patient_id = p.mrn || p.patient_id || targetMrn || '09091102';
|
||||
machVitals.bed_id = p.bed_id || '1';
|
||||
machVitals.device_id = p.device_id || 'CMS8500_192.168.100.106';
|
||||
machVitals.patient_name = p.name || targetName || null;
|
||||
machVitals.patient_id = p.mrn || p.patient_id || targetMrn || null;
|
||||
machVitals.bed_id = p.bed_id || null;
|
||||
machVitals.device_id = p.device_id || '';
|
||||
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = machVitals.patient_name.toUpperCase();
|
||||
if (elName) elName.textContent = machVitals.patient_name ? machVitals.patient_name.toUpperCase() : '--';
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = `MRN: ${machVitals.patient_id}`;
|
||||
if (elMrn) elMrn.textContent = machVitals.patient_id ? `MRN: ${machVitals.patient_id}` : 'MRN: --';
|
||||
const elBed = document.getElementById('machBedPill');
|
||||
if (elBed) elBed.textContent = `BED ${machVitals.bed_id}`;
|
||||
if (elBed) elBed.textContent = machVitals.bed_id ? `BED ${machVitals.bed_id}` : 'BED --';
|
||||
|
||||
if (p.latest_vitals) {
|
||||
applyVitalsToMachine(p.latest_vitals);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Query latest readings directly for target patient
|
||||
const targetId = targetMrn || targetName;
|
||||
if (targetId) {
|
||||
const readResp = await fetch(`${API_BASE}/latest-readings?mrn=${encodeURIComponent(targetId)}&limit=10`);
|
||||
if (readResp.ok) {
|
||||
const readings = await readResp.json();
|
||||
if (readings && readings.length > 0) {
|
||||
const merged = {};
|
||||
for (let i = readings.length - 1; i >= 0; i--) {
|
||||
const r = readings[i];
|
||||
for (const k in r) {
|
||||
if (r[k] !== null && r[k] !== undefined) merged[k] = r[k];
|
||||
}
|
||||
}
|
||||
applyVitalsToMachine(merged);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no readings or machine data exists for target patient, strictly clear all vitals to '--' / LEAD OFF / flat line
|
||||
clearMachineVitals();
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Fallback: Fetch latest single reading directly from DB (limit=1: NO FAKE DATA)
|
||||
const readResp = await fetch(`${API_BASE}/latest-readings?mrn=${encodeURIComponent(targetId)}&limit=1`);
|
||||
if (readResp.ok) {
|
||||
const readings = await readResp.json();
|
||||
if (readings && readings.length > 0) {
|
||||
applyVitalsToMachine(readings[0]);
|
||||
} else {
|
||||
applyVitalsToMachine(null);
|
||||
// General mode (no target filter):
|
||||
// Determine target patient: active device patient
|
||||
let targetId = null;
|
||||
if (activeDeviceId && connectedDevices[activeDeviceId]) {
|
||||
const activeDev = connectedDevices[activeDeviceId];
|
||||
targetId = activeDev.patient_id || activeDev.mrn;
|
||||
}
|
||||
|
||||
// 1. Demographics from registered patient list
|
||||
const patResp = await fetch(`${API_BASE}/patients`);
|
||||
if (patResp.ok) {
|
||||
const patients = await patResp.json();
|
||||
let p = null;
|
||||
if (activeDeviceId) {
|
||||
p = patients.find(pt => pt.device_id === activeDeviceId);
|
||||
}
|
||||
if (!p && patients.length > 0) {
|
||||
// Find patient corresponding to a live transmitting device
|
||||
p = patients.find(pt => pt.device_id && connectedDevices[pt.device_id]?._liveData) ||
|
||||
patients.find(pt => pt.device_id && pt.device_id === activeDeviceId);
|
||||
}
|
||||
|
||||
if (p) {
|
||||
machVitals.patient_name = p.name || null;
|
||||
machVitals.patient_id = p.mrn || p.patient_id || null;
|
||||
machVitals.bed_id = p.bed_id || null;
|
||||
machVitals.device_id = p.device_id || activeDeviceId || '';
|
||||
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = machVitals.patient_name ? machVitals.patient_name.toUpperCase() : '--';
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = machVitals.patient_id ? `MRN: ${machVitals.patient_id}` : 'MRN: --';
|
||||
const elBed = document.getElementById('machBedPill');
|
||||
if (elBed) elBed.textContent = machVitals.bed_id ? `BED ${machVitals.bed_id}` : 'BED --';
|
||||
|
||||
if (p.latest_vitals) {
|
||||
applyVitalsToMachine(p.latest_vitals);
|
||||
return;
|
||||
}
|
||||
} else if (activeDeviceId && connectedDevices[activeDeviceId]) {
|
||||
const dev = connectedDevices[activeDeviceId];
|
||||
if (dev.patient_name || dev.name) machVitals.patient_name = dev.patient_name || dev.name;
|
||||
if (dev.mrn || dev.patient_id) machVitals.patient_id = dev.mrn || dev.patient_id;
|
||||
if (dev.bed_id || dev.bedLabel) machVitals.bed_id = dev.bed_id || dev.bedLabel;
|
||||
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = machVitals.patient_name ? machVitals.patient_name.toUpperCase() : '--';
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = machVitals.patient_id ? `MRN: ${machVitals.patient_id}` : 'MRN: --';
|
||||
const elBed = document.getElementById('machBedPill');
|
||||
if (elBed) elBed.textContent = machVitals.bed_id ? `BED ${machVitals.bed_id}` : 'BED --';
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fallback: Fetch latest readings directly from DB (merge up to 10 recent readings so all active parameters display)
|
||||
if (targetId) {
|
||||
const readResp = await fetch(`${API_BASE}/latest-readings?mrn=${encodeURIComponent(targetId)}&limit=10`);
|
||||
if (readResp.ok) {
|
||||
const readings = await readResp.json();
|
||||
if (readings && readings.length > 0) {
|
||||
const merged = {};
|
||||
for (let i = readings.length - 1; i >= 0; i--) {
|
||||
const r = readings[i];
|
||||
for (const k in r) {
|
||||
if (r[k] !== null && r[k] !== undefined) merged[k] = r[k];
|
||||
}
|
||||
}
|
||||
applyVitalsToMachine(merged);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
@@ -3071,39 +3204,39 @@
|
||||
if (!data) return;
|
||||
|
||||
// Heart Rate
|
||||
if (data.heart_rate !== undefined) {
|
||||
machVitals.heart_rate = (data.heart_rate != null && data.heart_rate > 0) ? Math.round(data.heart_rate) : null;
|
||||
if (data.heart_rate !== undefined && data.heart_rate !== null) {
|
||||
machVitals.heart_rate = (data.heart_rate > 0) ? Math.round(data.heart_rate) : null;
|
||||
}
|
||||
|
||||
// SpO2
|
||||
if (data.spo2 !== undefined) {
|
||||
machVitals.spo2 = (data.spo2 != null && data.spo2 > 0) ? Math.round(data.spo2) : null;
|
||||
if (data.spo2 !== undefined && data.spo2 !== null) {
|
||||
machVitals.spo2 = (data.spo2 > 0) ? Math.round(data.spo2) : null;
|
||||
}
|
||||
|
||||
// Respiration Rate
|
||||
if (data.respiratory_rate !== undefined) {
|
||||
machVitals.respiratory_rate = (data.respiratory_rate != null && data.respiratory_rate > 0) ? Math.round(data.respiratory_rate) : null;
|
||||
if (data.respiratory_rate !== undefined && data.respiratory_rate !== null) {
|
||||
machVitals.respiratory_rate = (data.respiratory_rate > 0) ? Math.round(data.respiratory_rate) : null;
|
||||
}
|
||||
|
||||
// NIBP
|
||||
if (data.systolic_bp !== undefined) {
|
||||
machVitals.systolic_bp = (data.systolic_bp != null && data.systolic_bp > 0) ? Math.round(data.systolic_bp) : null;
|
||||
if (data.systolic_bp !== undefined && data.systolic_bp !== null) {
|
||||
machVitals.systolic_bp = (data.systolic_bp > 0) ? Math.round(data.systolic_bp) : null;
|
||||
}
|
||||
if (data.diastolic_bp !== undefined) {
|
||||
machVitals.diastolic_bp = (data.diastolic_bp != null && data.diastolic_bp > 0) ? Math.round(data.diastolic_bp) : null;
|
||||
if (data.diastolic_bp !== undefined && data.diastolic_bp !== null) {
|
||||
machVitals.diastolic_bp = (data.diastolic_bp > 0) ? Math.round(data.diastolic_bp) : null;
|
||||
}
|
||||
if (data.map_bp !== undefined) {
|
||||
machVitals.map_bp = (data.map_bp != null && data.map_bp > 0) ? Math.round(data.map_bp) : null;
|
||||
if (data.map_bp !== undefined && data.map_bp !== null) {
|
||||
machVitals.map_bp = (data.map_bp > 0) ? Math.round(data.map_bp) : null;
|
||||
}
|
||||
|
||||
// Temperature 1 (T1)
|
||||
if (data.temperature !== undefined) {
|
||||
machVitals.temperature = (data.temperature != null && data.temperature > 0) ? Number(data.temperature) : null;
|
||||
if (data.temperature !== undefined && data.temperature !== null) {
|
||||
machVitals.temperature = (data.temperature > 0) ? Number(data.temperature) : null;
|
||||
}
|
||||
|
||||
// Temperature 2 (T2)
|
||||
if (data.temperature2 !== undefined) {
|
||||
machVitals.temperature2 = (data.temperature2 != null && data.temperature2 > 0) ? Number(data.temperature2) : null;
|
||||
if (data.temperature2 !== undefined && data.temperature2 !== null) {
|
||||
machVitals.temperature2 = (data.temperature2 > 0) ? Number(data.temperature2) : null;
|
||||
}
|
||||
|
||||
// Temperature Difference (TD)
|
||||
@@ -3111,16 +3244,25 @@
|
||||
machVitals.temperature_diff = Number(data.temperature_diff);
|
||||
} else if (machVitals.temperature != null && machVitals.temperature2 != null) {
|
||||
machVitals.temperature_diff = Math.round(Math.abs(machVitals.temperature - machVitals.temperature2) * 10) / 10;
|
||||
} else {
|
||||
machVitals.temperature_diff = null;
|
||||
}
|
||||
|
||||
if (data.patient_name && data.patient_name !== 'Unknown') machVitals.patient_name = data.patient_name;
|
||||
if (data.name && data.name !== 'Unknown') machVitals.patient_name = data.name;
|
||||
if (data.mrn && data.mrn !== 'UNKNOWN') machVitals.patient_id = data.mrn;
|
||||
if (data.patient_id && data.patient_id !== 'UNKNOWN') machVitals.patient_id = data.patient_id;
|
||||
if (data.patient_name && data.patient_name !== 'Unknown' && data.patient_name !== 'UNKNOWN') machVitals.patient_name = data.patient_name;
|
||||
if (data.name && data.name !== 'Unknown' && data.name !== 'UNKNOWN') machVitals.patient_name = data.name;
|
||||
if (data.mrn && data.mrn !== 'UNKNOWN' && data.mrn !== 'UNASSIGNED') machVitals.patient_id = data.mrn;
|
||||
if (data.patient_id && data.patient_id !== 'UNKNOWN' && data.patient_id !== 'UNASSIGNED') machVitals.patient_id = data.patient_id;
|
||||
if (data.bed_id) machVitals.bed_id = data.bed_id;
|
||||
if (data.device_id) machVitals.device_id = data.device_id;
|
||||
if (data.patient_type) machVitals.patient_type = data.patient_type;
|
||||
|
||||
// Ensure top machine pills reflect current patient directly from machine
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = machVitals.patient_name ? machVitals.patient_name.toUpperCase() : '--';
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = machVitals.patient_id ? `MRN: ${machVitals.patient_id}` : 'MRN: --';
|
||||
const elBed = document.getElementById('machBedPill');
|
||||
if (elBed) elBed.textContent = machVitals.bed_id ? `BED ${machVitals.bed_id}` : 'BED --';
|
||||
const elCat = document.getElementById('machCategoryPill');
|
||||
if (elCat && machVitals.patient_type) elCat.textContent = machVitals.patient_type.toUpperCase();
|
||||
|
||||
updateMachineDisplay();
|
||||
}
|
||||
@@ -3638,6 +3780,22 @@
|
||||
function selectDevice(devId) {
|
||||
activeDeviceId = devId;
|
||||
setViewMode('single');
|
||||
if (devId && connectedDevices[devId]) {
|
||||
const dev = connectedDevices[devId];
|
||||
machVitals.patient_name = (dev.patient_name && dev.patient_name !== 'Unknown' && dev.patient_name !== 'UNKNOWN') ? dev.patient_name : (dev.name && dev.name !== 'Unknown' && dev.name !== 'UNKNOWN' ? dev.name : null);
|
||||
machVitals.patient_id = (dev.patient_id && dev.patient_id !== 'UNKNOWN' && dev.patient_id !== 'UNASSIGNED') ? dev.patient_id : ((dev.mrn && dev.mrn !== 'UNKNOWN' && dev.mrn !== 'UNASSIGNED') ? dev.mrn : null);
|
||||
machVitals.bed_id = dev.bed_id || dev.bedLabel || null;
|
||||
machVitals.device_id = devId;
|
||||
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = machVitals.patient_name ? machVitals.patient_name.toUpperCase() : '--';
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = machVitals.patient_id ? `MRN: ${machVitals.patient_id}` : 'MRN: --';
|
||||
const elBed = document.getElementById('machBedPill');
|
||||
if (elBed) elBed.textContent = machVitals.bed_id ? `BED ${machVitals.bed_id}` : 'BED --';
|
||||
|
||||
applyVitalsToMachine(dev);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDeviceTabs() {
|
||||
@@ -3865,6 +4023,22 @@
|
||||
bed_id: data.bed_id,
|
||||
bedLabel: data.bed_id || connectedDevices[devId]?.bedLabel
|
||||
};
|
||||
if (activeDeviceId === devId || !activeDeviceId) {
|
||||
machVitals.patient_name = (data.patient_name && data.patient_name !== 'Unknown' && data.patient_name !== 'UNKNOWN') ? data.patient_name : (data.name && data.name !== 'Unknown' && data.name !== 'UNKNOWN' ? data.name : null);
|
||||
machVitals.patient_id = (data.mrn && data.mrn !== 'UNKNOWN' && data.mrn !== 'UNASSIGNED') ? data.mrn : ((data.patient_id && data.patient_id !== 'UNKNOWN' && data.patient_id !== 'UNASSIGNED') ? data.patient_id : null);
|
||||
machVitals.bed_id = data.bed_id || null;
|
||||
machVitals.device_id = devId;
|
||||
if (data.patient_type) machVitals.patient_type = data.patient_type;
|
||||
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = machVitals.patient_name ? machVitals.patient_name.toUpperCase() : '--';
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = machVitals.patient_id ? `MRN: ${machVitals.patient_id}` : 'MRN: --';
|
||||
const elBed = document.getElementById('machBedPill');
|
||||
if (elBed) elBed.textContent = machVitals.bed_id ? `BED ${machVitals.bed_id}` : 'BED --';
|
||||
const elCat = document.getElementById('machCategoryPill');
|
||||
if (elCat && machVitals.patient_type) elCat.textContent = machVitals.patient_type.toUpperCase();
|
||||
}
|
||||
updateDeviceTabs();
|
||||
if (hasTargetFilter) {
|
||||
if (matchesTargetPatient(connectedDevices[devId], devId)) {
|
||||
@@ -3929,16 +4103,13 @@
|
||||
};
|
||||
|
||||
// Real-time sync with Contec Machine Display (Strictly live telemetry, zero fake values)
|
||||
if (devId) {
|
||||
const isMatch = !hasTargetFilter || matchesTargetPatient(connectedDevices[devId], devId) ||
|
||||
(devId.includes('192.168.100.106') && (targetMrn === '09091102' || (targetName && targetName.toLowerCase().includes('shahil'))));
|
||||
if (isMatch) {
|
||||
applyVitalsToMachine(data);
|
||||
}
|
||||
}
|
||||
|
||||
const isTargetMatch = !hasTargetFilter || matchesTargetPatient(connectedDevices[devId], devId);
|
||||
|
||||
if (devId && isTargetMatch) {
|
||||
if (!activeDeviceId) activeDeviceId = devId;
|
||||
applyVitalsToMachine(connectedDevices[devId]);
|
||||
}
|
||||
|
||||
if (isTargetMatch) {
|
||||
if (!activeDeviceId || hasTargetFilter) {
|
||||
activeDeviceId = devId;
|
||||
@@ -3949,21 +4120,23 @@
|
||||
|
||||
if (isTargetMatch && hasTargetFilter) {
|
||||
// Target patient matched — force single view and render immediately
|
||||
// (don't wait for fetchInitialDevicesAndPatients async race)
|
||||
if (viewMode !== 'single') setViewMode('single');
|
||||
renderSingleDevice(connectedDevices[devId]);
|
||||
} else if (hasTargetFilter && !isTargetMatch) {
|
||||
// Incoming data is for ANOTHER patient/device - do NOT show it on target patient view!
|
||||
if (viewMode === 'single') {
|
||||
renderSingleDevice(null);
|
||||
}
|
||||
} else if (viewMode === 'grid') {
|
||||
renderMultiBedGrid();
|
||||
} else if (viewMode === 'single') {
|
||||
if (isTargetMatch && activeDeviceId === devId) {
|
||||
if (activeDeviceId === devId) {
|
||||
renderSingleDevice(connectedDevices[devId]);
|
||||
} else if (hasTargetFilter && !activeDeviceId) {
|
||||
renderSingleDevice(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderSingleDevice(data) {
|
||||
function renderSingleDevice(dev) {
|
||||
const waitingState = document.getElementById('singleTargetWaitingState');
|
||||
const patientBanner = document.getElementById('singlePatientBanner');
|
||||
const vitalsGrid = document.getElementById('singleVitalsGrid');
|
||||
@@ -3972,67 +4145,52 @@
|
||||
// Always ensure the ICU Live Monitor is visible in single view
|
||||
if (icuMon) icuMon.style.display = 'flex';
|
||||
|
||||
if (!data && hasTargetFilter) {
|
||||
data = {
|
||||
patient_name: targetName || machVitals.patient_name || 'Shahilfaah',
|
||||
name: targetName || machVitals.patient_name || 'Shahilfaah',
|
||||
patient_id: targetMrn || machVitals.patient_id || '09091102',
|
||||
mrn: targetMrn || machVitals.patient_id || '09091102',
|
||||
device_id: machVitals.device_id || 'CMS8500_192.168.100.106',
|
||||
bed_id: machVitals.bed_id || 'Bed 01',
|
||||
bedLabel: machVitals.bed_id || 'Bed 01',
|
||||
heart_rate: null,
|
||||
spo2: null,
|
||||
systolic_bp: null,
|
||||
diastolic_bp: null,
|
||||
map_bp: null,
|
||||
respiratory_rate: null,
|
||||
temperature: null
|
||||
};
|
||||
}
|
||||
|
||||
if (hasTargetFilter && !isMinimal) {
|
||||
const isMatch = data && matchesTargetPatient(data, data.device_id);
|
||||
if (!isMatch) {
|
||||
if (waitingState) {
|
||||
waitingState.style.display = 'flex';
|
||||
const badge = document.getElementById('targetWaitingMrnBadge');
|
||||
if (badge) badge.innerHTML = getTargetPatientBadge();
|
||||
let data = dev;
|
||||
if (hasTargetFilter) {
|
||||
if (data && !matchesTargetPatient(data, data.device_id)) {
|
||||
data = null;
|
||||
}
|
||||
if (!data) {
|
||||
const matchDev = Object.values(connectedDevices).find(d => matchesTargetPatient(d, d.device_id));
|
||||
if (matchDev) {
|
||||
data = matchDev;
|
||||
}
|
||||
} else {
|
||||
if (waitingState) waitingState.style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
if (waitingState) waitingState.style.display = 'none';
|
||||
}
|
||||
|
||||
if (hasTargetFilter && !data) {
|
||||
// Target patient has NO connected machine or matching readings
|
||||
clearMachineVitals();
|
||||
|
||||
// Clear standard vital cards
|
||||
updateVitalCard('hr', null, 'heart_rate');
|
||||
updateVitalCard('spo2', null, 'spo2');
|
||||
updateVitalCard('bp', null, 'systolic_bp');
|
||||
updateVitalCard('rr', null, 'respiratory_rate');
|
||||
updateVitalCard('temp', null, 'temperature');
|
||||
updateVitalCard('map', null, 'map_bp');
|
||||
|
||||
if (!isMinimal && waitingState) {
|
||||
waitingState.style.display = 'flex';
|
||||
const badge = document.getElementById('targetWaitingMrnBadge');
|
||||
if (badge) badge.innerHTML = getTargetPatientBadge();
|
||||
}
|
||||
if (!isMinimal) {
|
||||
if (patientBanner) patientBanner.style.display = 'none';
|
||||
if (vitalsGrid) vitalsGrid.style.display = 'none';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (waitingState) waitingState.style.display = 'none';
|
||||
if (!isMinimal) {
|
||||
if (patientBanner) patientBanner.style.display = 'flex';
|
||||
if (vitalsGrid) vitalsGrid.style.display = 'grid';
|
||||
}
|
||||
|
||||
if (!data) return;
|
||||
// Sync with ICU Live Monitor
|
||||
if (data) {
|
||||
if (data.heart_rate != null) icuVitals.heart_rate = data.heart_rate;
|
||||
if (data.spo2 != null) icuVitals.spo2 = data.spo2;
|
||||
if (data.systolic_bp != null) icuVitals.systolic_bp = data.systolic_bp;
|
||||
if (data.diastolic_bp != null) icuVitals.diastolic_bp = data.diastolic_bp;
|
||||
if (data.map_bp != null) icuVitals.map_bp = data.map_bp;
|
||||
if (data.respiratory_rate != null) icuVitals.respiratory_rate = data.respiratory_rate;
|
||||
if (data.temperature != null) icuVitals.temperature = data.temperature;
|
||||
if (data.patient_name && data.patient_name !== 'Unknown') icuVitals.patient_name = data.patient_name;
|
||||
if (data.mrn || data.patient_id) icuVitals.patient_id = data.mrn || data.patient_id;
|
||||
if (data.device_id) icuVitals.device_id = data.device_id;
|
||||
if (data.bed_id || data.bedLabel) icuVitals.bed_id = data.bed_id || data.bedLabel;
|
||||
|
||||
document.getElementById('icuPatientNameText').textContent = icuVitals.patient_name;
|
||||
document.getElementById('icuAvatar').textContent = icuVitals.patient_name.charAt(0).toUpperCase();
|
||||
document.getElementById('icuMrnTag').textContent = `MRN: ${icuVitals.patient_id}`;
|
||||
document.getElementById('icuBedTag').textContent = `BED: ${icuVitals.bed_id}`;
|
||||
document.getElementById('icuDevTag').textContent = `DEV: ${icuVitals.device_id}`;
|
||||
updateIcuMonitorReadouts();
|
||||
}
|
||||
// Sync with Contec Machine Screen
|
||||
applyVitalsToMachine(data);
|
||||
|
||||
// 1. Update Patient Banner
|
||||
const hasAssigned = data.patient_name && data.patient_name !== 'Unknown' && data.patient_name !== 'UNKNOWN' && data.patient_name !== 'Unassigned Patient';
|
||||
@@ -4182,6 +4340,17 @@
|
||||
};
|
||||
|
||||
closeAssignPatientModal();
|
||||
if (activeDeviceId === device_id || !activeDeviceId) {
|
||||
machVitals.patient_name = name;
|
||||
machVitals.patient_id = mrn;
|
||||
machVitals.bed_id = bed_id;
|
||||
const elName = document.getElementById('machPatientName');
|
||||
if (elName) elName.textContent = name ? name.toUpperCase() : '--';
|
||||
const elMrn = document.getElementById('machMrnPill');
|
||||
if (elMrn) elMrn.textContent = mrn ? `MRN: ${mrn}` : 'MRN: --';
|
||||
const elBed = document.getElementById('machBedPill');
|
||||
if (elBed) elBed.textContent = bed_id ? `BED ${bed_id}` : 'BED --';
|
||||
}
|
||||
updateDeviceTabs();
|
||||
if (viewMode === 'grid') renderMultiBedGrid();
|
||||
else if (viewMode === 'single' && activeDeviceId === device_id) {
|
||||
@@ -4343,12 +4512,18 @@
|
||||
const updateEl = document.getElementById(`update-${cardKey}`);
|
||||
const cardEl = document.getElementById(`card-${cardKey}`);
|
||||
|
||||
if (!valueEl) return;
|
||||
|
||||
if (value === null || value === undefined) {
|
||||
valueEl.innerHTML = '---';
|
||||
valueEl.className = 'vital-value no-data';
|
||||
statusEl.textContent = 'No Data';
|
||||
statusEl.className = 'status-badge offline';
|
||||
cardEl.classList.remove('has-value');
|
||||
if (statusEl) {
|
||||
statusEl.textContent = 'No Data';
|
||||
statusEl.className = 'status-badge offline';
|
||||
}
|
||||
if (cardEl) {
|
||||
cardEl.classList.remove('has-value');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user