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.1.1 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.1.0 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.167 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.166 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.165 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.164 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.163 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.162 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.161 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.160 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.159 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.158 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.157 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.156 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.155 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.153 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.152 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.151 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.149 app/controllers/renalware/patients/practices_controller.rb
renalware-core-2.0.148 app/controllers/renalware/patients/practices_controller.rb