Lokasi:
/
home
/
u847703118
/
domains
/
alphamed.cloud
/
public_html
/
Ubah: doctor_requests.php
<?php require('includes/auth_session.php'); if (function_exists('isClinicManagementEnabled') && !isClinicManagementEnabled($pdo)) { header("Location: dashboard.php"); exit(); } include('includes/header.php'); // Determine if user is a doctor $current_doctor_id = 0; $stmt = $pdo->prepare("SELECT id FROM doctors WHERE user_id = ?"); $stmt->execute([$_SESSION['user_id']]); $doc = $stmt->fetch(); if ($doc) { $current_doctor_id = $doc['id']; } $is_admin = ($_SESSION['role'] === 'admin') || userHasModule('system_doctors'); $can_view_all = $is_admin; // Access Control if (!$is_admin && $current_doctor_id == 0) { // Not an admin and not a doctor echo '<div class="alert alert-danger">Access Denied. Only doctors and administrators can view this page.</div>'; include('includes/footer.php'); exit(); } // Filters $start_date = $_GET['start_date'] ?? date('Y-m-01'); $end_date = $_GET['end_date'] ?? date('Y-m-d'); $filter_doctor_id = $_GET['doctor_id'] ?? ''; // Build Query $params = [$start_date, $end_date]; $sql = "SELECT dr.*, p.first_name, p.last_name, p.patient_code, d.name as doctor_name FROM doctor_requests dr JOIN patients p ON dr.patient_id = p.id JOIN doctors d ON dr.doctor_id = d.id WHERE dr.request_date BETWEEN ? AND ?"; if (!$can_view_all) { // Restrict to current doctor $sql .= " AND dr.doctor_id = ?"; $params[] = $current_doctor_id; } elseif ($filter_doctor_id) { // Admin filtering by doctor $sql .= " AND dr.doctor_id = ?"; $params[] = $filter_doctor_id; } $sql .= " ORDER BY dr.request_date DESC, dr.created_at DESC"; $stmt = $pdo->prepare($sql); $stmt->execute($params); $requests = $stmt->fetchAll(); // Fetch Doctors for Filter (if admin) if ($can_view_all) { $doc_stmt = $pdo->query("SELECT id, name FROM doctors ORDER BY name"); $doctors = $doc_stmt->fetchAll(); } ?> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> <h1 class="h2">Doctor Requests (Lab/Imaging)</h1> </div> <div class="card shadow-sm mb-4"> <div class="card-body"> <form method="GET" class="row g-3 align-items-end"> <div class="col-md-3"> <label class="form-label">Start Date</label> <input type="date" name="start_date" class="form-control" value="<?php echo $start_date; ?>"> </div> <div class="col-md-3"> <label class="form-label">End Date</label> <input type="date" name="end_date" class="form-control" value="<?php echo $end_date; ?>"> </div> <?php if ($can_view_all): ?> <div class="col-md-3"> <label class="form-label">Doctor</label> <select name="doctor_id" class="form-select"> <option value="">All Doctors</option> <?php foreach ($doctors as $d): ?> <option value="<?php echo $d['id']; ?>" <?php echo $filter_doctor_id == $d['id'] ? 'selected' : ''; ?>> <?php echo htmlspecialchars($d['name']); ?> </option> <?php endforeach; ?> </select> </div> <?php endif; ?> <div class="col-md-3"> <button type="submit" class="btn btn-primary w-100"> <i class="bi bi-filter"></i> Filter </button> </div> </form> </div> </div> <div class="card shadow-sm"> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-hover table-striped mb-0"> <thead class="bg-light"> <tr> <th>Date</th> <th>Request ID</th> <th>Patient</th> <th>Doctor</th> <th>Items</th> <th class="text-end">Actions</th> </tr> </thead> <tbody> <?php if (count($requests) > 0): ?> <?php foreach ($requests as $r): ?> <tr> <td><?php echo date('M d, Y', strtotime($r['request_date'])); ?></td> <td>REQ-<?php echo str_pad($r['id'], 6, '0', STR_PAD_LEFT); ?></td> <td> <a href="patients.php?action=edit&id=<?php echo $r['patient_id']; ?>" class="text-decoration-none fw-bold"> <?php echo htmlspecialchars($r['first_name'] . ' ' . $r['last_name']); ?> </a> <div class="small text-muted"><?php echo htmlspecialchars($r['patient_code']); ?></div> </td> <td><?php echo htmlspecialchars($r['doctor_name']); ?></td> <td> <?php $items = json_decode($r['request_items'], true) ?? []; $names = array_column($items, 'test_name'); $display = implode(', ', array_slice($names, 0, 2)); if (count($names) > 2) $display .= ' + ' . (count($names) - 2) . ' more'; echo htmlspecialchars($display); ?> </td> <td class="text-end"> <a href="print_doctor_request.php?id=<?php echo $r['id']; ?>" target="_blank" class="btn btn-sm btn-outline-secondary"> <i class="bi bi-printer"></i> Print </a> </td> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="6" class="text-center py-4 text-muted">No requests found for the selected period.</td> </tr> <?php endif; ?> </tbody> </table> </div> </div> </div> <?php include('includes/footer.php'); ?>
Batal