Sha256: d60e720d38a9dc4042e8786fbcfafdae1bd4d112bd2033562a020f435095f0e1

Contents?: true

Size: 1.85 KB

Versions: 20

Compression:

Stored size: 1.85 KB

Contents

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_attributes(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)
          .merge(document: document_attributes, 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

      def document_attributes
        params
          .require(:hd_profile)
          .fetch(:document, nil).try(:permit!)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
renalware-core-2.0.5 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.4 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.3 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.2 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.1 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc7 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc6 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc5 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc4 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc3 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.rc1 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.beta12 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.beta11 app/controllers/renalware/hd/current_profile_controller.rb
renalware-core-2.0.0.pre.beta10 app/controllers/renalware/hd/current_profile_controller.rb