Sha256: 1e2288c40574b9822547b20cd0475dba7d5a7a6f35d0e329292edd3dca82f7e8

Contents?: true

Size: 1.4 KB

Versions: 32

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/transplants/base_controller"

module Renalware
  module Transplants
    class DonorWorkupsController < BaseController
      before_action :load_patient

      def show
        workup = DonorWorkup.for_patient(patient).first_or_initialize
        if workup.new_record?
          redirect_to edit_patient_transplants_donor_workup_path(patient)
        else
          render locals: { patient: patient, workup: workup }
        end
      end

      def edit
        workup = DonorWorkup.for_patient(patient).first_or_initialize
        render locals: { patient: patient, workup: workup }
      end

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

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

      private

      def workup_params
        params
          .require(:transplants_donor_workup)
          .permit
          .merge(document: document_attributes)
      end

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

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
renalware-core-2.0.51 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.50 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.48 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.47 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.46 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.45 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.44 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.43 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.42 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.41 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.40 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.39 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.38 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.37 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.36 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.35 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.34 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.33 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.32 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.31 app/controllers/renalware/transplants/donor_workups_controller.rb