Sha256: fcc6d662b323ba55eaae31989655babc2d8e613ef98638958c8718d3cf9e8e8f

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

module Renalware
  module Patients
    class WorryController < BaseController
      before_action :load_patient, only: :create

      # idempotent
      def create
        worry = Worry.find_or_create_by!(patient: patient) do |wor|
          wor.by = user
        end
        update_worry_notes_if_supplied(worry)
        redirect_back(fallback_location: patient_path(patient),
                      notice: t(".success", patient: patient))
      end

      # idempotent
      def destroy
        if (worry = patient.worry)
          authorize worry
          worry.destroy!
        else
          skip_authorization
        end
        redirect_back(fallback_location: patient_path(patient),
                      notice: t(".success", patient: patient))
      end

      private

      def update_worry_notes_if_supplied(worry)
        if worry_params[:notes].present?
          worry.update(worry_params.merge!(by: current_user))
        end
      end

      def user
        @user ||= Renalware::Patients.cast_user(current_user)
      end

      def worry_params
        params.require(:patients_worry).permit(:notes)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.15 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.14 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.13 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.12 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.11 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.9 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.8 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.7 app/controllers/renalware/patients/worry_controller.rb