class Patient:
def __init__(self, patient_id, name, disease, date_of_registration,
date_of_admission, medicines_taken=None, doctor_appointments=None):
self.id = patient_id
self.name = name
self.disease = disease
self.date_of_registration = date_of_registration
self.date_of_admission = date_of_admission
self.medicines_taken = medicines_taken if medicines_taken is not None
else []
self.doctor_appointments = doctor_appointments if
doctor_appointments is not None else []
def add_medicine(self, medicine):
self.medicines_taken.append(medicine)
def add_appointment(self, appointment):
self.doctor_appointments.append(appointment)
def update_details(self, name=None, disease=None,
date_of_admission=None):
if name:
self.name = name
if disease:
self.disease = disease
if date_of_admission:
self.date_of_admission = date_of_admission
def get_patient_info(self):
return {
"id": self.id,
"name": self.name,
"disease": self.disease,
"date_of_registration": self.date_of_registration,
"date_of_admission": self.date_of_admission,
"medicines_taken": self.medicines_taken,
"doctor_appointments": self.doctor_appointments
class Doctor:
def __init__(self, id, name, specialty, available_time_slots):
self.id = id
self.name = name
self.specialty = specialty
self.available_time_slots = available_time_slots
def get_doctor_info(self):
return {
"id": self.id,
"name": self.name,
"specialty": self.specialty,
"available_time_slots": self.available_time_slots
}
def get_available_time_slots(self):
return self.available_time_slots
class PatientService:
def __init__(self):
self.patients = {}
def add_patient(self, patient):
self.patients[patient.id] = patient
def get_patient(self, patient_id):
return self.patients.get(patient_id, None)
def get_all_patients(self):
return list(self.patients.values())
def update_patient(self, patient_id, updated_info):
patient = self.get_patient(patient_id)
if patient:
patient.update_details(**updated_info)
print("Patient information updated successfully.")
else:
print("Patient not found. Cannot update information.")
def manage_appointments(self, patient_id, appointment):
patient = self.get_patient(patient_id)
if patient:
patient.add_appointment(appointment)
else:
return "Patient not found."
class DoctorService:
def __init__(self):
self.doctors = []
def add_doctor(self, doctor):
self.doctors.append(doctor)
def get_available_doctors(self):
return [doctor for doctor in self.doctors if doctor.available_time_slots]
def get_doctor_time_slots(self, doctor_id):
for doctor in self.doctors:
if doctor.id == doctor_id:
return doctor.available_time_slots
return None
def generate_receipt(patient, medicine_costs, doctor_fees):
receipt = "----- Hospital Receipt -----\n"
receipt += f"Patient ID: {patient.id}\n"
receipt += f"Patient Name: {patient.name}\n"
receipt += f"Disease: {patient.disease}\n"
receipt += f"Date of Registration: {patient.date_of_registration}\n"
receipt += f"Date of Admission: {patient.date_of_admission}\n"
receipt += "\nMedicines Taken:\n"
for medicine, cost in medicine_costs.items():
receipt += f"- {medicine}: ${cost:.2f}\n"
total_medicine_cost = sum(medicine_costs.values())
total_cost = total_medicine_cost + doctor_fees
receipt += f"\nDoctor Fees: ${doctor_fees:.2f}\n"
receipt += f"Total Cost: ${total_cost:.2f}\n"
receipt += "---------------------------\n"
return receipt
def main():
patient_service = PatientService()
doctor_service = DoctorService()
while True:
print("\nWelcome to the Hospital Management System")
print("1. Add Patient Record")
print("2. View Patient Records")
print("3. View Available Doctors")
print("4. Generate Receipt")
print("5. Exit")
choice = input("Please select an option: ")
if choice == '1':
id = input("Enter Patient ID: ")
name = input("Enter Patient Name: ")
disease = input("Enter Disease: ")
date_of_registration = input("Enter Date of Registration (YYYY-MM-
DD): ")
date_of_admission = input("Enter Date of Admission (YYYY-MM-DD):
")
medicines_taken = input("Enter Medicines Taken (comma-separated):
").split(',')
doctor_appointments = input("Enter Doctor Appointments (comma-
separated): ").split(',')
patient = Patient(id, name, disease, date_of_registration,
date_of_admission, medicines_taken, doctor_appointments)
patient_service.add_patient(patient)
print("Patient record added successfully.")
elif choice == '2':
patients = patient_service.get_all_patients()
if patients:
for patient in patients:
print("\nPatient Information:")
for key, value in patient.get_patient_info().items():
print(f"{key.capitalize()}: {value}")
else:
print("No patient records found.")
elif choice == '3':
doctors = doctor_service.get_available_doctors()
if doctors:
for doctor in doctors:
print("\nDoctor Information:")
for key, value in doctor.get_doctor_info().items():
print(f"{key.capitalize()}: {value}")
else:
print("No available doctors at the moment.")
elif choice == '4':
patient_id = input("Enter Patient ID for receipt: ")
patient = patient_service.get_patient(patient_id)
if patient:
medicine_costs = {}
num_medicines = int(input("Enter number of medicines: "))
for _ in range(num_medicines):
medicine = input("Enter medicine name: ")
cost = float(input("Enter cost: $"))
medicine_costs[medicine] = cost
doctor_fees = float(input("Enter doctor fees: $"))
receipt = generate_receipt(patient, medicine_costs, doctor_fees)
print("\n" + receipt)
else:
print("Patient not found.")
elif choice == '5':
print("Exiting the system. Have a great day!")
break
else:
print("Invalid option. Please try again.")
if __name__ == "__main__":
main()