class Object

Public Instance Methods

add_data(patient_name, score) click to toggle source
# File lib/ausdrisk.rb, line 15
def add_data(patient_name, score)
  CSV.open('patient_data.csv', 'a') do |csv|
    csv << [patient_name, score]
  end
end
age_group(user) click to toggle source
# File lib/age_group.rb, line 5
def age_group(user)
  age_points = 0
  age = read_integer('How old are you?')

  if age < 34
    age_points += 0
  elsif age > 35 && age <= 44
    age_points += 2
  elsif age > 45 && age <= 54
    age_points += 4
  elsif age > 55 && age <= 64
    age_points += 6
  elsif age > 65
    age_points += 8
  else
    puts 'Wrong user input'
    age = read_integer('How old are you?')
    end
  user[:points_total] += age_points
  user
end
ausdrisk_test() click to toggle source
# File lib/ausdrisk.rb, line 21
def ausdrisk_test
  system 'clear'
  puts 'What is your name?'
  name = gets.chomp

  user = {
    name: name,
    gender: nil,
    ethnicity: nil,
    points_total: 0

  }

  user = age_group(user)
  user = get_gender(user)
  user = get_ethnicity(user)
  user = get_destination(user)
  user = get_family(user)
  user = get_glucose(user)
  user = Lifestyle.diet(user)
  user = Lifestyle.exercise(user)
  user = Lifestyle.blood_pressure(user)
  user = Lifestyle.smoking(user)
  result = waist_measurement(user)

  if user[:points_total] < 5
    puts 'Low risk - You scored 6-11 points in the AUSDRISK. You may be at increased risk of type 2 diabetes. Improving your lifestyle may reduce your risk of type 2 diabetes'.colorize(:green)
  elsif user[:points_total] > 6 && user[:points_total] <= 11
    puts 'intermediate risk'.colorize(:blue)
  else user[:points_total] > 12
       puts "You scored 12 points or more in the AUSDRISK. You may have
undiagnosed type 2 diabetes or be at high risk of developing the
disease. Speak to your healthcare professional as soon as possible.". colorize(:red)
  end
  add_data(user[:name], user[:points_total])
end
birth_place_menu() click to toggle source
# File lib/birth_place.rb, line 3
def birth_place_menu
  system 'clear'
  puts '1. Australia'
  puts '2. Asia (including the Indian sub-continent), Middle East, North Africa, Southern Europe'
  puts '3. Other'
  puts 'Where were you born?'
  print '>'
  user_input = gets.chomp.to_i
  user_input
end
delete_patient(patients_array) click to toggle source
# File lib/patient_history.rb, line 61
def delete_patient(patients_array)
  puts 'which patient would you like to delete?'
  patient_search = gets.chomp
  print = '>'
  found_patient = nil

  patients_array.each do |patient|
    if patient_search == patient['name']
      found_patient = patient
      patients_array.delete(found_patient)
    end
  end
  update_data(patients_array)
end
get_destination(user) click to toggle source
# File lib/birth_place.rb, line 14
def get_destination(user)
  points_birth_place = 0
  case birth_place_menu
  when 1
    points_birth_place += 0
  when 2
    points_birth_place += 2
  when 3
    points_birth_place += 0
  else
    puts 'Please choose an option from 1-3 only'
    return birth_place_menu
  end
  user[:points_total] = (points_birth_place + user[:points_total])
  user
end
get_ethnicity(user) click to toggle source
# File lib/ethnicity.rb, line 5
def get_ethnicity(user)
  system 'clear'
  user_input = read_string('Are you of Aboriginal, Torres Straight Islander or Maori descent? yes or no')
  print '>'
  valid_input = false
  points_ethnicity = 0

  until valid_input
    if user_input == 'yes'
      valid_input = true
      points_ethnicity += 2
    elsif user_input == 'no'
      valid_input = true
      points_ethnicity = 0
    else
      puts 'Please answer yes or no'
      puts "you entered #{user_input}"
      user_input = read_string('Are you of Aboriginal, Torres Straight Islander or Maori descent? yes or not')
      end
    end
  user[:ethnicity] = user_input
  user[:points_total] += points_ethnicity
  user
end
get_family(user) click to toggle source
# File lib/family.rb, line 3
def get_family(user)
  system 'clear'
  family_points = 0
  repeat = true
  while repeat
    puts 'Have either of your parents, or any of your brothers or sisters been diagnosed with diabetes (type 1 or type 2)? '
    puts 'yes or No'
    print '>'
    user_input = gets.chomp.to_s.downcase

    if user_input == 'yes'
      family_points = 3
      repeat = false
    elsif user_input == 'no'
      family_points = 0
      repeat = false
    else
      puts 'Wrong user input'
    end
  end
  return user
  user[:points_total] += family_points
end
get_gender(user) click to toggle source
# File lib/Gender.rb, line 5
def get_gender(user)
  system 'clear'
  sex = read_string('Are you male or female?')
  valid_input = false
  points_total = 0

  until valid_input
    if sex == 'female'
      valid_input = true
      points_total = 0
    elsif sex == 'male'
      valid_input = true
      points_total += 3
    else
      puts 'Please choose male or female'
      puts "you entered #{sex}"
      sex = read_string('Are you male or female?')
    end
  end
  user[:gender] = sex
  user[:points_total] += points_total
  user
end
get_glucose(user) click to toggle source
# File lib/glucose.rb, line 3
def get_glucose(user)
  system 'clear'
  glucose_points = 0
  repeat = true
  while repeat
    puts "Have you ever been found to have high blood glucose
    (sugar) (for example, in a health examination,
    during an illness, during pregnancy)? yes or no"
    print '>'
    user_input = gets.chomp.to_s.downcase
    if user_input == 'yes'
      glucose_points = 6
      repeat = false
    elsif user_input == 'no'
      glucose_points = 0
      repeat = false
    else
      puts 'Wrong user input'
    end
    # user[:points_total] = (glucose_points + user[:points_total])
  end
  user[:points_total] += glucose_points
  user
end
get_waist_measurement() click to toggle source
# File lib/waist_measurement.rb, line 3
def get_waist_measurement
  system 'clear'
  puts 'Please measure your waist measurement taken  below the ribs usually at the level of the navel, and while standing'
  puts 'Waist measurement (in cm)'
  print '>'
  user_input = gets.chomp.to_i
end
menu() click to toggle source
menu_patient() click to toggle source
patient_look_up(patients_array) click to toggle source
# File lib/patient_history.rb, line 17
def patient_look_up(patients_array)
  system 'clear'
  loop do
    puts 'which patient would you like to look up?'
    print = '>'
    patient_search = gets.chomp.downcase
    found_patient = nil
    patients_array.each do |patient|
      return patient if patient_search == patient['name']
    end
    puts 'patient does not exist'
  end
end
read_csv(csv) click to toggle source
# File lib/patient_history.rb, line 31
def read_csv(csv)
  arr = []
  csv.each do |row|
    patient = row.to_hash
    arr << patient
  end
  arr
end
read_integer(question) click to toggle source
# File lib/input.rb, line 9
def read_integer(question)
  read_string(question).to_i
end
read_string(question) click to toggle source
# File lib/input.rb, line 3
def read_string(question)
  puts question
  print '>'
  user_input = gets.chomp
end
update_data(patients) click to toggle source
# File lib/patient_history.rb, line 6
def update_data(patients)
  CSV.open('patient_data.csv', 'w') do |csv|
    csv << %w[name score]
    patients.each do |patient|
      print 'PATIENT: '
      p patient
      csv << patient.values
    end
  end
end
update_patient(patients_array) click to toggle source
# File lib/patient_history.rb, line 40
def update_patient(patients_array)
  system 'clear'
  puts 'which patient would you like to look up?'
  patient_search = gets.chomp.downcase
  print = '>'
  found_patient = nil
  patients_array.each do |patient|
    found_patient = patient if patient_search == patient['name']
  end
  puts "what was the patient's new score? "
  new_score = gets.chomp
  print '>'
  patients_array.each do |patient|
    next unless patient_search == patient['name']

    found_patient = patient
    patient['score'] = new_score
  end
  update_data(patients_array)
end
view_targets() click to toggle source
# File lib/glucose_targets.rb, line 5
def view_targets
  puts 'Normal Range'
  rows = []
  rows << ['HBA1C', '<7%']
  rows << ['random glucose test', '4-7.8 mmol/L']
  table = Terminal::Table.new rows: rows
  table = Terminal::Table.new headings: %w[Name Target], rows: rows
  puts table
end
waist_measurement(user) click to toggle source
# File lib/waist_measurement.rb, line 11
def waist_measurement(user)
  waist_points = 0
  waist_measurement = get_waist_measurement
  if user[:gender] == 'female' && user[:ethnicity] == 'yes'
    if waist_measurement < 80
      waist_points += 0
    elsif waist_measurement > 80 && waist_measurement <= 90
      waist_points += 4
    else waist_measurement > 90
         waist_points += 7
    end
  elsif
  if user[:gender] == 'female' && user[:ethnicity] == 'no'
    if waist_measurement < 88
      waist_points += 0
    elsif waist_measurement > 88 && waist_measurement <= 100
      waist_points += 4
    else waist_measurement > 100
         waist_points += 7
    end
  elsif
  if user[:gender] == 'male' && user[:ethnicity] == 'no'
    if waist_measurement < 102
      waist_points += 0
    elsif waist_measurement > 102 && waist_measurement <= 110
      waist_points += 4
    else waist_measurement > 110
         waist_points += 7
    end
    if user[:gender] == 'male' && user[:ethnicity] == 'yes'
      if waist_measurement < 90
        waist_points += 0
      elsif waist_measurement > 90 && waist_measurement <= 100
        waist_points += 4
      else waist_measurement > 100
           waist_points += 7
      end
      user[:points_total] = (waist_points + user[:points_total])
    end
  end
  end
  end
  user
end