-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit_db.sql
More file actions
72 lines (66 loc) · 2.65 KB
/
init_db.sql
File metadata and controls
72 lines (66 loc) · 2.65 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
-- Drop existing tables if they exist (optional, for reset purposes)
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS patients;
DROP TABLE IF EXISTS appointments;
DROP TABLE IF EXISTS messages;
DROP TABLE IF EXISTS system_settings;
-- Create the users table
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
role TEXT DEFAULT 'doctor', -- 'doctor' or 'admin'
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create the patients table
CREATE TABLE patients (
id INTEGER PRIMARY KEY AUTOINCREMENT,
doctor_id INTEGER NOT NULL, -- Foreign key linking to users table
name TEXT NOT NULL,
age INTEGER NOT NULL,
gender TEXT NOT NULL CHECK (gender IN ('Male', 'Female', 'Other')),
condition TEXT NOT NULL,
allergies TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (doctor_id) REFERENCES users (id) ON DELETE CASCADE
);
-- Create the appointments table
CREATE TABLE appointments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
patient_id INTEGER NOT NULL, -- Foreign key linking to patients table
doctor_id INTEGER NOT NULL, -- Foreign key linking to users table
appointment_date DATE NOT NULL,
appointment_time TIME NOT NULL,
reason TEXT,
status TEXT DEFAULT 'Scheduled', -- 'Scheduled', 'Completed', 'Cancelled'
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (patient_id) REFERENCES patients (id) ON DELETE CASCADE,
FOREIGN KEY (doctor_id) REFERENCES users (id) ON DELETE CASCADE
);
-- Create the messages table
CREATE TABLE messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
sender_id INTEGER NOT NULL, -- Foreign key linking to users table
receiver_id INTEGER NOT NULL, -- Foreign key linking to users table
message TEXT NOT NULL,
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (sender_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (receiver_id) REFERENCES users (id) ON DELETE CASCADE
);
-- Create the system_settings table
CREATE TABLE system_settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
setting_name TEXT NOT NULL UNIQUE,
setting_value TEXT NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert default admin user
INSERT INTO users (name, email, password, role)
VALUES (
'Admin',
'admin@ehrsystem.com',
'scrypt:32768:8:1$oICSE7k2zFIQ9bo8$be980a0edd97a1ef6becca9a97307c639e344ffab1056932cc08cd20c3f387d71e565021a46aa95b2c9dd99e5facab68d60b9bcee28cf23cd37bfe06286e38b2',
'admin'
);