Class: MalawiHivProgramReports::Clinic::PatientsOnTreatment
- Inherits:
-
Object
- Object
- MalawiHivProgramReports::Clinic::PatientsOnTreatment
- Defined in:
- app/services/malawi_hiv_program_reports/clinic/patients_on_treatment.rb
Instance Attribute Summary collapse
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
Class Method Summary collapse
-
.within(start_date, end_date) ⇒ Object
Returns patients that were on treatment within the given time period.
Instance Method Summary collapse
-
#find_report ⇒ Object
We an interface to satisfy, let’s be good citizens.
-
#initialize(start_date:, end_date:) ⇒ PatientsOnTreatment
constructor
A new instance of PatientsOnTreatment.
Constructor Details
#initialize(start_date:, end_date:) ⇒ PatientsOnTreatment
Returns a new instance of PatientsOnTreatment.
11 12 13 14 |
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_treatment.rb', line 11 def initialize(start_date:, end_date:) @start_date = start_date @end_date = end_date end |
Instance Attribute Details
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
9 10 11 |
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_treatment.rb', line 9 def end_date @end_date end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
9 10 11 |
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_treatment.rb', line 9 def start_date @start_date end |
Class Method Details
.within(start_date, end_date) ⇒ Object
Returns patients that were on treatment within the given time period.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_treatment.rb', line 17 def self.within(start_date, end_date) sql_conditions = <<~SQL ((start_date >= :start_date AND start_date <= :end_date) OR (end_date >= :start_date AND end_date <= :end_date) OR (start_date < :start_date AND end_date IS NULL)) AND state = :state SQL on_arvs = ::PatientState.where(sql_conditions, start_date:, end_date:, state: ::ArtService::Constants::States::ON_ANTIRETROVIRALS) ::PatientProgram.select('DISTINCT patient_program.patient_id') .joins(:patient_states) .merge(on_arvs) .where(program_id: ::ArtService::Constants::PROGRAM_ID) end |
Instance Method Details
#find_report ⇒ Object
We an interface to satisfy, let’s be good citizens
37 38 39 |
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_treatment.rb', line 37 def find_report within(start_date, end_date).map(&:patient_id) end |