prepare($countQuery); $stmt->execute($params); $totalVisits = $stmt->fetchColumn(); $totalPages = ceil($totalVisits / $limit); // Fetch Data $query = " SELECT v.*, p.name as patient_name, p.dob as patient_dob, p.gender as patient_gender, doc.name_$lang as doctor_name, nur.name_$lang as nurse_name FROM visits v JOIN patients p ON v.patient_id = p.id LEFT JOIN employees doc ON v.doctor_id = doc.id LEFT JOIN employees nur ON v.nurse_id = nur.id $where ORDER BY v.visit_date DESC LIMIT $limit OFFSET $offset"; $stmt = $db->prepare($query); $stmt->execute($params); $raw_visits = $stmt->fetchAll(); $visits = []; foreach ($raw_visits as $v) { // Fetch Lab Inquiries $v['lab_inquiries'] = $db->query("SELECT li.* FROM laboratory_inquiries li WHERE li.visit_id = " . (int)$v['id'])->fetchAll(); foreach($v['lab_inquiries'] as &$li) { $li['items'] = $db->query("SELECT it.*, lt.name_$lang as test_name FROM inquiry_tests it JOIN laboratory_tests lt ON it.test_id = lt.id WHERE it.inquiry_id = " . (int)$li['id'])->fetchAll(); $li['results'] = implode(', ', array_map(function($item) { return $item['test_name'] . ': ' . ($item['result'] ?: '-'); }, $li['items'])); } // Fetch X-Ray Inquiries $v['xray_inquiries'] = $db->query("SELECT xi.* FROM xray_inquiries xi WHERE xi.visit_id = " . (int)$v['id'])->fetchAll(); foreach($v['xray_inquiries'] as &$xi) { $xi['items'] = $db->query("SELECT xit.*, xt.name_$lang as xray_name FROM xray_inquiry_items xit JOIN xray_tests xt ON xit.xray_id = xt.id WHERE xit.inquiry_id = " . (int)$xi['id'])->fetchAll(); } // Fetch Prescriptions $v['prescriptions'] = $db->query("SELECT * FROM visit_prescriptions WHERE visit_id = " . (int)$v['id'])->fetchAll(); $visits[] = $v; } // --- AJAX HANDLER --- if (isset($_GET['ajax_search'])) { ob_start(); if (empty($visits)): ?>
Home
(' . __('nurse') . ')'; } ?> ' . htmlspecialchars($v['blood_pressure'] ?? ''); if(!empty($v['weight'])) $vitals[] = '' . htmlspecialchars($v['weight'] ?? '') . 'kg'; if(!empty($v['temperature'])) $vitals[] = '' . htmlspecialchars($v['temperature'] ?? '') . '°C'; echo implode('
', $vitals); ?>
1): ?>
-
$table_html, 'pagination' => $pagination_html]); exit; } ?>

#

Home

(' . __('nurse') . ')'; } ?> ' . htmlspecialchars($v['blood_pressure'] ?? ''); if(!empty($v['weight'])) $vitals[] = '' . htmlspecialchars($v['weight'] ?? '') . 'kg'; if(!empty($v['temperature'])) $vitals[] = '' . htmlspecialchars($v['temperature'] ?? '') . '°C'; echo implode('
', $vitals); ?>
1): ?>
-