CS Investigatory Project Class 12
CS Investigatory Project Class 12
1. Acknowledgement 2
2. Certificate 3
4. Technical Details 6
5. Question Index 7
7. Scope of Improvement 22
8. Bibliography 23
1
Acknowledgement:
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.
Gautam Sarkar
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:
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!')
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!')
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 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: ")
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()
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 : ")
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!')
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!')
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:
21
Bibliography:
Computer Science NCERT:
https://ncert.nic.in/textbook.php?lecs1=0-13
PyPi – PrettyTable:
https://pypi.org/project/prettytable/
22
23