-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
80 lines (73 loc) · 2.52 KB
/
schema.sql
File metadata and controls
80 lines (73 loc) · 2.52 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
-- Users table (for authentication and roles)
CREATE TABLE Users (
UserID INT AUTO_INCREMENT PRIMARY KEY,
Username VARCHAR(50) UNIQUE NOT NULL,
PasswordHash VARCHAR(100) NOT NULL,
Role VARCHAR(20) NOT NULL CHECK (Role IN ('Admin', 'Doctor', 'Nurse', 'Receptionist')),
IsActive BOOLEAN DEFAULT FALSE
);
-- Wards table
CREATE TABLE Wards (
WardID VARCHAR(4) PRIMARY KEY,
WardName VARCHAR(25) NOT NULL,
NumberBeds INT DEFAULT 5,
NurseInCharge VARCHAR(50) NOT NULL
);
-- Patients table with foreign key reference to Wards
CREATE TABLE Patients (
PatientID VARCHAR(5) PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Initials VARCHAR(3),
Sex CHAR(1) NOT NULL CHECK (Sex IN ('M', 'F')),
Address VARCHAR(50),
PostCode VARCHAR(6),
AdmissionDate DATE,
DOB DATE,
WardID VARCHAR(4),
FOREIGN KEY (WardID) REFERENCES Wards(WardID)
);
-- Doctors table with foreign key reference to Users
CREATE TABLE Doctors (
DoctorID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Specialization VARCHAR(50),
UserID INT UNIQUE,
FOREIGN KEY (UserID) REFERENCES Users(UserID) ON DELETE CASCADE
);
-- Nurses table with foreign key reference to Users
CREATE TABLE Nurses (
NurseID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
UserID INT UNIQUE,
FOREIGN KEY (UserID) REFERENCES Users(UserID) ON DELETE CASCADE
);
-- Appointments table with foreign key references to Patients and Doctors
CREATE TABLE Appointments (
AppointmentID INT AUTO_INCREMENT PRIMARY KEY,
PatientID VARCHAR(5) NOT NULL,
DoctorID VARCHAR(5) NOT NULL,
AppointmentDatetime DATETIME NOT NULL,
Status VARCHAR(20) DEFAULT 'Scheduled',
FOREIGN KEY (PatientID) REFERENCES Patients(PatientID),
FOREIGN KEY (DoctorID) REFERENCES Doctors(DoctorID)
);
-- MedicalRecords table with foreign key references to Patients and Doctors
CREATE TABLE MedicalRecords (
RecordID INT AUTO_INCREMENT PRIMARY KEY,
PatientID VARCHAR(5) NOT NULL,
DoctorID VARCHAR(5) NOT NULL,
Diagnosis TEXT,
TreatmentPlan TEXT,
Prescription TEXT,
FOREIGN KEY (PatientID) REFERENCES Patients(PatientID),
FOREIGN KEY (DoctorID) REFERENCES Doctors(DoctorID)
);
-- Billing table with foreign key reference to Patients
CREATE TABLE Billing (
BillID INT AUTO_INCREMENT PRIMARY KEY,
PatientID VARCHAR(5) NOT NULL,
BillAmount DECIMAL(10, 2) NOT NULL,
BillDate DATE NOT NULL,
Status VARCHAR(20) DEFAULT 'Unpaid',
FOREIGN KEY (PatientID) REFERENCES Patients(PatientID)
);