Class: Renalware::Patients::PracticeSearchQuery
- Inherits:
-
Object
- Object
- Renalware::Patients::PracticeSearchQuery
- Defined in:
- app/models/renalware/patients/practice_search_query.rb
Instance Attribute Summary collapse
-
#search_term ⇒ Object
readonly
Returns the value of attribute search_term.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(search_term:) ⇒ PracticeSearchQuery
constructor
A new instance of PracticeSearchQuery.
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_term ⇒ Object (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
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# 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) .left_outer_joins(:address) .includes(:address) .where("patient_practices.name ILIKE ? "\ "OR addresses.street_1 ILIKE ? " \ "OR addresses.postcode ILIKE ?", term, term, term) .limit(50) end |