Sha256: 009e4ea86ba857494f2203046e490ccf46bb92541a14b4dd0e7e74df955eeeb6

Contents?: true

Size: 775 Bytes

Versions: 86

Compression:

Stored size: 775 Bytes

Contents

# frozen_string_literal: true

module Renalware
  module Patients
    class PracticeSearchQuery
      attr_reader :search_term

      def initialize(search_term:)
        @search_term = search_term
      end

      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
    end
  end
end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
renalware-core-2.0.84 app/models/renalware/patients/practice_search_query.rb
renalware-core-2.0.83 app/models/renalware/patients/practice_search_query.rb
renalware-core-2.0.82 app/models/renalware/patients/practice_search_query.rb
renalware-core-2.0.81 app/models/renalware/patients/practice_search_query.rb
renalware-core-2.0.80 app/models/renalware/patients/practice_search_query.rb
renalware-core-2.0.79 app/models/renalware/patients/practice_search_query.rb