Class: Qrda::Export::Helper::AggregateCount

Inherits:
Object
  • Object
show all
Defined in:
lib/qrda-export/helper/aggregate_object_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(measure_id) ⇒ AggregateCount

Returns a new instance of AggregateCount.



102
103
104
105
106
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 102

def initialize(measure_id)
  @populations = []
  @measure_id = measure_id
  @population_groups = []
end

Instance Attribute Details

#measure_idObject

Returns the value of attribute measure_id.



100
101
102
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 100

def measure_id
  @measure_id
end

#population_groupsObject

Returns the value of attribute population_groups.



100
101
102
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 100

def population_groups
  @population_groups
end

#populationsObject

Returns the value of attribute populations.



100
101
102
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 100

def populations
  @populations
end

Instance Method Details

#add_entry(cache_entry, population_sets) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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) ⇒ Object



133
134
135
136
137
138
139
140
141
142
# 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?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 144

def is_cv?
  populations.any? { |pop| pop.type == 'MSRPOPL' }
end