Class: EtnaApp::Administrate::Models::Attributes::LoadTableFromCsv
- Inherits:
-
Etna::Command
- Object
- Etna::Command
- EtnaApp::Administrate::Models::Attributes::LoadTableFromCsv
- Includes:
- WithEtnaClients
- Defined in:
- lib/commands.rb
Instance Attribute Summary
Attributes inherited from Etna::Command
Instance Method Summary collapse
Methods included from WithEtnaClients
#environment, #exit, exit, #janus_client, #magma_client, #metis_client, #polyphemus_client, #token
Methods inherited from Etna::Command
#completions, #fill_in_missing_params, #find_command, #initialize, parent_scope, #setup
Methods included from Etna::CommandOrExecutor
#command_name, #completions_for, #desc, #flag_argspec, #flag_as_parameter, included, #parse_flags, #program_name, #usage
Constructor Details
This class inherits a constructor from Etna::Command
Instance Method Details
#execute(project_name, model_name, file_path, execute: false) ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/commands.rb', line 338 def execute(project_name, model_name, file_path, execute: false) request = Etna::Clients::Magma::RetrievalRequest.new(project_name: project_name) request.model_name = model_name request.attribute_names = 'all' request.record_names = [] model = magma_client.retrieve(request).models.model(model_name) model_parent_name = model.template.attributes.all.select do |attribute| attribute.attribute_type == Etna::Clients::Magma::AttributeType::PARENT end.first.name other_attribute_names = model.template.attributes.all.reject do |attribute| attribute.attribute_type == Etna::Clients::Magma::AttributeType::PARENT end.map do |attribute| attribute.name end # NOTE: This does not call ensure_parent currently because of MVIR1 consent-- # if the timepoint doesn't exist, the patient may be no study? (one example, at least) update_request = Etna::Clients::Magma::UpdateRequest.new(project_name: project_name) data = CSV.parse(File.read(file_path), headers: true) data.by_row.each do |row| revision = {} other_attribute_names.each do |attribute_name| revision[attribute_name] = row[attribute_name] unless row[attribute_name].nil? end update_request.append_table(model_parent_name, row[model_parent_name], model_name, revision) end puts update_request if execute magma_client.update_json(update_request) end end |