Sha256: b1391bd1c8d9086371bcb2631218b4591ca2200351cb35c463bd508ccc6d16bd

Contents?: true

Size: 1.82 KB

Versions: 27

Compression:

Stored size: 1.82 KB

Contents

require_dependency "renalware/pd"

module Renalware
  module PD
    class AssessmentsController < BaseController
      def show
        assessment = find_assessment
        authorize assessment
        render locals: { patient: patient, assessment: assessment }
      end

      def new
        assessment = PD::Assessment.for_patient(patient).new
        authorize assessment
        render locals: { patient: patient, assessment: assessment }
      end

      def create
        assessment = PD::Assessment.for_patient(patient).new(assessment_params)
        authorize assessment
        if assessment.save
          redirect_to patient_pd_dashboard_path(patient),
                      notice: success_msg_for("assessment")
        else
          render :new, locals: { patient: patient, assessment: assessment }
        end
      end

      def edit
        assessment = find_assessment
        authorize assessment
        render locals: { patient: patient, assessment: assessment }
      end

      def update
        assessment = find_assessment
        authorize assessment
        if assessment.update(assessment_params)
          redirect_to patient_pd_dashboard_path(patient),
                      notice: success_msg_for("assessment")
        else
          render :edit, locals: { patient: patient, assessment: assessment }
        end
      end

      private

      def find_assessment
        PD::Assessment.for_patient(patient).find(params[:id])
      end

      def assessment_params
        params
          .require(:assessment)
          .permit(attributes)
          .merge(document: document_attributes, by: current_user)
      end

      def attributes
        [
          document: []
        ]
      end

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

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.15 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.14 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.13 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.12 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.11 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.9 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.8 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.7 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.5 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.4 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.3 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.2 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.1 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.0 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/pd/assessments_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/pd/assessments_controller.rb