module Lab::Loaders::SpecimensLoader
Load specimens and their tests into the database
Public Class Methods
create_specimen_type(name, test_type)
click to toggle source
# File lib/tasks/loaders/specimens_loader.rb, line 52 def create_specimen_type(name, test_type) concept_id = find_or_create_concept(name).concept_id [ add_concept_to_set(set_concept_id: specimen_type_concept_id, concept_id: concept_id), add_concept_to_set(set_concept_id: test_type.concept_id, concept_id: concept_id) ] rescue StandardError => e raise "Failed to create specimen type `#{name}`: #{e}" end
create_test_type(name)
click to toggle source
# File lib/tasks/loaders/specimens_loader.rb, line 44 def create_test_type(name) concept_id = find_or_create_concept(name, is_set: true).concept_id add_concept_to_set(set_concept_id: test_type_concept_id, concept_id: concept_id) rescue StandardError => e raise "Failed to create test type `#{name}`: #{e}" end
load()
click to toggle source
# File lib/tasks/loaders/specimens_loader.rb, line 14 def load puts "------- Loading tests and specimens ---------" CSV.open(data_path('tests.csv'), headers: :first_row) do |csv| csv.each_with_object({}) do |row, test_types| specimen_name = row['specimen_name'] test_name = row['test_name'] ActiveRecord::Base.transaction do test_type = test_types[test_name] || create_test_type(test_name) create_specimen_type(specimen_name, test_type) test_types[test_name] ||= test_type end puts "Created test #{test_name} <--< #{specimen_name}" rescue StandardError => e puts "Error: #{test_name}: #{e}" end end end
specimen_type_concept_id()
click to toggle source
# File lib/tasks/loaders/specimens_loader.rb, line 39 def specimen_type_concept_id find_or_create_concept(Lab::Metadata::SPECIMEN_TYPE_CONCEPT_NAME).concept_id end
test_type_concept_id()
click to toggle source
# File lib/tasks/loaders/specimens_loader.rb, line 35 def test_type_concept_id find_or_create_concept(Lab::Metadata::TEST_TYPE_CONCEPT_NAME).concept_id end