Class: Renalware::HD::SessionsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- BaseController
- Renalware::HD::SessionsController
- Includes:
- PresenterHelper, Concerns::Pageable
- Defined in:
- app/controllers/renalware/hd/sessions_controller.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #save_failure(session) ⇒ Object
- #save_session ⇒ Object
- #save_success(_session) ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from PresenterHelper
Methods inherited from BaseController
Instance Method Details
#create ⇒ Object
54 55 56 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 54 def create save_session end |
#destroy ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 79 def destroy session = Session.for_patient(patient).find(params[:id]) session session.destroy! regenerate_rolling_hd_statistics = t(".success", model_name: "HD session") redirect_to patient_hd_dashboard_path(patient), notice: end |
#edit ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 58 def edit session = Session.for_patient(patient).find(params[:id]) session.prescription_administrations.each do |a| if a. a. = a.administered_by&.auth_token end if a. a. = a.witnessed_by&.auth_token end end session render :edit, locals: locals(session) rescue Pundit::NotAuthorizedError flash[:warning] = t(".session_is_immutable") redirect_to patient_hd_session_path(session, patient_id: patient) end |
#index ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 15 def index query = sessions_query sessions = query .call .eager_load( :hospital_unit, :patient, :signed_on_by, :signed_off_by, prescription_administrations: [ { prescription: [:medication_route, :drug] }, :administered_by, :reason ]) .page(page) .per(per_page || 15) sessions presenter = CollectionPresenter.new(sessions, SessionPresenter, view_context) @q = query.search render :index, locals: { sessions: presenter } end |
#new ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 46 def new session = SessionFactory.new(patient: patient, user: current_user, type: params[:type]).build session render :new, locals: locals(session) end |
#save_failure(session) ⇒ Object
102 103 104 105 106 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 102 def save_failure(session) flash.now[:error] = t(".failed", model_name: "HD session") action = action_name.to_sym == :create ? :new : :edit render action, locals: locals(session) end |
#save_session ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 88 def save_session command = Sessions::SaveSession.new(patient: patient, current_user: current_user) command.subscribe(self) command.call(params: session_params, id: params[:id], signing_off: params[:signoff].present?) end |
#save_success(_session) ⇒ Object
96 97 98 99 100 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 96 def save_success(_session) url = patient_hd_dashboard_path(patient) = t(".success", model_name: "HD session") redirect_to url, notice: end |
#show ⇒ Object
39 40 41 42 43 44 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 39 def show session = Session.for_patient(patient).find(params[:id]) session presenter = SessionPresenter.new(session, view_context) render :show, locals: { session: presenter, patient: patient } end |
#update ⇒ Object
75 76 77 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 75 def update save_session end |