diff --git a/app/Controllers/Api/v1/DoctorApi.php b/app/Controllers/Api/v1/DoctorApi.php index d40eaa9..a94fef8 100644 --- a/app/Controllers/Api/v1/DoctorApi.php +++ b/app/Controllers/Api/v1/DoctorApi.php @@ -167,43 +167,54 @@ class DoctorApi extends BaseController $db = db_connect(); helper('common'); - $sql = "SELECT o.opd_id, o.opd_code, o.opd_no, o.opd_status, o.apointment_date, - o.opd_fee_desc, o.opd_fee_amount, o.payment_status, o.opd_fee_type, - coalesce(o.running_opd, 0) as running_opd, - p.id as p_id, p.p_code, p.p_fname as P_name, p.gender, p.age, p.age_in_month, p.estimate_dob, p.dob, p.mphone1, - (CASE - WHEN (coalesce(o.running_opd,0)=1 OR o.opd_fee_type=3 OR UPPER(coalesce(o.opd_fee_desc,'')) LIKE '%RUNNING%') THEN 'Running' - WHEN o.payment_mode=4 THEN 'Credit to ECHS' - WHEN o.payment_status=1 AND o.payment_mode=0 THEN 'No Cost' - WHEN o.payment_mode=1 THEN 'Cash' - WHEN o.payment_mode=2 THEN 'Bank Card' - ELSE 'Pending' - END) as opd_type, - IF(pr.id IS NULL, 0, 1) as has_prescription, - coalesce(pr.queue_no, 0) as queue_no - FROM opd_master o - JOIN patient_master p ON o.p_id = p.id - LEFT JOIN opd_prescription pr ON o.opd_id = pr.opd_id"; + $dateMode = $this->request->getGet('date_mode') ?? 'today'; // 'today' or 'all' + + $baseSql = "SELECT o.opd_id, o.opd_code, o.opd_no, o.opd_status, o.apointment_date, + o.opd_fee_desc, o.opd_fee_amount, o.payment_status, o.opd_fee_type, + coalesce(o.running_opd, 0) as running_opd, + p.id as p_id, p.p_code, p.p_fname as P_name, p.gender, p.age, p.age_in_month, p.estimate_dob, p.dob, p.mphone1, + (CASE + WHEN (coalesce(o.running_opd,0)=1 OR o.opd_fee_type=3 OR UPPER(coalesce(o.opd_fee_desc,'')) LIKE '%RUNNING%') THEN 'Running' + WHEN o.payment_mode=4 THEN 'Credit to ECHS' + WHEN o.payment_status=1 AND o.payment_mode=0 THEN 'No Cost' + WHEN o.payment_mode=1 THEN 'Cash' + WHEN o.payment_mode=2 THEN 'Bank Card' + ELSE 'Pending' + END) as opd_type, + IF(pr.id IS NULL, 0, 1) as has_prescription, + coalesce(pr.queue_no, 0) as queue_no + FROM opd_master o + JOIN patient_master p ON o.p_id = p.id + LEFT JOIN opd_prescription pr ON o.opd_id = pr.opd_id + WHERE 1=1"; if ($docId > 0) { - $sql .= " WHERE o.doc_id = " . (int) $docId; + $baseSql .= " AND o.doc_id = " . (int) $docId; } - $sql .= " ORDER BY o.opd_id DESC LIMIT 100"; + $sqlToday = $baseSql . " AND DATE(o.apointment_date) = CURDATE() ORDER BY o.opd_id DESC LIMIT 100"; + $sqlAll = $baseSql . " ORDER BY o.opd_id DESC LIMIT 100"; - $query = $db->query($sql); - $allRows = $query->getResultArray(); + $queryToday = $db->query($sqlToday); + $todayRows = $queryToday->getResultArray(); + + $queryAll = $db->query($sqlAll); + $allRows = $queryAll->getResultArray(); + + $targetRows = ($dateMode === 'today') ? $todayRows : $allRows; $appointments = []; $counts = [ - 'all' => count($allRows), + 'all' => count($targetRows), 'booked' => 0, 'waiting' => 0, 'visited' => 0, 'cancelled' => 0, + 'today_total' => count($todayRows), + 'all_total' => count($allRows), ]; - foreach ($allRows as $r) { + foreach ($targetRows as $r) { $statusInt = (int) ($r['opd_status'] ?? 0); $statusText = 'waiting'; if ($statusInt === 0) { @@ -245,6 +256,7 @@ class DoctorApi extends BaseController return $this->response->setJSON([ 'status' => 1, 'doctor_id' => $docId, + 'date_mode' => $dateMode, 'counts' => $counts, 'appointments' => $appointments, ]); diff --git a/public/App/Doctor/index.html b/public/App/Doctor/index.html index a9b7b76..cc67004 100644 --- a/public/App/Doctor/index.html +++ b/public/App/Doctor/index.html @@ -284,10 +284,15 @@ function DoctorApp() { const [doctors, setDoctors] = useState([]); - const [ipdPatients, setIpdPatients] = useState([]); + const [myIpdPatients, setMyIpdPatients] = useState([]); + const [allIpdPatients, setAllIpdPatients] = useState([]); + const [ipdViewMode, setIpdViewMode] = useState('mine'); // 'mine' or 'all' + const [opdAppointments, setOpdAppointments] = useState([]); const [opdCounts, setOpdCounts] = useState({ all: 0, waiting: 0, visited: 0, booked: 0, cancelled: 0 }); const [opdFilter, setOpdFilter] = useState('all'); + const [opdDateMode, setOpdDateMode] = useState('today'); // 'today' or 'all' + const [loading, setLoading] = useState(true); const [searchQuery, setSearchQuery] = useState(''); const [mainTab, setMainTab] = useState('opd'); @@ -362,7 +367,8 @@ const res = await fetch(`/api/v1/doctor/ipd/list/${docId || 0}`); const json = await res.json(); if (json.status === 1) { - setIpdPatients(json.patients || []); + setAllIpdPatients(json.all_patients || json.patients || []); + setMyIpdPatients(json.patients || []); } } catch (err) { console.error('Failed to load IPD patients', err); @@ -371,9 +377,10 @@ } }; - const fetchOpdAppointments = async (docId) => { + const fetchOpdAppointments = async (docId, dateModeOverride) => { try { - const res = await fetch(`/api/v1/doctor/opd/list/${docId || 0}`); + const mode = dateModeOverride || opdDateMode; + const res = await fetch(`/api/v1/doctor/opd/list/${docId || 0}?date_mode=${mode}`); const json = await res.json(); if (json.status === 1) { setOpdAppointments(json.appointments || []); @@ -394,7 +401,7 @@ if (parsed && parsed.doctor && parsed.expires_at > Date.now()) { setAuthenticatedDoctor(parsed.doctor); fetchIpdPatients(parsed.doctor.id); - fetchOpdAppointments(parsed.doctor.id); + fetchOpdAppointments(parsed.doctor.id, opdDateMode); } else { localStorage.removeItem(DOC_DEVICE_AUTH_KEY); } @@ -447,7 +454,7 @@ localStorage.setItem(DOC_DEVICE_AUTH_KEY, JSON.stringify(deviceAuthObj)); setPinInput(''); fetchIpdPatients(json.doctor.id); - fetchOpdAppointments(json.doctor.id); + fetchOpdAppointments(json.doctor.id, opdDateMode); } else if (json.status === 2) { setIsSettingNewPin(true); } else { @@ -605,7 +612,7 @@ if (json.status === 1) { alert(json.message || 'Prescription saved & OPD Visit completed!'); setActiveOpd(null); - fetchOpdAppointments(authenticatedDoctor ? authenticatedDoctor.id : 0); + fetchOpdAppointments(authenticatedDoctor ? authenticatedDoctor.id : 0, opdDateMode); } else { alert(json.message || 'Failed to save prescription'); } @@ -648,7 +655,8 @@ return matchesFilter && matchesSearch; }); - const filteredIpdPatients = ipdPatients.filter(pat => { + const activeIpdSource = (ipdViewMode === 'mine') ? myIpdPatients : allIpdPatients; + const filteredIpdPatients = activeIpdSource.filter(pat => { const q = searchQuery.toLowerCase(); const name = (pat.patient_display_name || pat.fname || '').toLowerCase(); const uhid = (pat.uhid || '').toLowerCase(); @@ -773,7 +781,7 @@
-
{mainTab === 'opd' ? (
+ {/* Date Filter Segmented Bar (Current Date vs All Dates) */} +
+
+ + +
+ + {opdDateMode === 'today' ? '● Current Date Only' : '● All Appointments'} + +
+ {/* Status Filter Pills Bar */}
) : ( filteredOpdAppointments.map(app => { @@ -969,9 +1000,30 @@
) : ( /* ------------------------------------------------------------- - ADMITTED IPD PATIENTS LIST (ASSIGNED TO DOCTOR) + ADMITTED IPD PATIENTS LIST (ASSIGNED TO DOCTOR / ALL ADMISSIONS) ------------------------------------------------------------- */
+ {/* IPD Admission View Mode Segmented Bar */} +
+
+ + +
+ + {ipdViewMode === 'mine' ? '● Doctor Assignments' : '● Hospital Wide IPDs'} + +
+ {/* Search Input Bar */}
@@ -1020,6 +1072,9 @@ {pat.uhid} + + {pat.assigned_doctors || pat.r_doc_name || `Dr. ${authenticatedDoctor.name}`} +