Sha256: 252324562bd39c414eeaae1335cbeb1971ee9856f9a52ab34d186744f2b0ac8e

Contents?: true

Size: 1.99 KB

Versions: 34

Compression:

Stored size: 1.99 KB

Contents

require_dependency "renalware/transplants/base_controller"

module Renalware
  module Transplants
    class DonationsController < BaseController
      before_action :load_patient

      def show
        donation = Donation.for_patient(patient).find(params[:id])
        render locals: { patient: patient, donation: donation }
      end

      def new
        render locals: { patient: patient, donation: Donation.new }
      end

      def create
        donation = Donation.new(patient: patient)
        donation.attributes = donation_params

        if donation.save
          redirect_to patient_transplants_donor_dashboard_path(patient),
            notice: t(".success", model_name: "donation")
        else
          flash.now[:error] = t(".failed", model_name: "donation")
          render :new, locals: { patient: patient, donation: donation }
        end
      end

      def edit
        donation = Donation.for_patient(patient).find(params[:id])
        render locals: { patient: patient, donation: donation }
      end

      def update
        donation = Donation.for_patient(patient).find(params[:id])
        donation.attributes = donation_params

        if donation.save
          redirect_to patient_transplants_donor_dashboard_path(patient),
            notice: t(".success", model_name: "donation")
        else
          flash.now[:error] = t(".failed", model_name: "donation")
          render :edit, locals: { patient: patient, donation: donation }
        end
      end

      private

      def donation_params
        params.require(:transplants_donation).permit(attributes)
      end

      def attributes
        [
          :state,
          :recipient_id,
          :relationship_with_recipient,
          :relationship_with_recipient_other,
          :blood_group_compatibility,
          :mismatch_grade,
          :paired_pooled_donation,
          :volunteered_on,
          :first_seen_on,
          :workup_completed_on,
          :donated_on,
          :notes
        ]
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.15 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.14 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.13 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.12 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.11 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.9 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.8 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.7 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.5 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.4 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.3 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.2 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.1 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.0 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/transplants/donations_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/transplants/donations_controller.rb