ประวัติรับบริการ
HN:
ค้นหารายการ
ยังไม่ได้เลือกรายการรับบริการ
กรุณาคลิกเลือกวันที่มารับบริการจากเมนูด้านซ้ายเพื่อดูรายละเอียดการตรวจรักษาและผลการวินิจฉัยโรค
ค้นหาผู้รับบริการคนอื่นprepare($sql_pt); if($stmt) { $stmt->bind_param("s", $hn); $stmt->execute(); $res = $stmt->get_result(); if($row = $res->fetch_assoc()) { $patient_name = $row['pname'] . $row['fname'] . " " . $row['lname']; } $stmt->close(); } // Auto-select latest visit if $vdate is empty so user doesn't see a blank page if (empty($vdate)) { $sql_latest = "SELECT vstdate, vn, an FROM ovst WHERE hn=? ORDER BY vstdate DESC LIMIT 1"; $stmt_latest = $conn1->prepare($sql_latest); if($stmt_latest) { $stmt_latest->bind_param("s", $hn); $stmt_latest->execute(); $res_latest = $stmt_latest->get_result(); if($row_latest = $res_latest->fetch_assoc()) { $vdate = $row_latest['vstdate']; $nn = ($row_latest['an'] != NULL) ? $row_latest['an'] : $row_latest['vn']; } $stmt_latest->close(); } } // Log that the patient was viewed if (!empty($_SESSION['account'])) { system_log($conn2, $_SESSION['account'], 'VIEW_PATIENT', ['hn' => $hn, 'vdate' => $vdate, 'nn' => $nn]); } // Check if current visit is IPD if (!empty($vdate) && !empty($nn)) { $sql_check_ipd = "SELECT an FROM ovst WHERE hn=? AND vstdate=? AND (vn=? OR an=?)"; $stmt_check = $conn1->prepare($sql_check_ipd); if($stmt_check) { $stmt_check->bind_param("ssss", $hn, $vdate, $nn, $nn); $stmt_check->execute(); $res_check = $stmt_check->get_result(); if($row_check = $res_check->fetch_assoc()) { if (!empty($row_check['an'])) { $is_ipd_visit = true; } } $stmt_check->close(); } } // Fetch Upcoming Appointments $upcoming_appointments = []; try { $sql_app = "SELECT a.nextdate, a.nexttime, c.name as clinic_name FROM oapp a LEFT OUTER JOIN clinic c ON a.clinic = c.clinic LEFT OUTER JOIN patient p ON a.hn = p.hn WHERE DATEDIFF(a.nextdate, CURDATE()) > 1 AND a.hn = ? ORDER BY a.nextdate ASC, a.nexttime ASC"; $stmt_app = $conn1->prepare($sql_app); if($stmt_app) { $stmt_app->bind_param("s", $hn); $stmt_app->execute(); $res_app = $stmt_app->get_result(); while($row_app = $res_app->fetch_assoc()) { $upcoming_appointments[] = $row_app; } $stmt_app->close(); } } catch (Exception $e) { // Log the error but don't break the page error_log("Failed to fetch appointments: " . $e->getMessage()); } // Fetch Vaccines $vaccines_by_group = []; try { $app_settings = get_app_settings(); $vaccine_sql_template = $app_settings['vaccine_sql'] ?? ''; if (!empty($vaccine_sql_template)) { // Protect against basic SQL injection while supporting the arbitrary query design $safe_hn = $conn1->real_escape_string($hn); $vaccine_sql = str_replace("'ระบุ_HN'", "'" . $safe_hn . "'", $vaccine_sql_template); $res_vax = $conn1->query($vaccine_sql); if ($res_vax) { while($row_vax = $res_vax->fetch_assoc()) { $group = $row_vax['vaccine_group'] ?? 'อื่นๆ (Others)'; if (!isset($vaccines_by_group[$group])) { $vaccines_by_group[$group] = []; } $vaccines_by_group[$group][] = $row_vax; } } } } catch (Exception $e) { error_log("Failed to fetch vaccines: " . $e->getMessage()); } } $bg_class = $is_ipd_visit ? "bg-gradient-to-br from-yellow-50 to-amber-100" : "bg-gradient-to-br from-emerald-50 to-emerald-100"; ob_start(); ?>
HN:
กรุณาคลิกเลือกวันที่มารับบริการจากเมนูด้านซ้ายเพื่อดูรายละเอียดการตรวจรักษาและผลการวินิจฉัยโรค
ค้นหาผู้รับบริการคนอื่น