Sha256: e4bf9a7719d5ffcf6dde5880d7d5709f5976ab36124de950bc139c1b360542fa

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 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[: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[: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

1 entries across 1 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta4 app/controllers/renalware/transplants/donations_controller.rb