Class: MalawiHivProgramReports::Clinic::VisitsReport

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

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

Constructor Details

#initialize(name:, type:, start_date:, end_date:) ⇒ VisitsReport

Returns a new instance of VisitsReport.



8
9
10
11
12
13
# File 'app/services/malawi_hiv_program_reports/clinic/visits_report.rb', line 8

def initialize(name:, type:, start_date:, end_date:)
  @name = name
  @type = type
  @start_date = start_date.to_date
  @end_date = end_date.to_date
end

Instance Method Details

#build_reportObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/malawi_hiv_program_reports/clinic/visits_report.rb', line 15

def build_report
  visits = (@start_date..@end_date).each_with_object({}) do |date, visits|
    visits[date] ||= { incomplete: 0, complete: 0 }

    find_visiting_patients(date).each do |patient|
      if workflow_engine(patient, date).next_encounter
        visits[date][:incomplete] += 1
      else
        visits[date][:complete] += 1
      end
    end
  end

  save_report visits
end

#find_reportObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/malawi_hiv_program_reports/clinic/visits_report.rb', line 31

def find_report
  (@start_date..@end_date).each_with_object({}) do |date, parsed_report|
    report = fetch_report date

    parsed_values = report.values.each_with_object({}) do |report_value, parsed_values|
      parsed_values[report_value.indicator_name] = report_value.contents.to_i
    end

    break nil if parsed_values.empty? # Force regeneration of report

    parsed_report[date] = parsed_values
  end
end