0% found this document useful (0 votes)
107 views24 pages

CS Investigatory Project Class 12

This document contains code for a hospital record keeping system using Python and different data storage methods. It includes code to: 1. Store patient records in a binary file using pickle and display them in a formatted table. Functions allow adding, searching, and modifying patient records. 2. Store patient records in a MySQL database using mysql.connector. Functions allow displaying all patients, adding new patients, modifying doctor assignments, and searching by room number. 3. Store patient records in a CSV file using the csv module. Functions provide similar record keeping capabilities as the binary file and database versions.

Uploaded by

Random Acc
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)
107 views24 pages

CS Investigatory Project Class 12

This document contains code for a hospital record keeping system using Python and different data storage methods. It includes code to: 1. Store patient records in a binary file using pickle and display them in a formatted table. Functions allow adding, searching, and modifying patient records. 2. Store patient records in a MySQL database using mysql.connector. Functions allow displaying all patients, adding new patients, modifying doctor assignments, and searching by room number. 3. Store patient records in a CSV file using the csv module. Functions provide similar record keeping capabilities as the binary file and database versions.

Uploaded by

Random Acc
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/ 24

Index:

1. Acknowledgement 2

2. Certificate 3

3. About the Project 4

4. Technical Details 6

5. Question Index 7

6. Source Codes and Sample Outputs 8

7. Scope of Improvement 22

8. Bibliography 23

1
Acknowledgement:

I would like to thank our Computer Science teacher Mr.


Gautam Sarkar for teaching us Python and opening us
to a world of opportunities, as well as for introducing us
to other projects and points of research. We would also
like to thank the principal, Dr. Vijay Datta, for
providing us with the opportunity to do such wonderful
projects.

Certificate
2
This is to certify that the project titled “Computer
Science Project Report File” is submitted by Anshuman
Tyagi in fulfillment of the requirements for the
Computer Science Project Report File of class 12th,
2023-24. This project was an authentic work done by
them under my guidance and supervision.

This project has not been submitted to any other


institution for any similar purposes.

Gautam Sarkar

Modern School, Barakhamba Road

Teacher’s Signature

3
About the Project:
This project showcases a simple hospital record-keeping
system using CSV file, binary file and Python-SQL
connectivity. They offer several functionalities such as
displaying patients, adding new patients, showing doctors
assigned to each patient, and diagnosis. Let's discuss how this
could be useful in a practical, real-world application:
The codes can serve as a foundation for developing a hospital
management system.
The codes displays all patients in the hospital. This feature
can be useful for creating an online database of patients in
hospital allowing hospital staff to be up to date.
The function doctor()facilitate the assigning of doctor to a
case. They update the patient’s status. This functionality can
be utilized in a real-world.
By using a binary file/MySQL database, the codes ensure that
the data persists even after restarting the application.
The codes incorporate a menu-based user interface, allowing
users to interact easily. Users can select options using
numbers, making the application intuitive and straightforward
to navigate.
The codes demonstrate the use of third-party libraries such as
pickle, mysql.connector, tabulate. These libraries simplify the
interaction with MySQL and enable the creation of well-
formatted tables for displaying book records. Leveraging
existing hospitals saves development time and effort.
Overall, the codes provide a foundation for building a
functional hospital management system, which can be
4
extended and customized according to specific requirements.
It automates various administrative tasks, improves book
tracking, and enhances the user experience in a real-world
hospital setting.

5
Technical Details:
This project is a Hospital Record Keeping System
implemented in Python. It uses the pickle/MySQL connector
library to interact with a binary file/MySQL database. The
system allows users to perform various operations.
The program establishes a connection to the MySQL server
and creates a database named ‘HospitalDatabase’ if it doesn't
exist. It also creates a table named ‘patients’ to store patient
information, including the room no, patient name, diagnosis,
doctor incharge.
The main program loop presents a menu to the user and
executes the corresponding function based on their choice.
The program handles input validation and performs the
necessary database operations for each function.
Overall, this project provides a basic hospital management
system with essential functionalities for keeping track of
patients and managing doctor workload.

6
Question Index:

Binary File Based Program


(Page 8)

MySQL Based Program


(Page 13)

CSV Based Program


(Page 17)

7
Binary Based Program:
import pickle
from tabulate import tabulate

def Continue():
Response=input("Do you want to add more? (Y/N) ")
if Response.upper()=='N':
return 0
elif Response.upper()=='Y':
return 1
else:
print("Invalid Response")
if Continue():
return 1
else:
return 0

def patient():
BlockRecords=[]
RNos = []

try:
F2=open('Hospital.dat','rb')
while True:
try:
aRecord=pickle.load(F2)
RNos.append(aRecord[0])

except:
print(tabulate(data, headers=headers, tablefmt='grid'))
F2.close()
break

except:
pass

finally:
while True:
RNo=int(input("Room No: "))

if RNo in RNos:
print("Already a patient in this room")
else:
RNos.append(RNo)
Name=input("Patient’s Name: ")
doc=input("Doctor incharge : ")

8
diag= input("Patient’s diagnosis: ")
aRecord=[RNo,Name,doc,diag]
BlockRecords.append(aRecord)

if not Continue():
break

print()

F1=open(‘Hospital.dat','ab')
for i in BlockRecords:
pickle.dump(i,F1)
F1.close()

def display_patients():
headers = ['Room No', 'Patient’s Name', 'Doctor Incharge',
‘Diagnosis’]
data=[]
try:
F2=open(‘Hospital.dat','rb')
while True:
try:
aRecord=pickle.load(F2)

data.append([aRecord[0],aRecord[1],aRecord[2],aRecord[
3])

except:
print(tabulate(data, headers=headers, tablefmt='grid'))
F2.close()
break
except:
print('File opening problem!')

def Search():
Counter=0
P=input(“Enter Patient Name: “)
try:
F2=open(‘Hospital.dat','rb')
while True:
try:
BlockRecords=pickle.load(F2)
for aRecord in BlockRecords:
if P.upper()==aRecord[1].upper():
Counter+=1

9
print(aRecord[0],aRecord[1],aRecord[2],aRecord[3])
except:
F2.close()
break

except:
print('File opening problem!')

print('Total ',Counter,' record(s) found!')

def Modify():
NewRecords=[]
R= int(input(“Enter room no of patient you want to update data of:”))
Flag=0
try:
F2=open(‘Hospital.dat','rb')
while True:
try:
BlockRecords=pickle.load(F2)
for aRecord in BlockRecords:
if R==aRecord[0]:
print(aRecord[0],aRecord[1],aRecord[2])
aRecord[2]=input("Enter the new doctor’s name: ")
Flag+=1

NewRecords.append(aRecord)
except:
F2.close()
break
F1=open(‘Hospital.dat','wb')
pickle.dump(NewRecords,F1)
F1.close()

except:
print('File opening problem!')

print('Total ',Flag,' record(s) updated!')

while True:
print('== MAIN MENU ==')
print('1. Display all patients')
print('2. Add a new patient’)
print('3. Search a patient record’)
print('4. Modify doctor in-charge of a patient’)
print('5. Exit')
10
Choice=input("Your Choice: ")

if Choice=='1':
display_patients()
elif Choice=='2':
patient()
elif Choice=='3':
Search()
elif Choice=='4':
Modify()
elif Choice=='5':
print('Thank you!')
break
else:
print('Invalid Choice! Try Again.')

Output:

11
MySQL Based Program:
import mysql.connector
from prettytable import PrettyTable

cnx = mysql.connector.connect(
host="localhost",
user="root",
password="host"
)
12
cursor = cnx.cursor()

cursor.execute("CREATE DATABASE IF NOT EXISTS `HospitalDatabase`")


cursor.execute("USE `HospitalDatabase`")

cursor.execute("""
CREATE TABLE IF NOT EXISTS `patients` (
`roomno` INT AUTO_INCREMENT PRIMARY KEY,
`patient ` VARCHAR(30),
`doctor` VARCHAR(30),
`diagnosis` VARCHAR(255),
)
""")

def display_menu():
print("\n===== Library Record Keeping System =====")
print("1. Display all patients")
print("2. Add a new patient")
print("3. Search for a patient")
print("4. Change doctor-in-charge")
print("5. Exit")

def display_patients():
cursor.execute("SELECT * FROM patients")
patients = cursor.fetchall()

if not patients:
print("No patients found in the hospital.")

else:
T=PrettyTable(['RoomNo', 'Patient Name', 'Doctor', 'Diagnosis’])
for patient in patients:
patient=list(patient)
room_id, patient_name, doctor, diagnosis = patient

def add_patient():
PName = input("Enter the name of the patient: ")
doc = input("Enter the name of the doctor-in-charge: ")

cursor.execute("INSERT INTO patients (PName, doc) VALUES (%s, %s)",


(PName, doc))
cnx.commit()
print("Patient added successfully!")

def Modify():
room_no = input("Enter the room number of the patient: ")
D= input(“Enter the new doctor name: “)

13
C=“UPDATE patients SET doctor=%s where roomno= %s”
Val= (D, room_no)
cursor.execute(C,Val)
cnx.commit()

print(cursor.rowcount, "record(s) affected")

def Search():
R= input(“Enter room no to fetch data of: “)
S= “SELECT * from patients where roomno= %s”
Val=(R)
cursor.execute(S,Val)

while True:
display_menu()
choice = input("Enter your choice (1-5): ")

if choice == "1":
display_patients()
elif choice == "2":
add_patient()
elif choice == "3":
Search()
elif choice == "4":
Modify()
elif choice == "5":
break
else:
print("Invalid choice. Please try again.")
cursor.close()
cnx.close()

Output:

14
15
MySQL Based Program:

import csv
from tabulate import tabulate

def Continue():
Response=input("Do you want to add more? (Y/N) ")
if Response.upper()=='N':
return 0
elif Response.upper()=='Y':
return 1

16
else:
print("Invalid Response")
if Continue():
return 1
else:
return 0

def patient():
BlockRecords=[]
RNos = []

try:
F2=open('Hospital.txt,'r')
while True:
try
aRecord=csv.reader(F2)
RNos.append(aRecord[0])

except:
print(tabulate(data, headers=headers, tablefmt='grid'))
F2.close()
break

except:
pass

finally:
while True:
RNo=int(input("Room No: "))

if RNo in RNos:
print("Already a patient in this room")
else:
RNos.append(RNo)
Name=input("Patient’s Name: ")
doc=input("Doctor incharge : ")

diag= input("Patient’s diagnosis: ")


aRecord=[RNo,Name,doc,diag]
BlockRecords.append(aRecord)

if not Continue():
break

print()

F1=open(‘Hospital.txt','a')
ro=csv.writer(F1)
for i in BlockRecords:
ro.writerow(i)
17
F1.close()

def display_patients():
headers = ['Room No', 'Patient’s Name', 'Doctor Incharge',
‘Diagnosis’]
data=[]
try:
F2=open(‘Hospital.txt','r')
while True:
try:
aRecord=csv.reader(F2)

data.append([aRecord[0],aRecord[1],aRecord[2],aRecord[
3])

except:
print(tabulate(data, headers=headers, tablefmt='grid'))
F2.close()
break
except:
print('File opening problem!')

def Search():
Counter=0
P=input(“Enter Patient Name: “)
try:
F2=open(‘Hospital.txt','r')
while True:
try:
BlockRecords=csv.reader(F2)
for aRecord in BlockRecords:
if P.upper()==aRecord[1].upper():
Counter+=1

print(aRecord[0],aRecord[1],aRecord[2],aRecord[3])
except:
F2.close()
break

except:
print('File opening problem!')

print('Total ',Counter,' record(s) found!')

18
def Modify():
NewRecords=[]
R= int(input(“Enter room no of patient you want to update data of:”))
Flag=0
try:
F2=open(‘Hospital.txt','r')
while True:
try:
BlockRecords=csv.reader(F2)
for aRecord in BlockRecords:
if R==aRecord[0]:
print(aRecord[0],aRecord[1],aRecord[2])
aRecord[2]=input("Enter the new doctor’s name: ")
Flag+=1

NewRecords.append(aRecord)
except:
F2.close()
break
F1=open(‘Hospital.txt','w')
ro=csv.writer(F1)
ro.writerow(NewRecords)
F1.close()

except:
print('File opening problem!')

print('Total ',Flag,' record(s) updated!')

while True:
print('== MAIN MENU ==')
print('1. Display all patients')
print('2. Add a new patient’)
print('3. Search a patient record’)
print('4. Modify doctor in-charge of a patient’)
print('5. Exit')
Choice=input("Your Choice: ")

if Choice=='1':
display_patients()
elif Choice=='2':
patient()
elif Choice=='3':
Search()
elif Choice=='4':
Modify()
elif Choice=='5':
19
print('Thank you!')
break
else:
print('Invalid Choice! Try Again.')

Output:

20
Scope of Improvement:

1. Book Search and Filtering: Add functionality to search for


books based on criteria such as title, author, or availability.
Users should be able to search for books using keywords and
receive a list of matching results. Additionally, you can provide
filtering options to narrow down the search results based on
different attributes like genre, publication date, or language.

2. Cap on Money Owed: In the current system, the money owed to


the library for an overdue book grows indefinitely after 14 days.
However, a more logical approach would be to charge a little
over the current cost of the book at maximum, since that would
cover the cost of replacing the book.

3. Automated Email Notification System: Also collect the email


IDs of the borrower and have an automated system remind them
to return their book via email.

4. Reporting and Analytics: Implement reporting and analytics


features to gain insights into the library system's performance.
Generate reports on book popularity, borrowing patterns,
overdue books, and fines collected. Analytics can help identify
trends, optimize book purchasing decisions, and improve the
overall management of the library.

5. Multi-Library Support: Extend the system to support multiple


libraries or branches. Each library can have its own database and
manage its collection independently. Users should be able to
choose their preferred library during registration or switch
between libraries easily.

By incorporating these expansion ideas, the library system can be


transformed into a more comprehensive and efficient solution,
providing enhanced user experiences and enabling effective
management of library resources.

21
Bibliography:
Computer Science NCERT:
https://ncert.nic.in/textbook.php?lecs1=0-13

PyPi – PrettyTable:
https://pypi.org/project/prettytable/

AskPython – Python tabulate Module:


https://www.askpython.com/python-modules/tabulate-tables-in-
python

PYNative – Writing Lists to a File:


https://pynative.com/python-write-list-to-file/

GeeksforGeeks – SQL Using Python:


https://www.geeksforgeeks.org/sql-using-python/

22
23

You might also like