Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Hospital
- attr_accessor :name, :address, :employees, :patients
- def initialize(args)
- @name = args[:name]
- @address = args[:address]
- @employees = args[:employees] || []
- @patients = args[:patients] || []
- end
- def print_all_patients
- @patients.each { |patient| print_patient(patient) }
- end
- def print_patient(patient)
- puts "Name: #{patient.name}"
- puts "Age: #{patient.age}"
- puts "Gender: #{patient.gender}"
- puts "Blood Type: #{patient.blood_type}"
- puts "Is Sick? #{patient.is_sick}"
- puts ""
- end
- def admit_patient(patient)
- patient.is_sick = true
- @patients << patient
- end
- def discharge_patient(patient)
- patient.is_sick = false
- @patients.delete(patient)
- end
- def print_all_employees
- @employees.each { |employee| print_employee(employee) }
- end
- def print_employee(employee)
- puts "Name: #{employee.name}"
- puts "Age: #{employee.age}"
- puts "Gender: #{employee.gender}"
- puts "Job: #{employee.job}"
- puts ""
- end
- def add_employee(employee)
- @employees << employee
- end
- def remove_employee(employee)
- @employees.delete(employee)
- end
- def to_s
- "#{@name}"
- end
- end
- class Person
- attr_accessor :name, :age, :gender, :username, :password
- def initialize(args)
- @name = args[:name]
- @age = args[:age]
- @gender = args[:gender]
- @username = args[:username] || args[:name].downcase
- @password = args[:password] || '1234'
- end
- def to_s
- "#{@name}"
- end
- end
- class Patient < Person
- attr_accessor :is_sick
- attr_reader :blood_type
- def initialize(args)
- @is_sick = false
- @blood_type = args[:blood_type]
- super(args)
- end
- end
- class Employee < Person
- attr_accessor :job
- def initialize(args)
- @job = args[:job]
- super(args)
- end
- end
- class HostpitalRecordManagement
- attr_accessor :hospital
- def initialize(hospital)
- @hospital = hospital
- end
- def authenticate
- puts "Welcome to #{@hospital.name}"
- puts "----------------------------------------------------"
- access = nil
- while access == nil
- puts "Please enter your username:"
- username = gets.chomp
- puts "Please enter your password:"
- password = gets.chomp
- puts "----------------------------------------------------"
- person = retrieve_person(username)
- access = password_access_level(person, password)
- puts "Cannot find username/password combination. Please try again." if access == nil
- end
- puts "Welcome, #{person.name}. Your access level is: #{access}"
- puts "----------------------------------------------------"
- activate_options(person, access)
- end
- def activate_options(person, access)
- puts "What would you like to do?"
- puts "Enter a command. Options:"
- input = ""
- until input == "exit"
- puts ""
- case access
- when "ADMINISTRATOR"
- puts "view self record"
- puts "view patients"
- puts "add patient"
- puts "remove patient"
- puts "view employees"
- puts "add employee"
- puts "remove employee"
- puts "exit"
- puts ""
- input = gets.chomp
- puts ""
- case input
- when "view self record"
- view_self_employee_record(person)
- when "view patients"
- view_patient_records
- when "add patient"
- add_patient_to_records
- when "remove patient"
- remove_patient_from_records
- when "view employees"
- view_employee_records
- when "add employee"
- add_employee_to_records
- when "remove employee"
- remove_employee_from_records
- when "exit"
- puts "Thank you. Good day!"
- else
- puts "Cannot understand command. Please try agian:"
- end
- when "DOCTOR"
- puts "view self record"
- puts "view patients"
- puts "exit"
- input = gets.chomp
- puts ""
- case input
- when "view self record"
- view_self_employee_record(person)
- when "view patients"
- view_patient_records
- when "exit"
- puts "Thank you. Good day!"
- else
- puts "Cannot understand command. Please try agian:"
- end
- when "RECEPTIONIST"
- puts "view self record"
- puts "view patient records"
- puts "view employee records"
- puts "exit"
- input = gets.chomp
- puts ""
- case input
- when "view self record"
- view_self_employee_record(person)
- when "view patients"
- view_patient_records
- when "view employees"
- view_employee_records
- when "exit"
- puts "Thank you. Good day!"
- else
- puts "Cannot understand command. Please try agian:"
- end
- when "JANITOR"
- puts "view self record"
- puts "exit"
- input = gets.chomp
- puts ""
- case input
- when "view self record"
- view_self_employee_record(person)
- when "exit"
- puts "Thank you. Good day!"
- else
- puts "Cannot understand command. Please try agian:"
- end
- when "PATIENT"
- puts "view self record"
- puts "exit"
- input = gets.chomp
- puts ""
- case input
- when "view self record"
- view_self_patient_record(person)
- when "exit"
- puts "Thank you. Good day!"
- else
- puts "Cannot understand command. Please try agian:"
- end
- end
- end
- end
- def view_self_patient_record(person)
- @hospital.print_patient(person)
- end
- def view_patient_records
- @hospital.print_all_patients
- end
- def add_patient_to_records
- puts "Enter patient's name:"
- name = gets.chomp
- puts "Enter patient's age:"
- age = gets.chomp
- puts "Enter patient's gender:"
- gender = gets.chomp
- puts "Enter patient's blood type:"
- blood_type = gets.chomp
- @hospital.admit_patient(Patient.new( {name: name, age: age, gender: gender, blood_type: blood_type } ))
- puts "#{name} has been added to 'PATIENT RECORDS'."
- end
- def remove_patient_from_records
- puts "Enter patient's username:"
- username = gets.chomp
- patient = retrieve_patient(username)
- if patient
- @hospital.discharge_patient(patient)
- puts "#{username} has been discharged."
- else
- puts "Cannot find patient's username."
- end
- end
- def view_self_employee_record(person)
- @hospital.print_employee(person)
- end
- def view_employee_records
- @hospital.print_all_employees
- end
- def add_employee_to_records
- puts "Enter employee's name:"
- name = gets.chomp
- puts "Enter employee's age:"
- age = gets.chomp
- puts "Enter employee's gender:"
- gender = gets.chomp
- puts "Enter employee's job position:"
- job = gets.chomp
- @hospital.add_employee(Employee.new( {name: name, age: age, gender: gender, job: job } ))
- puts "#{name} has been added to 'EMPLOYEE RECORDS'."
- end
- def remove_employee_from_records
- puts "Enter employee's username:"
- username = gets.chomp
- employee = retrieve_employee(username)
- if employee
- @hospital.remove_employee(employee)
- puts "#{username} has been removed."
- else
- puts "Cannot find employee's username."
- end
- end
- def retrieve_patient(username)
- @hospital.patients.each { |patient| return patient if patient.username.downcase == username.downcase }
- nil
- end
- def retrieve_employee(username)
- @hospital.employees.each { |employee| return employee if employee.username.downcase == username.downcase }
- nil
- end
- def retrieve_person(username)
- all_people = @hospital.employees | @hospital.patients
- all_people.each { |person| return person if person.username.downcase == username.downcase }
- nil
- end
- def password_access_level(person, password)
- return nil if person == nil
- if person.password == password
- return "PATIENT" if person.is_a? Patient
- return person.job.upcase if person.is_a? Employee
- end
- nil
- end
- end
- # DRIVER CODE
- admin = Employee.new( { name: "Administrator", age: "35", gender: "male", job: "administrator", username: "admin" } )
- tim = Employee.new( { name: "Timothy", age: "27", gender: "male", job: "doctor", username: "tim" } )
- ling = Employee.new( { name: "Ling", age: "25", gender: "female", job: "doctor", username: "ling" } )
- kevin = Employee.new( { name: "Kevin", age: "22", gender: "male", job: "receptionist", username: "kevin" } )
- tony = Employee.new( { name: "Tony", age: "25", gender: "male", job: "janitor", username: "tony" } )
- mikhail = Patient.new( { name: "Mikhail", age: "28", gender: "male", blood_type: "O", username: "mikhail" } )
- marko = Patient.new( { name: "Marko", age: "29", gender: "male", blood_type: "AB", username: "marko" } )
- erin = Patient.new( { name: "Erin", age: "27", gender: "female", blood_type: "B", username: "erin" } )
- maimonides = Hospital.new( {name: "Maimonides Medical Center", address: "4802 10th Ave, Brooklyn, NY 11219", employees: [admin, tim, ling, kevin, tony], patients: [mikhail, marko, erin] } )
- software = HostpitalRecordManagement.new(maimonides)
- software.authenticate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement