class GcigCa125::Calculator

Public Class Methods

new(rx_date, normal_range=(0..30)) click to toggle source
# File lib/gcig_ca125/calculator.rb, line 5
def initialize(rx_date, normal_range=(0..30))
  @normal_range = normal_range
  @rx_date = rx_date
  @tests = []
end

Public Instance Methods

add_ca125_test(date, value) click to toggle source
# File lib/gcig_ca125/calculator.rb, line 15
def add_ca125_test(date, value)
  @tests << [date, value]
  sort_tests
end
first_twice_uln?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 47
def first_twice_uln?
  @tests.first[1] > @normal_range.max * 2
end
is_evaluable?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 20
def is_evaluable?
  sample_before_rx? && sample_within_a_week_of_rx? && first_twice_uln?
end
is_normalised?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 32
def is_normalised?
  find_normalised().any?
end
is_response?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 24
def is_response?
  if is_evaluable?
    @tests.select { |test| (test[0] > day_28_after_fall ) && test[1] < half_of_first }.any?
  else
    false
  end
end
reduced_by_half?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 43
def reduced_by_half?
  (@tests.last[1].to_f / @tests.first[1].to_f ) <= 0.5
end
reduction_maintained?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 63
def reduction_maintained?
  test =  Proc.new do |item|
    item[0] > day_28_after_fall && item[1] > (value_at_fall+15)
  end
  @tests.select(&test).empty?
end
result() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 11
def result
  Result.new self
end
sample_before_rx?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 55
def sample_before_rx?
  @tests.first[0] <= @rx_date
end
sample_within_a_week_of_rx?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 59
def sample_within_a_week_of_rx?
  @tests.first[0] >= (@rx_date - 9)
end
samples_28days_after_fall?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 36
def samples_28days_after_fall?
  test = Proc.new do |item|
    item[0] > day_28_after_fall
  end
  @tests.select(&test).any?
end
sort_tests() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 70
def sort_tests
  @tests = @tests.sort { |a,b| a[0] <=> b[0] }
end
test_pre_rx?() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 51
def test_pre_rx?
  sample_before_rx? && sample_within_a_week_of_rx?
end

Private Instance Methods

date_of_fall() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 79
def date_of_fall
  if tests_after_fall.any?
    tests_after_fall.first[0]
  else
    Date.parse('2999-01-01')
  end
end
day_28_after_fall() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 75
def day_28_after_fall
  date_of_fall + 28
end
find_normalised() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 102
def find_normalised
  @tests.select { |test| @normal_range.include? test[1] }
end
half_of_first() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 98
def half_of_first
  @tests.first[1] / 2.0
end
tests_after_fall() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 91
def tests_after_fall
  valid_response = Proc.new do |test|
    (test[1] < half_of_first) && (test[0] > (@tests.first[0]))
  end
  @tests.select(&valid_response)
end
value_at_fall() click to toggle source
# File lib/gcig_ca125/calculator.rb, line 87
def value_at_fall
  tests_after_fall.first[1] if tests_after_fall.any?
end