-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
75 lines (66 loc) · 2.14 KB
/
database.py
File metadata and controls
75 lines (66 loc) · 2.14 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
import sqlite3
def init_db():
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
# Users Table
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
fullname TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
role TEXT NOT NULL,
specialization TEXT,
license_id TEXT
)
''')
# Consultations Table
cursor.execute('''
CREATE TABLE IF NOT EXISTS consultations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
patient_username TEXT NOT NULL,
symptoms TEXT NOT NULL,
result TEXT,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (patient_username) REFERENCES users (username)
)
''')
# ✅ Appointments Table (NEW)
cursor.execute('''
CREATE TABLE IF NOT EXISTS appointments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
patient_username TEXT NOT NULL,
doctor_username TEXT NOT NULL,
specialization TEXT NOT NULL,
medical_info TEXT NOT NULL,
appointment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status TEXT DEFAULT 'Pending',
FOREIGN KEY (patient_username) REFERENCES users (username),
FOREIGN KEY (doctor_username) REFERENCES users (username)
)
''')
# Chat Messages
cursor.execute("""
CREATE TABLE IF NOT EXISTS messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
sender TEXT,
receiver TEXT,
message TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
cursor.execute('''
CREATE TABLE IF NOT EXISTS doctor_fees (
doctor_id INTEGER PRIMARY KEY,
fee_amount REAL NOT NULL CHECK (fee_amount >= 0),
upi_id TEXT NOT NULL,
last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (doctor_id) REFERENCES users (id)
)
''')
conn.commit()
conn.close()
print("Database initialized successfully.")
if __name__ == "__main__":
init_db()