Sha256: 15b599fc1fccce0f23a1967b93de50d12593faa88bc056b800ac17678175f983

Contents?: true

Size: 1.85 KB

Versions: 32

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

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

32 entries across 32 versions & 1 rubygems

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