Sha256: e4811716a8c175b63c56991d2ce9dc67a48fab8de9a6821a4d1a888feb4d2155

Contents?: true

Size: 1.77 KB

Versions: 55

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

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

55 entries across 55 versions & 1 rubygems

Version Path
renalware-core-2.0.77 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.76 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.75 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.74 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.73 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.72 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.71 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.70 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.69 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.68 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.67 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.64 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.63 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.62 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.61 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.60 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.58 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.57 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.56 app/controllers/renalware/transplants/registrations_controller.rb
renalware-core-2.0.55 app/controllers/renalware/transplants/registrations_controller.rb