Lokasi:
/
home
/
u847703118
/
domains
/
alphamed.cloud
/
public_html
/
Ubah: my_results.php
<?php session_start(); if(!isset($_SESSION["patient_id"])) { header("Location: patient_login.php"); exit(); } require('db_connect.php'); $patient_id = $_SESSION['patient_id']; $reservation_message = ''; $reservation_error = ''; $reservation_reference = ''; $last_queue_details = null; $patient_email = ''; $patient_phone = ''; try { $patient_stmt = $pdo->prepare("SELECT email, phone FROM patients WHERE id = ?"); $patient_stmt->execute([$patient_id]); $patient_row = $patient_stmt->fetch(PDO::FETCH_ASSOC); if ($patient_row) { $patient_email = $patient_row['email'] ?? ''; $patient_phone = $patient_row['phone'] ?? ''; } } catch (Exception $e) { $patient_email = ''; $patient_phone = ''; } $requires_contact = ($patient_email === '' || $patient_phone === ''); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['reserve_slot_id'])) { $slot_id = intval($_POST['reserve_slot_id']); $initial_condition = trim($_POST['initial_condition'] ?? ''); $contact_email = $patient_email; $contact_phone = $patient_phone; if ($requires_contact) { $contact_email = trim($_POST['contact_email'] ?? ''); $contact_phone = trim($_POST['contact_phone'] ?? ''); if ($contact_email === '' || $contact_phone === '') { $reservation_error = 'Please provide your email address and cellphone number to continue.'; } else { try { $upd = $pdo->prepare("UPDATE patients SET email = ?, phone = ? WHERE id = ?"); $upd->execute([$contact_email, $contact_phone, $patient_id]); $patient_email = $contact_email; $patient_phone = $contact_phone; $requires_contact = false; } catch (Exception $e) { $reservation_error = 'Unable to update contact information.'; } } } if ($reservation_error === '' && $slot_id > 0 && tableExists($pdo, 'clinic_reservations')) { try { $stmt = $pdo->prepare("SELECT * FROM clinic_reservations WHERE id = ? AND patient_id IS NULL"); $stmt->execute([$slot_id]); $slot = $stmt->fetch(); if ($slot) { $maxPatientsPerDoctorPerDay = 20; $stmtDoctorCap = $pdo->prepare("SELECT COUNT(*) FROM clinic_reservations WHERE doctor_id = ? AND reservation_date = ? AND patient_id IS NOT NULL"); $stmtDoctorCap->execute([$slot['doctor_id'], $slot['reservation_date']]); $totalBookedForDoctor = (int)$stmtDoctorCap->fetchColumn(); if ($totalBookedForDoctor >= $maxPatientsPerDoctorPerDay) { $reservation_error = 'This doctor is fully booked for this date.'; } else { $maxPerDayPerDoctor = 1; $stmtLimit = $pdo->prepare("SELECT COUNT(*) FROM clinic_reservations WHERE doctor_id = ? AND reservation_date = ? AND patient_id = ?"); $stmtLimit->execute([$slot['doctor_id'], $slot['reservation_date'], $patient_id]); $existingCount = (int)$stmtLimit->fetchColumn(); if ($existingCount >= $maxPerDayPerDoctor) { $reservation_error = 'You already have a clinic reservation with this doctor on this date.'; } else { $branchVal = $slot['branch'] ?? null; $hasBranch = false; if (function_exists('tableHasColumn')) { $hasBranch = tableHasColumn($pdo, 'clinic_reservations', 'branch'); } if ($hasBranch) { $stmtIns = $pdo->prepare( "INSERT INTO clinic_reservations (room_id, doctor_id, patient_id, reservation_date, start_time, end_time, notes, initial_condition, branch) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" ); $stmtIns->execute([ $slot['room_id'], $slot['doctor_id'], $patient_id, $slot['reservation_date'], $slot['start_time'], $slot['end_time'], $slot['notes'], $initial_condition, $branchVal ]); } else { $stmtIns = $pdo->prepare( "INSERT INTO clinic_reservations (room_id, doctor_id, patient_id, reservation_date, start_time, end_time, notes, initial_condition) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ); $stmtIns->execute([ $slot['room_id'], $slot['doctor_id'], $patient_id, $slot['reservation_date'], $slot['start_time'], $slot['end_time'], $slot['notes'], $initial_condition ]); } if ($stmtIns->rowCount() > 0) { $reservation_reference = $pdo->lastInsertId(); if ($reservation_reference) { $reservation_message = 'Reservation submitted. Waiting for clinic confirmation. Reference No.: ' . $reservation_reference; } else { $reservation_message = 'Reservation submitted. Waiting for clinic confirmation.'; } } else { $reservation_error = 'Selected slot is no longer available.'; } } } } else { $reservation_error = 'Selected slot is no longer available.'; } } catch (Exception $e) { $reservation_error = 'Unable to process reservation.'; } } elseif ($reservation_error === '') { $reservation_error = 'Invalid reservation slot.'; } } // Fetch Company Settings $company_sql = "SELECT * FROM company_settings LIMIT 1"; $company_stmt = $pdo->query($company_sql); $company = $company_stmt->fetch(); $theme_color = $company['theme_color'] ?? '#198754'; $company_name = $company['company_name'] ?? 'Diagnostic Center'; $company_logo = $company['company_logo'] ?? ''; $balance = 0; try { $b_stmt = $pdo->prepare("SELECT account_balance FROM patients WHERE id = ?"); $b_stmt->execute([$patient_id]); $balance = $b_stmt->fetchColumn() ?: 0; } catch (Exception $e) { $balance = 0; } $points = 0; $allowed_views = ['dashboard', 'results', 'wallet', 'book']; $view = $_GET['view'] ?? 'dashboard'; if (!in_array($view, $allowed_views, true)) { $view = 'dashboard'; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Results - <?php echo htmlspecialchars($company_name); ?></title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css"> <style> .bg-custom-theme { background-color: <?php echo htmlspecialchars($theme_color); ?> !important; } .text-custom-theme { color: <?php echo htmlspecialchars($theme_color); ?> !important; } .border-custom-theme { border-color: <?php echo htmlspecialchars($theme_color); ?> !important; } </style> </head> <body class="bg-light"> <nav class="navbar navbar-expand-lg navbar-dark bg-custom-theme mb-4"> <div class="container"> <a class="navbar-brand d-flex align-items-center" href="#"> <?php if (!empty($company_logo) && file_exists($company_logo)): ?> <img src="<?php echo htmlspecialchars($company_logo); ?>" alt="Logo" width="30" height="30" class="d-inline-block align-text-top me-2 rounded bg-white"> <?php else: ?> <i class="bi bi-hospital me-2"></i> <?php endif; ?> <?php echo htmlspecialchars($company_name); ?> </a> <div class="d-flex text-white"> <span class="me-3 align-self-center">Hello, <?php echo htmlspecialchars($_SESSION['patient_name']); ?></span> <a href="patient_logout.php" class="btn btn-outline-light btn-sm">Logout</a> </div> </div> </nav> <div class="container"> <div class="row"> <div class="col-md-3 mb-3"> <div class="list-group"> <a href="my_results.php?view=dashboard" class="list-group-item list-group-item-action<?php echo $view === 'dashboard' ? ' active' : ''; ?>"> <i class="bi bi-speedometer2 me-2"></i> Dashboard </a> <a href="my_results.php?view=results" class="list-group-item list-group-item-action<?php echo $view === 'results' ? ' active' : ''; ?>"> <i class="bi bi-file-earmark-text me-2"></i> My Result </a> <a href="my_results.php?view=wallet" class="list-group-item list-group-item-action<?php echo $view === 'wallet' ? ' active' : ''; ?>"> <i class="bi bi-wallet2 me-2"></i> My Wallet </a> <a href="my_results.php?view=book" class="list-group-item list-group-item-action<?php echo $view === 'book' ? ' active' : ''; ?>"> <i class="bi bi-calendar-check me-2"></i> Book a Consultation </a> </div> </div> <div class="col-md-9"> <?php if ($view === 'dashboard'): ?> <div class="mb-3" id="patient-dashboard"> <div class="card shadow-sm border-custom-theme"> <div class="card-body"> <div class="d-flex justify-content-between align-items-center mb-3"> <div> <h5 class="mb-0 text-custom-theme"><i class="bi bi-speedometer2"></i> Dashboard</h5> <small class="text-muted">Quick glance on your account</small> </div> </div> <div class="row g-3"> <div class="col-sm-6"> <div class="border rounded p-3 h-100"> <div class="text-muted small mb-1">Wallet Balance</div> <div class="h4 mb-0 text-success">₱<?php echo number_format($balance, 2); ?></div> </div> </div> <div class="col-sm-6"> <div class="border rounded p-3 h-100"> <div class="text-muted small mb-1">Points</div> <div class="h4 mb-0 text-primary"><?php echo (int)$points; ?></div> </div> </div> </div> </div> </div> </div> <?php endif; ?> <?php if (in_array($view, ['dashboard', 'wallet'], true)): ?> <div class="row mb-3"> <div class="col-md-12"> <div class="card shadow-sm border-custom-theme" id="patient-wallet"> <div class="card-body d-flex justify-content-between align-items-center"> <div> <h5 class="mb-0 text-custom-theme"><i class="bi bi-wallet2"></i> My Wallet Balance</h5> <small class="text-muted">Available funds for future transactions</small> </div> <h3 class="mb-0 fw-bold text-success">₱<?php echo number_format($balance, 2); ?></h3> </div> </div> </div> </div> <?php endif; ?> <?php if ($view === 'book'): ?> <?php $upcoming_reservations = []; $available_slots = []; $today_date = date('Y-m-d'); $now_time = date('H:i:s'); $queue_now_serving = null; $queue_next = null; if (tableExists($pdo, 'clinic_reservations') && tableExists($pdo, 'clinic_rooms')) { try { $sqlUpcoming = "SELECT r.*, d.name AS doctor_name, d.specialization AS doctor_specialization, c.room_name FROM clinic_reservations r JOIN doctors d ON r.doctor_id = d.id JOIN clinic_rooms c ON r.room_id = c.id WHERE r.patient_id = ? AND (r.reservation_date > ? OR (r.reservation_date = ? AND (r.end_time IS NULL OR r.end_time = '00:00:00' OR r.end_time > ?))) ORDER BY r.reservation_date, r.start_time"; $stmtUpcoming = $pdo->prepare($sqlUpcoming); $stmtUpcoming->execute([$patient_id, $today_date, $today_date, $now_time]); $upcoming_reservations = $stmtUpcoming->fetchAll(); } catch (Exception $e) { $upcoming_reservations = []; } try { $sqlSlots = "SELECT r.*, d.name AS doctor_name, d.specialization AS doctor_specialization, c.room_name FROM clinic_reservations r JOIN doctors d ON r.doctor_id = d.id JOIN clinic_rooms c ON r.room_id = c.id WHERE r.patient_id IS NULL AND c.is_active = 1 AND (r.reservation_date > ? OR (r.reservation_date = ? AND (r.end_time IS NULL OR r.end_time = '00:00:00' OR r.end_time > ?))) ORDER BY r.reservation_date, r.start_time LIMIT 50"; $stmtSlots = $pdo->prepare($sqlSlots); $stmtSlots->execute([$today_date, $today_date, $now_time]); $available_slots = $stmtSlots->fetchAll(); } catch (Exception $e) { $available_slots = []; } try { $sqlLast = "SELECT r.*, d.name AS doctor_name, d.specialization AS doctor_specialization, c.room_name FROM clinic_reservations r JOIN doctors d ON r.doctor_id = d.id JOIN clinic_rooms c ON r.room_id = c.id WHERE r.patient_id = ? AND r.queue_no IS NOT NULL AND (r.reservation_date > ? OR (r.reservation_date = ? AND (r.end_time IS NULL OR r.end_time = '00:00:00' OR r.end_time > ?))) ORDER BY r.reservation_date DESC, r.start_time DESC, r.id DESC LIMIT 1"; $stmtLast = $pdo->prepare($sqlLast); $stmtLast->execute([$patient_id, $today_date, $today_date, $now_time]); $rowLast = $stmtLast->fetch(PDO::FETCH_ASSOC); if ($rowLast) { $last_queue_details = $rowLast; } } catch (Exception $e) { $last_queue_details = null; } try { $sqlQueue = "SELECT r.queue_no, r.reservation_date, d.name AS doctor_name, c.room_name FROM clinic_reservations r JOIN clinic_rooms c ON r.room_id = c.id JOIN doctors d ON r.doctor_id = d.id WHERE r.reservation_date = ? AND r.patient_id IS NOT NULL AND r.is_confirmed = 1 AND (r.is_served IS NULL OR r.is_served = 0) AND (r.end_time IS NULL OR r.end_time = '00:00:00' OR r.end_time > ?) ORDER BY r.queue_no ASC, r.start_time"; $stmtQueue = $pdo->prepare($sqlQueue); $stmtQueue->execute([$today_date, $now_time]); $queue_patients = $stmtQueue->fetchAll(PDO::FETCH_ASSOC); try { // Fetch all active queues (doctors with patients today), showing current progress $sqlQueueStatus = "SELECT r.doctor_id, r.room_id, d.name AS doctor_name, c.room_name, MAX(CASE WHEN r.is_served = 1 THEN r.queue_no ELSE 0 END) as current_queue FROM clinic_reservations r JOIN clinic_rooms c ON r.room_id = c.id JOIN doctors d ON r.doctor_id = d.id WHERE r.reservation_date = ? AND r.patient_id IS NOT NULL AND r.is_confirmed = 1 AND (r.end_time IS NULL OR r.end_time = '00:00:00' OR r.end_time > ?) GROUP BY r.doctor_id, r.room_id, d.name, c.room_name ORDER BY d.name"; $stmtQueueStatus = $pdo->prepare($sqlQueueStatus); $stmtQueueStatus->execute([$today_date, $now_time]); $served_by_doctor = $stmtQueueStatus->fetchAll(PDO::FETCH_ASSOC); // For backward compatibility or "Next" logic if needed $queue_now_serving = null; if (!empty($served_by_doctor)) { // Just pick the first one with a non-zero queue, or the first one foreach ($served_by_doctor as $sbd) { if ($sbd['current_queue'] > 0) { $queue_now_serving = ['queue_no' => $sbd['current_queue']]; break; } } } } catch (Exception $e2) { $queue_now_serving = null; $served_by_doctor = []; } if (!empty($queue_patients)) { // ... (rest of logic can stay, but next patient logic might need adjustment if we want per-doctor next) // For simplicity, let's keep the generic "Next" as the very next globally, or per-doctor if we can match it. // But the UI below shows a single "Now Serving" and "Next". // We should update the UI to loop through $served_by_doctor if possible. if ($queue_now_serving && isset($queue_now_serving['queue_no'])) { $queue_next = null; foreach ($queue_patients as $qp) { if ((int)$qp['queue_no'] !== (int)$queue_now_serving['queue_no']) { // Try to find a next patient for the SAME doctor if possible, or just the next global $queue_next = $qp; break; } } } else { $queue_next = $queue_patients[0]; } } } catch (Exception $e) { $queue_now_serving = null; $queue_next = null; } } ?> <div class="card shadow-sm mb-4" id="book-consultation"> <div class="card-header bg-white d-flex justify-content-between align-items-center"> <h4 class="mb-0">Online Consultation Booking</h4> <small class="text-muted">Book a consultation based on your doctor’s clinic schedule</small> </div> <div class="card-body"> <?php if ($reservation_message): ?> <div class="alert alert-success"><?php echo htmlspecialchars($reservation_message); ?></div> <?php endif; ?> <?php if ($reservation_error): ?> <div class="alert alert-danger"><?php echo htmlspecialchars($reservation_error); ?></div> <?php endif; ?> <div id="patientQueueStatusWrapper" class="mb-3"> <?php if (!empty($served_by_doctor)): ?> <h6 class="text-muted mb-2">Current Queue Status</h6> <div class="row g-3"> <?php foreach ($served_by_doctor as $sbd): ?> <div class="col-md-6 col-lg-4"> <div class="card border-0 bg-light h-100 shadow-sm"> <div class="card-body text-center"> <div class="text-muted small mb-1 text-uppercase">Now Serving</div> <div class="h2 mb-0 text-primary fw-bold"> <?php echo $sbd['current_queue'] > 0 ? (int)$sbd['current_queue'] : '<span class="fs-6 text-muted">Not Started</span>'; ?> </div> <div class="fw-bold mt-1 text-dark"><?php echo htmlspecialchars($sbd['doctor_name']); ?></div> <div class="small text-muted"><?php echo htmlspecialchars($sbd['room_name']); ?></div> </div> </div> </div> <?php endforeach; ?> </div> <?php else: ?> <div class="card border-0 bg-light"> <div class="card-body text-center text-muted"> Queue has not started yet for today. </div> </div> <?php endif; ?> </div> <div id="patientUpcomingWrapper"> <?php if (!empty($upcoming_reservations)): ?> <h5 class="mb-3">My Upcoming Queues</h5> <div class="table-responsive mb-4"> <table class="table table-bordered align-middle"> <thead class="table-light"> <tr> <th>Ref No.</th> <th>Date</th> <th>Doctor</th> <th>Room</th> <th>Queue No.</th> <th>Status</th> <th>Time</th> </tr> </thead> <tbody> <?php foreach ($upcoming_reservations as $res): ?> <tr> <td><?php echo htmlspecialchars($res['id'] ?? ''); ?></td> <td><?php echo date('M d, Y', strtotime($res['reservation_date'])); ?></td> <td> <?php $doctorLabel = $res['doctor_name'] ?? ''; if (!empty($res['doctor_specialization'])) { $doctorLabel .= ' (' . $res['doctor_specialization'] . ')'; } echo htmlspecialchars($doctorLabel); ?> </td> <td><?php echo htmlspecialchars($res['room_name']); ?></td> <td><?php echo $res['queue_no'] ? (int)$res['queue_no'] : '-'; ?></td> <td> <?php $status = 'For confirmation'; if (!empty($res['is_confirmed']) || (!empty($res['queue_no']))) { $status = 'Confirmed'; } echo htmlspecialchars($status); ?> </td> <td> <?php $label = ''; if (!empty($res['start_time'])) { $label = date('h:i A', strtotime($res['start_time'])); if (!empty($res['end_time'])) { $label .= ' - ' . date('h:i A', strtotime($res['end_time'])); } } echo htmlspecialchars($label); ?> </td> </tr> <?php endforeach; ?> </tbody> </table> <div class="text-muted small mt-2"> Note: Schedule may vary depending on the patient flow. </div> </div> <?php endif; ?> </div> <div id="patientAvailableWrapper"> <h5 class="mb-3">Available Clinic Schedule</h5> <?php if (!empty($available_slots)): ?> <div class="row row-cols-1 row-cols-md-2 g-3"> <?php foreach ($available_slots as $slot): ?> <?php $label = ''; if (!empty($slot['start_time'])) { $label = date('h:i A', strtotime($slot['start_time'])); if (!empty($slot['end_time'])) { $label .= ' - ' . date('h:i A', strtotime($slot['end_time'])); } } $doctorDisplay = $slot['doctor_name'] ?? ''; if (!empty($slot['doctor_specialization'])) { $doctorDisplay .= ' (' . $slot['doctor_specialization'] . ')'; } ?> <div class="col"> <div class="card h-100"> <div class="card-body d-flex flex-column"> <div class="mb-2"> <div class="text-muted small">Date</div> <div class="fw-bold"><?php echo date('M d, Y', strtotime($slot['reservation_date'])); ?></div> </div> <div class="mb-2"> <div class="text-muted small">Doctor</div> <div><?php echo htmlspecialchars($doctorDisplay); ?></div> </div> <div class="mb-2"> <div class="text-muted small">Room</div> <div><?php echo htmlspecialchars($slot['room_name']); ?></div> </div> <div class="mb-3"> <div class="text-muted small">Clinic Schedule</div> <div><?php echo htmlspecialchars($label); ?></div> </div> <div class="mt-auto"> <button type="button" class="btn btn-sm btn-primary w-100 book-slot-btn" data-slot-id="<?php echo (int)$slot['id']; ?>" data-slot-date="<?php echo htmlspecialchars(date('M d, Y', strtotime($slot['reservation_date']))); ?>" data-slot-doctor="<?php echo htmlspecialchars($doctorDisplay, ENT_QUOTES); ?>" data-slot-room="<?php echo htmlspecialchars($slot['room_name'], ENT_QUOTES); ?>" data-slot-time="<?php echo htmlspecialchars($label); ?>" > Book Consultation </button> </div> </div> </div> </div> <?php endforeach; ?> </div> <?php else: ?> <div class="text-muted">No available online consultation slots at the moment.</div> <?php endif; ?> </div> <div id="patientQueueCardWrapper"> <?php if ($last_queue_details): ?> <?php $time_label_print = ''; if (!empty($last_queue_details['start_time'])) { $time_label_print = date('h:i A', strtotime($last_queue_details['start_time'])); if (!empty($last_queue_details['end_time'])) { $time_label_print .= ' - ' . date('h:i A', strtotime($last_queue_details['end_time'])); } } $doctorLabelPrint = $last_queue_details['doctor_name'] ?? ''; if (!empty($last_queue_details['doctor_specialization'])) { $doctorLabelPrint .= ' (' . $last_queue_details['doctor_specialization'] . ')'; } ?> <hr class="mt-4"> <div class="card border-custom-theme" id="queuePrintCard"> <div class="card-body"> <h5 class="text-custom-theme mb-3">Your Queue Number</h5> <div class="row"> <div class="col-md-6"> <p class="mb-1"><strong>Queue No.:</strong> <?php echo (int)$last_queue_details['queue_no']; ?></p> <p class="mb-1"><strong>Date:</strong> <?php echo date('M d, Y', strtotime($last_queue_details['reservation_date'])); ?></p> <p class="mb-1"><strong>Time (estimated):</strong> <?php echo htmlspecialchars($time_label_print ?: ''); ?></p> </div> <div class="col-md-6"> <p class="mb-1"><strong>Doctor:</strong> <?php echo htmlspecialchars($doctorLabelPrint); ?></p> <p class="mb-1"><strong>Room:</strong> <?php echo htmlspecialchars($last_queue_details['room_name'] ?? ''); ?></p> </div> </div> <div class="mt-3"> <button type="button" class="btn btn-outline-secondary btn-sm" onclick="window.print()">Print</button> </div> </div> </div> <?php endif; ?> </div> </div> </div> <?php endif; ?> <?php if ($view === 'results'): ?> <div class="card shadow-sm" id="patient-results"> <div class="card-header bg-white"> <h4 class="mb-0">My Result</h4> </div> <div class="card-body"> <h5 class="mb-3">Laboratory and Imaging Results</h5> <table class="table table-hover mb-4"> <thead class="table-light"> <tr> <th>Date</th> <th>Branch</th> <th>Test Name</th> <th>Result</th> <th>Unit</th> <th>Reference Range</th> <th>Status</th> <th>Remarks</th> <th>Action</th> </tr> </thead> <tbody> <?php $voidCondition = getInvoiceVoidCondition($pdo, 'i'); $sql = "SELECT tr.*, t.test_name, t.unit, t.normal_range, t.category, t.test_type, i.branch FROM test_results tr JOIN lab_tests t ON tr.test_id = t.id LEFT JOIN invoices i ON tr.invoice_id = i.id WHERE tr.patient_id = ? AND tr.status = 'Completed' AND (i.id IS NULL OR NOT ($voidCondition)) ORDER BY tr.created_at DESC"; $stmt = $pdo->prepare($sql); $stmt->execute([$patient_id]); $results = $stmt->fetchAll(); if(count($results) > 0): foreach($results as $row): $decoded = json_decode($row['result_value'], true); $is_json = (json_last_error() === JSON_ERROR_NONE && is_array($decoded)); $ancillary_cats = ['X-Ray', 'Ultrasound', 'ECG', '2D Echo', 'Cardiology', 'Endoscopy']; $is_ancillary = ($row['test_type'] == 'Imaging' || in_array($row['category'], $ancillary_cats)); $is_external = (isset($row['is_external_upload']) && $row['is_external_upload'] == 1); if ($is_external) { $print_url = "print_send_out_result.php?id=" . $row['id']; } elseif ($is_ancillary) { $print_url = "patient_print_ancillary.php?patient_id=" . $patient_id . "&date=" . date('Y-m-d', strtotime($row['created_at'])); if (!empty($row['invoice_id'])) { $print_url = "patient_print_ancillary.php?invoice_id=" . $row['invoice_id']; } } else { $print_url = "patient_print_result.php?patient_id=" . $patient_id . "&date=" . date('Y-m-d', strtotime($row['created_at'])); if (!empty($row['invoice_id'])) { $print_url = "patient_print_result.php?invoice_id=" . $row['invoice_id']; } } ?> <tr> <td><?php echo date('M d, Y', strtotime($row['created_at'])); ?></td> <td><?php echo htmlspecialchars($row['branch'] ?? '-'); ?></td> <td><?php echo htmlspecialchars($row['test_name']); ?></td> <td> <?php if ($is_json) { echo '<div class="table-responsive">'; echo '<table class="table table-sm table-bordered mb-0" style="font-size: 0.8rem;">'; echo '<thead class="table-light"><tr><th>Component</th><th>Result</th><th>Unit</th><th>Range</th></tr></thead>'; echo '<tbody>'; foreach($decoded as $item) { echo '<tr>'; echo '<td>'.htmlspecialchars($item['name']).'</td>'; echo '<td class="fw-bold text-primary">'.htmlspecialchars($item['result']).'</td>'; echo '<td>'.htmlspecialchars($item['unit']).'</td>'; echo '<td>'.htmlspecialchars($item['range']).'</td>'; echo '</tr>'; } echo '</tbody></table>'; echo '</div>'; } else { echo '<span class="fw-bold text-primary">'.htmlspecialchars($row['result_value']).'</span>'; } ?> </td> <td><?php echo $is_json ? '-' : htmlspecialchars($row['unit']); ?></td> <td><?php echo $is_json ? '-' : htmlspecialchars($row['normal_range']); ?></td> <td><span class="badge bg-success">Verified</span></td> <td><?php echo htmlspecialchars($row['remarks']); ?></td> <td> <a href="<?php echo $print_url; ?>" target="_blank" class="btn btn-sm btn-outline-danger" title="Download PDF"> <i class="bi bi-file-earmark-pdf"></i> PDF </a> </td> </tr> <?php endforeach; else: ?> <tr> <td colspan="8" class="text-center py-4"> <div class="text-muted">No completed results found yet.</div> </td> </tr> <?php endif; ?> </tbody> </table> <?php $consultations = []; try { $voidCondition = getInvoiceVoidCondition($pdo, 'i'); $sql = "SELECT cr.*, d.name AS doctor_name FROM consultation_records cr JOIN doctors d ON cr.doctor_id = d.id LEFT JOIN invoices i ON cr.invoice_id = i.id WHERE cr.patient_id = ? AND (i.id IS NULL OR NOT ($voidCondition)) ORDER BY cr.created_at DESC"; $stmtCons = $pdo->prepare($sql); $stmtCons->execute([$patient_id]); $consultations = $stmtCons->fetchAll(); } catch (Exception $e) { $consultations = []; } ?> <h5 class="mb-3">Consultation History</h5> <div class="table-responsive"> <table class="table table-hover"> <thead class="table-light"> <tr> <th>Date</th> <th>Doctor</th> <th>Diagnosis</th> <th>Action</th> </tr> </thead> <tbody> <?php if (!empty($consultations)): ?> <?php foreach ($consultations as $c): ?> <tr> <td><?php echo date('M d, Y h:i A', strtotime($c['created_at'])); ?></td> <td><?php echo htmlspecialchars($c['doctor_name'] ?? ''); ?></td> <td><?php echo nl2br(htmlspecialchars($c['diagnosis'] ?? '')); ?></td> <td>-</td> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="4" class="text-center py-3 text-muted">No consultation history available.</td> </tr> <?php endif; ?> </tbody> </table> </div> </div> </div> <?php endif; ?> </div> </div> </div> <div class="modal fade" id="bookConsultationModal" tabindex="-1" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <form method="post"> <div class="modal-header"> <h5 class="modal-title">Book Consultation</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <input type="hidden" name="reserve_slot_id" id="modalReserveSlotId"> <div class="mb-2"> <div class="text-muted small">Date</div> <div id="modalSlotDate" class="fw-bold"></div> </div> <div class="mb-2"> <div class="text-muted small">Doctor</div> <div id="modalSlotDoctor"></div> </div> <div class="mb-2"> <div class="text-muted small">Room</div> <div id="modalSlotRoom"></div> </div> <div class="mb-3"> <div class="text-muted small">Clinic Schedule</div> <div id="modalSlotTime"></div> </div> <div class="mb-3"> <label class="form-label">Symptoms / Initial Condition</label> <textarea name="initial_condition" id="modalInitialCondition" class="form-control" rows="3" required></textarea> </div> <div class="mb-3"> <label class="form-label">Other Details (optional)</label> <textarea name="other_details" class="form-control" rows="2"></textarea> </div> <?php if ($requires_contact): ?> <hr> <div class="mb-3"> <label class="form-label">Email Address</label> <input type="email" name="contact_email" class="form-control" value="<?php echo htmlspecialchars($patient_email); ?>" required> </div> <div class="mb-3"> <label class="form-label">Cellphone Number</label> <input type="tel" name="contact_phone" class="form-control" value="<?php echo htmlspecialchars($patient_phone); ?>" required> </div> <?php endif; ?> </div> <div class="modal-footer d-flex justify-content-between align-items-center"> <small class="text-muted">Reminder: Clinic time may change without prior notice.</small> <div> <button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Cancel</button> <button type="submit" class="btn btn-primary btn-sm">Confirm Booking</button> </div> </div> </form> </div> </div> </div> <script> document.addEventListener('DOMContentLoaded', function () { var modalElement = document.getElementById('bookConsultationModal'); var modal = null; if (modalElement) { modal = new bootstrap.Modal(modalElement); } var idInput = document.getElementById('modalReserveSlotId'); var dateEl = document.getElementById('modalSlotDate'); var doctorEl = document.getElementById('modalSlotDoctor'); var roomEl = document.getElementById('modalSlotRoom'); var timeEl = document.getElementById('modalSlotTime'); var conditionEl = document.getElementById('modalInitialCondition'); document.addEventListener('click', function (event) { var btn = event.target.closest('.book-slot-btn'); if (!btn || !modal) return; if (idInput) idInput.value = btn.getAttribute('data-slot-id') || ''; if (dateEl) dateEl.textContent = btn.getAttribute('data-slot-date') || ''; if (doctorEl) doctorEl.textContent = btn.getAttribute('data-slot-doctor') || ''; if (roomEl) roomEl.textContent = btn.getAttribute('data-slot-room') || ''; if (timeEl) timeEl.textContent = btn.getAttribute('data-slot-time') || ''; if (conditionEl) conditionEl.value = ''; modal.show(); }); var currentView = <?php echo json_encode($view); ?>; function refreshPatientBookingSections() { if (currentView !== 'book') { return; } var url = 'my_results.php?view=book'; fetch(url, { credentials: 'same-origin' }) .then(function (response) { if (!response.ok) { throw new Error('Network response was not ok'); } return response.text(); }) .then(function (html) { var parser = new DOMParser(); var doc = parser.parseFromString(html, 'text/html'); var wrapperIds = ['patientQueueStatusWrapper', 'patientUpcomingWrapper', 'patientAvailableWrapper', 'patientQueueCardWrapper']; wrapperIds.forEach(function (id) { var newEl = doc.getElementById(id); var curEl = document.getElementById(id); if (newEl && curEl) { curEl.innerHTML = newEl.innerHTML; } }); }) .catch(function () { }); } if (currentView === 'book') { setInterval(refreshPatientBookingSections, 5000); } }); </script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Batal