Class: Renalware::Patients::PracticeSearchQuery

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/patients/practice_search_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_term:) ⇒ PracticeSearchQuery

Returns a new instance of PracticeSearchQuery.



8
9
10
# File 'app/models/renalware/patients/practice_search_query.rb', line 8

def initialize(search_term:)
  @search_term = search_term
end

Instance Attribute Details

#search_termObject (readonly)

Returns the value of attribute search_term.



6
7
8
# File 'app/models/renalware/patients/practice_search_query.rb', line 6

def search_term
  @search_term
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/renalware/patients/practice_search_query.rb', line 12

def call
  return [] if search_term.blank?

  term = "%#{search_term}%"
  Practice.select(:id, :name, :code)
          .left_outer_joins(:address)
          .includes(:address)
          .where("patient_practices.name ILIKE ? "\
                 "OR patient_practices.code = ? " \
                 "OR addresses.street_1 ILIKE ? " \
                 "OR addresses.postcode ILIKE ?", term, search_term, term, term)
          .where(active: true)
          .limit(50)
end