Sha256: 29b48135c0ac8957ae28829ddbde815fc48e5af96778399d60df569beffd4716

Contents?: true

Size: 756 Bytes

Versions: 4

Compression:

Stored size: 756 Bytes

Contents

module Renalware
  module Patients
    class SearchQuery
      attr_reader :term, :page, :per_page

      def initialize(term:, page: 1, per_page: 20)
        @term = term
        @page = page
        @per_page = per_page
      end

      def call
        search
          .result.page(page).per(per_page)
          .select(fields)
          .map do |patient|
            {
              id: patient.id,
              label: patient.to_s(:long)
            }
          end
      end

      private

      def search
        @search ||= Patient.search(family_name_cont: term).tap do |srch|
          srch.sorts = %w(family_name given_name)
        end
      end

      def fields
        %i(id family_name given_name nhs_number)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta7 app/models/renalware/patients/search_query.rb
renalware-core-2.0.0.pre.beta6 app/models/renalware/patients/search_query.rb
renalware-core-2.0.0.pre.beta5 app/models/renalware/patients/search_query.rb
renalware-core-2.0.0.pre.beta4 app/models/renalware/patients/search_query.rb