Sha256: fc63093bbd0583a156984c6338247e4bc80b3b804b7397bd067a55f30a9f4baa

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

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
        redirect_to edit_patient_transplants_donor_workup_path(patient) if workup.new_record?
        render locals: { patient: patient, workup: workup }
      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_attributes(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

10 entries across 10 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc3 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.rc1 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.beta12 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.beta11 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.beta10 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.beta9 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.beta8 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.beta7 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.beta6 app/controllers/renalware/transplants/donor_workups_controller.rb
renalware-core-2.0.0.pre.beta5 app/controllers/renalware/transplants/donor_workups_controller.rb