212 lines
12 KiB
PHP
212 lines
12 KiB
PHP
<?php
|
|
$search_patient = $_GET['patient'] ?? '';
|
|
$search_doctor = $_GET['doctor'] ?? '';
|
|
$search_date = $_GET['date'] ?? '';
|
|
|
|
$query = "
|
|
SELECT v.*, p.name as patient_name, p.dob as patient_dob, p.gender as patient_gender, d.name_$lang as doctor_name
|
|
FROM visits v
|
|
JOIN patients p ON v.patient_id = p.id
|
|
JOIN doctors d ON v.doctor_id = d.id
|
|
WHERE 1=1";
|
|
$params = [];
|
|
|
|
if ($search_patient) {
|
|
$query .= " AND p.name LIKE ?";
|
|
$params[] = "%$search_patient%";
|
|
}
|
|
if ($search_doctor) {
|
|
$query .= " AND (d.name_en LIKE ? OR d.name_ar LIKE ?)";
|
|
$params[] = "%$search_doctor%";
|
|
$params[] = "%$search_doctor%";
|
|
}
|
|
if ($search_date) {
|
|
$query .= " AND DATE(v.visit_date) = ?";
|
|
$params[] = $search_date;
|
|
}
|
|
|
|
$query .= " ORDER BY v.visit_date DESC";
|
|
$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;
|
|
}
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h3 class="fw-bold text-secondary"><?php echo __('visits'); ?></h3>
|
|
<button class="btn btn-info shadow-sm text-white" data-bs-toggle="modal" data-bs-target="#recordVisitModal">
|
|
<i class="bi bi-plus-lg me-1"></i> <?php echo __('add_visit'); ?>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Search Bar -->
|
|
<div class="card shadow-sm border-0 mb-4">
|
|
<div class="card-body">
|
|
<form method="GET" action="" class="row g-3">
|
|
<div class="col-md-3">
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0 text-muted"><i class="bi bi-search"></i></span>
|
|
<input type="text" name="patient" class="form-control bg-light border-start-0" placeholder="<?php echo __('patient'); ?>" value="<?php echo htmlspecialchars($search_patient); ?>">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0 text-muted"><i class="bi bi-person-badge"></i></span>
|
|
<input type="text" name="doctor" class="form-control bg-light border-start-0" placeholder="<?php echo __('doctor'); ?>" value="<?php echo htmlspecialchars($search_doctor); ?>">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0 text-muted"><i class="bi bi-calendar-event"></i></span>
|
|
<input type="date" name="date" class="form-control bg-light border-start-0" value="<?php echo htmlspecialchars($search_date); ?>">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button type="submit" class="btn btn-secondary w-100"><?php echo __('search'); ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm border-0">
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="table-light text-secondary">
|
|
<tr>
|
|
<th class="px-4 py-3">#</th>
|
|
<th class="py-3"><?php echo __('date'); ?></th>
|
|
<th class="py-3"><?php echo __('patient'); ?></th>
|
|
<th class="py-3"><?php echo __('doctor'); ?></th>
|
|
<th class="py-3"><?php echo __('diagnosis'); ?></th>
|
|
<th class="py-3"><?php echo __('vitals'); ?></th>
|
|
<th class="py-3"><?php echo __('treatment'); ?></th>
|
|
<th class="py-3"><?php echo __('inquiries'); ?></th>
|
|
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($visits)): ?>
|
|
<tr>
|
|
<td colspan="9" class="text-center py-5 text-muted">
|
|
<i class="bi bi-clipboard2-pulse display-4 d-block mb-3"></i>
|
|
No visits found.
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($visits as $v): ?>
|
|
<tr>
|
|
<td class="px-4 text-muted small"><?php echo $v['id']; ?></td>
|
|
<td class="text-secondary"><?php echo date('Y-m-d H:i', strtotime($v['visit_date'])); ?></td>
|
|
<td class="fw-semibold text-dark"><?php echo htmlspecialchars($v['patient_name'] ?? ''); ?></td>
|
|
<td class="text-secondary"><?php echo htmlspecialchars($v['doctor_name'] ?? ''); ?></td>
|
|
<td>
|
|
<?php
|
|
$diagnosis_plain = strip_tags($v['diagnosis'] ?? '');
|
|
$snippet = mb_strimwidth($diagnosis_plain, 0, 30, "...");
|
|
?>
|
|
<small class="text-muted" title="<?php echo htmlspecialchars($diagnosis_plain); ?>"><?php echo htmlspecialchars($snippet); ?></small>
|
|
</td>
|
|
<td>
|
|
<?php
|
|
$vitals = [];
|
|
if(!empty($v['blood_pressure'])) $vitals[] = '<i class="bi bi-heart-pulse me-1"></i>' . htmlspecialchars($v['blood_pressure'] ?? '');
|
|
if(!empty($v['weight'])) $vitals[] = '<i class="bi bi-speedometer2 me-1"></i>' . htmlspecialchars($v['weight'] ?? '') . 'kg';
|
|
if(!empty($v['temperature'])) $vitals[] = '<i class="bi bi-thermometer-half me-1"></i>' . htmlspecialchars($v['temperature'] ?? '') . '°C';
|
|
echo implode('<br>', $vitals);
|
|
?>
|
|
</td>
|
|
<td>
|
|
<?php
|
|
$treatment_plain = strip_tags($v['treatment_plan'] ?? '');
|
|
$t_snippet = mb_strimwidth($treatment_plain, 0, 30, "...");
|
|
?>
|
|
<small class="text-muted" title="<?php echo htmlspecialchars($treatment_plain); ?>"><?php echo htmlspecialchars($t_snippet); ?></small>
|
|
</td>
|
|
<td>
|
|
<div class="d-flex gap-1">
|
|
<?php if (!empty($v['lab_inquiries'])): ?>
|
|
<span class="badge bg-info text-white" title="<?php echo count($v['lab_inquiries']); ?> <?php echo __('laboratory'); ?>" data-bs-toggle="tooltip">
|
|
<i class="bi bi-flask"></i> <?php echo count($v['lab_inquiries']); ?>
|
|
</span>
|
|
<?php endif; ?>
|
|
<?php if (!empty($v['xray_inquiries'])): ?>
|
|
<span class="badge bg-dark text-white" title="<?php echo count($v['xray_inquiries']); ?> <?php echo __('xray'); ?>" data-bs-toggle="tooltip">
|
|
<i class="bi bi-camera"></i> <?php echo count($v['xray_inquiries']); ?>
|
|
</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
<td class="text-end px-4">
|
|
<div class="d-flex justify-content-end gap-1">
|
|
<?php
|
|
// Encode safely for attribute
|
|
$json_v = htmlspecialchars(json_encode($v, JSON_UNESCAPED_UNICODE) ?: '{}', ENT_QUOTES, 'UTF-8');
|
|
$patient_name_json = htmlspecialchars(json_encode($v['patient_name'] ?? '', JSON_UNESCAPED_UNICODE) ?: '""', ENT_QUOTES, 'UTF-8');
|
|
?>
|
|
<button class="btn btn-sm btn-outline-success"
|
|
onclick="showVisitResultsModal(JSON.parse(this.getAttribute('data-visit')))"
|
|
data-visit="<?php echo $json_v; ?>"
|
|
data-bs-toggle="tooltip" title="<?php echo __('view_results'); ?>">
|
|
<i class="bi bi-eye"></i>
|
|
</button>
|
|
<button class="btn btn-sm btn-outline-warning"
|
|
onclick="showEditVisitModal(JSON.parse(this.getAttribute('data-visit')))"
|
|
data-visit="<?php echo $json_v; ?>"
|
|
data-bs-toggle="tooltip" title="<?php echo __('edit'); ?>">
|
|
<i class="bi bi-pencil-square"></i>
|
|
</button>
|
|
<button class="btn btn-sm btn-outline-info"
|
|
onclick="showLabInquiryModalFromVisit(<?php echo $v['id']; ?>, <?php echo $v['patient_id']; ?>, <?php echo $patient_name_json; ?>)"
|
|
data-bs-toggle="tooltip" title="<?php echo __('add_inquiry'); ?>">
|
|
<i class="bi bi-flask"></i>
|
|
</button>
|
|
<button class="btn btn-sm btn-outline-dark"
|
|
onclick="showXrayInquiryModalFromVisit(<?php echo $v['id']; ?>, <?php echo $v['patient_id']; ?>, <?php echo $patient_name_json; ?>)"
|
|
data-bs-toggle="tooltip" title="<?php echo __('add_xray_inquiry'); ?>">
|
|
<i class="bi bi-camera"></i>
|
|
</button>
|
|
<button class="btn btn-sm btn-outline-primary"
|
|
onclick="showReportModal(<?php echo $v['id']; ?>)"
|
|
data-bs-toggle="tooltip" title="<?php echo __('new_report'); ?>">
|
|
<i class="bi bi-file-earmark-plus"></i>
|
|
</button>
|
|
<button class="btn btn-sm btn-outline-success"
|
|
onclick="showBillModal(<?php echo $v['id']; ?>, <?php echo $v['patient_id']; ?>, <?php echo $patient_name_json; ?>)"
|
|
data-bs-toggle="tooltip" title="<?php echo __('create_bill'); ?>">
|
|
<i class="bi bi-receipt"></i>
|
|
</button>
|
|
<a href="print_prescription.php?visit_id=<?php echo $v['id']; ?>" target="_blank"
|
|
class="btn btn-sm btn-outline-dark"
|
|
data-bs-toggle="tooltip" title="<?php echo __('print_prescription'); ?>">
|
|
<i class="bi bi-printer"></i>
|
|
</a>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|