Class: HQMF2::Precondition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#attr_val, attr_val, #to_xml

Methods included from HQMF::Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(entry, doc) ⇒ Precondition

Returns a new instance of Precondition.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hqmf-parser/2.0/precondition.rb', line 9

def initialize(entry, doc)
  @doc = doc
  @entry = entry
  @preconditions = @entry.xpath('./*/cda:precondition', HQMF2::Document::NAMESPACES).collect do |precondition|
    Precondition.new(precondition, @doc)
  end
  reference_def = @entry.at_xpath('./*/cda:id', HQMF2::Document::NAMESPACES)
  if !reference_def
    reference_def = @entry.at_xpath('./cda:join/cda:templateId/cda:item', HQMF2::Document::NAMESPACES)
  end
  if reference_def
    @reference = Reference.new(reference_def)
  end
end

Instance Attribute Details

#preconditionsObject (readonly)

Returns the value of attribute preconditions.



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

def preconditions
  @preconditions
end

#referenceObject (readonly)

Returns the value of attribute reference.



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

def reference
  @reference
end

Instance Method Details

#conjunction?Boolean

Return true of this precondition represents a conjunction with nested preconditions or false of this precondition is a reference to a data criteria

Returns:

  • (Boolean)


26
27
28
# File 'lib/hqmf-parser/2.0/precondition.rb', line 26

def conjunction?
  @preconditions.length>0
end

#conjunction_codeString

Get the conjunction code, e.g. allTrue, allFalse

Returns:

  • (String)

    conjunction code



32
33
34
35
36
37
38
# File 'lib/hqmf-parser/2.0/precondition.rb', line 32

def conjunction_code
  if conjunction?
    @entry.at_xpath('./*[1]', HQMF2::Document::NAMESPACES).name
  else
    nil
  end
end

#to_modelObject



40
41
42
43
44
# File 'lib/hqmf-parser/2.0/precondition.rb', line 40

def to_model
  pcs = preconditions.collect {|p| p.to_model}
  mr = reference ? reference.to_model : nil
  HQMF::Precondition.new(nil, pcs, mr, conjunction_code, false)
end