INFORMATIC PRACTICES
Project Title:
Hospital Management System using Python and
MySQL
Objective of the Project:
The main objective of this project is to develop a
simple Hospital Management System using Python
and MySQL that allows users to:
• Store and manage patient details
• Maintain doctor records
• Schedule and manage appointments
• Retrieve and display data using SQL queries
This project helps students understand how to use
Python to interact with a MySQL database, implement
CRUD (Create, Read, Update, Delete) operations, and
develop a simple console-based application for real-
world use.
Technologies Used:
Component Tool/Language
Programming Python (v3.x)
MySQL (via mysql-connector-
Database
python)
IDE IDLE / PyCharm / VS Code
Operating System Windows / Linux / macOS
Database Schema (MySQL)
-- Create database
CREATE DATABASE IF NOT EXISTS hospital;
USE hospital;
-- Patients Table
CREATE TABLE IF NOT EXISTS patients (
patient_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
age INT,
gender VARCHAR(10),
disease VARCHAR(100),
admit_date DATE
);
-- Doctors Table
CREATE TABLE IF NOT EXISTS doctors (
doctor_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
specialization VARCHAR(100),
contact VARCHAR(15)
);
-- Appointments Table
CREATE TABLE IF NOT EXISTS appointments (
appointment_id INT AUTO_INCREMENT PRIMARY
KEY,
patient_id INT,
doctor_id INT,
appointment_date DATE,
FOREIGN KEY (patient_id) REFERENCES
patients(patient_id),
FOREIGN KEY (doctor_id) REFERENCES
doctors(doctor_id)
);
Python Code (Console-Based)
Connect to MySQL
import [Link]
def connect_db():
return [Link](
host="localhost",
user="root",
password="yourpassword",
database="hospital"
)
Add Patient
def add_patient():
db = connect_db()
cursor = [Link]()
name = input("Enter patient name: ")
age = int(input("Enter age: "))
gender = input("Enter gender: ")
disease = input("Enter disease: ")
admit_date = input("Enter admit date (YYYY-MM-
DD): ")
query = "INSERT INTO patients (name, age, gender,
disease, admit_date) VALUES (%s, %s, %s, %s, %s)"
[Link](query, (name, age, gender, disease,
admit_date))
[Link]()
print("Patient added successfully.")
[Link]()
View All Patients
def view_patients():
db = connect_db()
cursor = [Link]()
[Link]("SELECT * FROM patients")
records = [Link]()
print("\n--- Patient Records ---")
for row in records:
print(row)
[Link]()
Add Doctor
def add_doctor():
db = connect_db()
cursor = [Link]()
name = input("Enter doctor name: ")
specialization = input("Enter specialization: ")
contact = input("Enter contact number: ")
query = "INSERT INTO doctors (name, specialization,
contact) VALUES (%s, %s, %s)"
[Link](query, (name, specialization, contact))
[Link]()
print("Doctor added successfully.")
[Link]()
Book Appointment
def book_appointment():
db = connect_db()
cursor = [Link]()
patient_id = int(input("Enter Patient ID: "))
doctor_id = int(input("Enter Doctor ID: "))
appointment_date = input("Enter Appointment Date
(YYYY-MM-DD): ")
query = "INSERT INTO appointments (patient_id,
doctor_id, appointment_date) VALUES (%s, %s, %s)"
[Link](query, (patient_id, doctor_id,
appointment_date))
[Link]()
print("Appointment booked successfully.")
[Link]()
Main Menu
while True:
print("\n===== Hospital Management System
=====")
print("1. Add Patient")
print("2. View Patients")
print("3. Add Doctor")
print("4. Book Appointment")
print("5. Exit")
choice = input("Enter your choice (1-5): ")
if choice == '1':
add_patient()
elif choice == '2':
view_patients()
elif choice == '3':
add_doctor()
elif choice == '4':
book_appointment()
elif choice == '5':
print("Exiting the system.")
break
else:
print("Invalid choice. Please enter 1-5.")
Project Report Structure (for CBSE submission)
1. Title Page
o Project Name
o Student Name
o Roll Number
o School Name
o Year
2. Objective (as given above)
3. Introduction
o Description of hospital system
o Real-world importance
4. Tools & Technologies Used
o Python, MySQL, etc.
5. System Design
o Description of each table
o Input/output
6. Source Code Snapshots
o Add images of Python code and outputs
7. Sample Output
o Screenshot of successful operations (patient
added, appointment booked, etc.)
8. Conclusion
o What was learned
o How it can be improved (add GUI, billing,
reports, etc.)
9. Appendix
o MySQL table structure
o Full source code