Class: HQMF1::Precondition

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/hqmf-parser/1.0/precondition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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) ⇒ 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
32
# 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
  check_nil_conjunction_on_child
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



7
8
9
# File 'lib/hqmf-parser/1.0/precondition.rb', line 7

def expression
  @expression
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/hqmf-parser/1.0/precondition.rb', line 7

def id
  @id
end

#preconditionsObject (readonly)

Returns the value of attribute preconditions.



7
8
9
# File 'lib/hqmf-parser/1.0/precondition.rb', line 7

def preconditions
  @preconditions
end

#restrictionsObject (readonly)

Returns the value of attribute restrictions.



7
8
9
# File 'lib/hqmf-parser/1.0/precondition.rb', line 7

def restrictions
  @restrictions
end

#subsetObject (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

#comparisonObject



54
55
56
57
58
59
60
# File 'lib/hqmf-parser/1.0/precondition.rb', line 54

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

#conjunctionString

Get the conjunction code, e.g. AND, OR

Returns:

  • (String)

    conjunction code



36
37
38
# File 'lib/hqmf-parser/1.0/precondition.rb', line 36

def conjunction
  attr_val('./cda:conjunctionCode/@code')
end

#first_comparisonObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/hqmf-parser/1.0/precondition.rb', line 62

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

#negationObject

Return whether the precondition is negated (true) or not (false)



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hqmf-parser/1.0/precondition.rb', line 41

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_jsonObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/hqmf-parser/1.0/precondition.rb', line 76

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