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