Class: MalawiHivProgramReports::Clinic::PatientsAliveAndOnTreatment

Inherits:
Object
  • Object
show all
Includes:
Utils::ConcurrencyUtils
Defined in:
app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb

Constant Summary

Constants included from Utils::ConcurrencyUtils

Utils::ConcurrencyUtils::LOCK_FILES_DIR_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::ConcurrencyUtils

#with_lock

Constructor Details

#initialize(start_date:, end_date:, outcomes_definition: 'moh', rebuild_outcomes: true, **kwargs) ⇒ PatientsAliveAndOnTreatment

Returns a new instance of PatientsAliveAndOnTreatment.



12
13
14
15
16
17
18
19
# File 'app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb', line 12

def initialize(start_date:, end_date:, outcomes_definition: 'moh', rebuild_outcomes: true, **kwargs)
  @start_date = start_date
  @end_date = end_date
  @rebuild_outcomes = rebuild_outcomes
  @outcomes_definition = outcomes_definition
  @occupation = kwargs[:occupation]
  @location = kwargs[:location]
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



8
9
10
# File 'app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb', line 8

def end_date
  @end_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



8
9
10
# File 'app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb', line 8

def start_date
  @start_date
end

Instance Method Details

#find_reportObject



32
33
34
# File 'app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb', line 32

def find_report
  query.map(&:patient_id)
end

#queryObject



36
37
38
39
40
41
42
43
44
# File 'app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb', line 36

def query
  with_lock(Moh::Cohort::LOCK_FILE) do
    refresh_outcomes_table if @rebuild_outcomes || !outcomes_table_exists?

    ::Patient.find_by_sql <<~SQL
      SELECT patient_id FROM temp_patient_outcomes WHERE cum_outcome LIKE 'On antiretrovirals'
    SQL
  end
end

#refresh_outcomes_tableObject

Repopulates temp_patient_outcomes and temp_earliest_start_date tables.

The data in temp_patient_outcomes can be used to quickly find patients with various outcomes.



26
27
28
29
30
# File 'app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb', line 26

def refresh_outcomes_table
  logger.debug('Initialising cohort temporary tables...')
  MalawiHivProgramReports::Moh::CohortBuilder.new(outcomes_definition: @outcomes_definition, location: @location)
                                             .init_temporary_tables(@start_date, @end_date, @occupation)
end