0% found this document useful (0 votes)
13 views

Cs Project

This document contains code for a hospital management system that allows users to add and view patients and doctors, view appointments, and connect to a MySQL database. The code defines functions for a main menu and various options like adding patients, viewing appointments, and more.

Uploaded by

ritumishra14875
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)
13 views

Cs Project

This document contains code for a hospital management system that allows users to add and view patients and doctors, view appointments, and connect to a MySQL database. The code defines functions for a main menu and various options like adding patients, viewing appointments, and more.

Uploaded by

ritumishra14875
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/ 4

import mysql.

connector as mycon

# Database Connection

con = mycon.connect(host="localhost", user="root", passwd="123456", database="hospital",


port="3307")

# MAIN MENU

def showmenu():

while True:

print("*" * 50)

print("----------- HOSPITAL MANAGEMENT SYSTEM -----------")

print("*" * 50)

print("1 - Add New Patient")

print("2 - View All Patients")

print("3 - View Appointments")

print("4 - Add Doctor")

print("5 - View Doctors")

print("6 - Exit")

print("*" * 50)

choice = int(input("Enter your choice: "))

if choice == 1:

addPatient()

elif choice == 2:

viewPatients()

elif choice == 3:

viewAppointments()

elif choice == 4:

addDoctor()
elif choice == 5:

viewDoctors()

elif choice == 6:

print("*" * 50)

print("------ THANK YOU FOR USING HOSPITAL MANAGEMENT SYSTEM ------")

print("*" * 50)

break

# Add a New Patient

def addPatient():

print(" --- ENTER PATIENT DETAILS --- ")

pname = input("Enter Patient Name: ")

age = int(input("Enter Age: "))

gender = input("Enter Gender: ")

contact = input("Enter Contact Number: ")

diagnosis = input("Enter Diagnosis: ")

room_no = int(input("Enter Room Number: "))

q = "INSERT INTO patients (pname, age, gender, contact, diagnosis, room_no) VALUES ('{}', {}, '{}',
'{}', '{}', {})".format(pname, age, gender, contact, diagnosis, room_no)

cr1 = con.cursor()

cr1.execute(q)

con.commit()

print("--- Patient Added Successfully ---")

# View All Patients

def viewPatients():

q = "SELECT * FROM patients"

cr1 = con.cursor()
cr1.execute(q)

res = cr1.fetchall()

if res == []:

print("No patients in the database.")

else:

for row in res:

print(row)

# View Appointments

def viewAppointments():

q = "SELECT pname, age, gender, diagnosis FROM patients"

cr1 = con.cursor()

cr1.execute(q)

res = cr1.fetchall()

if res == []:

print("No appointments available.")

else:

for row in res:

print(row)

# Add Doctor

def addDoctor():

print(" --- ENTER DOCTOR DETAILS --- ")

dname = input("Enter Doctor Name: ")

specialty = input("Enter Specialty: ")

contact = input("Enter Contact Number: ")

q = "INSERT INTO doctors (dname, specialty, contact) VALUES ('{}', '{}', '{}')".format(dname,
specialty, contact)
cr1 = con.cursor()

cr1.execute(q)

con.commit()

print("--- Doctor Added Successfully ---")

# View Doctors

def viewDoctors():

q = "SELECT * FROM doctors"

cr1 = con.cursor()

cr1.execute(q)

res = cr1.fetchall()

if res == []:

print("No doctors in the database.")

else:

for row in res:

print(row)

if con.is_connected():

showmenu()

You might also like