Sha256: 3fb869ecf4bf33a4478722475e04f5513e8f9217a03445b50aff83d91359e466

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology"

module Renalware
  module Pathology
    class ObservationDescriptionsController < BaseController
      include Pagy::Backend

      def index
        query = ObservationDescription
          .includes(:measurement_unit)
          .order(:code)
          .ransack(params[:q] || {})
        pagy, descriptions = pagy(query.result)
        authorize descriptions
        render locals: { descriptions: descriptions, pagy: pagy, query: query }
      end

      def edit
        render_edit find_authorise_description
      end

      def update
        description = find_authorise_description
        if description.update(description_params)
          redirect_to(
            pathology_observation_descriptions_path,
            notice: t(".success", model_name: "observation descrition")
          )
        else
          render_edit(description)
        end
      end

      private

      def render_edit(description)
        render :edit, locals: { description: description }
      end

      def find_authorise_description
        ObservationDescription.find(params[:id]).tap { |desc| authorize desc }
      end

      def description_params
        params
          .require(:pathology_observation_description)
          .permit(
            :name,
            :measurement_unit_id,
            :lower_threshold,
            :upper_threshold
          )
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
renalware-core-2.0.167 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.166 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.165 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.164 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.163 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.162 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.161 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.160 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.159 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.158 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.157 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.156 app/controllers/renalware/pathology/observation_descriptions_controller.rb
renalware-core-2.0.155 app/controllers/renalware/pathology/observation_descriptions_controller.rb