Class: Renalware::Pathology::Requests::PatientRule

Inherits:
ApplicationRecord
  • Object
show all
Includes:
FrequencyMethods
Defined in:
app/models/renalware/pathology/requests/patient_rule.rb

Constant Summary collapse

OBSERVATION_REQUIRED =
true
OBSERVATION_NOT_REQUIRED =
false

Instance Method Summary collapse

Methods included from FrequencyMethods

#frequency

Instance Method Details

#last_observed_atObject



34
35
36
37
38
39
# File 'app/models/renalware/pathology/requests/patient_rule.rb', line 34

def last_observed_at
  last_request = patient.last_request_for_patient_rule(self)
  return if last_request.nil?

  last_request.created_at
end

#required?(date) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
# File 'app/models/renalware/pathology/requests/patient_rule.rb', line 25

def required?(date)
  return OBSERVATION_NOT_REQUIRED unless today_within_range?(date)
  return OBSERVATION_REQUIRED if last_observed_at.nil?

  days_ago_observed = date - last_observed_at.to_date

  frequency.observation_required?(days_ago_observed)
end