155 lines
9.0 KiB
PHP
155 lines
9.0 KiB
PHP
<?php
|
|
// right_panel.php - Dashboard stats
|
|
$timezone = "Asia/Bangkok";
|
|
date_default_timezone_set($timezone);
|
|
$today = date("Y-m-d H:i:s");
|
|
$d_conv_search = date("Y-m-d");
|
|
|
|
// Helper function for quick count queries
|
|
function get_count($conn, $query, $date_param) {
|
|
$stmt = $conn->prepare($query);
|
|
if($stmt) {
|
|
$stmt->bind_param("s", $date_param);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$row = $result->fetch_assoc();
|
|
$stmt->close();
|
|
return $row['cc'] ?? 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
$cc_er = get_count($conn1, "SELECT count(*) as cc FROM er_regist WHERE vstdate=?", $d_conv_search);
|
|
$cc_pq = get_count($conn1, "SELECT count(*) as cc FROM pq_screen WHERE screen_date=?", $d_conv_search);
|
|
$cc_pqd = get_count($conn1, "SELECT count(*) as cc FROM pq_doctor WHERE doctor_date=?", $d_conv_search);
|
|
$cc_dt = get_count($conn1, "SELECT count(distinct hn) as cc FROM dtmain WHERE vstdate=?", $d_conv_search);
|
|
$cc_lab1 = get_count($conn1, "SELECT count(*) as cc FROM lab_head WHERE order_date=?", $d_conv_search);
|
|
$cc_lab2 = get_count($conn1, "SELECT count(*) as cc FROM lab_head WHERE order_date=? AND confirm_report='Y'", $d_conv_search);
|
|
|
|
$sub_y = substr((date("Y") + 543), 2, 2);
|
|
$d_rx = $sub_y . date("md") . "%";
|
|
$cc_rx = get_count($conn1, "SELECT count(*) as cc FROM rx_operator WHERE vn like ?", $d_rx);
|
|
$cc_rx2 = get_count($conn1, "SELECT count(*) as cc FROM rx_operator WHERE vn like ? AND pay='Y'", $d_rx);
|
|
|
|
$cc_ipt = get_count($conn1, "SELECT count(*) as cc FROM ipt WHERE regdate=?", $d_conv_search);
|
|
$cc_ipt2 = get_count($conn1, "SELECT count(*) as cc FROM ipt WHERE dchdate=?", $d_conv_search);
|
|
$cc_ovst = get_count($conn1, "SELECT count(*) as cc FROM ovst WHERE vstdate=? AND ovstost='54'", $d_conv_search);
|
|
$cc_ipt3 = get_count($conn1, "SELECT count(*) as cc FROM ipt WHERE dchdate=? AND dchtype='04'", $d_conv_search);
|
|
|
|
// News from local DB
|
|
$news_items = [];
|
|
$result_news2 = $conn2->query("SELECT * FROM news ORDER BY date_add DESC LIMIT 10");
|
|
if ($result_news2) {
|
|
while($row = $result_news2->fetch_assoc()) {
|
|
$news_items[] = $row;
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="glass-header" style="margin-top: 10px;">
|
|
<h2>สรุปยอดให้บริการประจำวัน</h2>
|
|
<span class="text-muted">ข้อมูล ณ วันที่ <?php echo thai_date5(datetime_to_date($today)); ?> เวลา <?php echo datetime_to_time($today); ?> น.</span>
|
|
</div>
|
|
|
|
<div class="grid-2">
|
|
<!-- Stats Column -->
|
|
<div class="glass-panel" style="grid-column: span 1;">
|
|
<h3 style="margin-bottom: 20px; color: var(--primary); display: flex; align-items: center; gap: 8px;">
|
|
<svg style="width:24px;height:24px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path></svg>
|
|
ภาพรวมการให้บริการ (OPD & ER)
|
|
</h3>
|
|
|
|
<table class="modern-table">
|
|
<tbody>
|
|
<tr>
|
|
<td>ผู้ป่วยรับบริการห้องฉุกเฉิน (ER)</td>
|
|
<td style="text-align: right; font-weight: 600; color: var(--primary);"><?php echo number_format($cc_er); ?> ราย</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ผ่านการซักประวัติ</td>
|
|
<td style="text-align: right; font-weight: 600; color: var(--primary);"><?php echo number_format($cc_pq); ?> ราย</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ผ่านการตรวจ ณ ห้องตรวจ</td>
|
|
<td style="text-align: right; font-weight: 600; color: var(--primary);"><?php echo number_format($cc_pqd); ?> ราย</td>
|
|
</tr>
|
|
<tr>
|
|
<td>รับบริการห้องทันตกรรม</td>
|
|
<td style="text-align: right; font-weight: 600; color: var(--primary);"><?php echo number_format($cc_dt); ?> ราย</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ผู้ป่วยนอกถูกส่งต่อ (Refer Out)</td>
|
|
<td style="text-align: right; font-weight: 600; color: var(--primary);"><?php echo number_format($cc_ovst); ?> ราย</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h3 style="margin-top: 30px; margin-bottom: 20px; color: var(--success); display: flex; align-items: center; gap: 8px;">
|
|
<svg style="width:24px;height:24px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
|
|
ผู้ป่วยใน (IPD)
|
|
</h3>
|
|
<table class="modern-table">
|
|
<tbody>
|
|
<tr>
|
|
<td>รับใหม่ (Admit)</td>
|
|
<td style="text-align: right; font-weight: 600; color: var(--success);"><?php echo number_format($cc_ipt); ?> ราย</td>
|
|
</tr>
|
|
<tr>
|
|
<td>จำหน่าย (Discharge)</td>
|
|
<td style="text-align: right; font-weight: 600; color: var(--success);"><?php echo number_format($cc_ipt2); ?> ราย</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ผู้ป่วยในถูกส่งต่อ (Refer Out IPD)</td>
|
|
<td style="text-align: right; font-weight: 600; color: var(--success);"><?php echo number_format($cc_ipt3); ?> ราย</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h3 style="margin-top: 30px; margin-bottom: 20px; color: #8b5cf6; display: flex; align-items: center; gap: 8px;">
|
|
<svg style="width:24px;height:24px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"></path></svg>
|
|
บริการอื่นๆ
|
|
</h3>
|
|
<table class="modern-table">
|
|
<tbody>
|
|
<tr>
|
|
<td>ใบสั่งจ่ายยาจากห้องยา</td>
|
|
<td style="text-align: right; font-weight: 600; color: #8b5cf6;"><?php echo number_format($cc_rx); ?> ครั้ง</td>
|
|
</tr>
|
|
<tr>
|
|
<td>ใบส่งตรวจห้องแล็บ</td>
|
|
<td style="text-align: right; font-weight: 600; color: #8b5cf6;"><?php echo number_format($cc_lab1); ?> ใบ</td>
|
|
</tr>
|
|
<tr>
|
|
<td>รายงานผลแล็บแล้ว</td>
|
|
<td style="text-align: right; font-weight: 600; color: #8b5cf6;"><?php echo number_format($cc_lab2); ?> ใบ</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- News Column -->
|
|
<div class="glass-panel" style="grid-column: span 1;">
|
|
<h3 style="margin-bottom: 20px; color: var(--text-dark); display: flex; align-items: center; gap: 8px;">
|
|
<svg style="width:24px;height:24px;color:var(--warning);" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z"></path></svg>
|
|
รายการประกาศอัปเดต (News)
|
|
</h3>
|
|
|
|
<div style="display:flex; flex-direction:column; gap:16px;">
|
|
<?php if(count($news_items) > 0): ?>
|
|
<?php foreach($news_items as $news): ?>
|
|
<div style="padding: 16px; background: rgba(255,255,255,0.4); border-radius: 8px; border-left: 4px solid var(--primary);">
|
|
<div style="font-size: 0.8rem; color: var(--primary); margin-bottom: 8px; font-weight: 600;">
|
|
<?php echo datetime_to_date($news['date_add']); ?>
|
|
</div>
|
|
<div style="font-size: 0.95rem; color: var(--text-dark); line-height: 1.5;">
|
|
<?php echo htmlspecialchars($news['title']); ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<div style="text-align: center; color: var(--text-muted); padding: 40px 0;">ไม่มีข้อมูลประกาศ</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|