Sha256: 5bad31ad6616b3e6ad4901dbfd900df370a46f8ed1f2843bd92fcb70365cc459

Contents?: true

Size: 1.7 KB

Versions: 34

Compression:

Stored size: 1.7 KB

Contents

module Renalware
  module Accesses
    class ProfilesController < Accesses::BaseController
      before_action :load_patient

      def show
        profile = patient.profiles.find(params[:id])
        presenter = ProfilePresenter.new(profile)
        render locals: { patient: patient, profile: presenter }
      end

      def new
        profile = patient.profiles.new(by: current_user)
        render locals: { patient: patient, profile: profile }
      end

      def create
        profile = patient.profiles.new(profile_params)

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

      def edit
        profile = patient.profiles.find(params[:id])
        render locals: { patient: patient, profile: profile }
      end

      def update
        profile = patient.profiles.find(params[:id])

        if profile.update(profile_params)
          redirect_to patient_accesses_dashboard_path(patient),
            notice: t(".success", model_name: "Access profile")
        else
          flash.now[:error] = t(".failed", model_name: "Access profile")
          render :edit, locals: { patient: patient, profile: profile }
        end
      end

      protected

      def profile_params
        params
          .require(:accesses_profile)
          .permit(attributes)
          .merge(by: current_user)
      end

      def attributes
        [
          :formed_on, :started_on, :terminated_on, :side, :type_id, :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/accesses/profiles_controller.rb
renalware-core-2.0.15 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.14 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.13 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.12 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.11 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.9 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.8 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.7 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.5 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.4 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.3 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.2 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.1 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.0 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/accesses/profiles_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/accesses/profiles_controller.rb