setup_database.py
setup_database.py
cursor.execute('''
CREATE TABLE IF NOT EXISTS Hospitals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
address TEXT
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS Departments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
hospital_id INTEGER,
FOREIGN KEY(hospital_id) REFERENCES Hospitals(id)
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS Patients (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
age INTEGER,
department_id INTEGER,
status TEXT,
FOREIGN KEY(department_id) REFERENCES Departments(id)
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS Beds (
id INTEGER PRIMARY KEY AUTOINCREMENT,
department_id INTEGER,
is_occupied BOOLEAN DEFAULT 0,
patient_id INTEGER,
FOREIGN KEY(department_id) REFERENCES Departments(id),
FOREIGN KEY(patient_id) REFERENCES Patients(id)
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS Queues (
id INTEGER PRIMARY KEY AUTOINCREMENT,
department_id INTEGER,
patient_id INTEGER,
position INTEGER,
FOREIGN KEY(department_id) REFERENCES Departments(id),
FOREIGN KEY(patient_id) REFERENCES Patients(id)
)
''')
conn.commit()
conn.close()
if __name__ == "__main__":
init_db()