0% found this document useful (0 votes)
26 views8 pages

Hospetal Mangment

Uploaded by

p. saraswathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views8 pages

Hospetal Mangment

Uploaded by

p. saraswathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

import mysql.

connector

cnx = mysql.connector.connect(

user='username',

password='password',

host='localhost',

database='hospital_management_system'

def create_tables():

cursor = cnx.cursor()

cursor.execute("""

CREATE TABLE IF NOT EXISTS patients (

patient_id INT AUTO_INCREMENT PRIMARY

KEY, name VARCHAR(255),

date_of_birth DATE,

contact_number VARCHAR(20),

address VARCHAR(255)

""")

cursor.execute("""

CREATE TABLE IF NOT EXISTS appointments (

appointment_id INT AUTO_INCREMENT PRIMARY KEY,

patient_id INT,

doctor_id INT,
appointment_date DATE,

appointment_time TIME,

FOREIGN KEY (patient_id) REFERENCES patients(patient_id),

FOREIGN KEY (doctor_id) REFERENCES doctors(doctor_id)

""")

cursor.execute("""

CREATE TABLE IF NOT EXISTS doctors (

doctor_id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(255),

specialization VARCHAR(255),

contact_number VARCHAR(20)

""")

cursor.execute("""

CREATE TABLE IF NOT EXISTS bills (

bill_id INT AUTO_INCREMENT PRIMARY KEY,

patient_id INT,

bill_date DATE,

amount DECIMAL(10, 2),

FOREIGN KEY (patient_id) REFERENCES patients(patient_id)

""")

cursor.execute("""

CREATE TABLE IF NOT EXISTS lab_results (


lab_result_id INT AUTO_INCREMENT PRIMARY KEY,

patient_id INT,

test_name VARCHAR(255),

result VARCHAR(255),

date DATE,

FOREIGN KEY (patient_id) REFERENCES patients(patient_id)

""")

cursor.execute("""

CREATE TABLE IF NOT EXISTS medicines (

medicine_id INT AUTO_INCREMENT PRIMARY

KEY, name VARCHAR(255),

quantity INT,

price DECIMAL(10, 2)

""")

cursor.execute("""

CREATE TABLE IF NOT EXISTS inventory (

inventory_id INT AUTO_INCREMENT PRIMARY KEY,

medicine_id INT,

quantity INT,

FOREIGN KEY (medicine_id) REFERENCES medicines(medicine_id)

""")

cursor.execute("""
CREATE TABLE IF NOT EXISTS staff (

staff_id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(255),

role VARCHAR(255),

contact_number VARCHAR(20)

""")

cnx.commit()

def register_patient(name, date_of_birth, contact_number, address):

cursor = cnx.cursor()

query = "INSERT INTO patients (name, date_of_birth, contact_number, address) VALUES ({}, {}, {}, {})"

cursor.execute(query, (name, date_of_birth, contact_number, address))

cnx.commit()

return cursor.lastrowid

def schedule_appointment(patient_id, doctor_id, appointment_date, appointment_time):

cursor = cnx.cursor()

query = "INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time)


VALUES ({}, {}, {}, {})"

cursor.execute(query, (patient_id, doctor_id, appointment_date, appointment_time))

cnx.commit()

return cursor.lastrowid

def add _bill(patient_id, bill_date, amount):

cursor = cnx.cursor()
query = "INSERT INTO bills (patient_id, bill_date, amount) VALUES ({}, {}, {})"

cursor.execute(query, (patient_id, bill_date, amount))

cnx.commit()

return cursor.lastrowid

def add_lab_result(patient_id, test_name, result, date):

cursor = cnx.cursor()

query = "INSERT INTO lab_results (patient_id, test_name, result, date) VALUES ({}, {}, {}, {})"

cursor.execute(query, (patient_id, test_name, result, date))

cnx.commit()

return cursor.lastrowid

def add_medicine(name, quantity, price):

cursor = cnx.cursor()

query = "INSERT INTO medicines (name, quantity, price) VALUES ({}, {}, {})"

cursor.execute(query, (name, quantity, price))

cnx.commit()

return cursor.lastrowid

def add_inventory(medicine_id, quantity):

cursor = cnx.cursor()

query = "INSERT INTO inventory (medicine_id, quantity) VALUES ({}, {})"

cursor.execute(query, (medicine_id, quantity))

cnx.commit()

return cursor.lastrowid
def add_staff(name, role, contact_number):

cursor = cnx.cursor()

query = "INSERT INTO staff (name, role, contact_number) VALUES ({}, {}, {})"

cursor.execute(query, (name, role, contact_number))

cnx.commit()

return cursor.lastrowid

def main():

print("Hospital Management System")

print("1. Register Patient")

print("2. Schedule Appointment")

print("3. Add Bill")

print("4. Add Lab Result")

print("5. Add Medicine")

print("6. Add Inventory")

print("7. Add Staff")

print("8. Exit")

while True:

choice = input("Enter your choice: ")

if choice == "1":

name = input("Enter patient name: ")

date_of_birth = input("Enter patient date of birth (YYYY-MM-DD): ")

contact_number = input("Enter patient contact number: ")


address = input("Enter patient address: ")

patient_id = register_patient(name, date_of_birth, contact_number, address)

print("Patient registered successfully! Patient ID:", patient_id)

elif choice == "2":

patient_id = int(input("Enter patient ID: "))

doctor_id = int(input("Enter doctor ID: "))

appointment_date = input("Enter appointment date (YYYY-MM-DD): ")

appointment_time = input("Enter appointment time (HH:MM:SS): ")

appointment_id = schedule_appointment(patient_id, doctor_id, appointment_date,


appointment_time)

print("Appointment scheduled successfully! Appointment ID:", appointment_id)

elif choice == "3":

patient_id = int(input("Enter patient ID: "))

bill_date = input("Enter bill date (YYYY-MM-DD): ")

amount = float(input("Enter bill amount: "))

bill_id = add_bill(patient_id, bill_date, amount)

print("Bill added successfully! Bill ID:", bill_id)

elif choice == "4":

patient_id = int(input("Enter patient ID: "))

test_name = input("Enter test name: ")

result = input("Enter test result: ")

date = input("Enter test date (YYYY-MM-DD): ")

lab_result_id = add_lab_result(patient_id, test_name, result, date)

print("Lab result added successfully! Lab Result ID:", lab_result_id)

elif choice == "5":

name = input("Enter medicine name: ")


quantity = int(input("Enter medicine quantity: "))

price = float(input("Enter medicine price: "))

medicine_id = add_medicine(name, quantity, price)

print("Medicine added successfully! Medicine ID:", medicine_id)

elif choice == "6":

medicine_id = int(input("Enter medicine ID: "))

quantity = int(input("Enter inventory quantity: "))

inventory_id = add_inventory(medicine_id, quantity)

print("Inventory added successfully! Inventory ID:", inventory_id)

elif choice == "7":

name = input("Enter staff name: ")

role = input("Enter staff role: ")

contact_number = input("Enter staff contact number: ")

staff_id = add_staff(name, role, contact_number)

print("Staff added successfully! Staff ID:", staff_id)

elif choice == "8":

print("Exiting...")

break

else:

print("Invalid choice. Please try again.")

if name == " main ":

create_tables()

main()

You might also like