0% found this document useful (0 votes)
6 views4 pages

Hospital Management System Project Guide

The document outlines a Hospital Management System project for Class 12, detailing its objectives, ER diagram, algorithms, and a complete Python implementation. The system utilizes file handling with CSV-like text files and features a console interface for managing patients, doctors, appointments, and billing. Key functionalities include adding, listing, and searching for patients and doctors, as well as booking appointments and generating bills.

Uploaded by

amanimozhi10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Hospital Management System Project Guide

The document outlines a Hospital Management System project for Class 12, detailing its objectives, ER diagram, algorithms, and a complete Python implementation. The system utilizes file handling with CSV-like text files and features a console interface for managing patients, doctors, appointments, and billing. Key functionalities include adding, listing, and searching for patients and doctors, as well as booking appointments and generating bills.

Uploaded by

amanimozhi10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Hospital Management System - Class 12

This PDF contains:


1) Project overview and objectives
2) ER diagram description
3) Algorithms
4) Complete Python code implementing a simple file-based Hospital Management System

The Python code uses simple file handling (CSV-like text files) and a menu-driven con
sole interface.

--- Python Code ---

# Hospital Management System (Simple file-based) - Python 3


# Files used: [Link], [Link], [Link], [Link]
# Each record is stored as a pipe-separated line (|) for simplicity.

import os
import datetime

DATA_DIR = "hms_data"
[Link](DATA_DIR, exist_ok=True)

PATIENTS_FILE = [Link](DATA_DIR, "[Link]")


DOCTORS_FILE = [Link](DATA_DIR, "[Link]")
APPTS_FILE = [Link](DATA_DIR, "[Link]")
BILLS_FILE = [Link](DATA_DIR, "[Link]")

def write_record(filename, fields):


with open(filename, "a", encoding="utf-8") as f:
[Link]("|".join(fields) + "\\n")

def read_records(filename):
if not [Link](filename):
return []
with open(filename, "r", encoding="utf-8") as f:
lines = [[Link]() for line in f if [Link]()]
records = [[Link]("|") for line in lines]
return records

def generate_id(prefix, filename):


records = read_records(filename)
if not records:
return f"{prefix}1"
last = records[-1][0]
# assume id like P1, D1, A1...
try:
num = int(''.join(filter([Link], last)))
except:
num = len(records)
return f"{prefix}{num+1}"

# Patient functions
def add_patient():
pid = generate_id("P", PATIENTS_FILE)
name = input("Patient name: ").strip()
age = input("Age: ").strip()
gender = input("Gender: ").strip()
phone = input("Phone: ").strip()
address = input("Address: ").strip()
write_record(PATIENTS_FILE, [pid, name, age, gender, phone, address])
print(f"Patient added with ID {pid}")

def list_patients():
patients = read_records(PATIENTS_FILE)
if not patients:
print("No patients found.")
return
print("ID\tName\tAge\tGender\tPhone\tAddress")
for p in patients:
print("\\t".join(p))

def find_patient():
pid = input("Enter patient ID to search: ").strip()
patients = read_records(PATIENTS_FILE)
for p in patients:
if p[0] == pid:
print("Found:", p)
return p
print("Patient not found.")
return None

# Doctor functions
def add_doctor():
did = generate_id("D", DOCTORS_FILE)
name = input("Doctor name: ").strip()
specialization = input("Specialization: ").strip()
phone = input("Phone: ").strip()
write_record(DOCTORS_FILE, [did, name, specialization, phone])
print(f"Doctor added with ID {did}")

def list_doctors():
doctors = read_records(DOCTORS_FILE)
if not doctors:
print("No doctors found.")
return
print("ID\tName\tSpecialization\tPhone")
for d in doctors:
print("\\t".join(d))

def find_doctor():
did = input("Enter doctor ID to search: ").strip()
doctors = read_records(DOCTORS_FILE)
for d in doctors:
if d[0] == did:
print("Found:", d)
return d
print("Doctor not found.")
return None

# Appointment functions
def book_appointment():
appt_id = generate_id("A", APPTS_FILE)
print("Select patient for appointment:")
list_patients()
pid = input("Enter patient ID: ").strip()
print("Select doctor:")
list_doctors()
did = input("Enter doctor ID: ").strip()
date = input("Appointment date (YYYY-MM-DD): ").strip()
time = input("Appointment time (HH:MM): ").strip()
write_record(APPTS_FILE, [appt_id, pid, did, date, time])
print(f"Appointment booked with ID {appt_id}")

def list_appointments():
appts = read_records(APPTS_FILE)
if not appts:
print("No appointments found.")
return
print("ID\tPatientID\tDoctorID\tDate\tTime")
for a in appts:
print("\\t".join(a))

# Billing
def generate_bill():
bill_id = generate_id("B", BILLS_FILE)
appt_id = input("Enter appointment ID for billing: ").strip()
appts = read_records(APPTS_FILE)
appt = next((a for a in appts if a[0] == appt_id), None)
if not appt:
print("Appointment not found.")
return
patient = next((p for p in read_records(PATIENTS_FILE) if p[0] == appt[1]), None)
doctor = next((d for d in read_records(DOCTORS_FILE) if d[0] == appt[2]), None)
consult_fee = input("Consultation fee: ").strip()
other_charges = input("Other charges (0 if none): ").strip()
total = float(consult_fee or 0) + float(other_charges or 0)
date = [Link]().isoformat()
write_record(BILLS_FILE, [bill_id, appt_id, patient[0] if patient else "", doctor
[0] if doctor else "", str(total), date])
print(f"Bill generated with ID {bill_id}. Total: {total}")

def list_bills():
bills = read_records(BILLS_FILE)
if not bills:
print("No bills found.")
return
print("ID\tApptID\tPatientID\tDoctorID\tAmount\tDate")
for b in bills:
print("\\t".join(b))

def main_menu():
while True:
print("\\n--- Hospital Management System ---")
print("1. Add Patient")
print("2. List Patients")
print("3. Search Patient")
print("4. Add Doctor")
print("5. List Doctors")
print("6. Search Doctor")
print("7. Book Appointment")
print("8. List Appointments")
print("9. Generate Bill")
print("10. List Bills")
print("0. Exit")
choice = input("Enter choice: ").strip()
if choice == "1":
add_patient()
elif choice == "2":
list_patients()
elif choice == "3":
find_patient()
elif choice == "4":
add_doctor()
elif choice == "5":
list_doctors()
elif choice == "6":
find_doctor()
elif choice == "7":
book_appointment()
elif choice == "8":
list_appointments()
elif choice == "9":
generate_bill()
elif choice == "10":
list_bills()
elif choice == "0":
print("Exiting. Goodbye!")
break
else:
print("Invalid choice. Try again.")

if __name__ == "__main__":
main_menu()

Common questions

Powered by AI

Maintaining a file-based system might be preferable in scenarios where simplicity, low resource consumption, and ease of deployment are prioritized over complexity. Small organizations or educational projects with limited data, minimal functional requirements, and non-critical operations may benefit from a file system due to its straightforward operation and lack of dependency on extensive server infrastructure. Additionally, situations where the user base is expected to be small and data modification is infrequent can also justify the continued use of a file-based approach .

The system stores patient records in a text file named "patients.txt" using a pipe-separated format for each field. Data retrieval is handled through the read_records function, which reads the file line-by-line, splits each line based on the pipe separator, and returns it as a list of records. New patient records are added using the write_record function, which appends a new pipe-separated line with patient details to the file .

Booking an appointment involves several steps: First, the system prompts the user to select a patient from the list using their ID, which is retrieved from "patients.txt". Next, a doctor is similarly selected from "doctors.txt". The user is then asked to input the desired appointment date and time. An ID for the appointment is generated using the generate_id function, and the details are recorded in "appointments.txt" in a pipe-separated format. This process is conducted using input prompts and file-based records .

The console interface offers a straightforward, menu-driven approach that enables users to perform basic operations through numeric selections. This simplicity benefits users with minimal programming skills. However, the interface lacks visual representation and advanced navigation features found in graphical user interfaces (GUIs), which could improve user experience. Potential improvements include enhancing user feedback on invalid inputs, integrating error handling directly into menu actions, and considering a transition to a GUI with clickable buttons and dropdown menus for better accessibility and efficiency .

File handling in this system offers simplicity and ease of implementation, allowing for basic data persistence without the overhead of a database. It uses standard Python functions to read from and write to text files, making it accessible for those familiar with basic programming concepts. However, this approach has limitations, including lack of data integrity and concurrency control, difficulty in handling large datasets efficiently, and potential for errors in manual string processing. It does not support advanced queries or transactions, which limits its scalability for larger applications .

Transitioning to a database system would involve several steps: 1) Designing a database schema based on the existing data structure, using ER diagrams as a guide. 2) Choosing a database management system (DBMS) like MySQL or PostgreSQL. 3) Migrating existing data from text files to database tables, possibly using scripts for automated import. 4) Modifying the application logic to interface with the database through queries instead of file operations, using an appropriate database API or ORM framework. 5) Implementing data integrity, security constraints, and addressing concurrency issues within the database system .

Billing in the system is achieved by associating an appointment with a generated bill ID using inputs for consultation fees and additional charges. The total amount is calculated by summing these inputs. This method is significant as it links billing directly to service consumption (appointments), ensuring traceability and accountability. However, it is basic and might benefit from further validation checks and integration with patient insurance or discount systems for enhanced functionality in real-world applications .

The system generates unique IDs using the generate_id function. This function reads existing records from the respective file, extracts numerical parts from the last entry's ID, and increments it to create a new ID with a prefix (e.g., 'P' for patients, 'D' for doctors). If there are no existing records, it defaults to "P1", "D1", etc. This method ensures IDs are unique and sequentially numbered .

The system does not inherently handle concurrency, as it uses simple file-based storage without locks or transactions. Python's file handling does not support concurrent access by default, meaning if multiple operations are performed simultaneously, they may lead to data corruption or race conditions. To improve data integrity, mechanisms such as file locks, semaphores, or transitioning to a database that provides transactional support and concurrency control are recommended .

ER diagrams play a crucial role in system design by providing a visual representation of the data entities and their relationships. They help in identifying the key attributes and the structure of the database, which in this project translates to how files like "patients.txt" and "doctors.txt" organize data. Such diagrams guide the logical implementation of the system leading to the structured data storage and retrieval process evident in the implemented Python system .

You might also like