Spaces:
Running
Running
Download index.html from danursing/iv-tracker-special: direct link, hf CLI and curl.
- Browser
- Download file 38.6 kB
-
https://huggingface.co/spaces/danursing/iv-tracker-special/resolve/main/index.html
- Command line
-
hf download hf://spaces/danursing/iv-tracker-special/index.html
-
curl -L -o index.html https://huggingface.co/spaces/danursing/iv-tracker-special/resolve/main/index.html
38.6 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Nursing IV Fluid Tracker</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://unpkg.com/feather-icons"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> | |
| <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet"> | |
| <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script> | |
| <style> | |
| .progress-gradient { | |
| background: linear-gradient(90deg, #10b981 0%, #f59e0b 50%, #ef4444 100%); | |
| } | |
| .alert-pulse { | |
| animation: pulse 2s infinite; | |
| } | |
| @keyframes pulse { | |
| 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); } | |
| 70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } | |
| 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div class="container mx-auto px-4 py-8"> | |
| <!-- Header --> | |
| <header class="mb-8"> | |
| <h1 class="text-3xl font-bold text-blue-800">IV Fluid Tracker</h1> | |
| <p class="text-gray-600">Monitor multiple patients' IV infusions in real-time</p> | |
| </header> | |
| <!-- Main Content --> | |
| <div class="grid grid-cols-1 lg:grid-cols-3 gap-6"> | |
| <!-- Patient Dashboard --> | |
| <div class="lg:col-span-1 bg-white rounded-xl shadow-md p-6"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <h2 class="text-xl font-semibold text-gray-800">Patients</h2> | |
| <button id="addPatientBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center"> | |
| <i data-feather="plus" class="mr-2"></i> Add Patient | |
| </button> | |
| </div> | |
| <div id="patientList" class="space-y-3"> | |
| <!-- Patient cards will be added here dynamically --> | |
| <div class="text-center py-8 text-gray-400" id="emptyPatientList"> | |
| <i data-feather="users" class="w-12 h-12 mx-auto mb-3"></i> | |
| <p>No patients added yet</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- IV Tracking Panel --> | |
| <div class="lg:col-span-2 bg-white rounded-xl shadow-md p-6"> | |
| <div id="noPatientSelected" class="text-center py-12"> | |
| <i data-feather="activity" class="w-16 h-16 mx-auto text-gray-300 mb-4"></i> | |
| <h3 class="text-xl font-medium text-gray-500 mb-2">No patient selected</h3> | |
| <p class="text-gray-400">Select a patient from the list or add a new one to start tracking IV fluids</p> | |
| </div> | |
| <div id="patientTrackingPanel" class="hidden"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <div> | |
| <h2 class="text-xl font-semibold text-gray-800" id="selectedPatientName">Patient Name</h2> | |
| <p class="text-gray-500 text-sm" id="selectedPatientInfo">Room: 101 | MR#: 123456</p> | |
| </div> | |
| <div class="flex space-x-2"> | |
| <button id="addIvBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center"> | |
| <i data-feather="plus" class="mr-2"></i> Add IV | |
| </button> | |
| <button id="editPatientBtn" class="bg-gray-200 hover:bg-gray-300 text-gray-700 px-4 py-2 rounded-lg flex items-center"> | |
| <i data-feather="edit" class="mr-2"></i> Edit | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Current IVs --> | |
| <div id="currentIvs" class="space-y-4"> | |
| <!-- IV cards will be added here dynamically --> | |
| <div class="text-center py-8 text-gray-400" id="emptyIvList"> | |
| <i data-feather="droplet" class="w-12 h-12 mx-auto mb-3"></i> | |
| <p>No active IVs for this patient</p> | |
| </div> | |
| </div> | |
| <!-- IV History --> | |
| <div id="ivHistory" class="mt-8 pt-6 border-t border-gray-200 hidden"> | |
| <h3 class="text-lg font-medium text-gray-700 mb-4">IV History</h3> | |
| <div class="overflow-x-auto"> | |
| <table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Fluid</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Volume</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Rate</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Started</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Completed</th> | |
| </tr> | |
| </thead> | |
| <tbody id="historyTableBody" class="bg-white divide-y divide-gray-200"> | |
| <!-- History rows will be added here dynamically --> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Add Patient Modal --> | |
| <div id="addPatientModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden"> | |
| <div class="bg-white rounded-xl p-6 w-full max-w-md"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-xl font-semibold">Add New Patient</h3> | |
| <button id="closePatientModal" class="text-gray-400 hover:text-gray-500"> | |
| <i data-feather="x"></i> | |
| </button> | |
| </div> | |
| <form id="patientForm"> | |
| <div class="space-y-4"> | |
| <div> | |
| <label for="patientName" class="block text-sm font-medium text-gray-700 mb-1">Patient Name</label> | |
| <input type="text" id="patientName" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required> | |
| </div> | |
| <div> | |
| <label for="patientRoom" class="block text-sm font-medium text-gray-700 mb-1">Room Number</label> | |
| <input type="text" id="patientRoom" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> | |
| </div> | |
| <div> | |
| <label for="patientMrn" class="block text-sm font-medium text-gray-700 mb-1">Medical Record #</label> | |
| <input type="text" id="patientMrn" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> | |
| </div> | |
| </div> | |
| <div class="mt-6 flex justify-end space-x-3"> | |
| <button type="button" id="cancelPatientBtn" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">Cancel</button> | |
| <button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Save Patient</button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| <!-- Add IV Modal --> | |
| <div id="addIvModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden"> | |
| <div class="bg-white rounded-xl p-6 w-full max-w-md"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-xl font-semibold">Add New IV</h3> | |
| <button id="closeIvModal" class="text-gray-400 hover:text-gray-500"> | |
| <i data-feather="x"></i> | |
| </button> | |
| </div> | |
| <form id="ivForm"> | |
| <div class="space-y-4"> | |
| <div> | |
| <label for="ivType" class="block text-sm font-medium text-gray-700 mb-1">Fluid Type</label> | |
| <select id="ivType" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required> | |
| <option value="">Select fluid type</option> | |
| <option value="Normal Saline (0.9% NaCl)">Normal Saline (0.9% NaCl)</option> | |
| <option value="Lactated Ringer's">Lactated Ringer's</option> | |
| <option value="D5W (5% Dextrose in Water)">D5W (5% Dextrose in Water)</option> | |
| <option value="D5 1/2 Normal Saline">D5 1/2 Normal Saline</option> | |
| <option value="D5 Lactated Ringer's">D5 Lactated Ringer's</option> | |
| <option value="Parenteral Nutrition">Parenteral Nutrition</option> | |
| <option value="Other">Other</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label for="ivVolume" class="block text-sm font-medium text-gray-700 mb-1">Volume (mL)</label> | |
| <select id="ivVolume" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required> | |
| <option value="250">250 mL</option> | |
| <option value="500" selected>500 mL</option> | |
| <option value="1000">1000 mL</option> | |
| <option value="custom">Custom</option> | |
| </select> | |
| <input type="number" id="customVolume" class="w-full px-3 py-2 border border-gray-300 rounded-md mt-2 hidden" placeholder="Enter custom volume" min="1"> | |
| </div> | |
| <div> | |
| <label for="ivRate" class="block text-sm font-medium text-gray-700 mb-1">Infusion Rate</label> | |
| <div class="flex items-center space-x-2"> | |
| <input type="number" id="ivRate" class="flex-1 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Rate" required min="1"> | |
| <select id="rateUnit" class="w-24 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> | |
| <option value="mlPerHour">mL/hr</option> | |
| <option value="gttsPerMin">gtts/min</option> | |
| </select> | |
| </div> | |
| <div id="dropFactorContainer" class="mt-2 hidden"> | |
| <label for="dropFactor" class="block text-sm font-medium text-gray-700 mb-1">Drop Factor (gtts/mL)</label> | |
| <select id="dropFactor" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> | |
| <option value="10">10 gtts/mL (Macro drip)</option> | |
| <option value="15">15 gtts/mL</option> | |
| <option value="20">20 gtts/mL</option> | |
| <option value="60">60 gtts/mL (Micro drip)</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div> | |
| <label for="ivStartTime" class="block text-sm font-medium text-gray-700 mb-1">Start Time</label> | |
| <input type="time" id="ivStartTime" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required> | |
| </div> | |
| </div> | |
| <div class="mt-6 flex justify-end space-x-3"> | |
| <button type="button" id="cancelIvBtn" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50">Cancel</button> | |
| <button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Start IV</button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| <!-- Alert Modal --> | |
| <div id="alertModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden"> | |
| <div class="bg-white rounded-xl p-6 w-full max-w-sm alert-pulse"> | |
| <div class="flex items-start"> | |
| <div class="flex-shrink-0"> | |
| <i data-feather="alert-triangle" class="w-8 h-8 text-red-500"></i> | |
| </div> | |
| <div class="ml-3"> | |
| <h3 class="text-lg font-medium text-gray-900" id="alertTitle">IV Nearly Complete</h3> | |
| <div class="mt-2"> | |
| <p class="text-sm text-gray-500" id="alertMessage">Patient's IV is nearly finished. Please check and replace if needed.</p> | |
| </div> | |
| <div class="mt-4"> | |
| <button type="button" id="closeAlertBtn" class="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700">Acknowledged</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Initialize AOS and Feather Icons | |
| document.addEventListener('DOMContentLoaded', function() { | |
| AOS.init(); | |
| feather.replace(); | |
| // Set current time as default for IV start time | |
| const now = new Date(); | |
| const hours = String(now.getHours()).padStart(2, '0'); | |
| const minutes = String(now.getMinutes()).padStart(2, '0'); | |
| document.getElementById('ivStartTime').value = `${hours}:${minutes}`; | |
| // Initialize app data | |
| let patients = JSON.parse(localStorage.getItem('ivTrackerPatients')) || []; | |
| let selectedPatientId = null; | |
| let alerts = []; | |
| // Load patients | |
| renderPatientList(); | |
| // Event listeners for modals | |
| document.getElementById('addPatientBtn').addEventListener('click', openAddPatientModal); | |
| document.getElementById('closePatientModal').addEventListener('click', closeAddPatientModal); | |
| document.getElementById('cancelPatientBtn').addEventListener('click', closeAddPatientModal); | |
| document.getElementById('patientForm').addEventListener('submit', savePatient); | |
| document.getElementById('addIvBtn').addEventListener('click', openAddIvModal); | |
| document.getElementById('closeIvModal').addEventListener('click', closeAddIvModal); | |
| document.getElementById('cancelIvBtn').addEventListener('click', closeAddIvModal); | |
| document.getElementById('ivForm').addEventListener('submit', saveIv); | |
| document.getElementById('closeAlertBtn').addEventListener('click', closeAlertModal); | |
| // IV form dynamic elements | |
| document.getElementById('ivVolume').addEventListener('change', function() { | |
| const customVolume = document.getElementById('customVolume'); | |
| customVolume.classList.toggle('hidden', this.value !== 'custom'); | |
| if (this.value !== 'custom') { | |
| customVolume.value = ''; | |
| } | |
| }); | |
| document.getElementById('rateUnit').addEventListener('change', function() { | |
| const dropFactorContainer = document.getElementById('dropFactorContainer'); | |
| dropFactorContainer.classList.toggle('hidden', this.value !== 'gttsPerMin'); | |
| }); | |
| // Start IV update timer | |
| setInterval(updateAllIvs, 1000); | |
| // Functions | |
| function openAddPatientModal() { | |
| document.getElementById('addPatientModal').classList.remove('hidden'); | |
| document.getElementById('patientName').focus(); | |
| } | |
| function closeAddPatientModal() { | |
| document.getElementById('addPatientModal').classList.add('hidden'); | |
| document.getElementById('patientForm').reset(); | |
| } | |
| function openAddIvModal() { | |
| if (!selectedPatientId) return; | |
| document.getElementById('addIvModal').classList.remove('hidden'); | |
| document.getElementById('ivType').focus(); | |
| } | |
| function closeAddIvModal() { | |
| document.getElementById('addIvModal').classList.add('hidden'); | |
| document.getElementById('ivForm').reset(); | |
| document.getElementById('customVolume').classList.add('hidden'); | |
| document.getElementById('dropFactorContainer').classList.add('hidden'); | |
| } | |
| function closeAlertModal() { | |
| document.getElementById('alertModal').classList.add('hidden'); | |
| } | |
| function savePatient(e) { | |
| e.preventDefault(); | |
| const name = document.getElementById('patientName').value.trim(); | |
| const room = document.getElementById('patientRoom').value.trim(); | |
| const mrn = document.getElementById('patientMrn').value.trim(); | |
| const patient = { | |
| id: Date.now().toString(), | |
| name, | |
| room, | |
| mrn, | |
| ivs: [], | |
| history: [] | |
| }; | |
| patients.push(patient); | |
| saveToLocalStorage(); | |
| renderPatientList(); | |
| selectPatient(patient.id); | |
| closeAddPatientModal(); | |
| } | |
| function saveIv(e) { | |
| e.preventDefault(); | |
| const type = document.getElementById('ivType').value; | |
| let volume = document.getElementById('ivVolume').value; | |
| if (volume === 'custom') { | |
| volume = document.getElementById('customVolume').value; | |
| } | |
| const rate = parseFloat(document.getElementById('ivRate').value); | |
| const rateUnit = document.getElementById('rateUnit').value; | |
| const dropFactor = rateUnit === 'gttsPerMin' ? parseInt(document.getElementById('dropFactor').value) : null; | |
| const startTime = document.getElementById('ivStartTime').value; | |
| // Calculate rate in mL/hr (standardize for calculations) | |
| let rateMlPerHour; | |
| if (rateUnit === 'mlPerHour') { | |
| rateMlPerHour = rate; | |
| } else { | |
| // Convert gtts/min to mL/hr: (gtts/min) * (60 min/hr) / (gtts/mL) | |
| rateMlPerHour = (rate * 60) / dropFactor; | |
| } | |
| const iv = { | |
| id: Date.now().toString(), | |
| type, | |
| volume: parseInt(volume), | |
| rate, | |
| rateUnit, | |
| rateMlPerHour, | |
| dropFactor, | |
| startTime, | |
| remainingVolume: parseInt(volume), | |
| status: 'active', | |
| completedTime: null | |
| }; | |
| const patient = patients.find(p => p.id === selectedPatientId); | |
| if (patient) { | |
| patient.ivs.push(iv); | |
| saveToLocalStorage(); | |
| renderPatientTracking(patient); | |
| closeAddIvModal(); | |
| } | |
| } | |
| function renderPatientList() { | |
| const patientList = document.getElementById('patientList'); | |
| const emptyPatientList = document.getElementById('emptyPatientList'); | |
| if (patients.length === 0) { | |
| emptyPatientList.classList.remove('hidden'); | |
| patientList.innerHTML = ''; | |
| return; | |
| } | |
| emptyPatientList.classList.add('hidden'); | |
| patientList.innerHTML = ''; | |
| patients.forEach(patient => { | |
| const activeIvs = patient.ivs.filter(iv => iv.status === 'active').length; | |
| const patientCard = document.createElement('div'); | |
| patientCard.className = `bg-white border rounded-lg p-4 cursor-pointer hover:border-blue-500 transition-colors ${selectedPatientId === patient.id ? 'border-blue-500 bg-blue-50' : 'border-gray-200'}`; | |
| patientCard.dataset.patientId = patient.id; | |
| patientCard.innerHTML = ` | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <h3 class="font-medium text-gray-800">${patient.name}</h3> | |
| <p class="text-sm text-gray-500">${patient.room ? 'Room ' + patient.room : ''} ${patient.mrn ? '| MR# ' + patient.mrn : ''}</p> | |
| </div> | |
| ${activeIvs > 0 ? `<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full">${activeIvs} active IV${activeIvs > 1 ? 's' : ''}</span>` : ''} | |
| </div> | |
| `; | |
| patientCard.addEventListener('click', () => selectPatient(patient.id)); | |
| patientList.appendChild(patientCard); | |
| }); | |
| } | |
| function selectPatient(patientId) { | |
| selectedPatientId = patientId; | |
| const patient = patients.find(p => p.id === patientId); | |
| if (patient) { | |
| document.getElementById('noPatientSelected').classList.add('hidden'); | |
| document.getElementById('patientTrackingPanel').classList.remove('hidden'); | |
| document.getElementById('selectedPatientName').textContent = patient.name; | |
| let info = []; | |
| if (patient.room) info.push(`Room: ${patient.room}`); | |
| if (patient.mrn) info.push(`MR#: ${patient.mrn}`); | |
| document.getElementById('selectedPatientInfo').textContent = info.join(' | '); | |
| renderPatientTracking(patient); | |
| } | |
| // Update patient list to show selected state | |
| renderPatientList(); | |
| } | |
| function renderPatientTracking(patient) { | |
| const currentIvs = document.getElementById('currentIvs'); | |
| const emptyIvList = document.getElementById('emptyIvList'); | |
| const ivHistory = document.getElementById('ivHistory'); | |
| // Clear existing IVs | |
| currentIvs.innerHTML = ''; | |
| // Filter active IVs | |
| const activeIvs = patient.ivs.filter(iv => iv.status === 'active'); | |
| if (activeIvs.length === 0) { | |
| emptyIvList.classList.remove('hidden'); | |
| } else { | |
| emptyIvList.classList.add('hidden'); | |
| activeIvs.forEach(iv => { | |
| const ivCard = createIvCard(iv, patient); | |
| currentIvs.appendChild(ivCard); | |
| }); | |
| } | |
| // Show/hide history section if there are completed IVs | |
| const completedIvs = patient.ivs.filter(iv => iv.status === 'completed'); | |
| if (completedIvs.length > 0) { | |
| ivHistory.classList.remove('hidden'); | |
| renderIvHistory(completedIvs); | |
| } else { | |
| ivHistory.classList.add('hidden'); | |
| } | |
| saveToLocalStorage(); | |
| } | |
| function createIvCard(iv, patient) { | |
| // Calculate current progress | |
| const progress = ((iv.volume - iv.remainingVolume) / iv.volume) * 100; | |
| const remainingTime = calculateRemainingTime(iv); | |
| const ivCard = document.createElement('div'); | |
| ivCard.className = 'bg-white border border-gray-200 rounded-lg p-4 shadow-sm'; | |
| ivCard.dataset.ivId = iv.id; | |
| ivCard.innerHTML = ` | |
| <div class="flex justify-between items-start mb-3"> | |
| <div> | |
| <h3 class="font-medium text-gray-800">${iv.type}</h3> | |
| <p class="text-sm text-gray-500">${iv.volume} mL | ${iv.rate} ${iv.rateUnit === 'mlPerHour' ? 'mL/hr' : 'gtts/min'}</p> | |
| </div> | |
| <div class="text-right"> | |
| <p class="text-sm font-medium ${progress > 90 ? 'text-red-600' : progress > 70 ? 'text-yellow-600' : 'text-green-600'}"> | |
| ${Math.round(progress)}% complete | |
| </p> | |
| <p class="text-xs text-gray-500">${remainingTime}</p> | |
| </div> | |
| </div> | |
| <div class="mb-4"> | |
| <div class="h-4 w-full bg-gray-200 rounded-full overflow-hidden"> | |
| <div class="h-full progress-gradient" style="width: ${progress}%"></div> | |
| </div> | |
| <div class="flex justify-between text-xs text-gray-500 mt-1"> | |
| <span>${iv.remainingVolume} mL remaining</span> | |
| <span>Started: ${formatTime(iv.startTime)}</span> | |
| </div> | |
| </div> | |
| <div class="flex justify-between items-center"> | |
| <div class="text-sm"> | |
| <span class="font-medium">Rate:</span> | |
| <input type="number" value="${iv.rate}" min="1" class="w-16 ml-2 px-2 py-1 border border-gray-300 rounded" data-rate-input> | |
| <select class="ml-2 px-2 py-1 border border-gray-300 rounded" data-rate-unit> | |
| <option value="mlPerHour" ${iv.rateUnit === 'mlPerHour' ? 'selected' : ''}>mL/hr</option> | |
| <option value="gttsPerMin" ${iv.rateUnit === 'gttsPerMin' ? 'selected' : ''}>gtts/min</option> | |
| </select> | |
| ${iv.rateUnit === 'gttsPerMin' ? ` | |
| <span class="ml-2">Drop factor:</span> | |
| <select class="ml-2 px-2 py-1 border border-gray-300 rounded" data-drop-factor> | |
| <option value="10" ${iv.dropFactor === 10 ? 'selected' : ''}>10</option> | |
| <option value="15" ${iv.dropFactor === 15 ? 'selected' : ''}>15</option> | |
| <option value="20" ${iv.dropFactor === 20 ? 'selected' : ''}>20</option> | |
| <option value="60" ${iv.dropFactor === 60 ? 'selected' : ''}>60</option> | |
| </select> | |
| ` : ''} | |
| </div> | |
| <div class="space-x-2"> | |
| <button class="px-3 py-1 bg-gray-100 text-gray-700 rounded hover:bg-gray-200 text-sm" data-save-rate> | |
| <i data-feather="save" class="w-4 h-4"></i> | |
| </button> | |
| <button class="px-3 py-1 bg-green-100 text-green-700 rounded hover:bg-green-200 text-sm" data-complete-iv> | |
| <i data-feather="check" class="w-4 h-4"></i> Complete | |
| </button> | |
| </div> | |
| </div> | |
| `; | |
| // Add event listeners for dynamic elements | |
| const saveRateBtn = ivCard.querySelector('[data-save-rate]'); | |
| const completeBtn = ivCard.querySelector('[data-complete-iv]'); | |
| const rateInput = ivCard.querySelector('[data-rate-input]'); | |
| const rateUnitSelect = ivCard.querySelector('[data-rate-unit]'); | |
| const dropFactorSelect = ivCard.querySelector('[data-drop-factor]'); | |
| saveRateBtn.addEventListener('click', () => { | |
| const newRate = parseFloat(rateInput.value); | |
| const newRateUnit = rateUnitSelect.value; | |
| let newDropFactor = iv.dropFactor; | |
| if (newRateUnit === 'gttsPerMin' && dropFactorSelect) { | |
| newDropFactor = parseInt(dropFactorSelect.value); | |
| } | |
| // Calculate new rate in mL/hr | |
| let newRateMlPerHour; | |
| if (newRateUnit === 'mlPerHour') { | |
| newRateMlPerHour = newRate; | |
| } else { | |
| newRateMlPerHour = (newRate * 60) / newDropFactor; | |
| } | |
| // Update IV | |
| const patientIndex = patients.findIndex(p => p.id === patient.id); | |
| if (patientIndex !== -1) { | |
| const ivIndex = patients[patientIndex].ivs.findIndex(i => i.id === iv.id); | |
| if (ivIndex !== -1) { | |
| patients[patientIndex].ivs[ivIndex].rate = newRate; | |
| patients[patientIndex].ivs[ivIndex].rateUnit = newRateUnit; | |
| patients[patientIndex].ivs[ivIndex].dropFactor = newDropFactor; | |
| patients[patientIndex].ivs[ivIndex].rateMlPerHour = newRateMlPerHour; | |
| saveToLocalStorage(); | |
| renderPatientTracking(patient); | |
| } | |
| } | |
| }); | |
| completeBtn.addEventListener('click', () => { | |
| completeIv(iv.id, patient.id); | |
| }); | |
| // Update feather icons | |
| setTimeout(() => { | |
| feather.replace(); | |
| }, 0); | |
| return ivCard; | |
| } | |
| function renderIvHistory(completedIvs) { | |
| const historyTableBody = document.getElementById('historyTableBody'); | |
| historyTableBody.innerHTML = ''; | |
| // Sort by completed time (newest first) | |
| completedIvs.sort((a, b) => new Date(b.completedTime) - new Date(a.completedTime)); | |
| completedIvs.forEach(iv => { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = ` | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${iv.type}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${iv.volume} mL</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${iv.rate} ${iv.rateUnit === 'mlPerHour' ? 'mL/hr' : 'gtts/min'}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${formatTime(iv.startTime)}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${formatTime(iv.completedTime)}</td> | |
| `; | |
| historyTableBody.appendChild(row); | |
| }); | |
| } | |
| function completeIv(ivId, patientId) { | |
| const now = new Date(); | |
| const completedTime = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`; | |
| const patientIndex = patients.findIndex(p => p.id === patientId); | |
| if (patientIndex !== -1) { | |
| const ivIndex = patients[patientIndex].ivs.findIndex(i => i.id === ivId); | |
| if (ivIndex !== -1) { | |
| // Move to history | |
| const completedIv = { | |
| ...patients[patientIndex].ivs[ivIndex], | |
| status: 'completed', | |
| completedTime, | |
| remainingVolume: 0 | |
| }; | |
| patients[patientIndex].history.push(completedIv); | |
| patients[patientIndex].ivs.splice(ivIndex, 1); | |
| saveToLocalStorage(); | |
| const patient = patients.find(p => p.id === patientId); | |
| if (patient) { | |
| renderPatientTracking(patient); | |
| } | |
| } | |
| } | |
| } | |
| function updateAllIvs() { | |
| if (!selectedPatientId) return; | |
| const patient = patients.find(p => p.id === selectedPatientId); | |
| if (!patient) return; | |
| let needsUpdate = false; | |
| let newAlerts = []; | |
| // Update each active IV | |
| patient.ivs.forEach(iv => { | |
| if (iv.status === 'active') { | |
| const startDateTime = new Date(); | |
| const [startHours, startMinutes] = iv.startTime.split(':').map(Number); | |
| startDateTime.setHours(startHours, startMinutes, 0, 0); | |
| const now = new Date(); | |
| const elapsedHours = (now - startDateTime) / (1000 * 60 * 60); | |
| // Calculate infused volume | |
| const infusedVolume = elapsedHours * iv.rateMlPerHour; | |
| const remainingVolume = Math.max(0, iv.volume - infusedVolume); | |
| // Check if remaining volume has changed | |
| if (Math.abs(iv.remainingVolume - remainingVolume) > 0.1) { | |
| iv.remainingVolume = remainingVolume; | |
| needsUpdate = true; | |
| // Check for alerts (less than 10% remaining) | |
| if (remainingVolume < iv.volume * 0.1 && !alerts.includes(iv.id)) { | |
| newAlerts.push(iv.id); | |
| } | |
| } | |
| } | |
| }); | |
| // Save updates if needed | |
| if (needsUpdate) { | |
| saveToLocalStorage(); | |
| renderPatientTracking(patient); | |
| } | |
| // Show alerts if any | |
| if (newAlerts.length > 0) { | |
| alerts = [...new Set([...alerts, ...newAlerts])]; | |
| showAlert(patient, newAlerts); | |
| } | |
| } | |
| function showAlert(patient, ivIds) { | |
| const ivNames = ivIds.map(id => { | |
| const iv = patient.ivs.find(i => i.id === id); | |
| return iv ? iv.type : ''; | |
| }).filter(name => name); | |
| if (ivNames.length > 0) { | |
| document.getElementById('alertTitle').textContent = `IV Nearly Complete (${patient.name})`; | |
| document.getElementById('alertMessage').textContent = | |
| `${ivNames.join(', ')} ${ivNames.length > 1 ? 'are' : 'is'} nearly finished (less than 10% remaining). Please check and replace if needed.`; | |
| document.getElementById('alertModal').classList.remove('hidden'); | |
| } | |
| } | |
| function calculateRemainingTime(iv) { | |
| if (iv.remainingVolume <= 0) return 'Completed'; | |
| const remainingHours = iv.remainingVolume / iv.rateMlPerHour; | |
| const hours = Math.floor(remainingHours); | |
| const minutes = Math.round((remainingHours - hours) * 60); | |
| if (hours > 0) { | |
| return `${hours}h ${minutes}m remaining`; | |
| } else { | |
| return `${minutes}m remaining`; | |
| } | |
| } | |
| function formatTime(timeString) { | |
| if (!timeString) return ''; | |
| const [hours, minutes] = timeString.split(':'); | |
| const hour = parseInt(hours); | |
| const ampm = hour >= 12 ? 'PM' : 'AM'; | |
| const hour12 = hour % 12 || 12; | |
| return `${hour12}:${minutes} ${ampm}`; | |
| } | |
| function saveToLocalStorage() { | |
| localStorage.setItem('ivTrackerPatients', JSON.stringify(patients)); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> | |