Class: Renalware::Medications::PrescriptionsByDrugTypeQuery
- Inherits:
-
Object
- Object
- Renalware::Medications::PrescriptionsByDrugTypeQuery
- Defined in:
- app/models/renalware/medications/prescriptions_by_drug_type_query.rb
Instance Attribute Summary collapse
-
#drug_type_name ⇒ Object
readonly
Returns the value of attribute drug_type_name.
-
#search_params ⇒ Object
readonly
Returns the value of attribute search_params.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(drug_type_name:, search_params: nil) ⇒ PrescriptionsByDrugTypeQuery
constructor
A new instance of PrescriptionsByDrugTypeQuery.
- #search ⇒ Object
Constructor Details
#initialize(drug_type_name:, search_params: nil) ⇒ PrescriptionsByDrugTypeQuery
Returns a new instance of PrescriptionsByDrugTypeQuery.
8 9 10 11 12 |
# File 'app/models/renalware/medications/prescriptions_by_drug_type_query.rb', line 8 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 |
Instance Attribute Details
#drug_type_name ⇒ Object (readonly)
Returns the value of attribute drug_type_name.
6 7 8 |
# File 'app/models/renalware/medications/prescriptions_by_drug_type_query.rb', line 6 def drug_type_name @drug_type_name end |
#search_params ⇒ Object (readonly)
Returns the value of attribute search_params.
6 7 8 |
# File 'app/models/renalware/medications/prescriptions_by_drug_type_query.rb', line 6 def search_params @search_params end |
Instance Method Details
#call ⇒ Object
14 15 16 |
# File 'app/models/renalware/medications/prescriptions_by_drug_type_query.rb', line 14 def call search.result end |
#search ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/renalware/medications/prescriptions_by_drug_type_query.rb', line 18 def search @search ||= begin Prescription .current .includes(:medication_route, :drug) .includes(patient: { current_modality: :description }) .eager_load(drug: [:drug_types]) .where("lower(drug_types.name) = lower(?)", drug_type_name) .ransack(search_params) end end |