'คลินิกเบาหวาน (DM)', 'HT' => 'คลินิกความดันฯ (HT)', 'DLP' => 'คลินิกไขมันฯ (DLP)', 'CKD' => 'คลินิกโรคไต (CKD)' ]; $app_settings = get_app_settings(); $clinic_codes = [ 'DM' => $app_settings['ncd_clinic_dm_code'] ?? '001', 'HT' => $app_settings['ncd_clinic_ht_code'] ?? '002', 'DLP' => $app_settings['ncd_clinic_dlp_code'] ?? '039', 'CKD' => $app_settings['ncd_clinic_ckd_code'] ?? '051' ]; $clinic_code = $clinic_codes[$curr_clinic] ?? null; // Date parameters for filtering $ds1 = $_GET['ds1'] ?? date('Y-m-d', strtotime('-1 month')); $ds2 = $_GET['ds2'] ?? date('Y-m-d'); // Create reverse mapping for clinic codes to names $clinic_code_to_name = []; foreach ($clinic_codes as $key => $code) { $clinic_code_to_name[$code] = $ncd_clinics[$key]; } $patientsData = []; // Execute query only if ds1 and ds2 are submitted $dashboardData = []; if (isset($_GET['ds1']) && isset($_GET['ds2'])) { if ($curr_clinic === 'ALL') { // Run dashboard queries instead of fetching all patients $dashboard_keys = [ 'dashboard_dm_all', 'dashboard_dm_hba1c', 'dashboard_dm_1', 'dashboard_dm_2', 'dashboard_dm_3', 'dashboard_dm_4', 'dashboard_dm_5', 'dashboard_dm_eye', 'dashboard_ht_all', 'dashboard_ht_1', 'dashboard_ht_2', 'dashboard_dlp_all', 'dashboard_ckd_all', 'dashboard_ckd_1' ]; foreach ($dashboard_keys as $k) { $dashboardData[$k] = ($k === 'dashboard_ckd_1') ? [] : 0; if (!empty($app_settings[$k])) { $sql = str_replace(['{ds1}', '{ds2}'], [$ds1, $ds2], $app_settings[$k]); if ($res = $conn1->query($sql)) { if ($k === 'dashboard_ckd_1') { while ($r = $res->fetch_assoc()) { $dashboardData[$k][$r['stage']] = $r['total_patient']; } } else { if ($r = $res->fetch_assoc()) { $dashboardData[$k] = $r['total_patient'] ?? 0; } } } } } } else { $clinic_cond = "AND cl.clinic = '" . $conn1->real_escape_string($clinic_code) . "'"; $raw_sql = $app_settings['ncd_sql'] ?? ''; $sql = str_replace('{clinic_cond}', $clinic_cond, $raw_sql); if ($stmt = $conn1->prepare($sql)) { $stmt->bind_param("ss", $ds1, $ds2); $stmt->execute(); $result = $stmt->get_result(); if ($result) { while ($row = $result->fetch_assoc()) { $patientsData[] = $row; } } $stmt->close(); } // Bulk fetch additional clinical data (Labs & Screenings) if (!empty($patientsData)) { $hn_list = array_column($patientsData, 'hn'); $hn_sql_in = "'" . implode("','", array_map(function($hn) use ($conn1) { return $conn1->real_escape_string($hn); }, array_unique($hn_list))) . "'"; $extraData = []; foreach ($hn_list as $hn) { $extraData[$hn] = [ 'hba1c' => ['res' => '-', 'date' => '-'], 'urine_prot' => ['res' => '-', 'date' => '-'], 'cr' => ['res' => '-', 'date' => '-'], 'urine_alb' => ['res' => '-', 'date' => '-'], 'urine_cr' => ['res' => '-', 'date' => '-'], 'hbsag' => ['res' => '-', 'date' => '-'], 'anti_hcv' => ['res' => '-', 'date' => '-'], 'hpv' => ['res' => '-', 'date' => '-'], 'colon_cancer' => ['res' => '-', 'date' => '-'], 'ldl' => ['res' => '-', 'date' => '-'], 'eye_screen' => '-', 'foot_screen' => '-', 'oral_cancer' => '-' ]; } // 1. LAB Data $lab_sql = "SELECT a.hn, b.lab_items_code, b.lab_order_result, a.order_date FROM lab_head a JOIN lab_order b ON a.lab_order_number=b.lab_order_number WHERE a.hn IN ($hn_sql_in) AND b.lab_items_code IN ('288','223','224','802','78','226','227','641','656','659','2215','1896','1549','479') AND ( (b.lab_items_code != '1549' AND a.order_date BETWEEN '$ds1' AND '$ds2') OR (b.lab_items_code = '1549' AND a.order_date BETWEEN '2024-10-01' AND '2026-06-11') ) ORDER BY a.order_date ASC"; if ($res_lab = $conn1->query($lab_sql)) { while ($r = $res_lab->fetch_assoc()) { $hn = $r['hn']; $code = $r['lab_items_code']; $res = trim($r['lab_order_result'] ?? ''); $date = (!empty($r['order_date']) && $r['order_date'] != '0000-00-00') ? thai_date2($r['order_date']) : '-'; if ($code == '288') $extraData[$hn]['hba1c'] = ['res' => $res, 'date' => $date]; else if (in_array($code, ['223','224'])) $extraData[$hn]['urine_prot'] = ['res' => $res, 'date' => $date]; else if (in_array($code, ['802','78','226','227'])) { $extraData[$hn]['cr'] = ['res' => $res, 'date' => $date]; if ($code == '227') $extraData[$hn]['urine_cr'] = ['res' => $res, 'date' => $date]; } else if ($code == '641') $extraData[$hn]['urine_alb'] = ['res' => $res, 'date' => $date]; else if ($code == '656') $extraData[$hn]['hbsag'] = ['res' => $res, 'date' => $date]; else if ($code == '659') $extraData[$hn]['anti_hcv'] = ['res' => $res, 'date' => $date]; else if (in_array($code, ['2215','1896'])) $extraData[$hn]['hpv'] = ['res' => $res, 'date' => $date]; else if ($code == '1549') $extraData[$hn]['colon_cancer'] = ['res' => $res, 'date' => $date]; else if ($code == '479') $extraData[$hn]['ldl'] = ['res' => $res, 'date' => $date]; } } // 2. Eye/Foot Screening $screen_sql = "SELECT hn, screen_date, do_eye_screen, do_foot_screen FROM clinicmember_cormobidity_screen WHERE hn IN ($hn_sql_in) AND screen_date BETWEEN '$ds1' AND '$ds2' ORDER BY screen_date ASC"; if ($res_scr = $conn1->query($screen_sql)) { while ($r = $res_scr->fetch_assoc()) { $hn = $r['hn']; $date = (!empty($r['screen_date']) && $r['screen_date'] != '0000-00-00') ? thai_date2($r['screen_date']) : '-'; if ($r['do_eye_screen'] == 'Y') $extraData[$hn]['eye_screen'] = $date; if ($r['do_foot_screen'] == 'Y') $extraData[$hn]['foot_screen'] = $date; } } // 3. Oral Cancer Screening $oral_sql = "SELECT hn, vstdate FROM dtmain WHERE hn IN ($hn_sql_in) AND tmcode IN ('001480') AND vstdate BETWEEN '$ds1' AND '$ds2' ORDER BY vstdate ASC"; if ($res_oral = $conn1->query($oral_sql)) { while ($r = $res_oral->fetch_assoc()) { $date = (!empty($r['vstdate']) && $r['vstdate'] != '0000-00-00') ? thai_date2($r['vstdate']) : '-'; $extraData[$r['hn']]['oral_cancer'] = $date; } } // Merge back into patientsData foreach ($patientsData as &$p) { $h = $p['hn']; $p['extra'] = $extraData[$h] ?? []; } unset($p); } } } ?>

ทะเบียนผู้ป่วย

ระบบลงทะเบียนและติดตามผู้ป่วยโรคเรื้อรัง

ตัวชี้วัดสถิติ NCD

คลินิกโรคเบาหวาน (Diabetes Mellitus)

ผู้ป่วยเบาหวานทั้งหมด
คน
ได้รับการตรวจ HBA1C
คน
DM ไม่มีโรคร่วม (HbA1C < 7)
คน
DM มีโรคร่วม (HbA1C < 8)
คน
ได้รับการตรวจ LDL
คน
ได้รับการตรวจไต
คน
ได้รับการตรวจเท้า
คน
ได้รับการตรวจตา
คน

คลินิกโรคความดันโลหิตสูง (Hypertension)

ผู้ป่วยความดันโลหิตสูงทั้งหมด
คน
ความดัน 2 ครั้งสุดท้าย < 139/89
คน
ได้รับการตรวจไต
คน

คลินิกโรคไขมันในเลือดสูง (Dyslipidemia)

ผู้ป่วยไขมันในเลือดสูงทั้งหมด
คน

คลินิกโรคไตเรื้อรัง (CKD)

ผู้ป่วยโรคไตเรื้อรังทั้งหมด
คน
จำนวนผู้ป่วยโรคไตแยกตาม Stage
'Stage 1', '2' => 'Stage 2', '3a' => 'Stage 3a', '3b' => 'Stage 3b', '4' => 'Stage 4', '5' => 'Stage 5']; foreach ($stages as $st => $st_name): $val = isset($dashboardData['dashboard_ckd_1'][$st]) ? $dashboardData['dashboard_ckd_1'][$st] : 0; ?>

ทะเบียนผู้ป่วย

-'; return '' . htmlspecialchars($data['res']) . '(' . htmlspecialchars($data['date']) . ')'; } } if (!function_exists('fmtScrCell')) { function fmtScrCell($date) { if(empty($date) || $date === '-') return '-'; return '' . htmlspecialchars($date) . ''; } } $no = 1; foreach ($patientsData as $row): $bg = $no % 2 == 0 ? 'bg-white' : 'bg-slate-50'; ?>
ลำดับ HN ชื่อ-สกุล CID วันเกิด อายุ เพศ ที่อยู่ หมู่ ตำบล ประเภทบ้าน เบอร์โทร รหัสทะเบียน วันที่ขึ้นทะเบียน สิทธิการรักษา โรงพยาบาล Person ID Diag HbA1C Urine Protein Cr Urine Albumin Urine Cr HBsAg Anti HCV HPV มะเร็งลำไส้ LDL ตรวจตา ตรวจเท้า มะเร็งช่องปาก
$row['hn'] ?? '', 'name' => $row['pt_name'] ?? '', 'cid' => $row['cid'] ?? '', 'birthday' => $bday_formatted, 'age' => $row['age_y'] ?? '', 'sex' => $row['sex_name'] ?? '', 'address' => $row['addrpart'] ?? '', 'moo' => $row['moopart'] ?? '', 'tumbon' => $row['tmb_name'] ?? '', 'house_type' => $row['house_regist_type_id'] ?? '', 'phone' => $row['mobile_phone_number'] ?? '', 'member_id' => $row['clinicmember_id'] ?? '', 'clinic' => $row['clinic_name'] ?? $clinic_code_to_name[$row['clinic'] ?? ''] ?? $row['clinic'] ?? '-', 'regdate' => (!empty($row['regdate']) && $row['regdate'] != '0000-00-00') ? thai_date2($row['regdate']) : '-', 'dchdate' => (!empty($row['dchdate']) && $row['dchdate'] != '0000-00-00') ? thai_date2($row['dchdate']) : 'ยังไม่จำหน่าย', 'pttype' => $row['pttype_name'] ?? '', 'hospital' => $row['hosp_name'] ?? '', 'person_id' => $row['person_id'] ?? '', 'icd10' => $row['icd10'] ?? '', 'nextdate' => (!empty($row['nextdate']) && $row['nextdate'] != '0000-00-00') ? thai_date2($row['nextdate']) : 'ไม่มีนัด', 'nexttime' => (!empty($row['nexttime']) && $row['nexttime'] != '00:00:00') ? substr($row['nexttime'], 0, 5) . ' น.' : '-', 'labs' => [ 'hba1c' => $fmtLabObj($ext['hba1c'] ?? null), 'urine_prot' => $fmtLabObj($ext['urine_prot'] ?? null), 'cr' => $fmtLabObj($ext['cr'] ?? null), 'urine_alb' => $fmtLabObj($ext['urine_alb'] ?? null), 'urine_cr' => $fmtLabObj($ext['urine_cr'] ?? null), 'hbsag' => $fmtLabObj($ext['hbsag'] ?? null), 'anti_hcv' => $fmtLabObj($ext['anti_hcv'] ?? null), 'hpv' => $fmtLabObj($ext['hpv'] ?? null), 'colon' => $fmtLabObj($ext['colon_cancer'] ?? null), 'ldl' => $fmtLabObj($ext['ldl'] ?? null) ], 'screen' => [ 'eye' => $ext['eye_screen'] ?? '-', 'foot' => $ext['foot_screen'] ?? '-', 'oral' => $ext['oral_cancer'] ?? '-' ] ]), ENT_QUOTES, 'UTF-8'); ?>
ดึงข้อมูลจาก HOSxP Database ( รายการ)