Class: Renalware::Transplants::Registrations::WaitListQuery

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/transplants/registrations/wait_list_query.rb

Defined Under Namespace

Modules: Scopes Classes: QueryableRegistration

Instance Method Summary collapse

Constructor Details

#initialize(named_filter:, q: nil) ⇒ WaitListQuery

Returns a new instance of WaitListQuery.



9
10
11
12
# File 'app/models/renalware/transplants/registrations/wait_list_query.rb', line 9

def initialize(named_filter:, q: nil)
  @named_filter = named_filter&.to_sym || :active
  @q = (q || ActionController::Parameters.new).permit(:s, :q)
end

Instance Method Details

#callObject



14
15
16
17
18
19
# File 'app/models/renalware/transplants/registrations/wait_list_query.rb', line 14

def call
  search
    .result
    .extending(Scopes)
    .apply_filter(named_filter)
end

#searchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/renalware/transplants/registrations/wait_list_query.rb', line 21

def search
  @search ||= begin
    query = query_for_filter(named_filter).merge(q)
    QueryableRegistration
      .eager_load(patient: [current_modality: :description])
      .eager_load(current_status: :description)
      .merge(HD::Patient.with_profile)
      .merge(Renal::Patient.with_profile)
      .ransack(query).tap do |s|
      s.sorts = ["patient_family_name, patient_given_name"]
    end
  end
end