Class: HQMF1::Restriction
- Inherits:
-
Object
- Object
- HQMF1::Restriction
- Includes:
- Utilities
- Defined in:
- lib/hqmf-parser/1.0/restriction.rb
Overview
Represents a restriction on the allowable values of a data item
Instance Attribute Summary collapse
-
#comparison ⇒ Object
readonly
Returns the value of attribute comparison.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#from_parent ⇒ Object
Returns the value of attribute from_parent.
-
#preconditions ⇒ Object
readonly
Returns the value of attribute preconditions.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#restrictions ⇒ Object
readonly
Returns the value of attribute restrictions.
-
#subset ⇒ Object
readonly
Returns the value of attribute subset.
Instance Method Summary collapse
- #field ⇒ Object
- #field_code ⇒ Object
- #field_time ⇒ Object
-
#initialize(entry, parent, doc) ⇒ Restriction
constructor
A new instance of Restriction.
-
#negation ⇒ Object
is this type negated? true or false.
-
#target_id ⇒ Object
The id of the data criteria or measurement property that the value will be compared against.
- #to_json ⇒ Object
-
#type ⇒ Object
The type of restriction, e.g.
- #value ⇒ Object
Methods included from Utilities
#attr_val, #check_nil_conjunction_on_child, #clean_json, #clean_json_recursive
Methods included from HQMF::Conversion::Utilities
#build_hash, #check_equality, #json_array, #openstruct_to_json
Constructor Details
#initialize(entry, parent, doc) ⇒ Restriction
Returns a new instance of Restriction.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 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 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 10 def initialize(entry, parent, doc) @doc = doc @entry = entry @restrictions = [] range_def = @entry.at_xpath('./cda:pauseQuantity') if range_def @range = Range.new(range_def) end local_restrictions = @entry.xpath('./*/cda:sourceOf[@typeCode!="PRCN" and @typeCode!="COMP"]').collect do |entry| Restriction.new(entry, self, @doc) end @restrictions.concat(local_restrictions) local_subset = attr_val('./cda:subsetCode/@code') if local_subset @subset = local_subset end if @entry.at_xpath('./*/cda:derivationExpr') @expression = Expression.new(@entry) end comparison_def = @entry.at_xpath('./*/cda:sourceOf[@typeCode="COMP"]') if comparison_def data_criteria_id = attr_val('./*/cda:id/@root') data_criteria_id = comparison_def.at_xpath('./*/cda:id/@root').value if (data_criteria_id.nil? and comparison_def.at_xpath('./*/cda:id/@root')) @comparison = Comparison.new(data_criteria_id, comparison_def, self, @doc) end @preconditions = @entry.xpath('./*/cda:sourceOf[@typeCode="PRCN"]').collect do |entry| # create a dummy parent with a single restriction copied from self minus the # nested preconditions to avoid an infinite loop prior_comparison = nil if parent.class==HQMF1::Precondition prior_comparison = parent.first_comparison else prior_comparison = @comparsion end current_restriction = OpenStruct.new( 'range' => @range, 'comparison' => prior_comparison, 'restrictions' => [], 'preconditions' => [], 'subset' => @subset, 'type' => type, 'target_id' => target_id, 'field' => field, 'field_code' => field_code, 'field_time' => field_time, 'value' => value) all_restrictions = [] all_restrictions.concat @restrictions all_restrictions << current_restriction parent = OpenStruct.new( 'restrictions' => all_restrictions, 'subset' => @subset ) p = Precondition.new(entry, parent, @doc) end check_nil_conjunction_on_child end |
Instance Attribute Details
#comparison ⇒ Object (readonly)
Returns the value of attribute comparison.
7 8 9 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 7 def comparison @comparison end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
7 8 9 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 7 def expression @expression end |
#from_parent ⇒ Object
Returns the value of attribute from_parent.
8 9 10 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 8 def from_parent @from_parent end |
#preconditions ⇒ Object (readonly)
Returns the value of attribute preconditions.
7 8 9 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 7 def preconditions @preconditions end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
7 8 9 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 7 def range @range end |
#restrictions ⇒ Object (readonly)
Returns the value of attribute restrictions.
7 8 9 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 7 def restrictions @restrictions end |
#subset ⇒ Object (readonly)
Returns the value of attribute subset.
7 8 9 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 7 def subset @subset end |
Instance Method Details
#field ⇒ Object
94 95 96 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 94 def field attr_val('./cda:observation/cda:code/@displayName') end |
#field_code ⇒ Object
98 99 100 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 98 def field_code attr_val('./cda:observation/cda:code/@code') || attr_val('./cda:encounter/cda:participant/cda:roleParticipant/@classCode') end |
#field_time ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 102 def field_time effectiveTime = @entry.at_xpath('./cda:observation/cda:effectiveTime') || @entry.at_xpath('./cda:encounter/cda:participant/cda:roleParticipant/cda:effectiveTime') time = nil if effectiveTime time = :start if effectiveTime.at_xpath('./cda:low') time = :end if effectiveTime.at_xpath('./cda:high') end time end |
#negation ⇒ Object
is this type negated? true or false
84 85 86 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 84 def negation attr_val('./@inversionInd') == "true" end |
#target_id ⇒ Object
The id of the data criteria or measurement property that the value will be compared against
90 91 92 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 90 def target_id attr_val('./*/cda:id/@root') end |
#to_json ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 143 def to_json return nil if from_parent json = build_hash(self, [:subset,:type,:target_id,:field,:field_code,:from_parent, :negation, :field_time]) json[:range] = range.to_json if range if value if value.is_a? String json[:value] = value else json[:value] = value.to_json end end json[:comparison] = comparison.to_json if comparison json[:restrictions] = json_array(self.restrictions) json[:preconditions] = json_array(self.preconditions) json[:expression] = self.expression.to_json if self.expression json end |
#type ⇒ Object
The type of restriction, e.g. SBS, SBE etc
79 80 81 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 79 def type attr_val('./@typeCode') end |
#value ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/hqmf-parser/1.0/restriction.rb', line 114 def value value = nil type = attr_val('./cda:observation/cda:value/@xsi:type') || 'CD' case type when 'IVL_PQ' value = HQMF1::Range.new(@entry.xpath('./cda:observation/cda:value')) when 'PQ' value = HQMF1::Value.new(@entry.xpath('./cda:observation/cda:value')) when 'CD' if field && field.downcase == 'status' code = attr_val('./cda:observation/cda:value/@displayName').downcase value = HQMF::Coded.for_single_code('status',code,code) elsif attr_val('./cda:observation/cda:value/@code') oid = attr_val('./cda:observation/cda:value/@code') title = attr_val('./cda:observation/cda:value/@displayName') value = HQMF::Coded.for_code_list(oid,title) elsif attr_val('./cda:encounter/cda:participant/cda:roleParticipant/cda:code/@code') oid = attr_val('./cda:encounter/cda:participant/cda:roleParticipant/cda:code/@code') title = attr_val('./cda:encounter/cda:participant/cda:roleParticipant/cda:code/@displayName') value = HQMF::Coded.for_code_list(oid,title) end when 'ANYNonNull' value = HQMF::AnyValue.new else raise "Unknown restriction value type #{type}" end if type value end |