Sha256: ded7302a4e53893fded1cace1df86c6608022c219e5507a46c0b466ff60ea89c

Contents?: true

Size: 1.04 KB

Versions: 56

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/patients"

module Renalware
  module Patients
    class PracticesController < BaseController
      # Search for GP Practices matching part of a name
      def search
        authorize Practice, :search?
        respond_to do |format|
          format.json do
            render json: practices_matching_search_term
          end
        end
      end

      private

      def practices_matching_search_term
        PracticeSearchQuery.new(search_term: params[:q])
          .call
          .map { |practice| format_practice_into_hash_for_json(practice) }
      end

      def null_address
        Address.new
      end

      def format_practice_into_hash_for_json(practice)
        address = practice.address || null_address
        {
          id: practice.id,
          name: practice.name,
          address: [
            address.street_1,
            address.town,
            address.county,
            address.postcode
          ].reject(&:blank?).join(", ")
        }
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
renalware-core-2.0.78 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.77 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.76 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.75 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.74 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.73 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.72 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.71 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.70 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.69 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.68 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.67 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.64 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.63 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.62 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.61 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.60 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.58 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.57 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.56 app/controllers/renalware/patients/practices_controller.rb