Class: Renalware::Medications::Delivery::PrescriptionsDueForDeliveryQuery
- Inherits:
-
Object
- Object
- Renalware::Medications::Delivery::PrescriptionsDueForDeliveryQuery
- Defined in:
- app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb
Overview
Find current home delivery prescriptions with a next_delivery_date falling within the specified range.
Instance Attribute Summary collapse
-
#drug_type_code ⇒ Object
readonly
Returns the value of attribute drug_type_code.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#modality_description_id ⇒ Object
readonly
Returns the value of attribute modality_description_id.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(drug_type_code: nil, from: nil, to: nil, modality_description_id: nil, query: {}) ⇒ PrescriptionsDueForDeliveryQuery
constructor
A new instance of PrescriptionsDueForDeliveryQuery.
- #search ⇒ Object
Constructor Details
#initialize(drug_type_code: nil, from: nil, to: nil, modality_description_id: nil, query: {}) ⇒ PrescriptionsDueForDeliveryQuery
Returns a new instance of PrescriptionsDueForDeliveryQuery.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb', line 13 def initialize( drug_type_code: nil, from: nil, to: nil, modality_description_id: nil, query: {} ) @from = (from || 4.weeks.ago).beginning_of_day @to = (to || 2.weeks.since).end_of_day @drug_type_code = drug_type_code @query = query @modality_description_id = modality_description_id end |
Instance Attribute Details
#drug_type_code ⇒ Object (readonly)
Returns the value of attribute drug_type_code.
11 12 13 |
# File 'app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb', line 11 def drug_type_code @drug_type_code end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
11 12 13 |
# File 'app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb', line 11 def from @from end |
#modality_description_id ⇒ Object (readonly)
Returns the value of attribute modality_description_id.
11 12 13 |
# File 'app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb', line 11 def modality_description_id @modality_description_id end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
11 12 13 |
# File 'app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb', line 11 def query @query end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
11 12 13 |
# File 'app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb', line 11 def to @to end |
Instance Method Details
#call ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb', line 27 def call query = search.result .current .includes(:patient) .eager_load(drug: [:classifications, :drug_types]) .joins("inner join patient_current_modalities pcm on pcm.patient_id = patients.id") .where(provider: :home_delivery) .where(next_delivery_date: (from..to)) .order(next_delivery_date: :asc) if drug_type_code.present? query = query.where("lower(drug_types.code) = ?", drug_type_code) end if modality_description_id.present? query = query.where("pcm.modality_description_id = ?", modality_description_id) end query end |
#search ⇒ Object
47 48 49 |
# File 'app/models/renalware/medications/delivery/prescriptions_due_for_delivery_query.rb', line 47 def search @search ||= Medications::Prescription.ransack(query) end |