Module: Lab::Loaders::SpecimensLoader
- Extended by:
- LoaderMixin
- Defined in:
- lib/tasks/loaders/specimens_loader.rb
Overview
Load specimens and their tests into the database
Constant Summary
Constants included
from LoaderMixin
LoaderMixin::CONCEPT_CLASS_TEST, LoaderMixin::CONCEPT_DATATYPE_CODED
Class Method Summary
collapse
add_concept_to_set, data_path, find_or_create_concept, included
Class Method Details
.create_specimen_type(name, test_type) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# 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) ⇒ Object
44
45
46
47
48
49
50
|
# 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 ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# 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 ⇒ Object
.test_type_concept_id ⇒ Object
35
36
37
|
# 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
|