Sha256: 3554863816f6d6bbbd3e9a9a9e5b04628c8669d808f4fdba70f00ab38fbd9d44

Contents?: true

Size: 1.1 KB

Versions: 19

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Renalware
  class DeathsController < BaseController
    include PresenterHelper
    include Pagy::Backend

    def index
      query = Patients::DeceasedPatientsQuery.new(params[:q])
      pagy, patients = pagy(query.call.includes(previous_modality: :description))
      authorize patients
      render locals: {
        patients: present(patients, PatientPresenter),
        q: query.search,
        pagy: pagy
      }
    end

    def edit
      authorize patient
      render_edit
    end

    def update
      authorize patient
      if patient.update(death_params)
        redirect_to patient_clinical_profile_path(patient),
                    notice: t(".success", model_name: "patient")
      else
        flash.now[:error] = t(".failed", model_name: "patient")
        render_edit
      end
    end

    private

    def render_edit
      render :edit, locals: { patient: patient }
    end

    def death_params
      params
        .require(:patient)
        .permit(:died_on, :first_cause_id, :second_cause_id, :death_notes)
        .merge(by: current_user)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
renalware-core-2.0.167 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.166 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.165 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.164 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.163 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.162 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.161 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.160 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.159 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.158 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.157 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.156 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.155 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.153 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.152 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.151 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.149 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.148 app/controllers/renalware/deaths_controller.rb
renalware-core-2.0.147 app/controllers/renalware/deaths_controller.rb