Sha256: bc1165bc8981eed7210f29ac56ea69131643e10c83e815f55826f0bbd823a723

Contents?: true

Size: 1.59 KB

Versions: 18

Compression:

Stored size: 1.59 KB

Contents

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_attributes(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

18 entries across 18 versions & 1 rubygems

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