Sha256: 777acee2d2ff9eebf3a94278be67357a3936bb17ac7d04c86eb4cc3fb80ffe6a

Contents?: true

Size: 1.36 KB

Versions: 44

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

# Retrieve all patients who are taking ARVs in a given time period.
module MalawiHivProgramReports
  module Clinic
    class PatientsOnAntiretrovirals
      attr_reader :start_date, :end_date

      def initialize(start_date:, end_date:, **_kwargs)
        @start_date = start_date
        @end_date = end_date
      end

      def self.within(start_date, end_date)
        PatientsOnAntiretrovirals.new(start_date:, end_date:)
                                 .patients
      end

      def find_report
        patients
      end

      def patients
        ::DrugOrder.select('orders.patient_id AS patient_id')
                   .joins(:order)
                   .merge(art_orders)
                   .where(drug_inventory_id: ArtService::RegimenEngine.arv_drugs,
                          quantity: 1..Float::INFINITY)
                   .where('start_date BETWEEN :start_date AND :end_date
                         OR auto_expire_date BETWEEN :start_date AND :end_date
                         OR (start_date <= :start_date AND auto_expire_date >= :end_date)',
                          start_date:, end_date:)
                   .group('orders.patient_id')
      end

      private

      def art_orders
        ::Order.joins(:encounter)
               .where('encounter.program_id = ?', ::ArtService::Constants::PROGRAM_ID)
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
malawi_hiv_program_reports-1.1.18 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.17 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.16 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.15 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.14 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.13 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.12 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.11 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.10 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.9 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.8 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.7 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.6 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.5 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.4 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.3 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.2 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.1 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.1.0 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
malawi_hiv_program_reports-1.0.27 app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb