Sha256: f685b18859fde23c33102960fa34b6df27a4af4c5347e74dedd0da92f5ee2872

Contents?: true

Size: 1.54 KB

Versions: 43

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/clinical"

module Renalware
  module Clinical
    # Note that there is no concrete Clinical::Profile, most data here is persisted in the patient
    class ProfilesController < Clinical::BaseController
      def show
        authorize patient
        render locals: {
          patient: patient,
          profile: Clinical::ProfilePresenter.new(patient: patient, params: params)
        }
      end

      def edit
        authorize patient
        render locals: { patient: patient }
      end

      def update
        authorize patient
        if update_patient
          redirect_to patient_clinical_profile_path(patient),
                      notice: t(".success", model_name: "clinical history")
        else
          render :edit, locals: { patient: patient }
        end
      end

      private

      def update_patient
        patient.named_consultant_id = profile_params[:named_consultant_id]
        document = patient.document

        %i(diabetes history).each do |document_attribute|
          document.send(
            :"#{document_attribute}=",
            profile_params[:document][document_attribute].symbolize_keys
          )
        end
        patient.save_by! current_user
      end

      def profile_params
        params
          .require(:clinical_profile)
          .permit(
            :named_consultant_id,
            document: {
              diabetes: %i(diagnosis diagnosed_on),
              history: %i(alcohol smoking)
            }
          ).to_h
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
renalware-core-2.0.167 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.166 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.165 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.164 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.163 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.162 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.161 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.160 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.159 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.158 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.157 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.156 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.155 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.153 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.152 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.151 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.149 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.148 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.147 app/controllers/renalware/clinical/profiles_controller.rb
renalware-core-2.0.146 app/controllers/renalware/clinical/profiles_controller.rb