Sha256: 9dea2a10d94797b29bf512e1b98654804fa7220638957b4201dfd491f587c841

Contents?: true

Size: 1.71 KB

Versions: 23

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hd/base_controller"

module Renalware
  module HD
    class CurrentProfileController < BaseController
      before_action :load_patient
      before_action :load_profile

      def show
        render :show, locals: locals
      end

      def edit
        render :edit, locals: locals
      end

      def update
        if update_profile
          redirect_to patient_hd_dashboard_path(patient),
            notice: t(".success", model_name: "HD profile")
        else
          flash.now[:error] = t(".failed", model_name: "HD profile")
          render :edit, locals: locals
        end
      end

      private

      attr_reader :profile

      def locals
        { profile: profile_presenter, patient: patient }
      end

      def update_profile
        if profile.persisted?
          ReviseHDProfile.new(profile).call(profile_params)
        else
          profile.update(profile_params.merge(active: true))
        end
      end

      def preference_set
        PreferenceSet.for_patient(patient).first_or_initialize
      end

      def profile_presenter
        ProfilePresenter.new(profile, preference_set: preference_set)
      end

      def load_profile
        @profile = Profile.for_patient(patient).first_or_initialize
      end

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

      def attributes
        [
          :schedule_definition_id, :other_schedule, :hospital_unit_id, :dialysate_id,
          :prescribed_time, :prescribed_on, :prescriber_id,
          :named_nurse_id, :transport_decider_id,
          document: {}
        ]
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

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