Computer Science Investigatorymysql (2)
Computer Science Investigatorymysql (2)
KENDRIYA VIDYALAYA
OTTAPALAM
BY AVINASH NV
XII A
ROLL NO.___________
CERTIFICATE
Principal
Acknowledgement
[NAME]
Class XII
TABLE OF CONTENTS
1. introduction ………………………. 1
2. Objective and scope………….. 2
3. software development
Tools used ………………………….. 3
4. database design………………. 5
5. soURce code ………………………. 8
6. OUTPUT SCREENS……………………. 15
7. System ReqUiRements…………. 18
8. ReFeRences………………………….. 19
1. Introduction
P age |1
2. objective and scope
The objectives of the project are:
P age |2
3. software development tools used
The following software development tools were used:
Python:
The front-end of the project has been developed in Python language. Python
is free and open source and many libraries exist for performing different kinds of
work with it.
P age |3
MySQL:
Anaconda:
P age |4
4. DATABASE DESIGN
The following tables were created in MySQL:
USE HOSPITALMANAGEMENT;
CREATE TABLE patients (
patient_id INTEGER PRIMARY KEY AUTO_INCREMENT,
name TEXT NOT NULL,
age INTEGER,
gender TEXT,
phone TEXT,
address TEXT
);
P age |5
CREATE TABLE appointments (
appointment_id INTEGER PRIMARY KEY AUTO_INCREMENT,
patient_id INTEGER,
doctor_id INTEGER,
appointment_date TEXT,
status TEXT,
FOREIGN KEY (patient_id) REFERENCES patients (patient_id),
FOREIGN KEY (doctor_id) REFERENCES doctors (doctor_id)
);
P age |6
CREATE TABLE billing (
bill_id INTEGER PRIMARY KEY AUTO_INCREMENT,
patient_id INTEGER,
total_amount REAL,
payment_status TEXT,
billing_date TEXT,
FOREIGN KEY (patient_id) REFERENCES patients (patient_id)
);
P age |7
5. SOURCE CODE
import sqlite3
from datetime import datetime
# Database connection
conn = sqlite3.connect('hospital_management.db')
cursor = conn.cursor()
P age |8
cursor.execute('''CREATE TABLE IF NOT EXISTS appointments (
appointment_id INTEGER PRIMARY KEY AUTOINCREMENT,
patient_id INTEGER,
doctor_id INTEGER,
appointment_date TEXT,
status TEXT,
FOREIGN KEY (patient_id) REFERENCES patients (patient_id),
FOREIGN KEY (doctor_id) REFERENCES doctors (doctor_id)
)''')
# View patients
def view_patients():
cursor.execute("SELECT * FROM patients")
patients = cursor.fetchall()
for patient in patients:
print(patient)
# Add doctor
def add_doctor(name, specialization, phone, email):
cursor.execute('''INSERT INTO doctors (name, specialization, phone, email)
VALUES (?, ?, ?, ?)''', (name, specialization, phone, email))
conn.commit()
print("Doctor added successfully!")
P a g e | 10
# View doctors
def view_doctors():
cursor.execute("SELECT * FROM doctors")
doctors = cursor.fetchall()
for doctor in doctors:
print(doctor)
# Book appointment
def book_appointment(patient_id, doctor_id, appointment_date):
cursor.execute('''INSERT INTO appointments (patient_id, doctor_id,
appointment_date, status)
VALUES (?, ?, ?, ?)''', (patient_id, doctor_id, appointment_date,
'Scheduled'))
conn.commit()
print("Appointment booked successfully!")
# View appointments
def view_appointments():
cursor.execute('''SELECT a.appointment_id, p.name AS patient_name, d.name AS
doctor_name, a.appointment_date, a.status
FROM appointments a
JOIN patients p ON a.patient_id = p.patient_id
JOIN doctors d ON a.doctor_id = d.doctor_id''')
appointments = cursor.fetchall()
for appointment in appointments:
P a g e | 11
print(appointment)
# Generate bill
def generate_bill(patient_id, total_amount):
billing_date = datetime.now().strftime("%Y-%m-%d")
cursor.execute('''INSERT INTO billing (patient_id, total_amount, payment_status,
billing_date)
VALUES (?, ?, ?, ?)''', (patient_id, total_amount, 'Unpaid', billing_date))
conn.commit()
print("Bill generated successfully!")
# View billing
def view_billing():
cursor.execute("SELECT * FROM billing")
bills = cursor.fetchall()
for bill in bills:
print(bill)
# Main menu
def main_menu():
create_tables()
while True:
print("\n--- Hospital Management System ---")
print("1. Add Patient")
P a g e | 12
print("2. View Patients")
print("3. Add Doctor")
print("4. View Doctors")
print("5. Book Appointment")
print("6. View Appointments")
print("7. Generate Bill")
print("8. View Billing")
print("9. Exit")
choice = input("Enter your choice: ")
if choice == '1':
name = input("Enter patient name: ")
age = int(input("Enter patient age: "))
gender = input("Enter patient gender: ")
phone = input("Enter patient phone: ")
address = input("Enter patient address: ")
add_patient(name, age, gender, phone, address)
elif choice == '2':
view_patients()
elif choice == '3':
name = input("Enter doctor name: ")
specialization = input("Enter specialization: ")
phone = input("Enter phone: ")
email = input("Enter email: ")
add_doctor(name, specialization, phone, email)
elif choice == '4':
view_doctors()
P a g e | 13
elif choice == '5':
patient_id = int(input("Enter patient ID: "))
doctor_id = int(input("Enter doctor ID: "))
appointment_date = input("Enter appointment date (YYYY-MM-DD): ")
book_appointment(patient_id, doctor_id, appointment_date)
elif choice == '6':
view_appointments()
elif choice == '7':
patient_id = int(input("Enter patient ID: "))
total_amount = float(input("Enter total amount: "))
generate_bill(patient_id, total_amount)
elif choice == '8':
view_billing()
elif choice == '9':
break
else:
print("Invalid choice! Please try again.")
conn.close()
P a g e | 14
6. OUTPUT SCREENS
1. Add Patient’s details:
--- Hospital Management System ---
1. Add Patient
2. View Patients
3. Add Doctor
4. View Doctors
5. Book Appointment
6. View Appointments
7. Generate Bill
8. View Billing
9. Exit
Enter your choice: 1
Enter patient name: Raj
Enter patient age: 24
Enter patient gender: male
Enter patient phone: 9087564312
Enter patient address: B-52 skyline, street no. 23, delhi
Patient added successfully!
P a g e | 15
3. Book appointment:
--- Hospital Management System ---
1. Add Patient
2. View Patients
3. Add Doctor
4. View Doctors
5. Book Appointment
6. View Appointments
7. Generate Bill
8. View Billing
9. Exit
Enter your choice: 5
Enter patient ID: 132436
Enter doctor ID: 5372536
Enter appointment date (YYYY-MM-DD): 2024-11-23
Appointment booked successfully!
4. Generate billing
--- Hospital Management System ---
1. Add Patient
2. View Patients
3. Add Doctor
4. View Doctors
5. Book Appointment
6. View Appointments
7. Generate Bill
8. View Billing
9. Exit
Enter your choice: 7
Enter patient ID: 132436
Enter total amount: 2000
Bill generated successfully!
P a g e | 16
5. View patient:
--- Hospital Management System ---
1. Add Patient
2. View Patients
3. Add Doctor
4. View Doctors
5. Book Appointment
6. View Appointments
7. Generate Bill
8. View Billing
9. Exit
Enter your choice: 2
(1, 'raj', 24, 'male', '9087564312', 'B-52 skyline, street no. 23, delhi')
6. View doctor:
--- Hospital Management System ---
1. Add Patient
2. View Patients
3. Add Doctor
4. View Doctors
5. Book Appointment
6. View Appointments
7. Generate Bill
8. View Billing
9. Exit
Enter your choice: 4
(1, 'Sriya', 'Neurosurgeon ', '8907564312', '[email protected]')
P a g e | 17
7. SYSTEM REQUIREMENTS
HARDWARE:
11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz
3.00 GHz
8 GB RAM
SOFTWARE:
Windows 11 64 bit
Spyder Version 6.0.0
MySQL Version 8.0.0
P a g e | 18
8. REFERENCES
P a g e | 19