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