Class: MalawiHivProgramReports::Clinic::RegimensAndFormulations

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::CommonSqlQueryUtils

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

Constructor Details

#initialize(start_date:, end_date:, regimen: nil, formulation: 'tablets', **kwargs) ⇒ RegimensAndFormulations

Returns a new instance of RegimensAndFormulations.

Raises:

  • (::InvalidParameterError)


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb', line 11

def initialize(start_date:, end_date:, regimen: nil, formulation: 'tablets', **kwargs)
  raise ::InvalidParameterError, 'regimen is required' unless regimen

  unless %w[granules tablets pellets].include?(formulation)
    raise ::InvalidParameterError, "Invalid formalation: #{formulation}"
  end

  @start_date = start_date.to_date
  @end_date = end_date.to_date
  @formulation = formulation
  @regimen = regimen
  @occupation = kwargs[:occupation]
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



9
10
11
# File 'app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb', line 9

def end_date
  @end_date
end

#formulationObject (readonly)

Returns the value of attribute formulation.



9
10
11
# File 'app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb', line 9

def formulation
  @formulation
end

#regimenObject (readonly)

Returns the value of attribute regimen.



9
10
11
# File 'app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb', line 9

def regimen
  @regimen
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



9
10
11
# File 'app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb', line 9

def start_date
  @start_date
end

Instance Method Details

#find_reportObject



25
26
27
# File 'app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb', line 25

def find_report
  patients
end

#patientsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb', line 29

def patients
  patients_with_prescriptions.each_with_object([]) do |patient, matching_patients|
    prescribed_drugs = drugs_prescribed_to_patient(patient.patient_id, patient.prescription_date).map(&:drug_id)
    non_matching_drugs = Set.new(drugs) - prescribed_drugs

    next unless non_matching_drugs.empty?

    demographics = patient_demographics(patient.patient_id, patient.prescription_date)

    matching_patients << {
      patient_id: demographics.patient_id,
      arv_number: demographics.arv_number,
      birthdate: demographics.birthdate,
      gender: demographics.gender,
      weight: demographics.weight
    }
  end
end