Module: Inferno::DSL::InputOutputHandling

Defined in:
lib/inferno/dsl/input_output_handling.rb

Instance Method Summary collapse

Instance Method Details

#all_outputsObject



152
153
154
155
156
157
# File 'lib/inferno/dsl/input_output_handling.rb', line 152

def all_outputs
  outputs
    .map { |output_identifier| config.output_name(output_identifier) }
    .concat(all_children.flat_map(&:all_outputs))
    .uniq
end

#available_inputs(selected_suite_options = nil) ⇒ Object

Inputs available for the user for this runnable and all its children.



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/inferno/dsl/input_output_handling.rb', line 188

def available_inputs(selected_suite_options = nil)
  available_inputs =
    config.inputs
      .slice(*inputs)
      .each_with_object({}) do |(_, input), inputs|
        inputs[input.name.to_sym] = Entities::Input.new(**input.to_hash)
      end

  available_inputs.each do |input, current_definition|
    child_definition = children_available_inputs(selected_suite_options)[input]
    current_definition.merge_with_child(child_definition)
  end

  available_inputs = children_available_inputs(selected_suite_options).merge(available_inputs)

  order_available_inputs(available_inputs)
end

#children_available_inputs(selected_suite_options = nil) ⇒ Object

Inputs available for this runnable’s children. A running list of outputs created by the children is used to exclude any inputs which are provided by an earlier child’s output.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/inferno/dsl/input_output_handling.rb', line 163

def children_available_inputs(selected_suite_options = nil)
  child_outputs = []
  children(selected_suite_options).each_with_object({}) do |child, definitions|
    new_definitions = child.available_inputs(selected_suite_options).map(&:dup)
    new_definitions.each do |input, new_definition|
      existing_definition = definitions[input]

      updated_definition =
        if existing_definition.present?
          existing_definition.merge_with_child(new_definition)
        else
          new_definition
        end

      next if child_outputs.include?(updated_definition.name.to_sym)

      definitions[updated_definition.name.to_sym] = updated_definition
    end

    child_outputs.concat(child.all_outputs).uniq!
  end
end

#input(identifier, *other_identifiers, **input_params) ⇒ void

This method returns an undefined value.

Define inputs

Examples:

input :patient_id, title: 'Patient ID', description: 'The ID of the patient being searched for',
                  default: 'default_patient_id'
input :textarea, title: 'Textarea Input Example', type: 'textarea', optional: true

Parameters:

  • identifier (Symbol)

    identifier for the input

  • other_identifiers (Symbol)

    array of symbols if specifying multiple inputs

  • input_params (Hash)

    options for input such as type, description, or title

  • options (Hash)

    a customizable set of options

Options Hash (**input_params):

  • :title (String)

    Human readable title for input

  • :description (String)

    Description for the input

  • :type (String)

    text | textarea | radio | checkbox | oauth_credentials

  • :default (String)

    The default value for the input

  • :optional (Boolean)

    Set to true to not require input for test execution

  • :locked (Boolean)

    If true, the user can not alter the value

  • :hidden (Boolean)

    If true, the input will not be visible to the user in the UI

  • :options (Hash)

    Possible input option formats based on input type

  • :enable_when (Hash)

    Conditions for showing the input. Must be a Hash with String :input_name (the name of the controlling input) and String :value (the value that triggers visibility). For checkbox inputs the value must be a JSON-encoded sorted array, e.g. ‘[“a”,“b”]’.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/inferno/dsl/input_output_handling.rb', line 29

def input(identifier, *other_identifiers, **input_params)
  if other_identifiers.present?
    [identifier, *other_identifiers].compact.each do |input_identifier|
      inputs << input_identifier
      config.add_input(input_identifier)
      children
        .reject { |child| child.inputs.include? input_identifier }
        .each do |child|
          child.input(input_identifier)
        end
    end
  else
    inputs << identifier
    config.add_input(identifier, input_params)
    children
      .reject { |child| child.inputs.include? identifier }
      .each do |child|
        child.input(identifier, **input_params)
      end
  end
end

#input_order(*new_input_order) ⇒ Array<String, Symbol>

Define a particular order for inputs to be presented in the API/UI

Examples:

group do
  input :input1, :input2, :input3
  input_order :input3, :input2, :input1
end

Parameters:

  • new_input_order (Array<String,Symbol>)

Returns:

  • (Array<String, Symbol>)


121
122
123
124
125
# File 'lib/inferno/dsl/input_output_handling.rb', line 121

def input_order(*new_input_order)
  return @input_order = new_input_order if new_input_order.present?

  @input_order ||= []
end

#inputsObject



85
86
87
# File 'lib/inferno/dsl/input_output_handling.rb', line 85

def inputs
  @inputs ||= []
end

#missing_inputs(submitted_inputs, selected_suite_options) ⇒ Object



107
108
109
110
111
# File 'lib/inferno/dsl/input_output_handling.rb', line 107

def missing_inputs(, selected_suite_options)
   = [] if .nil?

  required_inputs(selected_suite_options).map(&:to_s) - .map { |input| input[:name] }
end

#order_available_inputs(original_inputs) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/inferno/dsl/input_output_handling.rb', line 128

def order_available_inputs(original_inputs)
  input_names = original_inputs.map { |_, input| input.name }.join(', ')

  ordered_inputs =
    input_order.each_with_object({}) do |input_name, inputs|
      key, input = original_inputs.find { |_, input| input.name == input_name.to_s }
      if input.nil?
        Inferno::Application[:logger].error <<~ERROR
          Error trying to order inputs in #{id}: #{title}:
          - Unable to find input #{input_name} in available inputs: #{input_names}
        ERROR
        next
      end
      inputs[key] = original_inputs.delete(key)
    end

  original_inputs.each do |key, input|
    ordered_inputs[key] = input
  end

  ordered_inputs
end

#output(identifier, *other_identifiers, **output_definition) ⇒ void

This method returns an undefined value.

Define outputs

Examples:

output :patient_id, :condition_id, :observation_id
output :oauth_credentials, type: 'oauth_credentials'

Parameters:

  • identifier (Symbol)

    identifier for the output

  • other_identifiers (Symbol)

    array of symbols if specifying multiple outputs

  • output_definition (Hash)

    options for output

Options Hash (**output_definition):

  • :type (String)

    text, textarea, or oauth_credentials



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/inferno/dsl/input_output_handling.rb', line 62

def output(identifier, *other_identifiers, **output_definition)
  if other_identifiers.present?
    [identifier, *other_identifiers].compact.each do |output_identifier|
      outputs << output_identifier
      config.add_output(output_identifier)
      children
        .reject { |child| child.outputs.include? output_identifier }
        .each do |child|
          child.output(output_identifier)
        end
    end
  else
    outputs << identifier
    config.add_output(identifier, output_definition)
    children
      .reject { |child| child.outputs.include? identifier }
      .each do |child|
        child.output(identifier, **output_definition)
      end
  end
end

#output_definitionsObject



95
96
97
# File 'lib/inferno/dsl/input_output_handling.rb', line 95

def output_definitions
  config.outputs.slice(*outputs)
end

#outputsObject



90
91
92
# File 'lib/inferno/dsl/input_output_handling.rb', line 90

def outputs
  @outputs ||= []
end

#required_inputs(selected_suite_options) ⇒ Object



100
101
102
103
104
# File 'lib/inferno/dsl/input_output_handling.rb', line 100

def required_inputs(selected_suite_options)
  available_inputs(selected_suite_options)
    .reject { |_, input| input.optional }
    .map { |_, input| input.name }
end