Class: MalawiHivProgramReports::Pepfar::ViralLoadCoverage2

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

Overview

Viral Load Coverage Report

  1. given the start and end dates, this report will go back 12 months using the end date

  2. pick all clients that are due in the mentioned period

  3. the picked clients should also include those that are new on ART 6 months before the end date

  4. for the sample drawns available pick the latest sample drawn within the reporting period

  5. for the results pick the latest result within the reporting period

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 Utils::ModelUtils

#concept, #concept_id_to_name, #concept_name, #concept_name_to_id, #drug, #encounter_type, #global_property, #order_type, #patient_identifier_type, #program, #report_type, #user_property

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::CommonSqlQueryUtils

#current_occupation_query, #external_client_query, #occupation_filter, #partition_by_site, #process_occupation

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) ⇒ ViralLoadCoverage2

Returns a new instance of ViralLoadCoverage2.

Raises:

  • (InvalidParameterError)


18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb', line 18

def initialize(start_date:, end_date:, **kwargs)
  @start_date = start_date&.to_date
  raise InvalidParameterError, 'start_date is required' unless @start_date

  @end_date = end_date&.to_date || (@start_date + 12.months)
  raise InvalidParameterError, "start_date can't be greater than end_date" if @start_date > @end_date

  @occupation = kwargs.delete(:occupation)
  @type = kwargs.delete(:application)
  @location = kwargs.delete(:location)
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



16
17
18
# File 'app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb', line 16

def end_date
  @end_date
end

#locationObject (readonly)

Returns the value of attribute location.



16
17
18
# File 'app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb', line 16

def location
  @location
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



16
17
18
# File 'app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb', line 16

def start_date
  @start_date
end

Instance Method Details

#find_reportObject



30
31
32
33
34
# File 'app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb', line 30

def find_report
  report = init_report
  build_report(report)
  report
end

#process_due_peopleObject

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb', line 53

def process_due_people
  @clients = []
  start = Time.now
  results = clients_on_art
  # get all clients that are females from results
  @maternal_status = vl_maternal_status(results.filter_map do |patient|
                                          patient['patient_id'] if patient['gender'] == 'F'
                                        end)
  if @type.blank? || @type == 'poc'
    Parallel.each(results, in_threads: 20) do |patient|
      process_client_eligibility(patient)
    end
  end
  results.each { |patient| process_client_eligibility(patient) } if @type == 'emastercard'
  end_time = Time.now
  Rails.logger.info "Time taken to process #{results.length} clients: #{end_time - start} seconds.
                    These are the clients returned: #{@clients.length}"
  @clients
end

#vl_maternal_status(patient_list) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb', line 36

def vl_maternal_status(patient_list)
  return { FP: [], FBf: [] } if patient_list.blank?

  pregnant = pregnant_women(patient_list).map { |woman| woman['person_id'].to_i }
  return { FP: pregnant, FBf: [] } if (patient_list - pregnant).blank?

  feeding = breast_feeding(patient_list - pregnant).map { |woman| woman['person_id'].to_i }

  {
    FP: pregnant,
    FBf: feeding
  }
end