import React, { useState, useEffect } from 'react'; import { Clock, User, Bell, CheckCircle, AlertCircle, Plus, X, ChevronRight, Activity } from 'lucide-react'; const ClinicQueueManager = () => { const [view, setView] = useState('receptionist'); const [patients, setPatients] = useState([]); const [showAddForm, setShowAddForm] = useState(false); const [formData, setFormData] = useState({ name: '', phone: '', appointmentTime: '', reason: '' }); // Load patients from storage on mount useEffect(() => { const loadPatients = async () => { try { const result = await window.storage.get('clinic-patients'); if (result && result.value) { setPatients(JSON.parse(result.value)); } } catch (error) { console.log('No existing patients found'); } }; loadPatients(); }, []); // Save patients to storage whenever they change useEffect(() => { const savePatients = async () => { if (patients.length > 0) { try { await window.storage.set('clinic-patients', JSON.stringify(patients)); } catch (error) { console.error('Error saving patients:', error); } } }; savePatients(); }, [patients]); const addPatient = () => { if (formData.name && formData.phone && formData.appointmentTime) { const newPatient = { id: Date.now(), ...formData, status: 'scheduled', addedAt: new Date().toISOString() }; setPatients([...patients, newPatient]); setFormData({ name: '', phone: '', appointmentTime: '', reason: '' }); setShowAddForm(false); } }; const checkInPatient = (id) => { setPatients(patients.map(p => p.id === id ? { ...p, status: 'waiting', checkedInAt: new Date().toISOString() } : p )); }; const callNextPatient = () => { const nextPatient = patients.find(p => p.status === 'waiting'); if (nextPatient) { setPatients(patients.map(p => p.id === nextPatient.id ? { ...p, status: 'in-consultation', calledAt: new Date().toISOString() } : p )); } }; const completeConsultation = (id) => { setPatients(patients.map(p => p.id === id ? { ...p, status: 'completed', completedAt: new Date().toISOString() } : p )); }; const sendReminder = (patient) => { alert(`Reminder sent to ${patient.name} at ${patient.phone}\n\n"Your appointment is scheduled for ${patient.appointmentTime}. Please arrive 10 minutes early."`); }; const deletePatient = (id) => { setPatients(patients.filter(p => p.id !== id)); }; const getStatusColor = (status) => { switch(status) { case 'scheduled': return 'bg-gradient-to-r from-blue-500 to-cyan-500 text-white'; case 'waiting': return 'bg-gradient-to-r from-amber-500 to-orange-500 text-white'; case 'in-consultation': return 'bg-gradient-to-r from-emerald-500 to-teal-500 text-white'; case 'completed': return 'bg-gradient-to-r from-slate-400 to-slate-500 text-white'; default: return 'bg-gradient-to-r from-slate-400 to-slate-500 text-white'; } }; const getStatusIcon = (status) => { switch(status) { case 'scheduled': return ; case 'waiting': return ; case 'in-consultation': return ; case 'completed': return ; default: return ; } }; const formatStatus = (status) => { return status.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); }; const waitingPatients = patients.filter(p => p.status === 'waiting'); const activePatient = patients.find(p => p.status === 'in-consultation'); const todayPatients = patients.filter(p => p.status !== 'completed'); return (
{/* Header */}

Clinic Queue Manager

Real-time patient flow management

{/* Main Content */}
{view === 'receptionist' ? (
{/* Stats */}
Total Today
{todayPatients.length}
Waiting
{waitingPatients.length}
In Consultation
{activePatient ? 1 : 0}
Completed
{patients.filter(p => p.status === 'completed').length}
{/* Add Patient Button */}
{/* Add Patient Form */} {showAddForm && (

Add New Patient

setFormData({...formData, name: e.target.value})} className="px-4 py-3 bg-white border-2 border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-200" /> setFormData({...formData, phone: e.target.value})} className="px-4 py-3 bg-white border-2 border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-200" /> setFormData({...formData, appointmentTime: e.target.value})} className="px-4 py-3 bg-white border-2 border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-200" /> setFormData({...formData, reason: e.target.value})} className="px-4 py-3 bg-white border-2 border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-200" />
)} {/* Patient Queue */}

Patient Queue

Manage today's appointments

{todayPatients.length === 0 ? (

No patients scheduled today

) : ( todayPatients.map((patient, index) => (
{patient.name} {getStatusIcon(patient.status)} {formatStatus(patient.status)}
Appointment: {patient.appointmentTime}
Phone: {patient.phone}
{patient.reason && (
Reason: {patient.reason}
)}
{patient.status === 'scheduled' && ( <> )} {patient.status !== 'completed' && ( )}
)) )}
) : (
{/* Current Patient */} {activePatient && (

Current Patient in Consultation

{activePatient.name}
Phone: {activePatient.phone}
Appointment: {activePatient.appointmentTime}
{activePatient.reason && (
Reason: {activePatient.reason}
)}
)} {/* Waiting Queue */}

Waiting Queue

{waitingPatients.length} patients waiting

{!activePatient && waitingPatients.length > 0 && ( )}
{waitingPatients.length === 0 ? (

No patients waiting

) : ( waitingPatients.map((patient, index) => (
{index + 1}
{patient.name}
Appointment: {patient.appointmentTime}
{patient.reason && (
Reason: {patient.reason}
)}
)) )}
)}
); }; export default ClinicQueueManager;