Module: Lab::Loaders::LoaderMixin
- Included in:
- ReasonsForTestLoader, SpecimensLoader, TestResultIndicatorsLoader
- Defined in:
- lib/tasks/loaders/loader_mixin.rb
Constant Summary collapse
- CONCEPT_DATATYPE_CODED =
2
- CONCEPT_CLASS_TEST =
1
Class Method Summary collapse
Instance Method Summary collapse
- #add_concept_to_set(set_concept_id:, concept_id:) ⇒ Object
- #data_path(filename) ⇒ Object
- #find_or_create_concept(name, is_set: false) ⇒ Object
Class Method Details
.included(_mod) ⇒ Object
6 7 8 9 |
# File 'lib/tasks/loaders/loader_mixin.rb', line 6 def self.included(_mod) User.current = User.find_by_username('admin') || User.first Location.current = Location.find_by_name('Registration') || Location.first end |
Instance Method Details
#add_concept_to_set(set_concept_id:, concept_id:) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/tasks/loaders/loader_mixin.rb', line 38 def add_concept_to_set(set_concept_id:, concept_id:) set = ConceptSet.find_by(concept_set: set_concept_id, concept_id: concept_id) return set if set ConceptSet.create!(concept_set: set_concept_id, concept_id: concept_id, creator: User.current.user_id, date_created: Time.now) end |
#data_path(filename) ⇒ Object
48 49 50 |
# File 'lib/tasks/loaders/loader_mixin.rb', line 48 def data_path(filename) "#{__dir__}/data/#{filename}" end |
#find_or_create_concept(name, is_set: false) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tasks/loaders/loader_mixin.rb', line 14 def find_or_create_concept(name, is_set: false) # Filter out concept_names with voided concepts concept = ConceptName.joins(:concept).find_by_name(name) return concept if concept ConceptName.create!( concept: Concept.create!( short_name: name, datatype_id: CONCEPT_DATATYPE_CODED, class_id: CONCEPT_CLASS_TEST, is_set: is_set, uuid: SecureRandom.uuid, creator: User.current.user_id, date_created: Time.now ), name: name, locale: 'en', concept_name_type: 'FULLY_SPECIED', uuid: SecureRandom.uuid, creator: User.current.user_id, date_created: Time.now ) end |