Sha256: a3a1c49cedf6e7ddd972980cc971c0b5e93ac39318d116b885dc5acb6ec873ef

Contents?: true

Size: 1.33 KB

Versions: 142

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

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

142 entries across 142 versions & 1 rubygems

Version Path
renalware-core-2.0.127 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.126 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.125 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.124 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.123 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.121 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.120 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.119 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.118 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.117 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.116 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.115 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.113 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.112 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.111 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.110 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.109 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.108 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.106 app/controllers/renalware/hd/patients_controller.rb
renalware-core-2.0.105 app/controllers/renalware/hd/patients_controller.rb