Class: NcsNavigator::Mdes::TransmissionTable
- Inherits:
-
Object
- Object
- NcsNavigator::Mdes::TransmissionTable
- Defined in:
- lib/ncs_navigator/mdes/transmission_table.rb
Overview
One table in the MDES.
Instance Attribute Summary collapse
- #child_instrument_table writeonly
-
#name ⇒ String
readonly
The machine name of the table.
-
#variables ⇒ Array<Variable>
The variables that make up this table.
Class Method Summary collapse
-
.from_element(element, options = {}) ⇒ TransmissionTable
Creates a new instance from an
xs:element
describing the table.
Instance Method Summary collapse
-
#[](variable_name) ⇒ Variable
Search for a variable by name.
-
#child_instrument_table? ⇒ true, ...
Is this a child instrument data table? (As opposed to a parent instrument data table or neither.).
-
#diff(other_table, options = {}) ⇒ Differences::Entry?
Computes the differences between this table and the other.
-
#initialize(name) ⇒ TransmissionTable
constructor
A new instance of TransmissionTable.
-
#inspect ⇒ String
Provides a briefer inspection for cleaner IRB use.
-
#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).
-
#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).
-
#parent_instrument_table? ⇒ true, ...
Is this a parent instrument data table? (As opposed to a child instrument data table or neither.).
-
#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])?.
-
#primary_key_variables ⇒ Array<Variable>
This method allows for a table to have a multiple column PK.
Constructor Details
#initialize(name) ⇒ TransmissionTable
Returns a new instance of TransmissionTable.
41 42 43 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 41 def initialize(name) @name = name end |
Instance Attribute Details
#child_instrument_table=(value) (writeonly)
This method returns an undefined value.
39 40 41 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 39 def child_instrument_table=(value) @child_instrument_table = value end |
#name ⇒ String (readonly)
Returns the machine name of the table. This is also the name of the XML element in the VDR export.
28 29 30 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 28 def name @name end |
#variables ⇒ Array<Variable>
Returns the variables that make up this table. (A relational model might call these the columns of this table.).
34 35 36 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 34 def variables @variables end |
Class Method Details
.from_element(element, options = {}) ⇒ TransmissionTable
Creates a new instance from an xs:element
describing the table.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 11 def self.from_element(element, ={}) log = [:log] || NcsNavigator::Mdes.default_logger new(element['name']).tap do |table| opts = .merge({ :log => log, :current_table_name => table.name }) table.variables = element. xpath('xs:complexType/xs:sequence/xs:element', SourceDocuments.xmlns). collect { |col_elt| Variable.from_element(col_elt, opts) } end end |
Instance Method Details
#[](variable_name) ⇒ Variable
Search for a variable by name.
54 55 56 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 54 def [](variable_name) variables.find { |c| c.name == variable_name } end |
#child_instrument_table? ⇒ true, ...
Is this a child instrument data table? (As opposed to a parent instrument data table or neither.)
This reports the type of participant whose p_id should go in this table's p_id variable.
Return values:
true
: The p_id should be a child's p_id.false
: The p_id should be a parent's p_id.nil
: The table isn't an instrument data table, or it doesn't have a p_id variable, or the childness of the p_id isn't known.
142 143 144 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 142 def child_instrument_table? @child_instrument_table end |
#diff(other_table, options = {}) ⇒ Differences::Entry?
Computes the differences between this table and the other.
175 176 177 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 175 def diff(other_table, ={}) Differences::Entry.compute(self, other_table, DIFF_CRITERIA, ) end |
#inspect ⇒ String
Provides a briefer inspection for cleaner IRB use.
62 63 64 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 62 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 theinstrument
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.
102 103 104 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 102 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).
123 124 125 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 123 def operational_table? !instrument_table? end |
#parent_instrument_table? ⇒ true, ...
Is this a parent instrument data table? (As opposed to a child instrument data table or neither.)
This reports the type of participant whose p_id should go in this table's p_id variable.
Return values:
true
: The p_id should be a parent's p_id.false
: The p_id should be a child's p_id.nil
: The table isn't an instrument data table, or it doesn't have a p_id variable, or the childness of the p_id isn't known.
161 162 163 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 161 def parent_instrument_table? child_instrument_table?.nil? ? nil : !child_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])?
73 74 75 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 73 def primary_instrument_table? self.name != 'instrument' && variables.any? { |v| v.name == 'instrument_version' } end |
#primary_key_variables ⇒ Array<Variable>
This method allows for a table to have a multiple column PK. At this writing there are not any, so this is out of an abundance of caution.
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/ncs_navigator/mdes/transmission_table.rb', line 185 def primary_key_variables pks = variables.select { |v| v.type.name == 'primaryKeyType' } if !pks.empty? pks elsif name == 'study_center' variables.select { |v| v.name == 'sc_id' } elsif name == 'psu' variables.select { |v| v.name == 'psu_id' } else [] end end |