Class: HQMF::PopulationCriteria
- Inherits:
-
Object
- Object
- HQMF::PopulationCriteria
- Includes:
- Conversion::Utilities
- Defined in:
- lib/hqmf-model/population_criteria.rb
Overview
Represents an HQMF population criteria, also supports all the same methods as HQMF::Precondition
Direct Known Subclasses
Constant Summary collapse
- IPP =
'IPP'
- DENOM =
'DENOM'
- NUMER =
'NUMER'
- NUMEX =
'NUMEX'
- DENEXCEP =
'DENEXCEP'
- DENEX =
'DENEX'
- MSRPOPL =
'MSRPOPL'
- OBSERV =
'OBSERV'
- MSRPOPLEX =
'MSRPOPLEX'
- STRAT =
'STRAT'
- ALL_POPULATION_CODES =
[STRAT, IPP, DENOM, DENEX, NUMER, NUMEX, DENEXCEP, MSRPOPL, OBSERV, MSRPOPLEX]
Instance Attribute Summary collapse
-
#aggregator ⇒ Object
Returns the value of attribute aggregator.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#hqmf_id ⇒ Object
readonly
Returns the value of attribute hqmf_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#preconditions ⇒ Object
readonly
Returns the value of attribute preconditions.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.from_json(id, json) ⇒ Object
Create a new population criteria from a JSON hash keyed off symbols.
Instance Method Summary collapse
- #base_json ⇒ Object
-
#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 if it is an observation population criteria, then it is not a conjunction, it is instead doing a calculation.
-
#conjunction_code ⇒ String
Get the conjunction code, e.g.
-
#conjunction_code_with_negation ⇒ Object
Can’t have negation on population so this is the same as conjunction_code.
-
#initialize(id, hqmf_id, type, preconditions, title = '', aggregator = nil, comments = nil) ⇒ PopulationCriteria
constructor
Create a new population criteria.
- #referenced_data_criteria ⇒ Object
- #to_json ⇒ Object
Methods included from Conversion::Utilities
#build_hash, #check_equality, #json_array, #openstruct_to_json
Constructor Details
#initialize(id, hqmf_id, type, preconditions, title = '', aggregator = nil, comments = nil) ⇒ PopulationCriteria
Create a new population criteria
30 31 32 33 34 35 36 37 38 |
# File 'lib/hqmf-model/population_criteria.rb', line 30 def initialize(id, hqmf_id, type, preconditions, title='', aggregator=nil, comments=nil) @id = id @hqmf_id = hqmf_id @preconditions = preconditions @type = type @title = title @aggregator = aggregator @comments = comments end |
Instance Attribute Details
#aggregator ⇒ Object
Returns the value of attribute aggregator.
9 10 11 |
# File 'lib/hqmf-model/population_criteria.rb', line 9 def aggregator @aggregator end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
8 9 10 |
# File 'lib/hqmf-model/population_criteria.rb', line 8 def comments @comments end |
#hqmf_id ⇒ Object (readonly)
Returns the value of attribute hqmf_id.
8 9 10 |
# File 'lib/hqmf-model/population_criteria.rb', line 8 def hqmf_id @hqmf_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/hqmf-model/population_criteria.rb', line 8 def id @id end |
#preconditions ⇒ Object (readonly)
Returns the value of attribute preconditions.
8 9 10 |
# File 'lib/hqmf-model/population_criteria.rb', line 8 def preconditions @preconditions end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/hqmf-model/population_criteria.rb', line 8 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/hqmf-model/population_criteria.rb', line 8 def type @type end |
Class Method Details
.from_json(id, json) ⇒ Object
Create a new population criteria from a JSON hash keyed off symbols
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hqmf-model/population_criteria.rb', line 41 def self.from_json(id, json) preconditions = json["preconditions"].map do |precondition| HQMF::Precondition.from_json(precondition) end if json['preconditions'] type = json["type"] title = json['title'] hqmf_id = json['hqmf_id'] aggregator = json['aggregator'] comments = json['comments'] HQMF::PopulationCriteria.new(id, hqmf_id, type, preconditions, title, aggregator, comments) end |
Instance Method Details
#base_json ⇒ Object
58 59 60 61 62 63 |
# File 'lib/hqmf-model/population_criteria.rb', line 58 def base_json x = nil json = build_hash(self, [:conjunction?, :type, :title, :hqmf_id, :aggregator, :comments]) json[:preconditions] = x if x = json_array(@preconditions) json end |
#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 if it is an observation population criteria, then it is not a conjunction, it is instead doing a calculation
68 69 70 |
# File 'lib/hqmf-model/population_criteria.rb', line 68 def conjunction? type != HQMF::PopulationCriteria::OBSERV end |
#conjunction_code ⇒ String
Get the conjunction code, e.g. allTrue, atLeastOneTrue
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/hqmf-model/population_criteria.rb', line 74 def conjunction_code case @type when IPP, STRAT, DENOM, NUMER, MSRPOPL HQMF::Precondition::ALL_TRUE when DENEXCEP, DENEX, MSRPOPLEX, NUMEX HQMF::Precondition::AT_LEAST_ONE_TRUE else raise "Unknown population type [#{@type}]" end end |
#conjunction_code_with_negation ⇒ Object
Can’t have negation on population so this is the same as conjunction_code
88 89 90 |
# File 'lib/hqmf-model/population_criteria.rb', line 88 def conjunction_code_with_negation conjunction_code end |
#referenced_data_criteria ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/hqmf-model/population_criteria.rb', line 92 def referenced_data_criteria data_criteria_ids = [] @preconditions.each do |precondition| data_criteria_ids.concat(precondition.referenced_data_criteria) end if @preconditions data_criteria_ids end |
#to_json ⇒ Object
54 55 56 |
# File 'lib/hqmf-model/population_criteria.rb', line 54 def to_json {self.id.to_sym => base_json} end |