Class: BroadcastEvent::QcAssay

Inherits:
BroadcastEvent show all
Defined in:
app/models/broadcast_event/qc_assay.rb

Overview

Serializes lab events for the event warehouse

Constant Summary

Constants inherited from BroadcastEvent

EVENT_JSON_ROOT, UNKNOWN_USER_IDENTIFIER

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BroadcastEvent

#json_root, #metadata, #routing_key, set_event_type, #subjects, #user_identifier

Methods included from RenderHelpers::RenderableClassMethods

#render_class

Methods included from MetadataHelpers::MetadatableClassMethods

#has_metadata, #metadata_finders

Methods included from SubjectHelpers::SubjectableClassMethods

#has_subject, #has_subjects, #seed_class, #seed_subject, #subject_associations

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Class Method Details

.generate_events(qc_assay) ⇒ Object


9
10
11
12
13
14
15
# File 'app/models/broadcast_event/qc_assay.rb', line 9

def self.generate_events(qc_assay)
  # A qc_assay is made up of multiple qc_results, which usually have the same assay_type, don't HAVE to.
  # We generate an event per assay type, and distinguish between then with properties
  qc_assay.qc_results.distinct.pluck(:assay_type, :assay_version).map do |assay_type, assay_version|
    create!(seed: qc_assay, properties: { assay_type: assay_type, assay_version: assay_version })
  end
end

Instance Method Details

#assay_typeObject


29
30
31
# File 'app/models/broadcast_event/qc_assay.rb', line 29

def assay_type
  properties.fetch(:assay_type, template_result.assay_type)
end

#assay_versionObject


33
34
35
# File 'app/models/broadcast_event/qc_assay.rb', line 33

def assay_version
  properties.fetch(:assay_version, template_result.assay_version)
end

#assayed_labwareObject


53
54
55
# File 'app/models/broadcast_event/qc_assay.rb', line 53

def assayed_labware
  qc_results.flat_map { |qcr| qcr.asset.labware }.uniq
end

#event_typeObject


25
26
27
# File 'app/models/broadcast_event/qc_assay.rb', line 25

def event_type
  "quant_#{assay_type.downcase.gsub(/[^\w]+/, '_')}"
end

#qc_resultsObject


41
42
43
# File 'app/models/broadcast_event/qc_assay.rb', line 41

def qc_results
  @qc_results || seed.qc_results.where(properties).includes(%i[asset samples studies])
end

#samplesObject


45
46
47
# File 'app/models/broadcast_event/qc_assay.rb', line 45

def samples
  qc_results.flat_map(&:samples).uniq
end

#stock_platesObject


57
58
59
# File 'app/models/broadcast_event/qc_assay.rb', line 57

def stock_plates
  assayed_labware.flat_map(&:original_stock_plates).compact.uniq
end

#studiesObject


49
50
51
# File 'app/models/broadcast_event/qc_assay.rb', line 49

def studies
  qc_results.flat_map(&:studies).uniq
end

#template_resultObject


37
38
39
# File 'app/models/broadcast_event/qc_assay.rb', line 37

def template_result
  seed.qc_results.first
end