Sha256: 3fe10fcfb5290b055c4747fcf495189e4a945c4cdec40517e982d6e0af9c702d

Contents?: true

Size: 753 Bytes

Versions: 1

Compression:

Stored size: 753 Bytes

Contents

module Renalware
  module Medications
    class PrescriptionsByDrugTypeQuery
      attr_reader :drug_type_name, :search_params

      def initialize(drug_type_name:, search_params: nil)
        @drug_type_name = drug_type_name.downcase
        @search_params = search_params || {}
        @search_params.reverse_merge!(s: Prescription.default_search_order)
      end

      def call
        search.result
      end

      def search
        @search ||= begin
          Prescription
            .current
            .includes(:medication_route, :patient, :drug)
            .eager_load(drug: [:drug_types])
            .where("lower(drug_types.name) = lower(?)", drug_type_name)
            .search(search_params)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta4 app/models/renalware/medications/prescriptions_by_drug_type_query.rb