-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_database.py
More file actions
104 lines (89 loc) · 3.84 KB
/
Copy pathsetup_database.py
File metadata and controls
104 lines (89 loc) · 3.84 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
94
95
96
97
98
99
100
101
102
103
104
import sqlite3
import random
from datetime import datetime, timedelta
def setup_database():
conn = sqlite3.connect('clinic.db')
cursor = conn.cursor()
cursor.executescript('''
CREATE TABLE IF NOT EXISTS patients (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT,
phone TEXT,
date_of_birth DATE,
gender TEXT,
city TEXT,
registered_date DATE
);
CREATE TABLE IF NOT EXISTS doctors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
specialization TEXT,
department TEXT,
phone TEXT
);
CREATE TABLE IF NOT EXISTS appointments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
patient_id INTEGER,
doctor_id INTEGER,
appointment_date DATETIME,
status TEXT,
notes TEXT,
FOREIGN KEY(patient_id) REFERENCES patients(id),
FOREIGN KEY(doctor_id) REFERENCES doctors(id)
);
CREATE TABLE IF NOT EXISTS treatments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
appointment_id INTEGER,
treatment_name TEXT,
cost REAL,
duration_minutes INTEGER,
FOREIGN KEY(appointment_id) REFERENCES appointments(id)
);
CREATE TABLE IF NOT EXISTS invoices (
id INTEGER PRIMARY KEY AUTOINCREMENT,
patient_id INTEGER,
invoice_date DATE,
total_amount REAL,
paid_amount REAL,
status TEXT,
FOREIGN KEY(patient_id) REFERENCES patients(id)
);
''')
specializations = ['Dermatology', 'Cardiology', 'Orthopedics', 'General', 'Pediatrics']
cities = ['New York', 'London', 'Mumbai', 'Tokyo', 'Berlin', 'Paris', 'Dubai', 'Sydney']
# Insert 15 Doctors
for i in range(15):
spec = random.choice(specializations)
cursor.execute("INSERT INTO doctors (name, specialization, department, phone) VALUES (?, ?, ?, ?)",
(f"Dr. Smith_{i}", spec, f"{spec} Dept", f"555-010{i}"))
# Insert 200 Patients
for i in range(1, 201):
cursor.execute("INSERT INTO patients (first_name, last_name, email, city, gender, registered_date) VALUES (?, ?, ?, ?, ?, ?)",
(f"Patient_{i}", f"Last_{i}", f"p{i}@clinic.com", random.choice(cities), random.choice(['M', 'F']),
(datetime.now() - timedelta(days=random.randint(0, 365))).date()))
# Insert 500 Appointments, 350 Treatments, and 300 Invoices
for i in range(1, 501):
p_id = random.randint(1, 200)
d_id = random.randint(1, 15)
date = datetime.now() - timedelta(days=random.randint(0, 365))
status = random.choice(['Completed', 'Scheduled', 'Cancelled', 'No-Show'])
cursor.execute("INSERT INTO appointments (patient_id, doctor_id, appointment_date, status) VALUES (?, ?, ?, ?)",
(p_id, d_id, date, status))
# Link treatments to completed appointments
if status == 'Completed' and i <= 350:
cursor.execute("INSERT INTO treatments (appointment_id, treatment_name, cost, duration_minutes) VALUES (?, ?, ?, ?)",
(i, "Medical Procedure", random.uniform(50, 5000), random.randint(15, 120)))
# Link invoices
if i <= 300:
total = random.uniform(100, 5000)
inv_status = random.choice(['Paid', 'Pending', 'Overdue'])
paid = total if inv_status == 'Paid' else 0
cursor.execute("INSERT INTO invoices (patient_id, invoice_date, total_amount, paid_amount, status) VALUES (?, ?, ?, ?, ?)",
(p_id, date.date(), total, paid, inv_status))
conn.commit()
print(f"Created 200 patients, 15 doctors, 500 appointments, 350 treatments, and 300 invoices.")
conn.close()
if __name__ == "__main__":
setup_database()