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