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