Sha256: a14da34fda2bbf39e4432c457e96e682e80e54786079605076d65f2e8141fdba

Contents?: true

Size: 1.51 KB

Versions: 28

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module MalawiHivProgramReports
  module Pepfar
    # this module returns all the patient records on when
    # when the patient started ART
    # plus the last viral load result
    class PatientStartVl

      attr_reader :start_date, :end_date, :location, :patient_ids

      include Utils
      include MalawiHivProgramReports::Adapters::Moh::Custom

      def initialize(start_date:, end_date:, **kwargs)
        @start_date = start_date
        @end_date = end_date
        @location = kwargs[:location]
        @patient_ids = kwargs[:patient_ids]
        raise InvalidParameterError, 'Patient IDs are required' if patient_ids.blank?
      end

      def find_report
        get_patients_last_vl_and_latest_result
      end

      def get_patients_last_vl_and_latest_result
        ids = patient_ids.split(',')
        ActiveRecord::Base.connection.select_all <<~SQL
          SELECT p.person_id AS patient_id,
          patient_start_date(p.person_id) AS art_start_date,
          p.birthdate AS birthdate,
          p.gender,
          MIN(pi.identifier)
          FROM person #{current_partition} p
          LEFT JOIN patient_identifier #{current_partition} pi ON pi.patient_id = p.person_id AND pi.voided = 0 AND pi.identifier_type = 4
          WHERE p.voided = 0
          AND #{in_manager(column: 'p.person_id', values: ids)}
          #{site_manager(operator: 'AND', column: 'p.site_id', location: location)}
          GROUP BY p.person_id, p.birthdate, p.gender
        SQL
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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