Module: Renalware::Transplants::Registrations::WaitListQuery::Scopes

Defined in:
app/models/renalware/transplants/registrations/wait_list_query.rb

Overview

The status_mismatch filter finds patients with a UKT status that does not match their tx wait list status. We filter out UKT statuses of null or ”. At some point we will have turn this into a mapping object or hash because there will probably not be a 1 to 1 mapping from wait list to UKT status.

Instance Method Summary collapse

Instance Method Details

#apply_filter(filter) ⇒ Object

rubocop:disable Metrics/MethodLength



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/renalware/transplants/registrations/wait_list_query.rb', line 51

def apply_filter(filter)
  case filter
  when :status_mismatch
    joins(statuses: :description)
    .where(transplant_registration_statuses: { terminated_on: nil })
    .where(
      "      (\n        transplant_registration_status_descriptions.code in ('active')\n        and\n        (\n          transplant_registrations.document -> 'uk_transplant_centre' ->> 'status' not ilike 'A'\n        )\n      )\n      or\n      (\n        transplant_registration_status_descriptions.code not in ('active')\n        and\n        (\n          transplant_registrations.document -> 'uk_transplant_centre' ->> 'status' ilike 'A'\n        )\n      )\n      SQL\n    )\n  else\n    all\n  end\nend\n".squish

#having_ukt_recipient_number(number) ⇒ Object



42
43
44
45
46
47
48
# File 'app/models/renalware/transplants/registrations/wait_list_query.rb', line 42

def having_ukt_recipient_number(number)
  return all if number.blank?

  where("    transplant_registrations.document -> 'codes' ->> 'uk_transplant_patient_recipient_number' = ?\n  SQL\nend\n".squish, number)