Sha256: 7fafc7ae5b187e8729b2641696c12067b401adda8165f2f4980c76c2dad5ae56

Contents?: true

Size: 1.19 KB

Versions: 140

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/transplants"
require_dependency "renalware/transplants/base_controller"

module Renalware
  module Transplants
    class DonorStagesController < BaseController
      def new
        stage = DonorStage.new(patient: patient)
        authorize stage
        render locals: {
          patient: patient,
          stage: stage
        }
      end

      def create
        authorize donor_stage
        result = CreateDonorStage.new(patient: patient, options: donor_stage_params).call
        if result.success?
          redirect_to patient_transplants_donor_dashboard_path(patient),
                      notice: t(".success", model_name: "donor stage")
        else
          render :new, locals: {
            patient: patient,
            stage: result.object
          }
        end
      end

      private

      def donor_stage
        @donor_stage ||= DonorStage.for_patient(patient).first_or_initialize
      end

      def donor_stage_params
        params
          .require(:donor_stage)
          .permit(:started_on, :stage_position_id, :stage_status_id, :notes)
          .to_h
          .merge(by: current_user)
      end
    end
  end
end

Version data entries

140 entries across 140 versions & 1 rubygems

Version Path
renalware-core-2.0.125 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.124 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.123 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.121 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.120 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.119 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.118 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.117 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.116 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.115 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.113 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.112 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.111 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.110 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.109 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.108 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.106 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.105 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.104 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.103 app/controllers/renalware/transplants/donor_stages_controller.rb