Class: HQMF2::PopulationCriteria

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/hqmf-parser/2.0/population_criteria.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#attr_val, attr_val, #to_xml

Methods included from HQMF::Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(entry, doc) ⇒ PopulationCriteria

Create a new population criteria from the supplied HQMF entry

Parameters:

  • the (Nokogiri::XML::Element)

    HQMF entry



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hqmf-parser/2.0/population_criteria.rb', line 13

def initialize(entry, doc)
  @doc = doc
  @entry = entry
  @hqmf_id = attr_val('./*/cda:id/@extension') || attr_val('./*/cda:typeId/@extension')
  @title = attr_val('./*/cda:code/cda:displayName/@value') 
  @type = attr_val('./*/cda:code/@code')
  @aggregator = nil
  @comments = @entry.xpath("./*/cda:text/cda:xml/cda:qdmUserComments/cda:item/text()", HQMF2::Document::NAMESPACES)
                    .map{ |v| v.content }
  obs_test = attr_val('./cda:measureObservationDefinition/@classCode')
  if !@title && obs_test.to_s == "OBS"
      @title = attr_val('../cda:code/cda:displayName/@value')
      @aggregator = attr_val('./cda:measureObservationDefinition/cda:methodCode/cda:item/@code')
  end
  if(!@hqmf_id) # The id extension is not required, if it's not provided use the code
    @hqmf_id = @type
  end
  @preconditions = @entry.xpath('./*/cda:precondition[not(@nullFlavor)]', HQMF2::Document::NAMESPACES).collect do |precondition|
    Precondition.new(precondition, @doc)
  end
end

Instance Attribute Details

#aggregatorObject (readonly)

Returns the value of attribute aggregator.



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

def aggregator
  @aggregator
end

#commentsObject (readonly)

Returns the value of attribute comments.



8
9
10
# File 'lib/hqmf-parser/2.0/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-parser/2.0/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-parser/2.0/population_criteria.rb', line 8

def id
  @id
end

#preconditionsObject (readonly)

Returns the value of attribute preconditions.



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

def preconditions
  @preconditions
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#typeObject

need to do this to allow for setting the type to OBSERV for



10
11
12
# File 'lib/hqmf-parser/2.0/population_criteria.rb', line 10

def type
  @type
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)


41
42
43
# File 'lib/hqmf-parser/2.0/population_criteria.rb', line 41

def conjunction?
  true
end

#conjunction_codeString

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

Returns:

  • (String)

    conjunction code



47
48
49
50
51
52
53
54
55
56
# File 'lib/hqmf-parser/2.0/population_criteria.rb', line 47

def conjunction_code
  case @type
  when HQMF::PopulationCriteria::IPP, HQMF::PopulationCriteria::DENOM, HQMF::PopulationCriteria::NUMER,HQMF::PopulationCriteria::MSRPOPL
    HQMF::Precondition::ALL_TRUE
  when HQMF::PopulationCriteria::DENEXCEP, HQMF::PopulationCriteria::DENEX
    HQMF::Precondition::AT_LEAST_ONE_TRUE
  else
    raise "Unknown population type [#{@type}]"
  end
end

#create_human_readable_id(id) ⇒ Object



35
36
37
# File 'lib/hqmf-parser/2.0/population_criteria.rb', line 35

def create_human_readable_id(id)
  @id = id
end

#to_modelObject



58
59
60
61
# File 'lib/hqmf-parser/2.0/population_criteria.rb', line 58

def to_model
  mps = preconditions.collect {|p| p.to_model}
  HQMF::PopulationCriteria.new(id, hqmf_id, type, mps, title, aggregator, comments)
end