153 lines
6.5 KiB
PHP
153 lines
6.5 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_role('receptionist');
|
|
require_once 'db/config.php';
|
|
|
|
$message = '';
|
|
$error = '';
|
|
$doctors = [];
|
|
|
|
try {
|
|
$pdo = db();
|
|
// Fetch doctors (users with role 'doctor') for the dropdown
|
|
$stmt = $pdo->query("SELECT id, username FROM users WHERE role = 'doctor' ORDER BY username");
|
|
$doctors = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$error = "Database error: " . $e->getMessage();
|
|
}
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$patient_name = trim($_POST['patient_name']);
|
|
$phone_number = trim($_POST['phone_number']);
|
|
$address = trim($_POST['address']);
|
|
$doctor_id = $_POST['doctor_id'];
|
|
|
|
if (empty($patient_name) || empty($doctor_id)) {
|
|
$error = "Patient name and assigned doctor are required.";
|
|
} else {
|
|
try {
|
|
// Generate a unique patient ID
|
|
$prefix = 'PT';
|
|
$stmt = $pdo->query("SELECT MAX(id) FROM patients");
|
|
$last_id = $stmt->fetchColumn();
|
|
$next_id = ($last_id) ? $last_id + 1 : 1;
|
|
$patient_id = $prefix . str_pad($next_id, 6, '0', STR_PAD_LEFT);
|
|
|
|
// Set initial status
|
|
$status = 'Pending';
|
|
$total_fee = 20.00; // Example fee
|
|
|
|
$sql = "INSERT INTO patients (patient_id, patient_name, phone_number, address, doctor_id, status, total_fee) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
if ($stmt->execute([$patient_id, $patient_name, $phone_number, $address, $doctor_id, $status, $total_fee])) {
|
|
$_SESSION['message'] = "Patient registered successfully! Patient ID: $patient_id";
|
|
header("Location: reception.php");
|
|
exit();
|
|
} else {
|
|
$error = "Failed to register patient.";
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error = "Database error: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Register Patient - Hospital Management</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="d-flex">
|
|
<!-- Sidebar -->
|
|
<div class="sidebar d-flex flex-column flex-shrink-0 p-3" style="width: 280px;">
|
|
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
|
|
<i class="bi bi-heart-pulse-fill me-2"></i>
|
|
<span class="fs-4">ClinicSys</span>
|
|
</a>
|
|
<hr>
|
|
<ul class="nav nav-pills flex-column mb-auto">
|
|
<li class="nav-item">
|
|
<a href="reception.php" class="nav-link text-white">
|
|
<i class="bi bi-grid-fill me-2"></i>
|
|
Dashboard
|
|
</a>
|
|
</li>
|
|
<li>
|
|
<a href="patient_register.php" class="nav-link active" aria-current="page">
|
|
<i class="bi bi-person-plus-fill me-2"></i>
|
|
Register Patient
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
<hr>
|
|
<div class="dropdown">
|
|
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle me-2"></i>
|
|
<strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main Content -->
|
|
<div class="main-content flex-grow-1 p-4">
|
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h3 mb-0 text-gray-800">Register New Patient</h1>
|
|
</header>
|
|
|
|
<?php if (!empty($error)): ?>
|
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card shadow">
|
|
<div class="card-body p-5">
|
|
<form action="patient_register.php" method="post">
|
|
<div class="mb-4">
|
|
<label for="patient_name" class="form-label">Patient Name <span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="patient_name" name="patient_name" required>
|
|
</div>
|
|
<div class="mb-4">
|
|
<label for="phone_number" class="form-label">Phone Number</label>
|
|
<input type="text" class="form-control" id="phone_number" name="phone_number">
|
|
</div>
|
|
<div class="mb-4">
|
|
<label for="address" class="form-label">Address</label>
|
|
<input type="text" class="form-control" id="address" name="address">
|
|
</div>
|
|
<div class="mb-4">
|
|
<label for="doctor_id" class="form-label">Assign Doctor <span class="text-danger">*</span></label>
|
|
<select class="form-select" id="doctor_id" name="doctor_id" required>
|
|
<option value="">Select a Doctor</option>
|
|
<?php foreach ($doctors as $doctor): ?>
|
|
<option value="<?php echo htmlspecialchars($doctor['id']); ?>">
|
|
Dr. <?php echo htmlspecialchars($doctor['username']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="d-flex justify-content-end">
|
|
<button type="submit" class="btn btn-primary-custom">Register Patient</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|