Class: NcsNavigator::Mdes::TransmissionTable

Inherits:
Object
  • Object
show all
Defined in:
lib/ncs_navigator/mdes/transmission_table.rb

Overview

One table in the MDES.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ TransmissionTable

Returns a new instance of TransmissionTable.



32
33
34
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 32

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString (readonly)

Returns the machine name of the table. This is also the name of the XML element in the VDR export.

Returns:

  • (String)

    the machine name of the table. This is also the name of the XML element in the VDR export.



24
25
26
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 24

def name
  @name
end

#variablesArray<Variable>

Returns the variables that make up this table. (A relational model might call these the columns of this table.).

Returns:

  • (Array<Variable>)

    the variables that make up this table. (A relational model might call these the columns of this table.)



30
31
32
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 30

def variables
  @variables
end

Class Method Details

.from_element(element, options = {}) ⇒ TransmissionTable

Creates a new instance from an xs:element describing the table.

Returns:



11
12
13
14
15
16
17
18
19
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 11

def self.from_element(element, options={})
  log = options[:log] || NcsNavigator::Mdes.default_logger

  new(element['name']).tap do |table|
    table.variables = element.
      xpath('xs:complexType/xs:sequence/xs:element', SourceDocuments.xmlns).
      collect { |col_elt| Variable.from_element(col_elt, options) }
  end
end

Instance Method Details

#[](variable_name) ⇒ Variable

Search for a variable by name.

Parameters:

  • variable_name (String)

    the name of the variable to look for.

Returns:

  • (Variable)

    the variable with the given name, if any



41
42
43
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 41

def [](variable_name)
  variables.find { |c| c.name == variable_name }
end

#inspectString

Provides a briefer inspection for cleaner IRB use.

Returns:

  • (String)


49
50
51
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 49

def inspect
  "\#<#{self.class} name=#{name.inspect}>"
end

#instrument_table?true, false

Is this an instrument table (i.e., a table for storing results from an instrument)? Every table is either an instrument table or an operational table (never both).

This is not explicitly derivable from the MDES, so this method (and the related methods #operational_table? and #primary_instrument_table?) use this heuristic:

  • If this table contains a variable named instrument_version and is not the instrument table itself, it is a primary instrument table (and so is an instrument table).
  • If this table is not a primary instrument table, but one of its #variables references a table that is a primary instrument table, then this is an instrument table.
  • Similarly, if one of this table's variables references a table which is an instrument table according to the second definition, then this table is an instrument table as well. This continues for any depth of reference.

If none of these conditions are met, then this table is an operational table.

Returns:

  • (true, false)


89
90
91
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 89

def instrument_table?
  instrument_table_predicate_with_stack([])
end

#operational_table?true, false

Is this an operational table (i.e., a table for storing operational data about a participant, household, staff member, or other study management concept)? Every table is either an operational table or an instrument table (never both).

Returns:

  • (true, false)

See Also:



110
111
112
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 110

def operational_table?
  !instrument_table?
end

#primary_instrument_table?true, false

Is this a primary instrument table (i.e., is this the table for an instrument that stores all single-valued responses for one execution of that instrument and to which all other instrument tables for that instrument refer [directly or indirectly])?

Returns:

  • (true, false)


60
61
62
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 60

def primary_instrument_table?
  self.name != 'instrument' && variables.any? { |v| v.name == 'instrument_version' }
end