cqm-parsers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +29 -0
- data/README.md +21 -0
- data/Rakefile +19 -0
- data/lib/ext/code.rb +10 -0
- data/lib/ext/data_element.rb +24 -0
- data/lib/hqmf-model/attribute.rb +63 -0
- data/lib/hqmf-model/data_criteria.rb +467 -0
- data/lib/hqmf-model/document.rb +253 -0
- data/lib/hqmf-model/population_criteria.rb +102 -0
- data/lib/hqmf-model/precondition.rb +94 -0
- data/lib/hqmf-model/types.rb +457 -0
- data/lib/hqmf-model/utilities.rb +52 -0
- data/lib/hqmf-parser.rb +116 -0
- data/lib/hqmf-parser/1.0/attribute.rb +121 -0
- data/lib/hqmf-parser/1.0/comparison.rb +34 -0
- data/lib/hqmf-parser/1.0/data_criteria.rb +92 -0
- data/lib/hqmf-parser/1.0/document.rb +195 -0
- data/lib/hqmf-parser/1.0/expression.rb +60 -0
- data/lib/hqmf-parser/1.0/observation.rb +61 -0
- data/lib/hqmf-parser/1.0/population_criteria.rb +75 -0
- data/lib/hqmf-parser/1.0/precondition.rb +90 -0
- data/lib/hqmf-parser/1.0/range.rb +76 -0
- data/lib/hqmf-parser/1.0/restriction.rb +162 -0
- data/lib/hqmf-parser/1.0/utilities.rb +55 -0
- data/lib/hqmf-parser/2.0/data_criteria.rb +372 -0
- data/lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb +80 -0
- data/lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb +201 -0
- data/lib/hqmf-parser/2.0/data_criteria_helpers/dc_post_processing.rb +85 -0
- data/lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb +117 -0
- data/lib/hqmf-parser/2.0/document.rb +304 -0
- data/lib/hqmf-parser/2.0/document_helpers/doc_population_helper.rb +173 -0
- data/lib/hqmf-parser/2.0/document_helpers/doc_utilities.rb +131 -0
- data/lib/hqmf-parser/2.0/field_value_helper.rb +251 -0
- data/lib/hqmf-parser/2.0/population_criteria.rb +134 -0
- data/lib/hqmf-parser/2.0/precondition.rb +73 -0
- data/lib/hqmf-parser/2.0/source_data_criteria_helper.rb +112 -0
- data/lib/hqmf-parser/2.0/types.rb +448 -0
- data/lib/hqmf-parser/2.0/utilities.rb +45 -0
- data/lib/hqmf-parser/2.0/value_set_helper.rb +104 -0
- data/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb +257 -0
- data/lib/hqmf-parser/converter/pass1/document_converter.rb +133 -0
- data/lib/hqmf-parser/converter/pass1/population_criteria_converter.rb +185 -0
- data/lib/hqmf-parser/converter/pass1/precondition_converter.rb +173 -0
- data/lib/hqmf-parser/converter/pass1/precondition_extractor.rb +201 -0
- data/lib/hqmf-parser/converter/pass1/simple_data_criteria.rb +26 -0
- data/lib/hqmf-parser/converter/pass1/simple_operator.rb +89 -0
- data/lib/hqmf-parser/converter/pass1/simple_population_criteria.rb +10 -0
- data/lib/hqmf-parser/converter/pass1/simple_precondition.rb +51 -0
- data/lib/hqmf-parser/converter/pass1/simple_restriction.rb +64 -0
- data/lib/hqmf-parser/converter/pass2/comparison_converter.rb +112 -0
- data/lib/hqmf-parser/converter/pass2/operator_converter.rb +102 -0
- data/lib/hqmf-parser/cql/data_criteria.rb +57 -0
- data/lib/hqmf-parser/cql/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb +79 -0
- data/lib/hqmf-parser/cql/data_criteria_helpers/dc_post_processing.rb +43 -0
- data/lib/hqmf-parser/cql/document.rb +78 -0
- data/lib/hqmf-parser/cql/document_helpers/doc_population_helper.rb +124 -0
- data/lib/hqmf-parser/cql/value_set_helper.rb +103 -0
- data/lib/hqmf-parser/parser.rb +100 -0
- data/lib/qrda-export/catI-r5/qrda1_r5.rb +125 -0
- data/lib/qrda-export/helper/cat_1_view_helper.rb +142 -0
- data/lib/qrda-export/helper/code_system_helper.rb +77 -0
- data/lib/qrda-export/helper/date_helper.rb +81 -0
- data/lib/qrda-import/base-importers/demographics_importer.rb +47 -0
- data/lib/qrda-import/base-importers/medication_importer.rb +22 -0
- data/lib/qrda-import/base-importers/section_importer.rb +196 -0
- data/lib/qrda-import/cda_identifier.rb +19 -0
- data/lib/qrda-import/data-element-importers/adverse_event_importer.rb +23 -0
- data/lib/qrda-import/data-element-importers/allergy_intolerance_importer.rb +21 -0
- data/lib/qrda-import/data-element-importers/assessment_performed_importer.rb +23 -0
- data/lib/qrda-import/data-element-importers/communication_from_patient_to_provider_importer.rb +18 -0
- data/lib/qrda-import/data-element-importers/communication_from_provider_to_patient_importer.rb +18 -0
- data/lib/qrda-import/data-element-importers/communication_from_provider_to_provider_importer.rb +20 -0
- data/lib/qrda-import/data-element-importers/device_applied_importer.rb +23 -0
- data/lib/qrda-import/data-element-importers/device_order_importer.rb +18 -0
- data/lib/qrda-import/data-element-importers/diagnosis_importer.rb +23 -0
- data/lib/qrda-import/data-element-importers/diagnostic_study_order_importer.rb +20 -0
- data/lib/qrda-import/data-element-importers/diagnostic_study_performed_importer.rb +30 -0
- data/lib/qrda-import/data-element-importers/encounter_order_importer.rb +20 -0
- data/lib/qrda-import/data-element-importers/encounter_performed_importer.rb +41 -0
- data/lib/qrda-import/data-element-importers/immunization_administered_importer.rb +18 -0
- data/lib/qrda-import/data-element-importers/intervention_order_importer.rb +18 -0
- data/lib/qrda-import/data-element-importers/intervention_performed_importer.rb +22 -0
- data/lib/qrda-import/data-element-importers/laboratory_test_order_importer.rb +20 -0
- data/lib/qrda-import/data-element-importers/laboratory_test_performed_importer.rb +28 -0
- data/lib/qrda-import/data-element-importers/medication_active_importer.rb +17 -0
- data/lib/qrda-import/data-element-importers/medication_administered_importer.rb +17 -0
- data/lib/qrda-import/data-element-importers/medication_discharge_importer.rb +19 -0
- data/lib/qrda-import/data-element-importers/medication_dispensed_importer.rb +19 -0
- data/lib/qrda-import/data-element-importers/medication_order_importer.rb +16 -0
- data/lib/qrda-import/data-element-importers/patient_characteristic_expired.rb +21 -0
- data/lib/qrda-import/data-element-importers/physical_exam_performed_importer.rb +26 -0
- data/lib/qrda-import/data-element-importers/procedure_order_importer.rb +26 -0
- data/lib/qrda-import/data-element-importers/procedure_performed_importer.rb +34 -0
- data/lib/qrda-import/data-element-importers/substance_administered_importer.rb +16 -0
- data/lib/qrda-import/entry_finder.rb +20 -0
- data/lib/qrda-import/entry_package.rb +16 -0
- data/lib/qrda-import/narrative_reference_handler.rb +33 -0
- data/lib/qrda-import/patient_importer.rb +105 -0
- data/lib/util/code_system_helper.rb +76 -0
- data/lib/util/counter.rb +20 -0
- data/lib/util/hqmf_template_helper.rb +39 -0
- metadata +340 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
|
5
|
+
class SimpleDataCriteria < HQMF::DataCriteria
|
6
|
+
|
7
|
+
attr_accessor :precondition_id
|
8
|
+
|
9
|
+
def self.from_data_criteria(data_criteria)
|
10
|
+
HQMF::Converter::SimpleDataCriteria.new(data_criteria.id, data_criteria.title, data_criteria.display_name, data_criteria.description, data_criteria.code_list_id,
|
11
|
+
data_criteria.children_criteria, data_criteria.derivation_operator, data_criteria.definition,data_criteria.status, data_criteria.value, data_criteria.field_values,
|
12
|
+
data_criteria.effective_time, data_criteria.inline_code_list,data_criteria.negation,data_criteria.negation_code_list_id,data_criteria.temporal_references, data_criteria.subset_operators, data_criteria.specific_occurrence,data_criteria.specific_occurrence_const)
|
13
|
+
end
|
14
|
+
|
15
|
+
def assign_precondition(precondtion_id)
|
16
|
+
return if (@precondtion_id == precondtion_id)
|
17
|
+
raise "Cannot assign a second precondition to a data criteria" if @precondition_id
|
18
|
+
@precondition_id = precondtion_id
|
19
|
+
@id = "#{@id}_precondition_#{precondtion_id}"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
|
5
|
+
class SimpleOperator
|
6
|
+
|
7
|
+
TEMPORAL = 'TEMPORAL'
|
8
|
+
SUMMARY = 'SUMMARY'
|
9
|
+
UNKNOWN = 'UNKNOWN'
|
10
|
+
|
11
|
+
VALUE_FIELD_TIMES = {
|
12
|
+
'FACILITY_LOCATION_START' => 'FACILITY_LOCATION_ARRIVAL_DATETIME',
|
13
|
+
'FACILITY_LOCATION_END' => 'FACILITY_LOCATION_DEPARTURE_DATETIME'
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
attr_accessor :type, :value, :category, :field, :field_code, :field_time
|
18
|
+
|
19
|
+
def initialize(category, type, value, field = nil, field_code=nil, field_time=nil)
|
20
|
+
@category = category
|
21
|
+
@type = type
|
22
|
+
@value = value
|
23
|
+
@field = field
|
24
|
+
@field_code = field_code
|
25
|
+
@field_time = field_time
|
26
|
+
end
|
27
|
+
|
28
|
+
def temporal?
|
29
|
+
category == TEMPORAL
|
30
|
+
end
|
31
|
+
def summary?
|
32
|
+
category == SUMMARY
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_json
|
36
|
+
json = {}
|
37
|
+
json[:category] = @category if @category
|
38
|
+
json[:type] = @type if @type
|
39
|
+
json[:field] = @field if @field
|
40
|
+
json[:field_code] = @field_code if @field_code
|
41
|
+
json[:value] = @value.to_json if @value
|
42
|
+
json
|
43
|
+
end
|
44
|
+
|
45
|
+
def field_value_key
|
46
|
+
key = HQMF::DataCriteria::VALUE_FIELDS[field_code]
|
47
|
+
key = VALUE_FIELD_TIMES["#{key}_#{field_time.to_s.upcase}"] if (field_time)
|
48
|
+
raise "unsupported field value: #{field_code}, #{field}" unless key
|
49
|
+
key
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.parse_value(value)
|
53
|
+
return nil unless value
|
54
|
+
return value if value.is_a? String
|
55
|
+
if (value[:value])
|
56
|
+
# values should be inclusive since we will be asking if it equals the value, ranther than being part of a range
|
57
|
+
# if it's an offset we do not care that it is inclusive
|
58
|
+
val = HQMF::Value.from_json(JSON.parse(value.to_json))
|
59
|
+
val.inclusive=true
|
60
|
+
val
|
61
|
+
elsif (value[:high] or value[:low])
|
62
|
+
HQMF::Range.from_json(JSON.parse(value.to_json))
|
63
|
+
elsif (value[:type] == 'CD')
|
64
|
+
HQMF::Coded.from_json(JSON.parse(value.to_json))
|
65
|
+
elsif (value[:type] == 'ANYNonNull')
|
66
|
+
HQMF::AnyValue.from_json(JSON.parse(value.to_json))
|
67
|
+
else
|
68
|
+
raise "Unexpected value format: #{value.to_json}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.find_category(type)
|
73
|
+
return TEMPORAL if HQMF::TemporalReference::TYPES.include? type
|
74
|
+
return SUMMARY if HQMF::SubsetOperator::TYPES.include? type
|
75
|
+
return UNKNOWN
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
|
5
|
+
class SimplePrecondition < HQMF::Precondition
|
6
|
+
|
7
|
+
COMPARISON = "COMPARISON"
|
8
|
+
PRECONDITION = "PRECONDITION"
|
9
|
+
|
10
|
+
attr_accessor :klass, :processed, :subset_comparison, :conjunction_code
|
11
|
+
|
12
|
+
def initialize(id, preconditions,reference,conjunction_code,negation)
|
13
|
+
super(id, preconditions,reference,conjunction_code,negation)
|
14
|
+
@id = HQMF::Counter.instance.next if (@id.nil?)
|
15
|
+
@klass = PRECONDITION
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_json
|
19
|
+
json = super
|
20
|
+
# json[:klass] = @klass
|
21
|
+
json
|
22
|
+
end
|
23
|
+
|
24
|
+
def comparison?
|
25
|
+
@klass == COMPARISON
|
26
|
+
end
|
27
|
+
def restriction?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_preconditions?
|
32
|
+
preconditions and !preconditions.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def restrictions
|
36
|
+
preconditions.select {|precondition| precondition.restriction?}
|
37
|
+
end
|
38
|
+
|
39
|
+
def reference=(reference)
|
40
|
+
@reference = reference
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_converted_restrictions!
|
44
|
+
preconditions.delete_if {|precondition| precondition.restriction? and precondition.converted}
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
|
5
|
+
class SimpleRestriction
|
6
|
+
|
7
|
+
include HQMF::Conversion::Utilities
|
8
|
+
|
9
|
+
attr_accessor :operator, :target, :preconditions, :negation, :converted, :generated_data_criteria
|
10
|
+
def initialize(operator, target, preconditions = [])
|
11
|
+
@operator = operator
|
12
|
+
@target = target
|
13
|
+
@preconditions = preconditions
|
14
|
+
end
|
15
|
+
|
16
|
+
# Create a new population criteria from a JSON hash keyed off symbols
|
17
|
+
def self.from_json(json)
|
18
|
+
raise "not implemented"
|
19
|
+
end
|
20
|
+
|
21
|
+
def klass
|
22
|
+
"RESTRICTION"
|
23
|
+
end
|
24
|
+
|
25
|
+
def comparison?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
def restriction?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_preconditions?
|
33
|
+
preconditions and !preconditions.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
def single_target?
|
37
|
+
!target.nil?
|
38
|
+
end
|
39
|
+
def multi_target?
|
40
|
+
has_preconditions?
|
41
|
+
end
|
42
|
+
|
43
|
+
def restrictions
|
44
|
+
preconditions.select {|precondition| precondition.restriction?}
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_json
|
48
|
+
x = nil
|
49
|
+
json = {}
|
50
|
+
json[:klass] = klass
|
51
|
+
json[:operator] = @operator.to_json if @operator
|
52
|
+
json[:target] = @target if @target
|
53
|
+
json[:negation] = @negation if @negation
|
54
|
+
if (@preconditions)
|
55
|
+
json[:preconditions] = x if x = json_array(@preconditions)
|
56
|
+
end
|
57
|
+
json
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module HQMF
|
2
|
+
# Class for converting an HQMF 1.0 representation to an HQMF 2.0 representation
|
3
|
+
class ComparisonConverter
|
4
|
+
|
5
|
+
def initialize(data_criteria_converter)
|
6
|
+
@data_criteria_converter = data_criteria_converter
|
7
|
+
end
|
8
|
+
|
9
|
+
def convert_comparisons(population_criteria)
|
10
|
+
population_criteria.each do |population|
|
11
|
+
is_observation = population.type == HQMF::PopulationCriteria::OBSERV
|
12
|
+
walk_up_tree(population.preconditions)
|
13
|
+
rewrite_observation(population) if is_observation
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def walk_up_tree(preconditions)
|
18
|
+
preconditions.each do |precondition|
|
19
|
+
if (has_child_comparison(precondition))
|
20
|
+
walk_up_tree(precondition.preconditions)
|
21
|
+
end
|
22
|
+
if (precondition.comparison? && !precondition.processed)
|
23
|
+
new_data_criteria = nil
|
24
|
+
# duplicate the data criteria referenced by the comparision (unless it's the measurement period. we don't modify the measurement period)
|
25
|
+
if precondition.reference and precondition.reference.id != HQMF::Document::MEASURE_PERIOD_ID
|
26
|
+
data_criteria = @data_criteria_converter.v2_data_criteria_by_id[precondition.reference.id]
|
27
|
+
new_data_criteria = @data_criteria_converter.duplicate_data_criteria(data_criteria, precondition.id)
|
28
|
+
precondition.reference.id = new_data_criteria.id
|
29
|
+
end
|
30
|
+
# add restrictions to the duplicated data criteria
|
31
|
+
if precondition.has_preconditions?
|
32
|
+
restrictions = precondition.restrictions
|
33
|
+
# we want to process summary operators first since they can create new data criteria
|
34
|
+
restrictions.sort! {|left, right| (right.operator.summary? and !left.operator.summary?) ? 1 : 0 }
|
35
|
+
restrictions.each do |restriction|
|
36
|
+
operator = restriction.operator
|
37
|
+
# check if the data criteria has been changed by either a grouping addition or an operator
|
38
|
+
if (precondition.reference and (new_data_criteria == nil or new_data_criteria.id != precondition.reference.id))
|
39
|
+
new_data_criteria = @data_criteria_converter.v2_data_criteria_by_id[precondition.reference.id]
|
40
|
+
end
|
41
|
+
if (operator.temporal?)
|
42
|
+
HQMF::OperatorConverter.apply_temporal(new_data_criteria, precondition, restriction, @data_criteria_converter)
|
43
|
+
elsif(operator.summary?)
|
44
|
+
HQMF::OperatorConverter.apply_summary(new_data_criteria, precondition, restriction, @data_criteria_converter)
|
45
|
+
else
|
46
|
+
case operator.type
|
47
|
+
when 'REFR'
|
48
|
+
if operator.field.downcase == 'status'
|
49
|
+
# only set the status if we don't have one. We trust the template ID statuses more than the restrictions
|
50
|
+
new_data_criteria.status ||= operator.value.code
|
51
|
+
elsif operator.field.downcase == 'result value' or operator.field.downcase == 'result'
|
52
|
+
puts "\tREFR result value is nil: #{new_data_criteria.title}" if (operator.value.nil?)
|
53
|
+
new_data_criteria.value = operator.value
|
54
|
+
else
|
55
|
+
new_data_criteria.field_values ||= {}
|
56
|
+
new_data_criteria.field_values[operator.field_value_key] = operator.value
|
57
|
+
end
|
58
|
+
restriction.converted=true
|
59
|
+
when 'RSON'
|
60
|
+
new_data_criteria.negation_code_list_id = operator.value.code_list_id
|
61
|
+
new_data_criteria.negation=true
|
62
|
+
restriction.converted=true
|
63
|
+
when 'SUBJ'
|
64
|
+
new_data_criteria.field_values ||= {}
|
65
|
+
new_data_criteria.field_values[operator.field_value_key] = operator.value || HQMF::AnyValue.new
|
66
|
+
restriction.converted=true
|
67
|
+
else
|
68
|
+
puts "\tOperator is unknown: #{operator.type}"
|
69
|
+
restriction.converted=true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
precondition.delete_converted_restrictions!
|
74
|
+
precondition.processed = true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def has_child_comparison(node)
|
81
|
+
get_child_comparisons(node).length > 0
|
82
|
+
end
|
83
|
+
|
84
|
+
def rewrite_observation(observation)
|
85
|
+
first_comparison = get_child_comparisons(observation).first
|
86
|
+
# clear the conjunction code since this should be a comparison
|
87
|
+
first_comparison.conjunction_code = nil
|
88
|
+
|
89
|
+
# we want to pull the aggregation function off of the top level comparison
|
90
|
+
first_criteria = @data_criteria_converter.v2_data_criteria_by_id[first_comparison.reference.id]
|
91
|
+
# pop the last subset operator which should be the closest to the root of the logic tree. Add that aggregation function to the observation as the aggregator
|
92
|
+
observation.aggregator = first_criteria.subset_operators.pop.type
|
93
|
+
|
94
|
+
# we want to get rid of any AND statements at the top level. This is calculating a numeric value, not evaluating boolean logic
|
95
|
+
observation.preconditions.clear
|
96
|
+
observation.preconditions << first_comparison
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_child_comparisons(node)
|
100
|
+
values = []
|
101
|
+
node.preconditions.each do |precondition|
|
102
|
+
if (precondition.comparison?)
|
103
|
+
values << precondition
|
104
|
+
elsif precondition.preconditions
|
105
|
+
values.concat get_child_comparisons(precondition)
|
106
|
+
end
|
107
|
+
end if node.preconditions
|
108
|
+
values
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module HQMF
|
2
|
+
# Class for converting an HQMF 1.0 representation to an HQMF 2.0 representation
|
3
|
+
class OperatorConverter
|
4
|
+
|
5
|
+
def self.apply_temporal(data_criteria, precondition, restriction, data_criteria_converter)
|
6
|
+
data_criteria.temporal_references ||= []
|
7
|
+
value = restriction.operator.value
|
8
|
+
type = restriction.operator.type
|
9
|
+
temporal_reference = nil
|
10
|
+
if (restriction.single_target?)
|
11
|
+
# multiple targets appears to be the result of restrictions with restrictions
|
12
|
+
target = restriction.target
|
13
|
+
if (restriction.multi_target?)
|
14
|
+
found = false
|
15
|
+
# restrictions with restrictions can have a target that is modified by the child restrcitons
|
16
|
+
restriction.preconditions.each do |precondition|
|
17
|
+
if precondition.reference.id.start_with? target
|
18
|
+
found = true
|
19
|
+
target = precondition.reference.id
|
20
|
+
end
|
21
|
+
end
|
22
|
+
unless found
|
23
|
+
puts "\tmultiple targets... need to check this" if restriction.multi_target?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(target),value)
|
27
|
+
data_criteria_converter.validate_not_deleted(target)
|
28
|
+
elsif (restriction.multi_target?)
|
29
|
+
|
30
|
+
children_criteria = HQMF::DataCriteriaConverter.extract_data_criteria(restriction.preconditions, data_criteria_converter)
|
31
|
+
|
32
|
+
if (children_criteria.length == 1)
|
33
|
+
target = children_criteria[0].id
|
34
|
+
temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(target),value)
|
35
|
+
data_criteria_converter.validate_not_deleted(target)
|
36
|
+
else
|
37
|
+
parent_id = "GROUP"
|
38
|
+
if restriction.generated_data_criteria.nil?
|
39
|
+
# we pass in restriction.preconditions here rather than children_criteria because we need to be able to create grouping data criteria for and and or preconditions in a tree
|
40
|
+
group_criteria = data_criteria_converter.create_group_data_criteria(restriction.preconditions, "#{type}_CHILDREN", value, parent_id, HQMF::Counter.instance.next, "grouping", "temporal")
|
41
|
+
# save the generated grouping criteria so that we can reference it from other locations
|
42
|
+
restriction.generated_data_criteria = group_criteria
|
43
|
+
else
|
44
|
+
# we have already processed this restriction and have a grouping criteria for it. Take the one we have previously generated
|
45
|
+
group_criteria = restriction.generated_data_criteria
|
46
|
+
end
|
47
|
+
temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(group_criteria.id), value)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
raise "no target for temporal restriction"
|
51
|
+
end
|
52
|
+
restriction.converted=true
|
53
|
+
|
54
|
+
# add temporal reference to data criteria
|
55
|
+
data_criteria.temporal_references << temporal_reference unless data_criteria.has_temporal(temporal_reference)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def self.apply_summary(data_criteria, precondition, restriction, data_criteria_converter)
|
60
|
+
value = restriction.operator.value
|
61
|
+
type = restriction.operator.type
|
62
|
+
subset_operator = HQMF::SubsetOperator.new(type, value)
|
63
|
+
|
64
|
+
if (restriction.multi_target?)
|
65
|
+
children_criteria = HQMF::DataCriteriaConverter.extract_data_criteria(restriction.preconditions, data_criteria_converter)
|
66
|
+
|
67
|
+
data_criteria = nil
|
68
|
+
if (children_criteria.length == 1)
|
69
|
+
data_criteria = children_criteria[0]
|
70
|
+
data_criteria.subset_operators ||= []
|
71
|
+
# add subset operator to data criteria
|
72
|
+
data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator)
|
73
|
+
else
|
74
|
+
parent_id = "GROUP"
|
75
|
+
|
76
|
+
if restriction.generated_data_criteria.nil?
|
77
|
+
# we pass in restriction.preconditions here rather than children_criteria because we need to be able to create grouping data criteria for and and or preconditions in a tree
|
78
|
+
data_criteria = data_criteria_converter.create_group_data_criteria(restriction.preconditions, type, value, parent_id, HQMF::Counter.instance.next, "grouping", "summary")
|
79
|
+
# save the generated grouping criteria so that we can reference it from other locations
|
80
|
+
restriction.generated_data_criteria = data_criteria
|
81
|
+
else
|
82
|
+
# we have already processed this restriction and have a grouping criteria for it. Take the one we have previously generated
|
83
|
+
data_criteria = restriction.generated_data_criteria
|
84
|
+
end
|
85
|
+
|
86
|
+
data_criteria.subset_operators ||= []
|
87
|
+
# add subset operator to data criteria
|
88
|
+
data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator)
|
89
|
+
end
|
90
|
+
precondition.reference = HQMF::Reference.new(data_criteria.id)
|
91
|
+
elsif (restriction.single_target?)
|
92
|
+
subset_operator = HQMF::SubsetOperator.new(type, value)
|
93
|
+
data_criteria.subset_operators ||= []
|
94
|
+
# add subset operator to data criteria
|
95
|
+
data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator)
|
96
|
+
end
|
97
|
+
|
98
|
+
restriction.converted=true
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|