hqmf-parser 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,10 +48,12 @@ module HQMF
48
48
  end
49
49
  apply_to_submeasures(@sub_measures, HQMF::PopulationCriteria::DENOM, denoms.values)
50
50
  apply_to_submeasures(@sub_measures, HQMF::PopulationCriteria::IPP, ipps.values)
51
- apply_to_submeasures(@sub_measures, HQMF::PopulationCriteria::DENEX, excls.values)
52
- apply_to_submeasures(@sub_measures, HQMF::PopulationCriteria::DENEXCEP, denexcs.values)
51
+
52
+ apply_to_submeasures(@sub_measures, HQMF::PopulationCriteria::DENEX, excls.values, HQMF::PopulationCriteria::IPP, get_unmatched_population_keys(ipps, excls))
53
+ apply_to_submeasures(@sub_measures, HQMF::PopulationCriteria::DENEXCEP, denexcs.values, HQMF::PopulationCriteria::DENOM, get_unmatched_population_keys(denoms, denexcs))
53
54
 
54
55
  keep = []
56
+
55
57
  @sub_measures.each do |sub|
56
58
 
57
59
  value = sub
@@ -80,19 +82,37 @@ module HQMF
80
82
  end
81
83
  end
82
84
 
83
- def apply_to_submeasures(subs, type, values)
85
+ # source are things like exceptions or exclusions, target are IPP, or denom
86
+ # we want to find any denoms or IPPs that do not have exceptions or exclusions
87
+ def get_unmatched_population_keys(target, source)
88
+ return [] if target.length == source.length
89
+ all_target_keys = target.values.map(&:id)
90
+ with_ref_keys = source.values.map(&:id).map {|key| @population_criteria_by_id[@population_reference[key]].id if @population_criteria_by_id[@population_reference[key]]}
91
+ # if we have a population without a reference, we cannot trust the results.
92
+ return [] if with_ref_keys.include? nil
93
+ all_target_keys - with_ref_keys
94
+ end
95
+
96
+ # create a copy of each submeasre adding on the new values of the given type
97
+ # skip the unpaired values. Unpaired values are denominators without exclusions or populations without exceptions
98
+ def apply_to_submeasures(subs, type, values, unpaired_type=nil, unpaired_keys=[])
84
99
  new_subs = []
85
100
  subs.each do |sub|
86
- values.each do |value|
87
- if (sub[type] and sub[type] != value.id)
88
- tmp = {}
89
- HQMF::PopulationCriteria::ALL_POPULATION_CODES.each do |key|
90
- tmp[key] = sub[key] if sub[key]
101
+ # this unless prevents us from forcing an exclusion or excepion onto a measure that has a submeasure without
102
+ # an exclusion or exception, but other populations with an exclusion or excepion.
103
+ unless unpaired_keys.include? sub[unpaired_type]
104
+ # duplicate each new value if it is set, otherwise set this key on each submeasure.
105
+ values.each do |value|
106
+ if (sub[type] and sub[type] != value.id)
107
+ tmp = {}
108
+ HQMF::PopulationCriteria::ALL_POPULATION_CODES.each do |key|
109
+ tmp[key] = sub[key] if sub[key]
110
+ end
111
+ sub = tmp
112
+ new_subs << sub
91
113
  end
92
- sub = tmp
93
- new_subs << sub
114
+ sub[type] = value.id
94
115
  end
95
- sub[type] = value.id
96
116
  end
97
117
  end
98
118
  subs.concat(new_subs)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hqmf-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-14 00:00:00.000000000 Z
14
+ date: 2012-11-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rubyzip