Sha256: 48f35bcba2181869bf281dc3374fc2131996a1a33566783c16b88d557a80b904
Contents?: true
Size: 1.46 KB
Versions: 44
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true # Reports on all patients that were on treatment in given time period # regardless of whether they have a terminal state or not within the # period. module MalawiHivProgramReports module Clinic class PatientsOnTreatment attr_reader :start_date, :end_date def initialize(start_date:, end_date:) @start_date = start_date @end_date = end_date end # Returns patients that were on treatment within the given time period. def self.within(start_date, end_date) sql_conditions = <<~SQL ((start_date >= :start_date AND start_date <= :end_date) OR (end_date >= :start_date AND end_date <= :end_date) OR (start_date < :start_date AND end_date IS NULL)) AND state = :state SQL on_arvs = ::PatientState.where(sql_conditions, start_date:, end_date:, state: ::ArtService::Constants::States::ON_ANTIRETROVIRALS) ::PatientProgram.select('DISTINCT patient_program.patient_id') .joins(:patient_states) .merge(on_arvs) .where(program_id: ::ArtService::Constants::PROGRAM_ID) end # We an interface to satisfy, let's be good citizens def find_report within(start_date, end_date).map(&:patient_id) end end end end
Version data entries
44 entries across 44 versions & 1 rubygems