Sha256: 701a7cf89f72bcd67da5fd0ecca40e48136ee019cdea1a81ace982c53682a4f8

Contents?: true

Size: 1.06 KB

Versions: 52

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

# 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

52 entries across 52 versions & 1 rubygems

Version Path
renalware-core-2.0.67 app/models/renalware/patients/search_query.rb
renalware-core-2.0.64 app/models/renalware/patients/search_query.rb
renalware-core-2.0.63 app/models/renalware/patients/search_query.rb
renalware-core-2.0.62 app/models/renalware/patients/search_query.rb
renalware-core-2.0.61 app/models/renalware/patients/search_query.rb
renalware-core-2.0.60 app/models/renalware/patients/search_query.rb
renalware-core-2.0.58 app/models/renalware/patients/search_query.rb
renalware-core-2.0.57 app/models/renalware/patients/search_query.rb
renalware-core-2.0.56 app/models/renalware/patients/search_query.rb
renalware-core-2.0.55 app/models/renalware/patients/search_query.rb
renalware-core-2.0.54 app/models/renalware/patients/search_query.rb
renalware-core-2.0.53 app/models/renalware/patients/search_query.rb
renalware-core-2.0.52 app/models/renalware/patients/search_query.rb
renalware-core-2.0.51 app/models/renalware/patients/search_query.rb
renalware-core-2.0.50 app/models/renalware/patients/search_query.rb
renalware-core-2.0.48 app/models/renalware/patients/search_query.rb
renalware-core-2.0.47 app/models/renalware/patients/search_query.rb
renalware-core-2.0.46 app/models/renalware/patients/search_query.rb
renalware-core-2.0.45 app/models/renalware/patients/search_query.rb
renalware-core-2.0.44 app/models/renalware/patients/search_query.rb