class Qrda::Export::Helper::AggregateCount

Attributes

measure_id[RW]
population_groups[RW]
populations[RW]

Public Class Methods

new(measure_id) click to toggle source
# File lib/qrda-export/helper/aggregate_object_helper.rb, line 102
def initialize(measure_id)
  @populations = []
  @measure_id = measure_id
  @population_groups = []
end

Public Instance Methods

add_entry(cache_entry, population_sets) click to toggle source
# File lib/qrda-export/helper/aggregate_object_helper.rb, line 108
def add_entry(cache_entry, population_sets)
  population_set = population_sets.where(population_set_id: cache_entry.pop_set_hash[:population_set_id]).first
  entry_populations = []
  %w[IPP DENOM NUMER NUMEX DENEX DENEXCEP MSRPOPL MSRPOPLEX].each do |pop_code|
    next unless population_set.populations[pop_code]

    population = create_population_from_population_set(pop_code, population_set, cache_entry)
    if cache_entry.pop_set_hash[:stratification_id]
      strat_id = population_set.stratifications.where(stratification_id: cache_entry.pop_set_hash[:stratification_id]).first&.hqmf_id
      observation = cache_entry['observations'][pop_code] if cache_entry['observations'] && cache_entry['observations'][pop_code]
      population.add_stratification(strat_id,cache_entry[pop_code], observation)
    else
      population.value = cache_entry[pop_code]
      population.observation = cache_entry['observations'][pop_code] if cache_entry['observations'] && cache_entry['observations'][pop_code]
      population.supplemental_data = cache_entry.supplemental_data[pop_code]
    end
    entry_populations << population if population
  end
  return if population_groups.find {|pg| pg.populations.collect(&:id).compact.sort == entry_populations.collect(&:id).compact.sort }

  pg = PopulationGroup.new
  pg.populations = entry_populations
  population_groups << pg
end
create_population_from_population_set(pop_code, population_set, cache_entry) click to toggle source
# File lib/qrda-export/helper/aggregate_object_helper.rb, line 133
def create_population_from_population_set(pop_code, population_set, cache_entry)
  population = populations.find { |pop| pop.id == population_set.populations[pop_code]&.hqmf_id } if pop_code != 'STRAT'
  return population unless population.nil? && !cache_entry.pop_set_hash[:stratification_id]

  population = Population.new
  population.type = pop_code
  population.id = population_set.populations[pop_code]&.hqmf_id
  populations << population
  population
end
is_cv?() click to toggle source
# File lib/qrda-export/helper/aggregate_object_helper.rb, line 144
def is_cv?
  populations.any? {|pop| pop.type == 'MSRPOPL'}
end