Sha256: 5d6deb585ea3e294bde4178dcd21e0a8e66bb285d78bfde95633a403ccabe83b

Contents?: true

Size: 1.3 KB

Versions: 27

Compression:

Stored size: 1.3 KB

Contents

require_dependency "renalware/hd/base_controller"

module Renalware
  module HD
    class PatientsController < BaseController
      def dialysing_at_unit
        skip_authorization
        unit_id = params.fetch(:unit_id)
        patients = all_hd_patients_matching_search_term
                    .eager_load(:hd_profile)
                    .merge(HD::Profile.dialysing_at_unit(unit_id))
        render json: simplify(patients).to_json
      end

      def dialysing_at_hospital
        skip_authorization
        patients = all_hd_patients_matching_search_term
        render json: simplify(patients).to_json
      end

      private

      def all_hd_patients_matching_search_term
        Patients::SearchQuery.new(scope: HD::Patient.all, term: params[:term])
          .call
          .eager_load(hd_profile: [:hospital_unit, :schedule_definition])
          .extending(ModalityScopes)
          .with_current_modality_of_class(HD::ModalityDescription)
      end

      def simplify(patients)
        patients.map do |patient|
          hd_profile = patient.hd_profile
          text = "#{patient.to_s(:long)} - "\
                 "#{hd_profile&.schedule_definition} "\
                 "#{hd_profile&.hospital_unit&.unit_code}".strip.truncate(65)
          { id: patient.id, text: text }
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.15 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.14 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.13 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.12 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.11 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.9 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.8 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.7 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.5 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.4 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.3 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.2 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.1 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.0 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/hd/patients_controller.rb