Sha256: 379c0ff402d710ed75489867db89e6d5afb0194aea72cf5e91a236d3911d6863

Contents?: true

Size: 907 Bytes

Versions: 24

Compression:

Stored size: 907 Bytes

Contents

# Works in concert with Patients::SearchQuery and Patients::SearchForm.
# Example usage in a controller:
#
#   my_relation = Thing.all.joins(:patient)
#   filter = Patients::SearchFilter.new(search_term, request)
#   my_relation = patient_filter.call(my_relation)
#   render locals: { search_form: filter.search_form }
require_dependency "renalware/patients"

module Renalware
  module Patients
    class SearchFilter
      attr_reader :search_form

      def initialize(search_term, request)
        @search_form = build_search_form(search_term, request)
      end

      def call(relation)
        matching_patients = Patients::SearchQuery.new(term: search_form.term).call
        relation.merge(matching_patients)
      end

      def build_search_form(search_term, request)
        Patients::SearchForm.new(
          term: search_term,
          url: request.path
        )
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.7 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.5 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.4 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.3 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.2 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.1 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/patients/search_filter.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/patients/search_filter.rb