Sha256: b30db4465ef0bf5efa635e091c8263543e437394925d56a81b1e994ac96e6e9c
Contents?: true
Size: 1.47 KB
Versions: 16
Compression:
Stored size: 1.47 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 p LEFT JOIN patient_identifier 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
16 entries across 16 versions & 1 rubygems