Sha256: 82c23edd4fb7cd2fce8cd5f35b7375d6fc69850d3f3ec5a5f795ea9036a042ff

Contents?: true

Size: 1.61 KB

Versions: 32

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/renal"
require_dependency "renalware/renal/base_controller"

module Renalware
  module Renal
    class ProfilesController < BaseController
      before_action :load_patient

      def show
        render locals: {
          patient: patient,
          profile: find_profile
        }
      end

      def edit
        render locals: {
          patient: patient,
          profile: find_profile
        }
      end

      def update
        profile = find_profile

        if profile.update(profile_params)
          redirect_to patient_renal_profile_path(patient),
            notice: t(".success", model_name: "profile")
        else
          render :edit, locals: {
            patient: patient,
            profile: find_profile
          }
        end
      end

      private

      def profile_params
        params
          .require(:renal_profile)
          .permit(
            :esrf_on, :first_seen_on, :prd_description_id, :weight_at_esrf,
            :modality_at_esrf, :comorbidities_updated_on,
            address_at_diagnosis_attributes: address_params
          )
          .merge(document: document_attributes)
      end

      def address_params
        [
          :id, :name, :organisation_name, :street_1, :street_2, :street_3, :county, :country_id,
          :town, :postcode, :telephone, :email
        ]
      end

      def find_profile
        patient.profile || patient.build_profile
      end

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

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
renalware-core-2.0.51 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.50 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.48 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.47 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.46 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.45 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.44 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.43 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.42 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.41 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.40 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.39 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.38 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.37 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.36 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.35 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.34 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.33 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.32 app/controllers/renalware/renal/profiles_controller.rb
renalware-core-2.0.31 app/controllers/renalware/renal/profiles_controller.rb