Sha256: ca6f64624f9fc50349a3c9994d0605bb84c6fc12bf1fd10fc3a7ff970ada68f2

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/admissions"

module Renalware
  module Admissions
    class ConsultQuery
      attr_reader :query

      def initialize(query = nil)
        @query = query || {}
        @query[:ended_on_null] ||= true
      end

      def call
        search.result
      end

      # Note we *MUST* join onto patients for PatientsRansackHelper.identity_match to work.
      # It might be better to refactor PatientsRansackHelper so we can include where required
      # eg below using .extending(PatientsRansackHelper) rather than relying on it being in
      # included in the model file.
      def search
        @search ||= begin
          Consult
            .joins(:patient)
            .eager_load(patient: [current_modality: :description])
            .includes(
              :created_by,
              :consult_site,
              :hospital_ward,
              patient: { current_modality: :description }
            )
            .order(created_at: :desc)
            .ransack(query)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
renalware-core-2.0.24 app/models/renalware/admissions/consult_query.rb
renalware-core-2.0.23 app/models/renalware/admissions/consult_query.rb
renalware-core-2.0.22 app/models/renalware/admissions/consult_query.rb
renalware-core-2.0.21 app/models/renalware/admissions/consult_query.rb
renalware-core-2.0.20 app/models/renalware/admissions/consult_query.rb