Class: HQMF::PopulationCriteria

Inherits:
Object
  • Object
show all
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

Converter::SimplePopulationCriteria

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

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, hqmf_id, type, preconditions, title = '', aggregator = nil, comments = nil) ⇒ PopulationCriteria

Create a new population criteria

Parameters:

  • id (String)
  • hqmf_id (String)
  • preconditions (Array#Precondition)
  • title (String) (defaults to: '')

    (optional)



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

#aggregatorObject

Returns the value of attribute aggregator.



9
10
11
# File 'lib/hqmf-model/population_criteria.rb', line 9

def aggregator
  @aggregator
end

#commentsObject (readonly)

Returns the value of attribute comments.



8
9
10
# File 'lib/hqmf-model/population_criteria.rb', line 8

def comments
  @comments
end

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

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/hqmf-model/population_criteria.rb', line 8

def id
  @id
end

#preconditionsObject (readonly)

Returns the value of attribute preconditions.



8
9
10
# File 'lib/hqmf-model/population_criteria.rb', line 8

def preconditions
  @preconditions
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/hqmf-model/population_criteria.rb', line 8

def title
  @title
end

#typeObject (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_jsonObject



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

Returns:

  • (Boolean)


68
69
70
# File 'lib/hqmf-model/population_criteria.rb', line 68

def conjunction?
  type != HQMF::PopulationCriteria::OBSERV
end

#conjunction_codeString

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

Returns:

  • (String)

    conjunction code



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_negationObject

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_criteriaObject



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_jsonObject



54
55
56
# File 'lib/hqmf-model/population_criteria.rb', line 54

def to_json
  {self.id.to_sym => base_json}
end