Class: HQMF::Precondition

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

Direct Known Subclasses

Converter::SimplePrecondition

Constant Summary collapse

AT_LEAST_ONE_TRUE =
'atLeastOneTrue'
AT_LEAST_ONE_FALSE =
'atLeastOneFalse'
ALL_TRUE =
'allTrue'
ALL_FALSE =
'allFalse'
NEGATIONS =
{
  AT_LEAST_ONE_TRUE => ALL_FALSE,
  ALL_FALSE => AT_LEAST_ONE_TRUE,
  ALL_TRUE => AT_LEAST_ONE_FALSE,
  AT_LEAST_ONE_FALSE => ALL_TRUE
}
INVERSIONS =
{
  AT_LEAST_ONE_TRUE => ALL_TRUE,
  ALL_FALSE => AT_LEAST_ONE_FALSE,
  ALL_TRUE => AT_LEAST_ONE_TRUE,
  AT_LEAST_ONE_FALSE => ALL_FALSE
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(id, preconditions, reference, conjunction_code, negation, comments = nil) ⇒ Precondition

Create a new population criteria

Parameters:



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

def initialize(id, preconditions, reference, conjunction_code, negation, comments=nil)
  @preconditions = preconditions || []
  @reference = reference
  @conjunction_code = conjunction_code
  @negation = negation
  @id = id
  @comments = comments
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



25
26
27
# File 'lib/hqmf-model/precondition.rb', line 25

def comments
  @comments
end

#conjunction_codeObject (readonly)

Returns the value of attribute conjunction_code.



24
25
26
# File 'lib/hqmf-model/precondition.rb', line 24

def conjunction_code
  @conjunction_code
end

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/hqmf-model/precondition.rb', line 24

def id
  @id
end

#negationObject

Returns the value of attribute negation.



25
26
27
# File 'lib/hqmf-model/precondition.rb', line 25

def negation
  @negation
end

#preconditionsObject (readonly)

Returns the value of attribute preconditions.



24
25
26
# File 'lib/hqmf-model/precondition.rb', line 24

def preconditions
  @preconditions
end

#referenceObject (readonly)

Returns the value of attribute reference.



24
25
26
# File 'lib/hqmf-model/precondition.rb', line 24

def reference
  @reference
end

Class Method Details

.from_json(json) ⇒ Object

Create a new population criteria from a JSON hash keyed off symbols



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hqmf-model/precondition.rb', line 49

def self.from_json(json)
  preconditions = []
  id = json["id"] if json["id"]
  preconditions = json["preconditions"].map {|precondition| HQMF::Precondition.from_json(precondition)} if json["preconditions"]
  reference = Reference.new(json["reference"]) if json["reference"] 
  conjunction_code = json["conjunction_code"] if json["conjunction_code"]
  negation = json["negation"] if json["negation"]
  comments = json['comments'] if json['comments']
  
  HQMF::Precondition.new(id, preconditions, reference, conjunction_code, negation, comments)
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)


75
76
77
# File 'lib/hqmf-model/precondition.rb', line 75

def conjunction?
  @preconditions.length>0
end

#conjunction_code_with_negationObject



40
41
42
43
44
45
46
# File 'lib/hqmf-model/precondition.rb', line 40

def conjunction_code_with_negation
  if negation
    NEGATIONS[conjunction_code]
  else
    conjunction_code
  end
end

#referenced_data_criteriaObject



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/hqmf-model/precondition.rb', line 79

def referenced_data_criteria
  data_criteria_ids = []
  if @preconditions.empty?
    data_criteria_ids << self.reference.id
  else
    @preconditions.each do |precondition|
      data_criteria_ids.concat(precondition.referenced_data_criteria)
    end
  end
  data_criteria_ids
end

#to_jsonObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/hqmf-model/precondition.rb', line 61

def to_json
  x = nil
  json = {}
  json[:id] = self.id
  json[:reference] = self.reference.id if self.reference
  json[:preconditions] = x if x = json_array(@preconditions)
  json[:conjunction_code] = self.conjunction_code if self.conjunction_code && self.preconditions.length > 0
  json[:negation] = self.negation if self.negation
  json[:comments] = self.comments if self.comments
  json
end