Sha256: 62009ce38f854e198612ddb4bb3f01291a5fa6768b473f49aca4316ee298a939

Contents?: true

Size: 1.74 KB

Versions: 34

Compression:

Stored size: 1.74 KB

Contents

require_dependency "renalware/transplants/base_controller"

module Renalware
  module Transplants
    class RegistrationsController < BaseController
      before_action :load_patient

      def show
        if registration.new_record?
          redirect_to edit_patient_transplants_registration_path(patient)
        else
          render locals: { patient: patient, registration: registration }
        end
      end

      def edit
        render locals: { patient: patient, registration: registration }
      end

      def update
        if update_registration
          redirect_to patient_transplants_recipient_dashboard_path(patient),
            notice: t(".success", model_name: "registration")
        else
          flash.now[:error] = t(".failed", model_name: "registration")
          render :edit, locals: { patient: patient, registration: registration }
        end
      end

      protected

      def update_registration
        registration.attributes = registration_params
        registration.statuses.first.by = current_user if registration.new_record?
        registration.save
      end

      def registration
        @registration ||= Registration.for_patient(@patient).first_or_initialize
      end

      def registration_params
        params
          .require(:transplants_registration)
          .permit(attributes)
          .merge(document: document_attributes)
      end

      def attributes
        [
          :referred_on, :assessed_on, :entered_on, :contact, :notes,
          statuses_attributes: [:started_on, :description_id],
          document: []
        ]
      end

      def document_attributes
        params
          .require(:transplants_registration)
          .fetch(:document, nil).try(:permit!)
      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/registrations_controller.rb
renalware-core-2.0.15 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.14 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.13 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.12 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.11 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.9 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.8 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.7 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.5 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.4 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.3 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.2 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.1 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.0 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/transplants/registrations_controller.rb