You are on page 1of 18

2023

HOSPITAL
MANAGEMENT
SYSTEM
PYTHON – MYSQL PROJECT
This Hospital Management System is specially designed
for the students who are preparing for Computer
Science XII, Informatics Practices XII, BCA, BSc (CS), BSc
(IT), and PGDCA. It contains different modules to
manage Books, Members, Book Issue, Book Return and
many Search options. This project also has provision of
Chart for Data Visualization.

Website : www.techtipnow.in
YouTube : www.youtube.com/c/techtipnow
Email : techtipnow@gmail.com
support@techtipnow.in
telegram : https://t.me/CBSE_IP_Class_12
https://t.me/CBSE_Computer_Science

SANJAYKUMAR
TECHTIPNOW COMPUTER EDUCATION AND PROGRAMMING
1/1/2023
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

HOSPITAL MANAGEMENT SYSTEM

DATABASE DESIGN-

OPD
OPDNO INT (PRIMARY KEY)
PNAME VARCHAR
DNAME VARCHAR
FEE INT

DOCTOR

DID INT (PRIMARY KEY)

DNAME VARCHAR

DEPARTMENT VARCHAR

APPOINT

OPDNO INT

DOA DATE

PNAME VARCHAR

DNAME VARCHAR

SYMPTOM VARCHAR

TREATMENT VARCHAR

PATIENT
PID INT (PRIMARY KEY)
PNAME VARCHAR
PADD VARCHAR
PMOB VARCHAR

1
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

CODE-

‘MAIN’ MODULE-

import os
import doctor
import appointment
import opd
import report
while(True):
#os.system('cls')
print("="*80)
print("\t\t\t------Hospital Management System------\n")
print("="*80)
print("\t\t\t\tEnter your choice")
print("\t\t\t\t1. OPD\n\t\t\t\t2. Doctor Details\n\t\t\t\t3. Appointment\n\t\t\t\t4.
Reports\n\t\t\t\t5. Exit\n")
print("="*80)
choice=int(input())
os.system('cls')
if choice == 1:
while(True):
print("\t\t\t\tSelect the Action")
print("\t\t\t\t1. New OPD\n\t\t\t\t2. Edit OPD\
\n\t\t\t\t3. Delete OPD\n\t\t\t\t4. Search OPD\
\n\t\t\t\t5. Back to Main Menu")
choice=int(input())
if choice==1:
opd.opd_input()
print("Successfully Added")

elif choice == 2:
opd.opd_edit()
elif choice ==3:
opd.opd_delete()
elif choice == 4:
opd.opd_search()
print()
elif choice ==5:
break

elif choice ==2:


while(True):
2
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

print("\t\t\t\tSelect the Action")


print("\t\t\t\t1. Add New Doctor\n\t\t\t\t2. Edit Doctor Details\
\n\t\t\t\t3. Delete Doctor Details\n\t\t\t\t4. Serch Doctor Details\
\n\t\t\t\t5. Back to Main Menu")
choice=int(input())
if choice==1:
doctor.doctor_input()
elif choice == 2:
doctor.doctor_edit()
elif choice ==3:
doctor.doctor_delete()
elif choice == 4:
doctor.doctor_search()
elif choice == 5:
break
elif choice ==3:
while(True):
print("\t\t\t\tSelect the Action")
print("\t\t\t\t1. Appointment\n\t\t\t\t2. Appointment Edit\n\t\t\t\t3. Back to
Main Menu")
choice=int(input())
if choice == 1:
appointment.appointment()
elif choice == 2:
appointment.appointment_edit()
elif choice == 3:
break
elif choice == 4:
while(True):
print("\t\t\t\tSelect the Action")
print("\t\t\t\t1. Display Doctors List\n\t\t\t\t2. Display Patient List\
\n\t\t\t\t3. Doctor History\n\t\t\t\t4. Patient History \
\n\t\t\t\t5. OPD Details\
\n\t\t\t\t6. Max Diagnose(Chart)\n\t\t\t\t7. Back to Main Menu")
choice=int(input())
if choice==1:
report.doctor_list()
print()
elif choice == 2:
report.patient_list()
elif choice ==3:
report.doctor_treatment()
elif choice == 4:

3
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

report.patient_history()
elif choice == 5:
report.opd_list()
elif choice == 6:
report.col_chart()
elif choice == 7:
break
elif choice == 5:
break

‘OPD’ MODULE-

import pandas as pd
import mysql.connector as sqlt
from tabulate import tabulate
con = sqlt.connect(host = "localhost", user = "root", passwd = "sanjay", database = "hospital")
cursor = con.cursor()
def opd_input():

opdno = int(input("Enter OPD No"))


doa = input("Enter Date of Appointment")
pname = input("Enter Patient Name")
padd = input("Enter Patient Address")
pmob = input("Enter Patient Mobile")
print("Enter Doctor Name")
qry="select * from doctor;"
df=pd.read_sql(qry,con)
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
print()
dname = input()
symptom = input("Symptom")
fee = int(input("Enter Fees"))
#rem_copies = copies
qry = "insert into opd values({},'{}','{}','{}',{})".format(opdno,doa,pname,dname,fee)
#qry = "insert into book values({},'{}','{}',{},{},{})".format(bookid, bname, author, price,
copies,rem_copies)
cursor.execute(qry)
con.commit()
qry = "insert into appoint
values({},'{}','{}','{}','{}','{}')".format(opdno,doa,pname,dname,symptom,'')
cursor.execute(qry)
con.commit()
qry1 = "select max(pid) from patient;"

4
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

cursor.execute(qry1)
t = cursor.fetchone()
if not t[0]:
pid = 1
else:
pid = t[0] + 1

print(pid)
qry2 = "insert into patient values({},'{}','{}','{}')".format(pid,pname,padd,pmob)
cursor.execute(qry2)
con.commit()
print("Successfully Added")
#cursor.close()

def opd_edit():
x=int(input("Enter OPD No"))
qry="select * from opd where opdno = {};".format(x)
cursor.execute(qry)
r=cursor.fetchone()
#con.commit()
if r:
#print("Exist")
fee = int(input("Enter New Price"))
qry = "update opd set fee = {} where opdno = {};".format(fee,x)
cursor.execute(qry)
con.commit()
print("updated")
else:
print("Wrong OPD No")
#cursor.close()

def opd_delete():
x=int(input("Enter OPD No"))
qry="select * from opd where opdno = {};".format(x)
cursor.execute(qry)
r=cursor.fetchone()
#con.commit()
if r:
#print("Exist")
ch = input("Are you sure you want to delete y/n")
if ch == 'y':
qry = "delete from opd where opdno = {};".format(x)

5
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

cursor.execute(qry)
con.commit()
print("Successfully Deleted")
else:
print("Wrong OPD No")
#cursor.close()

def opd_search():
try:
x=int(input("Enter OPD No"))
qry="select * from OPD where opdno = {};".format(x)
df=pd.read_sql(qry,con)
#print(df,"\n")
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
except:
print("Error...Please check OPD No")

‘DOCTOR’ MODULE-

import pandas as pd
import mysql.connector as sqlt
from tabulate import tabulate
con = sqlt.connect(host = "localhost", user = "root", passwd = "sanjay", database = "hospital")
cursor = con.cursor()

def doctor_input():

qry1 = "select max(did) from doctor;"


cursor.execute(qry1)
t = cursor.fetchone()
if not t[0]:
did = 1
else:
did = t[0] + 1

print(did)

#did = int(input("Enter Doctor ID"))


dname = input("Enter Doctor Name")
dept = input("Enter Department")
qry = "insert into doctor values({},'{}','{}')".format(did, dname, dept)
cursor.execute(qry)

6
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

con.commit()
print("Successfully Added")
#cursor.close()

def doctor_edit():
x=int(input("Enter Doctor ID"))
qry="select * from doctor where did = {};".format(x)
cursor.execute(qry)
r=cursor.fetchone()
#con.commit()
if r:
#print("Exist")
d = input("Enter New Dept")
qry = "update doctor set department = '{}' where did = {};".format(d,x)
cursor.execute(qry)
con.commit()
print("Successfull updated")
else:
print("Wrong DoctorID")
#cursor.close()

def doctor_delete():
x=int(input("Enter Doctor ID"))
qry="select * from doctor where did = {};".format(x)
cursor.execute(qry)
r=cursor.fetchone()
#con.commit()
if r:
#print("Exist")
ch = input("Are you sure you want to delete y/n")
if ch == 'y':
qry = "delete from doctor where did = {};".format(x)
cursor.execute(qry)
con.commit()
print("Successfully Deleted")
else:
print("Wrong Doctor ID")
#cursor.close()

def doctor_search():
x=int(input("Enter Doctor ID"))
qry="select * from doctor where did = {};".format(x)

7
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

df=pd.read_sql(qry,con)
#print(df,"\n")
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))

‘APPOINTMENT’ MODULE-

import pandas as pd
import mysql.connector as sqlt
from tabulate import tabulate
con = sqlt.connect(host = "localhost", user = "root", passwd = "sanjay", database = "hospital")
cursor = con.cursor()

def appointment():

qry="select * from appoint where doa = curdate();"


df=pd.read_sql(qry,con)
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
print()
x=input("Enter Doctor Name")
qry="select * from appoint where dname = '{}';".format(x)
cursor.execute(qry)
r=cursor.fetchone()
df=pd.read_sql(qry,con)
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
print()
#con.commit()
if r:
#print("Exist")
t = input("Treatment")
qry = "update appoint set treatment = '{}' where dname = '{}';".format(t,x)
cursor.execute(qry)
con.commit()
print("Successfull updated")
else:
print("Wrong Doctor Name")

def appointment_edit():
x=input("Enter Doctor Name")
qry="select * from appoint where dname = '{}';".format(x)
cursor.execute(qry)
r=cursor.fetchone()
#con.commit()
if r:

8
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

#print("Exist")
d = input("Enter treatment")
qry = "update appoint set treatment = '{}' where dname = '{}';".format(d,x)
cursor.execute(qry)
con.commit()
print("Successfull updated")
else:
print("Wrong Doctor Name")
#cursor.close()

‘REPORT’ MODULE-

import pandas as pd
import mysql.connector as sqlt
import matplotlib.pyplot as plt
from tabulate import tabulate
con = sqlt.connect(host = "localhost", user = "root", passwd = "sanjay", database = "hospital")
cursor = con.cursor()

def doctor_list():
qry = "select * from doctor;"
df=pd.read_sql(qry,con)
#cursor.execute(qry)
#x=cursor.fetchall()
#print(x)
#print(df.to_string(index = False))
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
print()

def patient_list():
qry = "select * from patient;"
df=pd.read_sql(qry,con)
#cursor.execute(qry)
#x=cursor.fetchall()
#print(x)
#df = df.to_string(index = False)
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
print()

def doctor_treatment():
x=input("Enter Doctor Name")
qry="select * from appoint where dname = '{}';".format(x)
df=pd.read_sql(qry,con)

9
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))


print()

def opd_list():
bdate = input("Enter Beginning Date")
edate = input("Enter End Date")
qry = "select opd.opdno, doa, pname, dname, symptom, treatment, fee from opd where doa
between '{}' and '{}';".format(bdate, edate)
df=pd.read_sql(qry,con)
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
print()
def patient_history():
df = pd.read_sql("select * from appoint, opd where opd.opdno = appoint.opdno;",con)
#print(df.to_string(index = False))
#df=pd.read_sql(qry,con)
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
print()
def col_chart():
qry = "select symptom, count(symptom) as total_cases from appoint group by symptom;"
df = pd.read_sql(qry,con)
#print(df.to_string(index = False))
print(tabulate(df , headers = 'keys',tablefmt = 'psql', showindex = False))
plt.bar(df.symptom, df.total_cases)
plt.title("Bimaari")
plt.xlabel("Problem")
plt.ylabel("Total Cases")
plt.xticks(df.symptom)
plt.show()

10
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

MCQs
Class 12 Computer Science MCQs
https://techtipnow.in/class-12-computer-science-mcqs/

Class 12 Informatics Practices MCQs


https://techtipnow.in/ip-class-12-mcq/

Class 11 Informatics Practices MCQs


https://techtipnow.in/ip-class-11-mcq/

IT-802 Class 12 MCQs


https://techtipnow.in/it-802-class-12-mcq/

IT-402 Class 10 MCQs


https://techtipnow.in/it-code-402-class-10-mcq/

Exception Handling in Python MCQ


https://techtipnow.in/exception-handling-python-mcq/

File Handling in Python MCQ


https://techtipnow.in/file-handling-python-mcq/

Stack in Python MCQ


https://techtipnow.in/python-stack-mcq/

Computer Network MCQ


https://techtipnow.in/computer-network-mcq/

Data Communication MCQ


https://techtipnow.in/class-12-computer-science-mcqs/

SQL MCQ
https://techtipnow.in/sql-mcq-class-12/

Python Pandas Series MCQs

11
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

https://techtipnow.in/python-pandas-series-mcq/

Python Pandas Dataframe MCQs


https://techtipnow.in/python-pandas-dataframe-mcq

Plotting with PyPlot MCQ:


https://techtipnow.in/python-data-visualization-mcq/

Societal Impact MCQ:


https://techtipnow.in/python-data-visualization-mcq/

MySQL Functions MCQ


https://techtipnow.in/mysql-functions-mcq/

Database Query using SQL MCQ


https://techtipnow.in/database-query-sql-function-mcq/

KVS PGT Computer Science MCQ


https://techtipnow.in/kvs-pgt-computer-science-mcqs/

KVS PGT Computer Science Notes


https://techtipnow.in/kvs-pgt-computer-science-notes/

CUET Computer Science MCQ

https://techtipnow.in/cuet-mcq-computer-science-informatics-practices/

Comprehensive Notes
Informatics Practices Class 12

Data Handling and Visualization Notes : https://techtipnow.in/data-handling-


pandas-data-visualization-notes/

Database Query Using SQL Notes : https://techtipnow.in/class-12-ip-database-


query-using-sql-notes/

12
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

Introduction to Computer Network : https://techtipnow.in/introduction-to-


computer-network-notes/

Societal Impact Notes : https://techtipnow.in/societal-impact-notes-societal-


impact-ip-class-12/

Computer Science Class 12

Python Revision Tour: Notes


https://techtipnow.in/python-revision-tour-class-12-notes/

Working with Function Notes


https://techtipnow.in/function-in-python-class-12/

Computer Network Notes


https://techtipnow.in/computer-networks-class-12-computer-science/

Database Concept Notes


https://techtipnow.in/database-concepts-class-12/

Structured Query Language Notes


https://techtipnow.in/sql-class-12-notes/

Computer Science Class 11

Boolean Logic Notes


https://techtipnow.in/boolean-logic-class-11/

Computer System and Organization Notes


https://techtipnow.in/computer-system-organization-class-11-notes/

Encoding Scheme and Number System Notes


https://techtipnow.in/encoding-scheme-and-number-system-class-11/

Introduction to Problem Solving


https://techtipnow.in/problem-solving-class-11-notes/

13
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

Getting Started with Python


https://techtipnow.in/python-fundamentals-class-11-notes/

Python Flow of Control Notes


https://techtipnow.in/python-fundamentals-class-11-notes/

Python Function Notes:


https://techtipnow.in/function-in-python-class-12/

Strings in Python Notes


https://techtipnow.in/strings-in-python-class-11/

List in Python Notes


https://techtipnow.in/list-in-python-class-11-notes/

Tuples in Python Notes


https://techtipnow.in/tuples-in-python-class-11-notes/

Dictionary in Python Notes


https://techtipnow.in/dictionary-in-python-class-11-notes/

IT-802 Class 11

Computer Organization Notes


https://techtipnow.in/computer-organization-class-11-notes/

Networking and Internet Notes


https://techtipnow.in/networking-and-internet-class-11-notes/

RDBMS Notes
https://techtipnow.in/rdbms-class-11-notes/

Fundamentals of Java
https://techtipnow.in/fundamentals-of-java-class-11/

14
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

IT-802 Class 12

Database Concept Notes


https://techtipnow.in/it-802-class-12-database-concept-notes/

Operating Web and Applications Notes


https://techtipnow.in/operating-web-class-12-notes/

Java Programming Notes


https://techtipnow.in/fundamentals-of-java-class-12-notes/

Work Integrated Learning IT DMA


https://techtipnow.in/work-integrated-learning-it-dma-notes/

IT-402 Class 10 Notes

Digital Documentation Notes


https://techtipnow.in/digital-documentation-class-10-notes/

Electronic Spreadsheet Notes


https://techtipnow.in/electronic-spreadsheet-class-10/

Relational Database Management System Notes


https://techtipnow.in/rdbms-class-10-notes/

Web Application and Security Notes


https://techtipnow.in/web-applications-and-security-class-10-notes/

Projects and Practicals


Python MySQL Project with Source Code
https://techtipnow.in/python-mysql-projects-with-source-code/

Inventory Management System


https://techtipnow.in/inventory-management-system-in-python

15
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

Library Management System


https://techtipnow.in/library-management-system-in-python/

Hospital Management System


https://techtipnow.in/hospital-management-system-in-python/

Class 12 IP Practical File


https://techtipnow.in/ip-project-file-class-12/

Class 12 IP Practical Questions with answers


https://techtipnow.in/class-12-ip-practical-questions-with-answers/

Class 12 IP Practical VIVA Question | Python Viva Questions | SQL Viva Questions
https://techtipnow.in/class-12-ip-viva-questions/

Sample Paper /PYQ


Previous Year Question Paper IP Class 12:
https://techtipnow.in/previous-year-question-paper-ip-class-12/

CBSE Sample Papers :


https://techtipnow.in/ip-sample-paper/

Practice Sample Paper IP :


https://techtipnow.in/ip-sample-paper-class-12-with-solutions/

Textbook Solutions
NCERT Text Book Solution IP Class 12:
https://techtipnow.in/ncert-solution-ip-class-12/

Sumita Arora Textbook Solution :


https://techtipnow.in/sumita-arora-textbook-solution-information-practices-xii/

NCERT Solution Class 11:


https://techtipnow.in/ncert-textbook-solution-ip-class-11/
16
Website: www.techtipnow.in
YouTube: www.youtube.com/c/techtipnow

17

You might also like