Selling hospital Management Application Code

class Patient

  attr_accessor :name, :age, :id


  def initialize(name, age, id)

    @name = name

    @age = age

    @id = id

  end


  def display_info

    puts "Patient ID: #{@id}, Name: #{@name}, Age: #{@age}"

  end

end


class Doctor

  attr_accessor :name, :specialization, :id


  def initialize(name, specialization, id)

    @name = name

    @specialization = specialization

    @id = id

  end


  def display_info

    puts "Doctor ID: #{@id}, Name: #{@name}, Specialization: #{@specialization}"

  end

end


class Appointment

  attr_accessor :patient, :doctor, :date


  def initialize(patient, doctor, date)

    @patient = patient

    @doctor = doctor

    @date = date

  end


  def display_info

    puts "Appointment: [Date: #{@date}, Patient: #{@patient.name}, Doctor: #{@doctor.name}]"

  end

end


class Hospital

  def initialize

    @patients = []

    @doctors = []

    @appointments = []

  end


  def add_patient(patient)

    @patients << patient

  end


  def add_doctor(doctor)

    @doctors << doctor

  end


  def schedule_appointment(patient_id, doctor_id, date)

    patient = @patients.find { |p| p.id == patient_id }

    doctor = @doctors.find { |d| d.id == doctor_id }

    if patient && doctor

      appointment = Appointment.new(patient, doctor, date)

      @appointments << appointment

      puts "Appointment scheduled successfully."

    else

      puts "Patient or Doctor not found!"

    end

  end


  def display_patients

    puts "List of Patients:"

    @patients.each(&:display_info)

  end


  def display_doctors

    puts "List of Doctors:"

    @doctors.each(&:display_info)

  end


  def display_appointments

    puts "List of Appointments:"

    @appointments.each(&:display_info)

  end

end


# Example usage

hospital = Hospital.new


# Adding patients

patient1 = Patient.new("Alice", 30, 1)

patient2 = Patient.new("Bob", 40, 2)

hospital.add_patient(patient1)

hospital.add_patient(patient2)


# Adding doctors

doctor1 = Doctor.new("Dr. Smith", "Cardiology", 1)

doctor2 = Doctor.new("Dr. Jones", "Orthopedics", 2)

hospital.add_doctor(doctor1)

hospital.add_doctor(doctor2)


# Scheduling appointments

hospital.schedule_appointment(1, 1, "2024-08-15")

hospital.schedule_appointment(2, 2, "2024-08-16")


# Displaying information

hospital.display_patients

hospital.display_doctors

hospital.display_appointments


Comments

Popular posts from this blog

Why I married Sarah the world's Fittest Woman

Generic Digital Super35 Action Camera

How to stop cheating