Sha256: 1b52352d140ce966b36ea5c44e50dfa99ea033ead54f88d916129443b5de008d

Contents?: true

Size: 1.62 KB

Versions: 85

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/transplants/base_controller"

module Renalware
  module Transplants
    class RecipientWorkupsController < BaseController
      before_action :load_patient

      def show
        workup = RecipientWorkup.for_patient(patient).first_or_initialize

        if workup.new_record?
          redirect_to edit_patient_transplants_recipient_workup_path(patient)
        else
          render locals: { patient: patient, workup: workup }
        end
      end

      def edit
        workup = RecipientWorkup.for_patient(patient).first_or_initialize
        workup = RecipientWorkupBuilder.new(
          workup: workup,
          default_consenter_name: current_user.to_s
        ).build
        render locals: { patient: patient, workup: workup }
      end

      def update
        workup = RecipientWorkup.for_patient(patient).first_or_initialize

        if workup.update workup_params
          redirect_to patient_transplants_recipient_workup_path(patient),
                      notice: t(".success", model_name: "recipient work up")
        else
          flash.now[:error] = t(".failed", model_name: "recipient work up")
          render :edit, locals: { patient: patient, workup: workup }
        end
      end

      private

      def workup_params
        params
          .require(:transplants_recipient_workup)
          .permit
          .merge(document: document_attributes, by: current_user)
      end

      def document_attributes
        params
          .require(:transplants_recipient_workup)
          .fetch(:document, nil)
          .try(:permit!)
      end
    end
  end
end

Version data entries

85 entries across 85 versions & 1 rubygems

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