Sha256: 7e556a3f310be02107d3d175694a1d456630022b4962154d9e4e1a3c01383c73

Contents?: true

Size: 1.1 KB

Versions: 44

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module MalawiHivProgramReports
  module Clinic
    class PatientsOnDtg
      attr_reader :start_date, :end_date

      HIV_PROGRAM_ID = 1
      ARV_NUMBER_TYPE_ID = 4

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

      def find_report
        ::DrugOrder.joins(:order)
                   .joins('INNER JOIN encounter USING (encounter_id)')
                   .joins('LEFT JOIN patient_identifier ON patient_identifier.patient_id = orders.patient_id')
                   .where(drug: dtg_drugs,
                          encounter: { program_id: HIV_PROGRAM_ID },
                          patient_identifier: { identifier_type: ARV_NUMBER_TYPE_ID })
                   .where('start_date BETWEEN ? AND ?', start_date, end_date)
                   .group('orders.patient_id')
                   .select('identifier')
                   .map(&:identifier)
      end

      private

      def dtg_drugs
        ::Drug.where(concept_id: ::ConceptName.find_by_name('Dolutegravir').concept_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_dtg.rb
malawi_hiv_program_reports-1.1.17 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.16 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.15 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.14 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.13 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.12 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.11 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.10 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.9 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.8 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.7 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.6 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.5 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.4 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.3 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.2 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.1 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.1.0 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
malawi_hiv_program_reports-1.0.27 app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb