Sanjana XII

Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

STARLING INTERNATIONAL SCHOOL

ACADEMIC YEAR- 2024-2025

PROJECT ON HOSPITAL MANAGEMENT


SYSTEM

SUBJECT : COMPUTER SCIENCE (083)

SUBMITTED TO : SUBMITTED BY :
MR. SAURAV BHATTACHARJEE NAME: SANJANA ROUTH
PGT (COMPUTER SCIENCE) CLASS: XII
ROLL NO.: 41
STREAM :- SCIENCE (PCM)

1|P a ge
CERTIFICATE

This is to certify that Sanjana Routh of class XII(Science) of Starling


International School submitted the "Computer Project File" on topic
“HOSPITAL MANAGEMENT SYSTEM”. She has prepared the file under my
supervision.

She has taken interest and has shown at most sincerity in completion of this
project.

I certify this practical up to my expectation & as per guidelines issued by CBSE,


for the session 2024-25.

Internal Examiner : External Examiner :

---------------------------- -----------------------------

Signature of Principal :

---------------------------------

2|P a ge
ACKNOWLEDGEMENT

I would like to express a deep sense of thanks & gratitude to my teacher Mr.
Saurav Bhattacharjee who taught and undertook the responsibility of teaching
the subject computer science.
My sincere thanks goes to our Principal Mrs. Hemasree Datta who has always
been a source of encouragement and support and without whose inspiration, this
project would not have been a successfully completed.
I sincerely thank my family and especially to my parents for unconditional
support and love.
It is a pleasure to pay praise also to my friends for their valuable help and
debugging some of the problems during the studies.

SANJANA ROUTH
XII (Science)

3|P a ge
INDEX

SL.NO DESCRIPTION PAGE. NO


1 INTRODUCTION 5
2 OBJECTIVES OF THE PROJECT 6
3 PROPOSED SYSTEM 7
4 SYSTEM DEVELOPMENT LIFE 8
CYCLE (SDLC)
5 PHASES OF SDLC 9 – 13
6 SOUCE CODE 14 – 39
7 OUTPUT 40 – 46
8 HARDWARE AND SOFTWARE 47
REQUIREMENTS
9 MySQL DATABASE TABLES 48 – 49
10 BIBLIOGRAPHY 50

4|P a ge
INTRODUCTION

Hospital Management System is a system enabling hospitals to


manage information and data related to all aspects of healthcare –
processes, providers, patients, and more, which in turn ensures that
processes are completed swiftly and effectively. When one thinks of
the various aspects and departments of a hospital, it becomes apparent
that an HMS is critical. The hospital database management system
was introduced in 1960, and has greatly evolved since then – with the
ability to integrate with the existing facilities, technologies, software,
and systems of a hospital. Today, patients can begin the process of
healthcare in the palm of their hand – the mobile devices and apps –
make this possible. This process then moves to the healthcare
providers and hospitals.

5|P a ge
OBJECTIVES OF THE PROJECT

The objective of this project is to let the students apply the


programming knowledge into a real world situation/problem and
exposed the students how programming skills helps in developing a
good software.
1. Write programs utilizing modern software tools.
2. Apply object oriented programming principles effectively when
developing small to medium sized projects.
3. Write effective procedural code to solve small to medium sized
problems.
4. Students will demonstrate a breadth of knowledge in computer
science, as exemplified in the areas of systems, theory and software
development.
5. Students will demonstrate ability to conduct a research or applied
Computer Science project, requiring writing and presentation skills
which exemplify scholarly style in computer science.

6|P a ge
PROPOSED SYSTEM

Today one cannot afford to rely on the fallible human beings of be


really wants to stand against today's merciless competition where not
to wise saying "to err is human" no longer valid, it's outdated to
rationalize your mistake. So, to keep pace with time, to bring about
the best result without malfunctioning and greater efficiency so to
replace the unending heaps of flies with a much sophisticated hard
disk of the computer.

One has to use the data management software. Software has been an
ascent in atomization various organisations. Many software products
working are now in markets, which have helped in making the
organizations work easier and efficiently. Data management initially
had to maintain a lot of ledgers and a lot of paperwork has to be done
but now software producton this organization has made their work
faster and easier. Now only this software has to be loaded on the
computer and work can be done.

This prevents a lot of time and money. The work becomes fully
automated and any information regarding the organization can be
obtained by clicking the button. Moreover, now it's an age of
computers of and automating such an organization gives the better
look.

7|P a ge
SYSTEM DEVELOPMENT LIFE CYCLE (SDLC)

SOFTWARE DEVELOPMENT LIFE CYCLE STEPS

The systems development life cycle (SDLC) is a conceptual model


used in project management that describes the stages involved in an
information system development project, from an initial feasibility
study through maintenance of the completed application. SDLC can
apply to technical and non-technical systems. In most use cases, a
system is an IT technology such as hardware and software. Project
and program managers typically take part in SDLC. along with
system and software engineers, development teams and end-users.
Every hardware or software system will go through a development
process which can be thought as an iterative process with multiple
steps. SDLC is used to give a rigid structure and framework to define
the phases and steps involved in the development of a system.
SDLC is also an abbreviation for Synchronous Data Link Control and
software development life cycle. Software development life cycle is a
very similar process to systems development life cycle, but it focuses
exclusively on the development life cycle of software.

8|P a ge
PHASES OF SYSTEM DEVELOPMENT LIFE CYCLE
(SDLC)

There are seven primary stages of the modern system development


life cycle.
Planning Stage

 Feasibility or Requirements of Analysis Stage

 Design and Prototyping Stage

 Software Development Stage

 Software Testing Stage

 Implementation and Integration

 Operations and Maintenance Stage

PICTORIAL REPRESENTATION OF SDLC

9|P a ge
PLANNING STAGE

The planning stage (also called the feasibility stage) is exactly what it
sounds like: the phase in which developers will plan for the upcoming
project.
It helps to define the problem and scope of any existing systems, as
well as determine the objectives for their new systems.
By developing an effective outline for the upcoming development
cycle, they'll theoretically catch problems before they affect
development.
And help to secure the funding and resources they need to make their
plan happen.
Perhaps most importantly, the planning stage sets the project
schedule, which can be of key importance if development is for a
commercial product that must be sent to market by a certain time.

ANALYSIS STAGE

The analysis stage includes gathering all the specific details required
for a new system as well as determining the first ideas for prototypes.

Developers may:

Define any prototype system requirements


Evaluate alternatives to existing prototypes
Perform research and analysis to determine the needs of end-users
Furthermore, developers will often create a software requirement
specification or SRS document.

This includes all the specifications for software, hardware, and


network requirements for the system they plan to build. This will
prevent them from overdrawing funding or resources w working at
the same place as other development teams.

10 | P a g e
DESIGN STAGE

The design stage is a necessary precursor to the main developer stage.


Developers will first outline the details for the overall application,
alongside specific aspects, such as its:
User interfaces
System interfaces
Network and network requirements
Databases

They'll typically tum the SRS document they created into a more
logical structure that can later be implemented in a programming
language. Operation, training, and maintenance plans wilt all he
drawn up so that developers know what they need to do throughout
every stage of the cycle moving forward.
Once complete, development managers will prepare a design
document to be referenced throughout the next phases of the SDLC

DEVELOPMENT STAGE

The development stage is the part where developers actually write


code and build the application according to the earlier design
documents and outlined specifications.

This is where Static Application Security Testing or SAST tools come


into play

Product program code is built per the design document specifications.


In theory, all of the prior planning and outlined should make the
actual development phase relatively straight forward.

Developers will follow any coding guidelines as defined by the


organization and utilize different tools such as compilers, debuggers,
and interpreters,

11 | P a g e
Programming languages can include staples such as C++, PHP, and
more. Developers will choose the right programming code to use
based on the project specifications and requirements.

TESTING STAGE

Building software is not the end.


Now it must be tested to make sure that there aren't any bugs and that
the end-user experience will not negatively be affected at any point.
During the testing stage, developers will go over their software with a
fine-tooth comb, noting any bugs or defects that need to be tracked,
fixed, and later retested.
It's important that the software overall ends up meeting the quality
standards that were previously defined in the SRS document.
Depending on the skill of the developers, the complexity of the
software, and the requirements for the end-user, testing can either be
an extremely short phase or take a very long time.

IMPLEMENTATION AND INTEGRATION STAGE

After testing, the overall design for the software will come together.
Different modules or designs will be integrated into the primary
source code through developer efforts, usually by leveraging training
environments to detect further errors or defects.

The information system will be integrated into its environment and


eventually installed. After passing this stage, the software is
theoretically ready for market and may be provided to any end-users.

MAINTENANCE STAGE

The SDLC doesn't end when software reaches the market. Developers
must now move into a maintenance mode and begin practicing any
activities required to handle issues reported by end-users.

12 | P a g e
Furthermore, developers are responsible for implementing any
changes that the software might need after deployment.

This can include handling residual bugs that were not able to be
patched before launch or resolving new issues that crop up due to user
reports. Larger systems may require longer maintenance stages
compared to smaller systems.

PURPOSE

The purpose of an SDLC methodology is to provide IT Project


Managers with the tools to help ensure successful implementation of
systems that satisfy University strategic and business objectives. The
documentation provides a mechanism to ensure that executive
leadership. functional managers and users sign-off on the
requirements and implementation of the system. The process provides
University Project Managers with the visibility of design,
development. and implementation status needed to ensure delivery on
time and within budget.

13 | P a g e
SOURCE CODE

import mysql.connector as sql

# Connect to the database


conn = sql.connect(host='localhost', user='root', passwd='123456')
if conn.is_connected():
print('SUCCESSFULLY CONNECTED TO DATABASE')
c1 = conn.cursor()
c1.execute('CREATE DATABASE IF NOT EXISTS AMRIHOSPITAL')
c1.execute('USE AMRIHOSPITAL')

# Create necessary tables

c1.execute('''CREATE TABLE IF NOT EXISTS feedback(


feedback_id INT AUTO_INCREMENT PRIMARY KEY,
patient_id VARCHAR(10),
doctor_id VARCHAR(10),
comments TEXT)''')

c1.execute('''CREATE TABLE IF NOT EXISTS doctor_availability(


d_id VARCHAR(10),
available_day VARCHAR(10),
available_from TIME,
available_to TIME,
PRIMARY KEY (d_id, available_day))''')

14 | P a g e
c1.execute('''CREATE TABLE IF NOT EXISTS patient_details(
p_id VARCHAR(10) PRIMARY KEY, p_name CHAR(20),
p_age INT, p_problems CHAR(50), p_phoneno BIGINT,
p_history TEXT)''')

c1.execute('''CREATE TABLE IF NOT EXISTS doctor_details(


d_id VARCHAR(10) PRIMARY KEY, d_name CHAR(20),
d_age INT, d_specialization CHAR(20), d_department CHAR(20),
d_phoneno BIGINT)''')

c1.execute('''CREATE TABLE IF NOT EXISTS nurse_details(


n_id VARCHAR(10) PRIMARY KEY, n_name CHAR(20),
n_age INT, n_department CHAR(20), n_phoneno BIGINT)''')

c1.execute('''CREATE TABLE IF NOT EXISTS staff_details(


st_id VARCHAR(10) PRIMARY KEY, st_name CHAR(20),
st_age INT, st_job CHAR(20), st_phoneno BIGINT)''')

c1.execute('''CREATE TABLE IF NOT EXISTS appointments(


appointment_id INT AUTO_INCREMENT PRIMARY KEY,
patient_id VARCHAR(10), doctor_id VARCHAR(10),
appointment_date DATE, appointment_time TIME,
status VARCHAR(20) DEFAULT 'Scheduled')''')

# Main menu for the system

15 | P a g e
def main_menu():
while True:

print("\n\n=================================================
===============================")
print("\t\t*WELCOME TO AMRI HOSPITAL*")
print("\t\t~ Your Health is in GOOD hands ~ ")

print("====================================================
============================\n")
print("\t\t1. LOGIN\n\t\t2. EXIT")
choice1 = int(input("ENTER YOUR CHOICE: "))

if choice1 == 1:
login_menu()
elif choice1 == 2:
print("Thank you for using AMRI Hospital System.")
break
else:
print("Invalid input. Please enter again.")

# Admin menu
def admin_login():
username = input("ENTER USERNAME: ")
password = input("ENTER PASSWORD: ")

if password == 'admin123':
print("\n---WELCOME ADMIN---")
16 | P a g e
admin_menu()
else:
print("Incorrect Password. Access Denied.")

def register_patient():
print("Registering New Patient:")
p_id = generate_id('P', 'patient_details', 'p_id')
p_name = input("Enter Patient Name: ")
p_age = int(input("Enter Age: "))
p_problems = input("Enter the Problem/Disease: ")
p_phoneno = int(input("Enter Phone number: "))
p_history = input("Enter Patient Medical History: ")
sql_insert = "INSERT INTO patient_details(p_id, p_name, p_age,
p_problems, p_phoneno, p_history) VALUES (%s, %s, %s, %s, %s, %s)"
c1.execute(sql_insert, (p_id, p_name, p_age, p_problems, p_phoneno,
p_history))
conn.commit()
print(f"Patient {p_name} registered successfully!")

def register_doctor():
print("Registering New Doctor:")
d_id = generate_id('D', 'doctor_details', 'd_id')
d_name = input("Enter Doctor Name: ")
d_age = int(input("Enter Age: "))
d_specialization = input("Enter Specialization: ")
d_department = input("Enter Department: ")
d_phoneno = int(input("Enter Phone number: "))

17 | P a g e
sql_insert = "INSERT INTO doctor_details(d_id, d_name, d_age,
d_specialization, d_department, d_phoneno) VALUES (%s, %s, %s, %s, %s,
%s)"
c1.execute(sql_insert, (d_id, d_name, d_age, d_specialization, d_department,
d_phoneno))
conn.commit()
print(f"Doctor {d_name} registered successfully!")

def register_nurse():
print("Registering New Nurse:")
n_id = generate_id('N', 'nurse_details', 'n_id')
n_name = input("Enter Nurse Name: ")
n_age = int(input("Enter Age: "))
n_department = input("Enter Department: ")
n_phoneno = int(input("Enter Phone number: "))
sql_insert = "INSERT INTO nurse_details(n_id, n_name, n_age,
n_department, n_phoneno) VALUES (%s, %s, %s, %s, %s)"
c1.execute(sql_insert, (n_id, n_name, n_age, n_department, n_phoneno))
conn.commit()
print(f"Nurse {n_name} registered successfully!")

def register_staff():
print("Registering New Staff:")
st_id = generate_id('S', 'staff_details', 'st_id')
st_name = input("Enter Staff Name: ")
st_age = int(input("Enter Age: "))
st_job = input("Enter Job Title: ")
st_phoneno = int(input("Enter Phone number: "))

18 | P a g e
sql_insert = "INSERT INTO staff_details(st_id, st_name, st_age, st_job,
st_phoneno) VALUES (%s, %s, %s, %s, %s)"
c1.execute(sql_insert, (st_id, st_name, st_age, st_job, st_phoneno))
conn.commit()
print(f"Staff {st_name} registered successfully!")

def view_records():
print("1. View Patients \n2. View Doctors\n3. View Nurses\n4. View
Staff\n")
choice = int(input("Enter choice to view: "))
if choice == 1:
view_table('patient_details')
elif choice == 2:
view_table('doctor_details')
elif choice == 3:
view_table('nurse_details')
elif choice == 4:
view_table('staff_details')
else:
print("Invalid choice.")

def view_table(table):
c1.execute(f"SELECT * FROM {table}")
rows = c1.fetchall()
if rows:
for row in rows:
print(row)
else:

19 | P a g e
print("No records found.")

def remove_records():
print("1. Remove Patients\n2. Remove Doctors\n3. Remove Nurses\n4.
Remove Staff\n")
choice = int(input("Enter choice to remove: "))
if choice == 1:
remove_patient()
elif choice == 2:
remove_doctor()
elif choice == 3:
remove_nurse()
elif choice == 4:
remove_staff()
else:
print("Invalid choice.")

def remove_patient():
p_id = input("Enter Patient ID to remove: ")
c1.execute("DELETE FROM patient_details WHERE p_id = %s", (p_id,))
conn.commit()
print("Patient record removed successfully!")

def remove_doctor():
d_id = input("Enter Doctor ID to remove: ")
c1.execute("DELETE FROM doctor_details WHERE d_id = %s", (d_id,))
conn.commit()
print("Doctor record removed successfully!")

20 | P a g e
def remove_nurse():
n_id = input("Enter Nurse ID to remove: ")
c1.execute("DELETE FROM nurse_details WHERE n_id = %s", (n_id,))
conn.commit()
print("Nurse record removed successfully!")

def remove_staff():
st_id = input("Enter Staff ID to remove: ")
c1.execute("DELETE FROM staff_details WHERE st_id = %s", (st_id,))
conn.commit()
print("Staff record removed successfully!")

def update_records():
print("1. Update Patients\n2. Update Doctors\n3. Update Nurses\n4. Update
Staff\n")
choice = int(input("Enter choice to update: "))
if choice == 1:
update_patient()
elif choice == 2:
update_doctor()
elif choice == 3:
update_nurse()
elif choice == 4:
update_staff()
else:
print("Invalid choice.")

21 | P a g e
def update_patient():
p_id = input("Enter Patient ID to update: ")
field = input("Which field to update? (name/age/problems/phoneno/history):
").lower()
new_value = input("Enter the new value: ")

if field == 'name':
c1.execute("UPDATE patient_details SET p_name = %s WHERE p_id =
%s", (new_value, p_id))
elif field == 'age':
c1.execute("UPDATE patient_details SET p_age = %s WHERE p_id =
%s", (new_value, p_id))
elif field == 'problems':
c1.execute("UPDATE patient_details SET p_problems = %s WHERE p_id
= %s", (new_value, p_id))
elif field == 'phoneno':
c1.execute("UPDATE patient_details SET p_phoneno = %s WHERE p_id
= %s", (new_value, p_id))
elif field == 'history':
c1.execute("UPDATE patient_details SET p_history = %s WHERE p_id =
%s", (new_value, p_id))
else:
print("Invalid field.")

conn.commit()
print("Patient record updated successfully!")

def update_doctor():
d_id = input("Enter Doctor ID to update: ")

22 | P a g e
field = input("Which field to update?
(name/age/specialization/department/phoneno): ").lower()
new_value = input("Enter the new value: ")

if field == 'name':
c1.execute("UPDATE doctor_details SET d_name = %s WHERE d_id =
%s", (new_value, d_id))
elif field == 'age':
c1.execute("UPDATE doctor_details SET d_age = %s WHERE d_id =
%s", (new_value, d_id))
elif field == 'specialization':
c1.execute("UPDATE doctor_details SET d_specialization = %s WHERE
d_id = %s", (new_value, d_id))
elif field == 'department':
c1.execute("UPDATE doctor_details SET d_department = %s WHERE
d_id = %s", (new_value, d_id))
elif field == 'phoneno':
c1.execute("UPDATE doctor_details SET d_phoneno = %s WHERE d_id
= %s", (new_value, d_id))

# Doctor Menu
def set_doctor_availability(doctor_id):
print("Setting availability for doctor:", doctor_id)
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
for day in days:
available_from = input(f"Enter available start time for {day} (HH:MM): ")
available_to = input(f"Enter available end time for {day} (HH:MM): ")
c1.execute("INSERT INTO doctor_availability(d_id, available_day,
available_from, available_to) VALUES (%s, %s, %s, %s)",
(d_id, day, available_from, available_to))
23 | P a g e
conn.commit()
print("Availability set successfully.")

def doctor_login():
username = input("ENTER DOCTOR ID: ")
password = input("ENTER PASSWORD: ")

c1.execute('SELECT d_id FROM doctor_details WHERE d_id = %s',


(username,))
doctor = c1.fetchone()

if password == 'doctor123':
print("\n---WELCOME DOCTOR---")
doctor_menu(username)
else:
print("Invalid Doctor ID or Password.")

def doctor_menu(doctor_id):
while True:
print("\n\t\t*DOCTOR MENU*")
print("1. View Appointments\n2. Update Status\n3. Set Availability\n4.
Log Out")
choice = int(input("ENTER YOUR CHOICE: "))

if choice == 1:
view_appointments(doctor_id)
elif choice == 2:

24 | P a g e
update_job_status(doctor_id)
elif choice == 3:
set_doctor_availability(doctor_id)
elif choice == 4:
print("Doctor logged out.")
break
else:
print("Invalid choice. Please select again.")

# Patient Menu

# Function to submit feedback


def submit_feedback():
patient_id = input("Enter Patient ID: ")
doctor_id = input("Enter Doctor ID: ")
comments = input("Enter your feedback: ")
c1.execute("INSERT INTO feedback(patient_id, doctor_id, comments)
VALUES (%s, %s, %s)",
(p_id, d_id, comments))
conn.commit()
print("Feedback submitted successfully!")

# Function to cancel an appointment


def cancel_appointment(patient_id):
c1.execute("DELETE FROM appointments WHERE appointment_id = %s",
(patient_id,))
conn.commit()

25 | P a g e
print("Appointment canceled successfully!")

def patient_menu(username):
while True:
print("\n\t\t*PATIENT MENU*")
print("1. View Appointments")
print("2. Book Appointment")
print("3. View Medical History")
print("4. Request Medication Refill")
print("5. View Lab Results")
print("6. Update Personal Information")
print("7. View Doctor Information")
print("8. Submit Feedback")
print("9. Cancel Appointment")
print("10. Log Out")

choice = int(input("ENTER YOUR CHOICE: "))

if choice == 1:
view_appointments(username)
elif choice == 2:
book_appointment(username)
elif choice == 3:
view_medical_history(username)
elif choice == 4:
add_lab_result(username)
elif choice == 5:

26 | P a g e
view_lab_results(username)
elif choice == 6:
update_personal_info(username)
elif choice == 7:
view_doctor_info(username)
elif choice == 8:
submit_feedback()
elif choice == 9:
appointment_id = int(input("Enter Patient Id to cancel: "))
cancel_appointment(patient_id)
elif choice == 10:
print("Patient logged out.")
break
else:
print("Invalid choice. Please select again.")

def patient_login():
username = input("ENTER PATIENT ID: ")
password = input("ENTER PASSWORD: ")

c1.execute('SELECT p_id FROM patient_details WHERE p_id = %s',


(username,))
patient = c1.fetchone()

if password == 'patient123':
print("\n---WELCOME PATIENT---")
patient_menu(username)
else:

27 | P a g e
print("Invalid Patient ID or Password.")

# Registration Functions
def register_patient():
print("Registering New Patient:")
p_id = generate_id('P', 'patient_details', 'p_id')
p_name = input("Enter Patient Name: ")
p_age = int(input("Enter Age: "))
p_problems = input("Enter the Problem/Disease: ")
p_phoneno = int(input("Enter Phone number: "))
p_history = input("Enter Patient Medical History: ")
sql_insert = "INSERT INTO patient_details(p_id, p_name, p_age,
p_problems, p_phoneno, p_history) VALUES (%s, %s, %s, %s, %s, %s)"
c1.execute(sql_insert, (p_id, p_name, p_age, p_problems, p_phoneno,
p_history))
conn.commit()
print(f"Patient {p_name} registered successfully!")

# Registering doctor, nurse, staff functions follow the same structure

# ID Generation Function
def generate_id(prefix, table, id_field):
c1.execute(f"SELECT MAX({id_field}) FROM {table}")
max_id = c1.fetchone()[0]

28 | P a g e
if max_id:
num = int(max_id[1:]) + 1
else:
num = 1
return f"{prefix}{num}"

# Appointment Functions
def book_appointment(patient_id):
print("Booking an Appointment:")
doctor_id = input("Enter Doctor ID for appointment: ")

c1.execute("SELECT d_id FROM doctor_details WHERE d_id = %s",


(doctor_id,))
if not c1.fetchone():
print("Invalid Doctor ID. Please try again.")
return

appointment_date = input("Enter Appointment Date (YYYY-MM-DD): ")


appointment_time = input("Enter Appointment Time (HH:MM): ")

try:
from datetime import datetime
datetime.strptime(appointment_date, '%Y-%m-%d')
except ValueError:
print("Invalid date format. Please enter in YYYY-MM-DD format.")
return

29 | P a g e
try:
datetime.strptime(appointment_time, '%H:%M')
except ValueError:
print("Invalid time format. Please enter in HH:MM format.")
return

sql_insert = '''INSERT INTO appointments(patient_id, doctor_id,


appointment_date, appointment_time)
VALUES (%s, %s, %s, %s)'''
c1.execute(sql_insert, (patient_id, doctor_id, appointment_date,
appointment_time))
conn.commit()
print("Appointment booked successfully!")

# Viewing Records Functions


def view_records():
print("1. View Patients\n2. View Doctors\n3. View Nurses\n4. View Staff\n")
choice = int(input("Enter choice to view: "))
if choice == 1:
view_table('patient_details')
elif choice == 2:
view_table('doctor_details')
elif choice == 3:
view_table('nurse_details')
elif choice == 4:

30 | P a g e
view_table('staff_details')
else:
print("Invalid choice.")

def view_table(table):
c1.execute(f"SELECT * FROM {table}")
rows = c1.fetchall()
if rows:
for row in rows:
print(row)
else:
print("No records found.")

# Update Records Functions


def update_records():
print("1. Update Patients\n2. Update Doctors\n3. Update Nurses\n4. Update
Staff\n")
choice = int(input("Enter choice to update: "))
if choice == 1:
update_patient()
elif choice == 2:
update_doctor()
elif choice == 3:
update_nurse()
elif choice == 4:
update_staff()
else:

31 | P a g e
print("Invalid choice.")

def update_patient():
p_id = input("Enter Patient ID to update: ")
field = input("Which field to update? (name/age/problems/phoneno/history):
").lower()
new_value = input("Enter the new value: ")

if field == 'name':
c1.execute("UPDATE patient_details SET p_name = %s WHERE p_id =
%s", (new_value, p_id))
elif field == 'age':
c1.execute("UPDATE patient_details SET p_age = %s WHERE p_id =
%s", (new_value, p_id))
elif field == 'problems':
c1.execute("UPDATE patient_details SET p_problems = %s WHERE p_id
= %s", (new_value, p_id))
elif field == 'phoneno':
c1.execute("UPDATE patient_details SET p_phoneno = %s WHERE p_id
= %s", (new_value, p_id))
elif field == 'history':
c1.execute("UPDATE patient_details SET p_history = %s WHERE p_id =
%s", (new_value, p_id))
else:
print("Invalid field.")

conn.commit()
print("Patient record updated successfully!")

32 | P a g e
# Removing Records Function
def remove_records():
print("1. Remove Patients\n2. Remove Doctors\n3. Remove Nurses\n4.
Remove Staff\n")
choice = int(input("Enter choice to remove: "))
if choice == 1:
remove_patient()
elif choice == 2:
remove_doctor()
elif choice == 3:
remove_nurse()
elif choice == 4:
remove_staff()
else:
print("Invalid choice.")

def remove_patient():
p_id = input("Enter Patient ID to remove: ")
c1.execute("DELETE FROM patient_details WHERE p_id = %s", (p_id,))
conn.commit()
print("Patient record removed successfully!")

# Search Records Function


def search_records():

33 | P a g e
print("1. Search Patients\n2. Search Doctors\n3. Search Nurses\n4. Search
Staff\n")
choice = int(input("Enter choice to search: "))
if choice == 1:
search_patient()
elif choice == 2:
search_doctor()
elif choice == 3:
search_nurse()
elif choice == 4:
search_staff()
else:
print("Invalid choice.")

def search_patient():
name = input("Enter Patient Name to search: ")
c1.execute("SELECT * FROM patient_details WHERE p_name LIKE %s",
('%' + name + '%',))
rows = c1.fetchall()
if rows:
for row in rows:
print(row)
else:
print("No matching records found.")

# Generating Reports
def generate_reports():
print("Generating reports...")

34 | P a g e
c1.execute("SELECT d_department, COUNT(*) FROM doctor_details
GROUP BY d_department")
departments = c1.fetchall()
print("Number of Doctors by Department:")
for dep in departments:
print(f"{dep[0]}: {dep[1]} doctors")

c1.execute("SELECT COUNT(*) FROM patient_details")


patients_count = c1.fetchone()
print(f"Total number of patients: {patients_count[0]}")

def add_lab_result():
print("Adding Lab Result:")
result_id = input("Enter Lab Result ID: ")
patient_id = input("Enter Patient ID: ")

c1.execute("SELECT p_id FROM patient_details WHERE p_id = %s",


(patient_id,))
if not c1.fetchone():
print("Invalid Patient ID. Please try again.")
return

lab_test = input("Enter Lab Test Name: ")


result = input("Enter Lab Result: ")
result_date = input("Enter Result Date (YYYY-MM-DD): ")

35 | P a g e
try:
from datetime import datetime
datetime.strptime(result_date, '%Y-%m-%d')
except ValueError:
print("Invalid date format. Please enter in YYYY-MM-DD format.")
return
sql_insert = '''INSERT INTO lab_results(result_id, patient_id, lab_test,
result, result_date)
VALUES (%s, %s, %s, %s, %s)'''
c1.execute(sql_insert, (result_id, patient_id, lab_test, result, result_date))
conn.commit()

print("Lab result added successfully!")

def view_lab_results():
print("Viewing Lab Results:")
patient_id = input("Enter Patient ID to view results: ")

c1.execute("SELECT * FROM lab_results WHERE patient_id = %s",


(patient_id,))
rows = c1.fetchall()

if rows:
for row in rows:
print(row)
else:
print("No lab results found for this patient.")

36 | P a g e
def admin_menu():
while True:
print("\n\t\t*ADMIN MAIN MENU*")
print("1. Register Patients")
print(" 2. Register Doctors")
print("3. Register Nurses")
print("4. Register Staff")
print("5. View All Records")
print("6. Remove Records")
print("7. Update Records")
print("8. Generate Reports")
print("9. Search Records")
print("10. Manage Appointments")
print("11. Manage Feedback")
print("12. Manage Medication Refills")
print("13. Manage Lab Results")
print("14. Manage Doctor Availability")
print("15. Log Out")

choice = int(input("ENTER YOUR CHOICE: "))

if choice == 1:
register_patient()
elif choice == 2:
register_doctor()
elif choice == 3:

37 | P a g e
register_nurse()
elif choice == 4:
register_staff()
elif choice == 5:
view_records()
elif choice == 6:
remove_records()
elif choice == 7:
update_records()
elif choice == 8:
generate_reports()
elif choice == 9:
search_records()
elif choice == 10:
cancel_appointments()
elif choice == 11:
manage_feedback()
elif choice == 12:
add_lab_result()
elif choice == 13:
view_lab_results()
elif choice == 14:
manage_doctor_availability()
elif choice == 15:
print("Admin logged out.")
break
else:

38 | P a g e
print("Invalid choice. Please select again.")

# Login system for admin, doctor, and patient


def login_menu():
print("\n\t\tLOGIN PORTAL")
role = int(input("Select Role:\n1. Admin\n2. Doctor\n3. Patient\nENTER
YOUR ROLE: "))

if role == 1:
admin_login()
elif role == 2:
doctor_login()
elif role == 3:
patient_login()
else:
print("Invalid role selection. Please retry.")
login_menu()

# Running the Program


main_menu()

39 | P a g e
OUTPUT

40 | P a g e
41 | P a g e
42 | P a g e
43 | P a g e
44 | P a g e
45 | P a g e
46 | P a g e
HARDWARE AND SOFTWARE REQUIREMENTS

Software Specifications :-
Operating System :- Windows 10
Platform :- Python IDLE 3.7
Database :- MySQL
Language :- Python

Hardware Specifications :-
PROCESSOR :- Intel i5 8th GEN
HARD DISK :- 1 TB
RAM :- 8 GB

47 | P a g e
MySQL (DATABASE TABLES)

48 | P a g e
49 | P a g e
BIBLIOGRAPHY

>> Notes given by my teachers


Books –
Computer Science with Python (Textbook for Class XII) - By
Sumita Arora

Internet -
>> www.w3resource.com
>> www.google.com
>> www.wikipedia.org

50 | P a g e
THANK YOU

51 | P a g e

You might also like