Sha256: bb7fa8756e5bfaac2c83a3ca961a4e8aefc2ece1615a4074b9dbdf222ec72419

Contents?: true

Size: 1.07 KB

Versions: 86

Compression:

Stored size: 1.07 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} (#{practice.code})",
          address: [
            address.street_1,
            address.town,
            address.county,
            address.postcode
          ].reject(&:blank?).join(", ")
        }
      end
    end
  end
end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
renalware-core-2.0.147 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.146 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.145 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.144 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.143 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.142 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.141 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.140 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.139 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.138 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.137 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.136 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.135 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.134 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.133 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.132 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.131 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.130 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.129 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.128 app/controllers/renalware/patients/practices_controller.rb