class HQMF2::Precondition

Represents the logic that defines grouping of criteria and actions done on it.

Attributes

conjunction[R]
id[R]
preconditions[R]
reference[R]

Public Class Methods

handle_aggregation(id_generator, reference, preconditions, aggregation, conjunction = nil) click to toggle source

“False” aggregators exist, and require special handling, so this manages that and returns the

proper precondition.
# File lib/hqmf-parser/2.0/precondition.rb, line 34
def self.handle_aggregation(id_generator, reference, preconditions, aggregation, conjunction = nil)
  negation = false
  conjunction = aggregation.name
  case conjunction
  # DeMorgan's law is used to handle negated caes: e.g. to find if all are false, negate the "at least one true"
  # check.
  when 'allFalse'
    negation = true
    conjunction = 'atLeastOneTrue'
  when 'atLeastOneFalse'
    negation = true
    conjunction = 'allTrue'
  end
  # Return the proper precondition given if a negation exists
  if negation
    # Wrap the negation in a seperate precondition which this will reference
    precondition_wrapper = new(id_generator.next_id, conjunction, preconditions, true, reference)
    new(id_generator.next_id, conjunction, [precondition_wrapper])
  else
    new(id_generator.next_id, conjunction, preconditions, false, reference)
  end
end
new(id, conjunction, preconditions = [], negation = false, reference = nil) click to toggle source
# File lib/hqmf-parser/2.0/precondition.rb, line 57
def initialize(id, conjunction, preconditions = [], negation = false, reference = nil)
  @preconditions = preconditions || []
  @conjunction = conjunction
  @reference = reference
  @negation = negation
  @id = id
end
parse(entry, doc, id_generator) click to toggle source
# File lib/hqmf-parser/2.0/precondition.rb, line 8
def self.parse(entry, doc, id_generator)
  doc = doc
  entry = entry
  aggregation = entry.at_xpath('./cda:allTrue | ./cda:atLeastOneTrue | ./cda:allFalse | ./cda:atLeastOneFalse',
                               HQMF2::Document::NAMESPACES)

  # Sets the reference criteria for the precondition (if it exists)
  reference_def = entry.at_xpath('./*/cda:id', HQMF2::Document::NAMESPACES)
  reference_def ||= entry.at_xpath('./cda:join/cda:templateId/cda:item', HQMF2::Document::NAMESPACES)
  reference = Reference.new(reference_def) if reference_def

  # Unless there is an aggregator, no further actions are necessary.
  return new(id_generator.next_id, nil, [], false, reference) unless aggregation

  precondition_entries = entry.xpath('./*/cda:precondition', HQMF2::Document::NAMESPACES)
  preconditions = precondition_entries.collect do |precondition|
    precondition = Precondition.parse(precondition, doc, id_generator)
    # There are cases where a precondition may contain no references or preconditions, and should be ignored.
    precondition.reference.nil? && precondition.preconditions.empty? ? nil : precondition
  end
  preconditions.compact!
  handle_aggregation(id_generator, reference, preconditions, aggregation)
end

Public Instance Methods

to_model() click to toggle source

Generates this classes hqmf-model equivalent

# File lib/hqmf-parser/2.0/precondition.rb, line 66
def to_model
  pcs = @preconditions.collect(&:to_model)
  mr = @reference ? @reference.to_model : nil
  cc = @conjunction
  HQMF::Precondition.new(@id, pcs, mr, cc, @negation)
end