Class: QcReceptionsFactory
- Inherits:
-
Object
- Object
- QcReceptionsFactory
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/qc_receptions_factory.rb
Overview
Receives an array of qc_results for multiple samples Converts them into rows to save them in the qc_results table Constructs the RabbitMQ message for each qc_result
Constant Summary collapse
- USED_BY =
'tol'
Instance Attribute Summary collapse
-
#qc_reception ⇒ Object
Returns the value of attribute qc_reception.
- #qc_results_list ⇒ Object
Instance Method Summary collapse
- #assay_types ⇒ Object
- #build_qc_result_message(qc_result) ⇒ Object
- #create_data ⇒ Object
- #create_qc_result!(request_obj, qc_assay_type_id, value) ⇒ Object
- #create_qc_results! ⇒ Object
- #create_row(request_obj, qc_assay_type_id, value) ⇒ Object
- #messages ⇒ Object
Instance Attribute Details
#qc_reception ⇒ Object
Returns the value of attribute qc_reception.
9 10 11 |
# File 'app/models/qc_receptions_factory.rb', line 9 def qc_reception @qc_reception end |
#qc_results_list ⇒ Object
16 17 18 |
# File 'app/models/qc_receptions_factory.rb', line 16 def qc_results_list @qc_results_list ||= [] end |
Instance Method Details
#assay_types ⇒ Object
44 45 46 47 |
# File 'app/models/qc_receptions_factory.rb', line 44 def assay_types assay_types = QcAssayType.where(used_by: USED_BY).pluck(:id, :key) assay_types.to_h.invert end |
#build_qc_result_message(qc_result) ⇒ Object
54 55 56 |
# File 'app/models/qc_receptions_factory.rb', line 54 def (qc_result) << qc_result end |
#create_data ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/qc_receptions_factory.rb', line 29 def create_data # 1. Iterate the array and for each object # 2. iterate through qc fields # 3. for each qc, if assay_type exists # 4. then create qc_results assay_types_hash = assay_types @qc_results_list.each do |request_obj| request_obj.each do |qc, value| next unless assay_types_hash.keys.include? qc create_row(request_obj, assay_types_hash[qc], value) end end end |
#create_qc_result!(request_obj, qc_assay_type_id, value) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'app/models/qc_receptions_factory.rb', line 58 def create_qc_result!(request_obj, qc_assay_type_id, value) QcResult.create!( labware_barcode: request_obj['labware_barcode'], sample_external_id: request_obj['sample_external_id'], qc_assay_type_id:, value:, qc_reception_id: @qc_reception.id ) end |
#create_qc_results! ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/models/qc_receptions_factory.rb', line 20 def create_qc_results! if @qc_results_list.empty? errors.add('QcReceptionsFactory', 'the qc_results_list is empty') return end create_data true end |
#create_row(request_obj, qc_assay_type_id, value) ⇒ Object
49 50 51 52 |
# File 'app/models/qc_receptions_factory.rb', line 49 def create_row(request_obj, qc_assay_type_id, value) qc_result = create_qc_result!(request_obj, qc_assay_type_id, value) (qc_result) end |
#messages ⇒ Object
68 69 70 |
# File 'app/models/qc_receptions_factory.rb', line 68 def @messages ||= [] end |