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'
DENEXCEP =
'DENEXCEP'
DENEX =
'DENEX'
MSRPOPL =
'MSRPOPL'
OBSERV =
'OBSERV'
ALL_POPULATION_CODES =
[IPP, DENOM, NUMER, DENEXCEP, DENEX, MSRPOPL, OBSERV]

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 = '') ⇒ PopulationCriteria

Create a new population criteria

Parameters:

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

    (optional)



25
26
27
28
29
30
31
# File 'lib/hqmf-model/population_criteria.rb', line 25

def initialize(id, hqmf_id, type, preconditions, title='')
  @id = id
  @hqmf_id = hqmf_id
  @preconditions = preconditions
  @type = type
  @title=title
end

Instance Attribute Details

#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



34
35
36
37
38
39
40
41
42
43
# File 'lib/hqmf-model/population_criteria.rb', line 34

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']
  
  HQMF::PopulationCriteria.new(id, hqmf_id, type, preconditions, title)
end

Instance Method Details

#base_jsonObject



49
50
51
52
53
54
# File 'lib/hqmf-model/population_criteria.rb', line 49

def base_json
  x = nil
  json = build_hash(self, [:conjunction?, :type, :title, :hqmf_id])
  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

Returns:

  • (Boolean)


58
59
60
# File 'lib/hqmf-model/population_criteria.rb', line 58

def conjunction?
  true
end

#conjunction_codeString

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

Returns:

  • (String)

    conjunction code



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/hqmf-model/population_criteria.rb', line 64

def conjunction_code
  
  case @type
  when IPP, DENOM, NUMER, MSRPOPL
    HQMF::Precondition::ALL_TRUE
  when DENEXCEP, DENEX
    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



78
79
80
# File 'lib/hqmf-model/population_criteria.rb', line 78

def conjunction_code_with_negation
  conjunction_code
end

#referenced_data_criteriaObject



82
83
84
85
86
87
88
# File 'lib/hqmf-model/population_criteria.rb', line 82

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



45
46
47
# File 'lib/hqmf-model/population_criteria.rb', line 45

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