Class: HQMF1::Precondition
- Inherits:
-
Object
- Object
- HQMF1::Precondition
- Includes:
- Utilities
- Defined in:
- lib/hqmf-parser/1.0/precondition.rb
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#preconditions ⇒ Object
readonly
Returns the value of attribute preconditions.
-
#restrictions ⇒ Object
readonly
Returns the value of attribute restrictions.
-
#subset ⇒ Object
readonly
Returns the value of attribute subset.
Instance Method Summary collapse
- #comparison ⇒ Object
-
#conjunction ⇒ String
Get the conjunction code, e.g.
- #first_comparison ⇒ Object
-
#initialize(entry, parent, doc) ⇒ Precondition
constructor
A new instance of Precondition.
-
#negation ⇒ Object
Return whether the precondition is negated (true) or not (false).
- #to_json ⇒ Object
Methods included from Utilities
#attr_val, #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) ⇒ Precondition
Returns a new instance of Precondition.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 9 def initialize(entry, parent, doc) @doc = doc @entry = entry @id = attr_val('./*/cda:id/@root') @restrictions = [] local_subset = attr_val('./cda:subsetCode/@code') if local_subset @subset = local_subset end #@subset = attr_val('./cda:subsetCode/@code') local_restrictions = @entry.xpath('./*/cda:sourceOf[@typeCode!="PRCN" and @typeCode!="COMP"]').collect do |entry| Restriction.new(entry, self, @doc) end @restrictions.concat(local_restrictions) @expression = Expression.new(@entry) if @entry.at_xpath('./*/cda:derivationExpr') @preconditions = @entry.xpath('./*/cda:sourceOf[@typeCode="PRCN"]').collect do |entry| Precondition.new(entry, self, @doc) end end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
7 8 9 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 7 def expression @expression end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 7 def id @id end |
#preconditions ⇒ Object (readonly)
Returns the value of attribute preconditions.
7 8 9 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 7 def preconditions @preconditions end |
#restrictions ⇒ Object (readonly)
Returns the value of attribute restrictions.
7 8 9 |
# File 'lib/hqmf-parser/1.0/precondition.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/precondition.rb', line 7 def subset @subset end |
Instance Method Details
#comparison ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 53 def comparison comparison_def = @entry.at_xpath('./*/cda:sourceOf[@typeCode="COMP"]') if comparison_def data_criteria_id = attr_val('./*/cda:id/@root') @comparison = Comparison.new(data_criteria_id, comparison_def, self, @doc) end end |
#conjunction ⇒ String
Get the conjunction code, e.g. AND, OR
35 36 37 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 35 def conjunction attr_val('./cda:conjunctionCode/@code') end |
#first_comparison ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 61 def first_comparison if comparison return comparison elsif @preconditions @preconditions.each do |precondition| first = precondition.first_comparison if first return first end end end return nil end |
#negation ⇒ Object
Return whether the precondition is negated (true) or not (false)
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 40 def negation if @entry.at_xpath('./cda:act[@actionNegationInd="true"]') is_negation_rationale = (comparison.restrictions.map {|restriction| restriction.type }).include? 'RSON' if comparison if is_negation_rationale false else true end else false end end |
#to_json ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/hqmf-parser/1.0/precondition.rb', line 75 def to_json json = build_hash(self, [:id,:conjunction,:negation,:subset]) json[:comparison] = self.comparison.to_json if self.comparison json[:expression] = self.expression.to_json if self.expression json[:preconditions] = json_array(self.preconditions) json[:restrictions] = json_array(self.restrictions) json end |