Class: MalawiHivProgramReports::Pepfar::PatientStartVl

Inherits:
Object
  • Object
show all
Includes:
Adapters::Moh::Custom, Utils
Defined in:
app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb

Overview

this module returns all the patient records on when when the patient started ART plus the last viral load result

Constant Summary

Constants included from Utils

Utils::COHORT_REGIMENS, Utils::FULL_3HP_COURSE_DAYS, Utils::FULL_6H_COURSE_PILLS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Adapters::Moh::Custom

#cast_manager, #current_partition, #exe_create_drill_down_table, #exe_temp_cohort_members_table, #exe_temp_order_details_table, #exe_temp_other_patient_types, #exe_temp_register_start_date_table, #exe_tmp_patient_table, #function_manager, #group_by_columns, #in_manager, #interval_manager, #min_filt, #site_manager, #timestampdiff_manager

Methods included from Utils

#drug_refills_and_external_consultation_list, #isoniazid_rifapentine_concept, #patient_completed_tpt?, #patient_on_3hp?, #patient_on_tb_treatment?, #pepfar_age_groups, #pepfar_patient_drilldown_information, #pepfar_patient_identifier_type, #rifapentine_concept

Constructor Details

#initialize(start_date:, end_date:, **kwargs) ⇒ PatientStartVl

Returns a new instance of PatientStartVl.

Raises:

  • (InvalidParameterError)


15
16
17
18
19
20
21
# File 'app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb', line 15

def initialize(start_date:, end_date:, **kwargs)
  @start_date = start_date
  @end_date = end_date
  @location = kwargs[:location]
  @patient_ids = kwargs[:patient_ids]
  raise InvalidParameterError, 'Patient IDs are required' if patient_ids.blank?
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



10
11
12
# File 'app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb', line 10

def end_date
  @end_date
end

#locationObject (readonly)

Returns the value of attribute location.



10
11
12
# File 'app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb', line 10

def location
  @location
end

#patient_idsObject (readonly)

Returns the value of attribute patient_ids.



10
11
12
# File 'app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb', line 10

def patient_ids
  @patient_ids
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



10
11
12
# File 'app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb', line 10

def start_date
  @start_date
end

Instance Method Details

#find_reportObject



23
24
25
# File 'app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb', line 23

def find_report
  get_patients_last_vl_and_latest_result
end

#get_patients_last_vl_and_latest_resultObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb', line 27

def get_patients_last_vl_and_latest_result
  ids = patient_ids.split(',')
  ActiveRecord::Base.connection.select_all <<~SQL
    SELECT p.person_id AS patient_id,
    patient_start_date(p.person_id) AS art_start_date,
    p.birthdate AS birthdate,
    p.gender,
    MIN(pi.identifier)
    FROM person #{current_partition} p
    LEFT JOIN patient_identifier #{current_partition} pi ON pi.patient_id = p.person_id AND pi.voided = 0 AND pi.identifier_type = 4
    WHERE p.voided = 0
    AND #{in_manager(column: 'p.person_id', values: ids)}
    #{site_manager(operator: 'AND', column: 'p.site_id', location: location)}
    GROUP BY p.person_id, p.birthdate, p.gender
  SQL
end