In [1]:
class Person:
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
def get_details(self):
return f"Name: {self.name}, Age: {self.age}, Gender: {self.gender}"
In [2]:
class Patient(Person):
def __init__(self, name, age, gender, patient_id, medical_history):
super().__init__(name, age, gender)
self.patient_id = patient_id
self.medical_history = medical_history
def get_details(self):
details = super().get_details()
return f"{details}, Patient ID: {self.patient_id}, Medical History: {self.medical_history}"
In [3]:
class Doctor(Person):
def __init__(self, name, age, gender, doctor_id, specialty):
super().__init__(name, age, gender)
self.doctor_id = doctor_id
self.specialty = specialty
def get_details(self):
details = super().get_details()
return f"{details}, Doctor ID: {self.doctor_id}, Specialty: {self.specialty}"
In [4]:
class Appointment:
def __init__(self, patient, doctor, date, time):
self.patient = patient
self.doctor = doctor
self.date = date
self.time = time
def get_details(self):
return (f"Appointment Details:\n"
f"Patient: {self.patient.get_details()}\n"
f"Doctor: {self.doctor.get_details()}\n"
f"Date: {self.date}, Time: {self.time}")
In [5]:
patient = Patient("John Doe", 30, "Male", "P12345", "No allergies")
doctor = Doctor("Dr. Smith", 45, "Female", "D67890", "Cardiology")
appointment = Appointment(patient, doctor, "2024-09-23", "10:00 AM")
In [6]:
print(appointment.get_details())
Appointment Details: Patient: Name: John Doe, Age: 30, Gender: Male, Patient ID: P12345, Medical History: No allergies Doctor: Name: Dr. Smith, Age: 45, Gender: Female, Doctor ID: D67890, Specialty: Cardiology Date: 2024-09-23, Time: 10:00 AM