Class: MalawiHivProgramReports::Clinic::ViralLoadDisaggregated

Inherits:
Object
  • Object
show all
Defined in:
app/services/malawi_hiv_program_reports/clinic/viral_load_disaggregated.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_date:, end_date:, from: nil, to: nil, **_kwargs) ⇒ ViralLoadDisaggregated

Returns a new instance of ViralLoadDisaggregated.



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

def initialize(start_date:, end_date:, from: nil, to: nil, **_kwargs)
  @start_date = start_date.to_date
  @end_date = end_date.to_date
  @from = from&.to_f
  @to = to&.to_f
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



6
7
8
# File 'app/services/malawi_hiv_program_reports/clinic/viral_load_disaggregated.rb', line 6

def end_date
  @end_date
end

#fromObject (readonly)

Returns the value of attribute from.



6
7
8
# File 'app/services/malawi_hiv_program_reports/clinic/viral_load_disaggregated.rb', line 6

def from
  @from
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



6
7
8
# File 'app/services/malawi_hiv_program_reports/clinic/viral_load_disaggregated.rb', line 6

def start_date
  @start_date
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'app/services/malawi_hiv_program_reports/clinic/viral_load_disaggregated.rb', line 6

def to
  @to
end

Instance Method Details

#find_reportObject



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

def find_report
  patients.each_with_object({}) do |patient, report|
    age_group = find_age_group(patient.birthdate)
    regimen = patient.regimen&.upcase
    report[age_group] ||= {}

    if report[age_group].include?(regimen)
      report[age_group][regimen] += 1
    else
      report[age_group][regimen] = 1
    end
  end
end