Sha256: 0d03f2a30a054a033290b71bb7a5f91d6dd7fc84742e810b1af5d06d2b94f8a9

Contents?: true

Size: 1.06 KB

Versions: 15

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(term:, scope: Patient.all)
        @term = term
        @scope = scope
      end

      def call
        search.result
      end

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/patients/search_query.rb
renalware-core-2.1.0 app/models/renalware/patients/search_query.rb
renalware-core-2.0.167 app/models/renalware/patients/search_query.rb
renalware-core-2.0.166 app/models/renalware/patients/search_query.rb
renalware-core-2.0.165 app/models/renalware/patients/search_query.rb
renalware-core-2.0.164 app/models/renalware/patients/search_query.rb
renalware-core-2.0.163 app/models/renalware/patients/search_query.rb
renalware-core-2.0.162 app/models/renalware/patients/search_query.rb
renalware-core-2.0.161 app/models/renalware/patients/search_query.rb
renalware-core-2.0.160 app/models/renalware/patients/search_query.rb
renalware-core-2.0.159 app/models/renalware/patients/search_query.rb
renalware-core-2.0.158 app/models/renalware/patients/search_query.rb
renalware-core-2.0.157 app/models/renalware/patients/search_query.rb
renalware-core-2.0.156 app/models/renalware/patients/search_query.rb
renalware-core-2.0.155 app/models/renalware/patients/search_query.rb