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.167 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.166 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.165 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.164 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.163 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.162 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.161 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.160 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.159 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.158 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.157 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.156 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.155 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.153 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.152 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.151 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.149 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.148 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.147 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.0.146 app/controllers/renalware/transplants/donor_stages_controller.rb