163 lines
7.9 KiB
PHP
163 lines
7.9 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['hospital_id'])) {
|
|
header("Location: hospital_login.php");
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
$pdo = db();
|
|
|
|
// Create recipients table if it doesn't exist
|
|
try {
|
|
$sql = "
|
|
CREATE TABLE IF NOT EXISTS recipients (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
hospital_id INT NOT NULL,
|
|
patient_name VARCHAR(255) NOT NULL,
|
|
patient_dob DATE NOT NULL,
|
|
blood_type VARCHAR(5) NOT NULL,
|
|
organ_needed VARCHAR(100) NOT NULL,
|
|
urgency_level VARCHAR(50) NOT NULL,
|
|
contact_phone VARCHAR(20) NOT NULL,
|
|
contact_email VARCHAR(255) NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (hospital_id) REFERENCES hospitals(id)
|
|
)";
|
|
$pdo->exec($sql);
|
|
} catch (PDOException $e) {
|
|
die("Could not create table: " . $e->getMessage());
|
|
}
|
|
|
|
$message = '';
|
|
$error = '';
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$patient_name = trim($_POST['patient_name']);
|
|
$patient_dob = trim($_POST['patient_dob']);
|
|
$blood_type = trim($_POST['blood_type']);
|
|
$organ_needed = trim($_POST['organ_needed']);
|
|
$urgency_level = trim($_POST['urgency_level']);
|
|
$contact_phone = trim($_POST['contact_phone']);
|
|
$contact_email = trim($_POST['contact_email']);
|
|
$hospital_id = $_SESSION['hospital_id'];
|
|
|
|
if (empty($patient_name) || empty($patient_dob) || empty($blood_type) || empty($organ_needed) || empty($urgency_level) || empty($contact_phone) || empty($contact_email)) {
|
|
$error = "All fields are required.";
|
|
} else {
|
|
$sql = "INSERT INTO recipients (hospital_id, patient_name, patient_dob, blood_type, organ_needed, urgency_level, contact_phone, contact_email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
$stmt = $pdo->prepare($sql);
|
|
try {
|
|
$stmt->execute([$hospital_id, $patient_name, $patient_dob, $blood_type, $organ_needed, $urgency_level, $contact_phone, $contact_email]);
|
|
$message = "Recipient registered successfully!";
|
|
} catch (PDOException $e) {
|
|
$error = "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>Recipient Registration - Organ Donation</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
font-family: 'Poppins', sans-serif;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="bg-gray-100">
|
|
|
|
<nav class="bg-white shadow-md">
|
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
<div class="flex justify-between h-16">
|
|
<div class="flex">
|
|
<a href="hospital_dashboard.php" class="flex-shrink-0 flex items-center">
|
|
<span class="font-bold text-xl text-blue-600">OrganConnect - Hospital Portal</span>
|
|
</a>
|
|
</div>
|
|
<div class="flex items-center">
|
|
<a href="hospital_dashboard.php" class="px-3 py-2 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-200">Dashboard</a>
|
|
<a href="logout.php" class="px-3 py-2 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-200">Logout</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mx-auto px-4 py-12">
|
|
<div class="max-w-2xl mx-auto bg-white p-8 rounded-lg shadow-lg">
|
|
<h1 class="text-3xl font-bold text-center text-gray-800 mb-6">Register New Recipient</h1>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4" role="alert">
|
|
<span class="block sm:inline"><?php echo htmlspecialchars($message); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($error): ?>
|
|
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4" role="alert">
|
|
<span class="block sm:inline"><?php echo htmlspecialchars($error); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!$message): ?>
|
|
<form action="recipient_registration.php" method="POST" class="space-y-6">
|
|
<div>
|
|
<label for="patient_name" class="block text-sm font-medium text-gray-700">Patient Full Name</label>
|
|
<input type="text" name="patient_name" id="patient_name" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="patient_dob" class="block text-sm font-medium text-gray-700">Date of Birth</label>
|
|
<input type="date" name="patient_dob" id="patient_dob" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="blood_type" class="block text-sm font-medium text-gray-700">Blood Type</label>
|
|
<select name="blood_type" id="blood_type" required class="mt-1 block w-full px-3 py-2 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
<option>A+</option>
|
|
<option>A-</option>
|
|
<option>B+</option>
|
|
<option>B-</option>
|
|
<option>AB+</option>
|
|
<option>AB-</option>
|
|
<option>O+</option>
|
|
<option>O-</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="organ_needed" class="block text-sm font-medium text-gray-700">Organ Needed</label>
|
|
<input type="text" name="organ_needed" id="organ_needed" required placeholder="e.g., Kidney, Liver, Heart" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="urgency_level" class="block text-sm font-medium text-gray-700">Urgency Level</label>
|
|
<select name="urgency_level" id="urgency_level" required class="mt-1 block w-full px-3 py-2 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
<option>High</option>
|
|
<option>Medium</option>
|
|
<option>Low</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="contact_phone" class="block text-sm font-medium text-gray-700">Emergency Contact Phone</label>
|
|
<input type="tel" name="contact_phone" id="contact_phone" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<label for="contact_email" class="block text-sm font-medium text-gray-700">Emergency Contact Email</label>
|
|
<input type="email" name="contact_email" id="contact_email" required class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm">
|
|
</div>
|
|
<div>
|
|
<button type="submit" class="w-full flex justify-center py-3 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
|
Register Recipient
|
|
</button>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|