Sha256: 8897a51cca7448a6afc98056c31d68fa6b1b2af5f3896da21cc3fb0232f2c597

Contents?: true

Size: 1.59 KB

Versions: 18

Compression:

Stored size: 1.59 KB

Contents

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_attributes 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

18 entries across 18 versions & 1 rubygems

Version Path
renalware-core-2.0.5 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.4 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.3 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.2 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.1 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc7 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc6 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc5 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc4 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc3 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.rc1 app/controllers/renalware/transplants/recipient_workups_controller.rb
renalware-core-2.0.0.pre.beta12 app/controllers/renalware/transplants/recipient_workups_controller.rb