Class: HealthDataStandards::CQM::QueryCache

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/health-data-standards/models/cqm/query_cache.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.aggregate_measure(measure_id, effective_date, test_id = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/health-data-standards/models/cqm/query_cache.rb', line 21

def self.aggregate_measure(measure_id, effective_date, test_id=nil)
  cache_entries = self.where(effective_date: effective_date, measure_id: measure_id, test_id: test_id)
  aggregate_count = AggregateCount.new
  aggregate_count.measure_id = measure_id
  cache_entries.each do |cache_entry|
    if cache_entry.is_stratification?
      stratification = Stratification.new
      stratification.populations = cache_entry.build_populations
      stratification.id = cache_entry.population_ids['stratification']
      aggregate_count.stratifications << stratification
    else
      aggregate_count.top_level_populations = cache_entry.build_populations
      if cache_entry.supplemental_data.present?
        aggregate_count.supplemental_data = cache_entry.supplemental_data
      end
    end
  end
  aggregate_count
end

Instance Method Details

#build_populationsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/health-data-standards/models/cqm/query_cache.rb', line 49

def build_populations
  populations = []
  population_ids.each do |population_type, population_id|
    unless population_type == 'stratification'
      population = Population.new
      population.type = population_type
      population.id = population_id
      population.value = self[population_type]
      populations << population
    end
  end
  populations
end

#is_cv?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/health-data-standards/models/cqm/query_cache.rb', line 45

def is_cv?
  population_ids.has_key?('MSRPOPL')
end

#is_stratification?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/health-data-standards/models/cqm/query_cache.rb', line 41

def is_stratification?
  population_ids.has_key?('stratification')
end