Sha256: 4db93d99495c99711adf720d2e1c3353a53543f8a617162d51d4f14c22d8425a

Contents?: true

Size: 1.66 KB

Versions: 18

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

18 entries across 18 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.1.0 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.167 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.166 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.165 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.164 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.163 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.162 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.161 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.160 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.159 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.158 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.157 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.156 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.155 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.153 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.152 app/controllers/renalware/pathology/observation_requests_controller.rb
renalware-core-2.0.151 app/controllers/renalware/pathology/observation_requests_controller.rb