-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDBMS hospital Project.session.sql
More file actions
93 lines (93 loc) · 2.97 KB
/
DBMS hospital Project.session.sql
File metadata and controls
93 lines (93 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
CREATE DATABASE hospital_db;
USE hospital_db;
-- Users Table
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
role ENUM('front_desk', 'data_entry', 'doctor', 'admin') NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert default admin credentials into users
INSERT INTO users (username, password, name, email, role)
VALUES (
'admin',
'$2b$12$yjVP.tZDZoPlMICBAKSbne85.8FUHg7DrdC1AbVurKfSL5xC5h3S2', -- password: admin123
'Admin User',
'admin@example.com',
'admin'
);
-- Rooms Table
CREATE TABLE rooms (
id INT AUTO_INCREMENT PRIMARY KEY,
room_number VARCHAR(10) NOT NULL UNIQUE,
capacity INT NOT NULL,
current_occupancy INT DEFAULT 0
);
-- Patients Table
CREATE TABLE patients (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
dob DATE NOT NULL,
gender ENUM('male', 'female', 'other') NOT NULL,
contact VARCHAR(20),
address TEXT,
status ENUM('outpatient', 'admitted', 'discharged') DEFAULT 'outpatient',
admission_date DATE,
discharge_date DATE,
room_id INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (room_id) REFERENCES rooms(id) ON DELETE
SET NULL
);
-- Doctors
CREATE TABLE doctors (
doctor_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
shift ENUM('Morning', 'Afternoon', 'Night') NOT NULL,
specialization VARCHAR(100) NOT NULL,
FOREIGN KEY (doctor_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Appointments Table
CREATE TABLE appointments (
id INT AUTO_INCREMENT PRIMARY KEY,
patient_id INT NOT NULL,
doctor_id INT NOT NULL,
appointment_date DATE NOT NULL,
appointment_time TIME NOT NULL,
reason TEXT,
priority ENUM('low', 'medium', 'high') DEFAULT 'medium',
FOREIGN KEY (patient_id) REFERENCES patients(id) ON DELETE CASCADE,
FOREIGN KEY (doctor_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Table to store types of diagnostic tests
CREATE TABLE tests (
id INT AUTO_INCREMENT PRIMARY KEY,
patient_id INT NOT NULL,
test_name VARCHAR(100),
result TEXT,
test_date DATE,
pdf_path VARCHAR(255),
FOREIGN KEY (patient_id) REFERENCES patients(id) ON DELETE CASCADE
);
CREATE TABLE prescriptions (
id INT AUTO_INCREMENT PRIMARY KEY,
patient_id INT NOT NULL,
doctor_id INT NOT NULL,
prescription TEXT NOT NULL,
date_prescribed DATE,
FOREIGN KEY (patient_id) REFERENCES patients(id) ON DELETE CASCADE,
FOREIGN KEY (doctor_id) REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE treatments (
id INT AUTO_INCREMENT PRIMARY KEY,
patient_id INT NOT NULL,
doctor_id INT NOT NULL,
treatment_name VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
treatment_date DATE NOT NULL,
FOREIGN KEY (patient_id) REFERENCES patients(id) ON DELETE CASCADE,
FOREIGN KEY (doctor_id) REFERENCES users(id) ON DELETE CASCADE
);