Class: MalawiHivProgramReports::Moh::TptNewlyInitiated
- Inherits:
-
Object
- Object
- MalawiHivProgramReports::Moh::TptNewlyInitiated
- Defined in:
- app/services/malawi_hiv_program_reports/moh/tpt_newly_initiated.rb
Overview
Patients newly initiated on TPT disaggregated by regimen type and age group.
Newly initiated is defined as patients who have received TPT for the first time in the reporting period or patients who have gone on a TPT course break for a period that is at least 9 months long before restarting TPT in the current reporting period. rubocop:disable Metrics/ClassLength
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.
Instance Method Summary collapse
- #find_report ⇒ Object
-
#initialize(start_date:, end_date:, **kwargs) ⇒ TptNewlyInitiated
constructor
A new instance of TptNewlyInitiated.
Constructor Details
#initialize(start_date:, end_date:, **kwargs) ⇒ TptNewlyInitiated
Returns a new instance of TptNewlyInitiated.
16 17 18 19 20 21 22 |
# File 'app/services/malawi_hiv_program_reports/moh/tpt_newly_initiated.rb', line 16 def initialize(start_date:, end_date:, **kwargs) @start_date = ActiveRecord::Base.connection.quote(start_date) @end_date = ActiveRecord::Base.connection.quote(end_date) @occupation = kwargs[:occupation] @location = kwargs[:location] @adapter = ActiveRecord::Base.connection.adapter_name.downcase end |
Instance Attribute Details
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
14 15 16 |
# File 'app/services/malawi_hiv_program_reports/moh/tpt_newly_initiated.rb', line 14 def end_date @end_date end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
14 15 16 |
# File 'app/services/malawi_hiv_program_reports/moh/tpt_newly_initiated.rb', line 14 def start_date @start_date end |
Instance Method Details
#find_report ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/services/malawi_hiv_program_reports/moh/tpt_newly_initiated.rb', line 24 def find_report report = init_report newly_initiated_on_tpt.each do |tpt, patients| patients.each do |patient| patient_id = patient['patient_id'] person = ActiveRecord::Base.connection.select_one <<~SQL SELECT disaggregated_age_group(birthdate, DATE('#{end_date.to_date}')) AS age_group, patient_identifier.identifier AS arv_number, person.* FROM person LEFT JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type IN (SELECT patient_identifier_type_id FROM patient_identifier_type WHERE name = 'ARV Number') AND patient_identifier.voided = 0 WHERE person_id = #{patient_id} LIMIT 1; SQL age_group = person['age_group'] gender = person['gender']&.strip&.first&.upcase || 'Unknown' # course = patient_on_3hp?(patient) ? '3HP' : '6H' report[age_group][tpt][gender] << { patient_id: person['person_id'], birthdate: person['birthdate'], arv_number: person['arv_number'], gender:, dispensation_date: dispensation_date(patient_id, patient['drug_concepts']), art_start_date: patient['earliest_start_date'], tpt_start_date: patient['tpt_start_date'] } end end report['Location'] = Location.current.city_village report end |