class HQMF::PopulationCriteria

Represents an HQMF population criteria, also supports all the same methods as HQMF::Precondition

Constants

ALL_POPULATION_CODES
DENEX
DENEXCEP
DENOM
IPP
MSRPOPL
MSRPOPLEX
NUMER
NUMEX
OBSERV
STRAT

Attributes

aggregator[RW]
comments[R]
hqmf_id[R]
id[R]
preconditions[R]
title[R]
type[R]

Public Class Methods

from_json(id, json) click to toggle source

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

# 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
new(id, hqmf_id, type, preconditions, title='', aggregator=nil, comments=nil) click to toggle source

Create a new population criteria @param [String] id @param [String] hqmf_id @param [Array#Precondition] preconditions @param [String] title (optional)

# 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

Public Instance Methods

base_json() click to toggle source
# 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?() click to toggle source

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

# File lib/hqmf-model/population_criteria.rb, line 68
def conjunction?
  type != HQMF::PopulationCriteria::OBSERV
end
conjunction_code() click to toggle source

Get the conjunction code, e.g. allTrue, atLeastOneTrue @return [String] conjunction code

# 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() click to toggle source

Can't have negation on population so this is the same as conjunction_code

# File lib/hqmf-model/population_criteria.rb, line 88
def conjunction_code_with_negation
  conjunction_code
end
referenced_data_criteria() click to toggle source
# 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() click to toggle source
# File lib/hqmf-model/population_criteria.rb, line 54
def to_json
  {self.id.to_sym => base_json}
end