Sha256: 325c1bf59b7eaf2b7e59ff08bd37e72569fe0dc54db93757ef46f719866aa41c

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 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: success_msg_for("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

2 entries across 2 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/transplants/donor_stages_controller.rb
renalware-core-2.1.0 app/controllers/renalware/transplants/donor_stages_controller.rb