Sha256: 0840bb4e1a38e961cc437201e0ff0159528ba8a1914a2e2e539476236362f1b7

Contents?: true

Size: 1.03 KB

Versions: 20

Compression:

Stored size: 1.03 KB

Contents

# A generic patient search that returns an AR relation that can used directly or merged into other
# queries if required in order to use the extensive patient search criteria added by the
# `identity_match` ransacker. See also a corresponding Patients::SearchForm form object and its
# partial.
#
# Example usage to find letters relating to any patient with rabbit in their surname:
#   Letter
#     .joins(:patients)
#     .merge(
#       Patients::SearchQuery.new(term: "rabbit").call
#     )
#
module Renalware
  module Patients
    class SearchQuery
      # FIELDS = %i(id family_name given_name nhs_number).freeze
      attr_reader :term, :scope

      def initialize(scope: Patient.all, term:)
        @term = term
        @scope = scope
      end

      def call
        search.result
      end

      # .select(FIELDS)
      def search
        @search ||= begin
          scope
            .search(identity_match: term).tap do |search|
              search.sorts = %w(family_name given_name)
            end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

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