Class: SimpleXml::DataCriteria
- Inherits:
-
Object
- Object
- SimpleXml::DataCriteria
- Includes:
- Utilities
- Defined in:
- lib/model/data_criteria.rb
Overview
Represents a data criteria specification
Constant Summary
Constants included from Utilities
Utilities::MEASURE_ATTRIBUTES_MAP
Instance Attribute Summary collapse
-
#children_criteria ⇒ Object
Returns the value of attribute children_criteria.
-
#code_list_id ⇒ Object
readonly
Returns the value of attribute code_list_id.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#derivation_operator ⇒ Object
Returns the value of attribute derivation_operator.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#display_name ⇒ Object
readonly
Returns the value of attribute display_name.
-
#effective_time ⇒ Object
readonly
Returns the value of attribute effective_time.
-
#field_values ⇒ Object
Returns the value of attribute field_values.
-
#hqmf_id ⇒ Object
readonly
Returns the value of attribute hqmf_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#inline_code_list ⇒ Object
readonly
Returns the value of attribute inline_code_list.
-
#negation ⇒ Object
Returns the value of attribute negation.
-
#negation_code_list_id ⇒ Object
Returns the value of attribute negation_code_list_id.
-
#source_data_criteria ⇒ Object
readonly
Returns the value of attribute source_data_criteria.
-
#specific_occurrence ⇒ Object
Returns the value of attribute specific_occurrence.
-
#specific_occurrence_const ⇒ Object
Returns the value of attribute specific_occurrence_const.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#subset_operators ⇒ Object
Returns the value of attribute subset_operators.
-
#temporal_references ⇒ Object
Returns the value of attribute temporal_references.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#value ⇒ Object
Returns the value of attribute value.
-
#variable ⇒ Object
readonly
Returns the value of attribute variable.
Class Method Summary collapse
- .convert_precondition_to_criteria(precondition, doc, operator) ⇒ Object
- .convert_to_grouping(precondition, doc, operator) ⇒ Object
- .format_so_const(description) ⇒ Object
- .get_criteria(element, precondition_id, doc, subset = nil, operator = nil, update_id = false) ⇒ Object
- .translate_field(name) ⇒ Object
Instance Method Summary collapse
- #add_temporal(temporal) ⇒ Object
- #create_criteria(entry, id) ⇒ Object
- #create_grouping_criteria(id) ⇒ Object
- #dup ⇒ Object
- #handle_specific_occurrence(instance) ⇒ Object
-
#initialize(entry, id = nil) ⇒ DataCriteria
constructor
Create a new instance based on the supplied HQMF entry.
- #push_down_temporal(temporal, doc) ⇒ Object
- #to_model ⇒ Object
Methods included from Utilities
#attr_val, attr_val, build_value, #children_of, #comments_on, #create_age_timing, #create_birthdate_criteria
Constructor Details
#initialize(entry, id = nil) ⇒ DataCriteria
Create a new instance based on the supplied HQMF entry
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/model/data_criteria.rb', line 16 def initialize(entry, id=nil) @entry = entry if (@entry) create_criteria(@entry, id) else create_grouping_criteria(id) end @source_data_criteria = @id @negation = false # the following remain nil: # @display_name, @children_criteria, @derivation_operator, @value, @field_values, # @effective_time , @inline_code_list, @negation_code_list_id, @temporal_references, @subset_operators end |
Instance Attribute Details
#children_criteria ⇒ Object
Returns the value of attribute children_criteria.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def children_criteria @children_criteria end |
#code_list_id ⇒ Object (readonly)
Returns the value of attribute code_list_id.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def code_list_id @code_list_id end |
#comments ⇒ Object
Returns the value of attribute comments.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def comments @comments end |
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def definition @definition end |
#derivation_operator ⇒ Object
Returns the value of attribute derivation_operator.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def derivation_operator @derivation_operator end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def description @description end |
#display_name ⇒ Object (readonly)
Returns the value of attribute display_name.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def display_name @display_name end |
#effective_time ⇒ Object (readonly)
Returns the value of attribute effective_time.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def effective_time @effective_time end |
#field_values ⇒ Object
Returns the value of attribute field_values.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def field_values @field_values end |
#hqmf_id ⇒ Object (readonly)
Returns the value of attribute hqmf_id.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def hqmf_id @hqmf_id end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def id @id end |
#inline_code_list ⇒ Object (readonly)
Returns the value of attribute inline_code_list.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def inline_code_list @inline_code_list end |
#negation ⇒ Object
Returns the value of attribute negation.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def negation @negation end |
#negation_code_list_id ⇒ Object
Returns the value of attribute negation_code_list_id.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def negation_code_list_id @negation_code_list_id end |
#source_data_criteria ⇒ Object (readonly)
Returns the value of attribute source_data_criteria.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def source_data_criteria @source_data_criteria end |
#specific_occurrence ⇒ Object
Returns the value of attribute specific_occurrence.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def specific_occurrence @specific_occurrence end |
#specific_occurrence_const ⇒ Object
Returns the value of attribute specific_occurrence_const.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def specific_occurrence_const @specific_occurrence_const end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def status @status end |
#subset_operators ⇒ Object
Returns the value of attribute subset_operators.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def subset_operators @subset_operators end |
#temporal_references ⇒ Object
Returns the value of attribute temporal_references.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def temporal_references @temporal_references end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def title @title end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/model/data_criteria.rb', line 5 def value @value end |
#variable ⇒ Object (readonly)
Returns the value of attribute variable.
8 9 10 |
# File 'lib/model/data_criteria.rb', line 8 def variable @variable end |
Class Method Details
.convert_precondition_to_criteria(precondition, doc, operator) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/model/data_criteria.rb', line 133 def self.convert_precondition_to_criteria(precondition, doc, operator) if (precondition.reference) # precondition is a single element criteria = doc.data_criteria(precondition.reference.id) else # precondition is a group criteria = convert_to_grouping(precondition, doc, operator) doc.derived_data_criteria << criteria end criteria end |
.convert_to_grouping(precondition, doc, operator) ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/model/data_criteria.rb', line 145 def self.convert_to_grouping(precondition, doc, operator) grouping = DataCriteria.new nil, "GROUP_#{operator}_CHILDREN_#{HQMF::Counter.instance.next}" grouping.children_criteria = precondition.preconditions.map {|p| convert_precondition_to_criteria(p, doc, operator).id} grouping.derivation_operator = case precondition.conjunction_code when HQMF::Precondition::ALL_TRUE then HQMF::DataCriteria::XPRODUCT when SimpleXml::Precondition::INTERSECTION then HQMF::DataCriteria::INTERSECT else HQMF::DataCriteria::UNION end grouping end |
.format_so_const(description) ⇒ Object
210 211 212 |
# File 'lib/model/data_criteria.rb', line 210 def self.format_so_const(description) description.gsub(/\W/,' ').upcase.split.join('_') end |
.get_criteria(element, precondition_id, doc, subset = nil, operator = nil, update_id = false) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 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/model/data_criteria.rb', line 74 def self.get_criteria(element, precondition_id, doc, subset=nil, operator=nil, update_id=false) if element.name == Precondition::TEMPORAL_OP # we have a chain of temporal references criteria = convert_precondition_to_criteria(Precondition.new(element, doc), doc, operator) elsif element.name == Precondition::LOGICAL_OP || element.name == Precondition::SET_OP # we have a logical group on the right criteria = convert_precondition_to_criteria(Precondition.new(element, doc), doc, operator) elsif element.name == Precondition::FUNCTIONAL_OP criteria = doc.data_criteria(Precondition.new(element, doc).reference.id) else criteria = doc.criteria_map[element.at_xpath('@id').value] if !criteria && element.name == Precondition::SUB_TREE criteria = doc.sub_tree_map[Utilities.attr_val(element, '@id')].convert_to_data_criteria # If this is a specific occurrence of a variable it won't appear in the elementLookUp, so include it in source data criteria here if criteria.specific_occurrence && criteria.variable doc.register_source_data_criteria(criteria) end end criteria = criteria.dup return criteria if criteria.id == HQMF::Document::MEASURE_PERIOD_ID # if we have attributes then we want to update the ID sice we have changed the DC attributes = element.xpath('attribute') update_id = update_id || !attributes.empty? criteria.id = "#{criteria.id}_precondition_#{precondition_id}" if update_id doc.derived_data_criteria << criteria unless doc.derived_data_criteria.map(&:id).include? criteria.id # handle attributes if (attributes) attributes.each do |attribute| orig_key = attribute.at_xpath('@name').value key = DataCriteria.translate_field(orig_key) value = Attribute.translate_attribute(attribute, doc) if key == 'RESULT' criteria.value = value elsif key == 'NEGATION_RATIONALE' criteria.negation = true criteria.negation_code_list_id = value.code_list_id else criteria.field_values ||= {} criteria.field_values[key] = value end end end end if subset criteria.subset_operators ||= [] criteria.subset_operators << subset end criteria end |
.translate_field(name) ⇒ Object
187 188 189 190 191 |
# File 'lib/model/data_criteria.rb', line 187 def self.translate_field(name) name = name.tr(' ','_').upcase raise "Unknown field name: #{name}" unless HQMF::DataCriteria::FIELDS[name] || name == 'RESULT' || name == 'NEGATION_RATIONALE' name end |
Instance Method Details
#add_temporal(temporal) ⇒ Object
164 165 166 167 |
# File 'lib/model/data_criteria.rb', line 164 def add_temporal(temporal) @temporal_references ||= [] @temporal_references << temporal end |
#create_criteria(entry, id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/model/data_criteria.rb', line 33 def create_criteria(entry, id) @entry = entry type = attr_val('@datatype') name = attr_val('@name') instance = attr_val('@instance') @description = "#{type}: #{name}" @title = name @code_list_id = attr_val('@oid') @hqmf_id = attr_val('@uuid') parts = type.split(',') def_and_status = parse_definition_and_status(type) @definition = def_and_status[:definition] @status = def_and_status[:status] specifics_counter = nil if instance fix_description_for_hqmf_match() specifics_counter = HQMF::Counter.instance.next @specific_occurrence = instance.split[1] @specific_occurrence_const = DataCriteria.format_so_const(@description) @id = id || format_id("#{instance} #{@title}#{specifics_counter}") else @id = id || format_id("#{@description}") end handle_transfer() if (['transfer_from', 'transfer_to'].include? definition) end |
#create_grouping_criteria(id) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/model/data_criteria.rb', line 67 def create_grouping_criteria(id) @id = id @definition = 'derived' @description = "" @title = @id end |
#dup ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/model/data_criteria.rb', line 156 def dup if @entry DataCriteria.new(@entry, @id) else Marshal.load(Marshal.dump(self)) end end |
#handle_specific_occurrence(instance) ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/model/data_criteria.rb', line 179 def handle_specific_occurrence(instance) fix_description_for_hqmf_match() specifics_counter = HQMF::Counter.instance.next @specific_occurrence = instance @specific_occurrence_const = DataCriteria.format_so_const(@description) @id = id || format_id("#{instance} #{@title}#{specifics_counter}") end |
#push_down_temporal(temporal, doc) ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/model/data_criteria.rb', line 169 def push_down_temporal(temporal, doc) # push down through a grouping if @children_criteria @children_criteria.each {|child_id| doc.data_criteria(child_id).push_down_temporal(temporal, doc)} else # if this is not a grouping, just add the temporal reference add_temporal(temporal) end end |
#to_model ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/model/data_criteria.rb', line 193 def to_model trs = temporal_references.collect {|t| t.to_model} if temporal_references if field_values fv = {} field_values.each {|k, v| fv[k] = v.to_model} end val = value.to_model if value subs = subset_operators.collect {|o| o.to_model} if subset_operators @variable ||= false HQMF::DataCriteria.new(@id, @title, @display_name, @description, @code_list_id, @children_criteria, @derivation_operator, @definition, @status, val, fv, @effective_time, @inline_code_list, @negation, @negation_code_list_id, trs, subs, @specific_occurrence, @specific_occurrence_const, @source_data_criteria, comments, @variable) end |