Sha256: 2f7582eb7fe56b2efc39708c47d533ab33f5390c0bfee780c6e6ff7be1f45538

Contents?: true

Size: 1.73 KB

Versions: 55

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

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

55 entries across 55 versions & 1 rubygems

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