Sha256: fcdf3577d9d16a86a297a10ac6c5563b7b492af052e118933311a4afd424826b

Contents?: true

Size: 1.66 KB

Versions: 34

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology"

module Renalware
  module Pathology
    class ObservationRequestsController < Pathology::BaseController
      include Renalware::Concerns::Pageable
      before_action :load_patient

      def index
        observation_requests = find_observation_requests
        render locals: {
          observation_requests: observation_requests.result .page(page).per(per_page),
          search: observation_requests,
          obr_filter_options: obr_filter_options,
          patient: @patient
        }
      end

      def show
        observation_request = find_observation_request

        render locals: { observation_request: observation_request, patient: @patient }
      end

      private

      # Select just the OBR description ids and codes that have been associated with this patient.
      # We'll uses them to build a filter dropdown list.
      def obr_filter_options
        @patient.observation_requests
          .joins(:description)
          .order("pathology_request_descriptions.code asc")
          .pluck(
            Arel.sql(
              "distinct on(pathology_request_descriptions.code) pathology_request_descriptions.code"
            ),
            "pathology_request_descriptions.id",
            "pathology_request_descriptions.name"
          )
      end

      def find_observation_requests
        @patient.observation_requests
          .includes(:description)
          .ordered
          .ransack(params[:q])
      end

      def find_observation_request
        @patient.observation_requests
          .includes(observations: :description)
          .find(params[:id])
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
renalware-core-2.0.149 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.148 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.147 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.146 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.145 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.144 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.143 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.142 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.141 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.140 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.139 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.138 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.137 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.136 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.135 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.134 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.133 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.132 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.131 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.130 app/controllers/renalware/pathology/observation_requests_controller.rb