Skip to content

Commit dbb972c

Browse files
New fields for batches entities, new table for NIH (#1996)
* New fields for batches entities, new table for NIH, batches fields removed from batches * spec fixes * New specs * Fixes PR review & faling spec
1 parent 04cf7eb commit dbb972c

24 files changed

+297
-102
lines changed

app/controllers/autocompletes_controller.rb

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
class AutocompletesController < ApplicationController
22
def index
3-
permitted_attributes = %w[reference_gene target_organism_taxonomy_id pango_lineage who_label]
3+
permitted_attributes = [
4+
'virus_shortname',
5+
'reference_gene',
6+
'target_organism_name',
7+
'target_organism_taxonomy_id',
8+
'pango_lineage',
9+
'who_label',
10+
'gisaid_id',
11+
'gisaid_clade',
12+
'nucleotide_db_id',
13+
'virus_sample_source',
14+
'virus_sample_source_url',
15+
'virus_source',
16+
'virus_location',
17+
'virus_sample_type',
18+
'virus_sample_formulation',
19+
'virus_sample_concentration',
20+
'virus_sample_concentration_unit',
21+
'virus_sample_genome_equivalents',
22+
'virus_sample_genome_equivalents_unit',
23+
'virus_sample_genome_equivalents_reference_gene',
24+
'virus_preinactivation_tcid50',
25+
'virus_preinactivation_tcid50_unit',
26+
'virus_sample_grow_cell_line'
27+
]
28+
429
@institution = Institution.find(params[:institution_id])
530

631
unless params[:field_name].in?(permitted_attributes)
@@ -22,11 +47,6 @@ def unique_values_for(field_name, query)
2247
values << value if value&.match?(matcher)
2348
end
2449

25-
check_access(@institution.samples, READ_SAMPLE).select(:id, :core_fields, :custom_fields).find_each do |sample|
26-
value = sample.send(field_name)
27-
values << value if value&.match?(matcher)
28-
end
29-
3050
values.to_a
3151
end
3252
end

app/controllers/batches_controller.rb

+20-1
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,28 @@ def batch_params
159159
:volume,
160160
:virus_lineage,
161161
:reference_gene,
162+
:virus_shortname,
162163
:target_organism_taxonomy_id,
164+
:target_organism_name,
163165
:pango_lineage,
164-
:who_label
166+
:who_label,
167+
:gisaid_id,
168+
:gisaid_clade,
169+
:nucleotide_db_id,
170+
:virus_sample_source,
171+
:virus_sample_source_url,
172+
:virus_source,
173+
:virus_location,
174+
:virus_sample_type,
175+
:virus_sample_formulation,
176+
:virus_sample_concentration,
177+
:virus_sample_concentration_unit,
178+
:virus_sample_genome_equivalents,
179+
:virus_sample_genome_equivalents_unit,
180+
:virus_sample_genome_equivalents_reference_gene,
181+
:virus_preinactivation_tcid50,
182+
:virus_preinactivation_tcid50_unit,
183+
:virus_sample_grow_cell_line
165184
)
166185
end
167186

app/controllers/nih_tables_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def show
55

66
@target_box = @samples_report.boxes.take
77
@target_sample = @samples_report.target_sample
8+
@target_batches = @samples_report.original_batches.distinct
89
zip_data = create_zip_file(@target_box.purpose)
910
send_data zip_data.read, type: 'application/zip', filename: "#{@samples_report.name}_nih_tables.zip"
1011
end
@@ -19,6 +20,7 @@ def create_zip_file(purpose)
1920

2021
add_nih_table('samples', stream)
2122
add_nih_table('results', stream)
23+
add_nih_table('batches', stream)
2224

2325
case purpose
2426
when "LOD"

app/controllers/samples_controller.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def create
106106
sample = Sample.new(sample_params.merge({
107107
institution: institution,
108108
site: @navigation_context.site,
109+
original_batch_id: sample_params[:batch_id] || nil,
109110
sample_identifiers: [SampleIdentifier.new({ uuid: uuid })],
110111
}))
111112
@sample_form = SamplePresenter.new(SampleForm.for(sample), request.format)
@@ -247,10 +248,6 @@ def sample_params
247248
:distractor,
248249
:instruction,
249250
:measured_signal,
250-
:reference_gene,
251-
:target_organism_taxonomy_id,
252-
:pango_lineage,
253-
:who_label,
254251
assay_attachments_attributes: [:id, :loinc_code_id, :result, :assay_file_id, :_destroy],
255252
notes_attributes: [:id, :description, :updated_at, :user_id, :_destroy],
256253
)

app/models/batch.rb

+21-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,28 @@ def self.entity_scope
2424
:volume,
2525
:virus_lineage,
2626
:reference_gene,
27+
:virus_shortname,
2728
:target_organism_taxonomy_id,
29+
:target_organism_name,
2830
:pango_lineage,
29-
:who_label
31+
:who_label,
32+
:gisaid_id,
33+
:gisaid_clade,
34+
:nucleotide_db_id,
35+
:virus_sample_source,
36+
:virus_sample_source_url,
37+
:virus_source,
38+
:virus_location,
39+
:virus_sample_type,
40+
:virus_sample_formulation,
41+
:virus_sample_concentration,
42+
:virus_sample_concentration_unit,
43+
:virus_sample_genome_equivalents,
44+
:virus_sample_genome_equivalents_unit,
45+
:virus_sample_genome_equivalents_reference_gene,
46+
:virus_preinactivation_tcid50,
47+
:virus_preinactivation_tcid50_unit,
48+
:virus_sample_grow_cell_line
3049

3150
validates_presence_of :inactivation_method
3251
validates_presence_of :volume
@@ -67,10 +86,7 @@ def build_sample(**attributes)
6786
isolate_name: isolate_name,
6887
inactivation_method: inactivation_method,
6988
virus_lineage: virus_lineage,
70-
reference_gene: reference_gene,
71-
target_organism_taxonomy_id: target_organism_taxonomy_id,
72-
pango_lineage: pango_lineage,
73-
who_label: who_label,
89+
original_batch_id: id,
7490
**attributes
7591
)
7692
end

app/models/batch_form.rb

+20-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,28 @@ def self.shared_attributes
1414
:volume,
1515
:virus_lineage,
1616
:reference_gene,
17+
:virus_shortname,
1718
:target_organism_taxonomy_id,
19+
:target_organism_name,
1820
:pango_lineage,
19-
:who_label]
21+
:who_label,
22+
:gisaid_id,
23+
:gisaid_clade,
24+
:nucleotide_db_id,
25+
:virus_sample_source,
26+
:virus_sample_source_url,
27+
:virus_source,
28+
:virus_location,
29+
:virus_sample_type,
30+
:virus_sample_formulation,
31+
:virus_sample_concentration,
32+
:virus_sample_concentration_unit,
33+
:virus_sample_genome_equivalents,
34+
:virus_sample_genome_equivalents_unit,
35+
:virus_sample_genome_equivalents_reference_gene,
36+
:virus_preinactivation_tcid50,
37+
:virus_preinactivation_tcid50_unit,
38+
:virus_sample_grow_cell_line]
2039
end
2140

2241
def self.model_name

app/models/box.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def detach_from_context
8989

9090
# Returns the full list of sample attributes that can be blinded.
9191
def self.blind_attribute_names
92-
%i[batch_number concentration replicate virus_lineage isolate_name reference_gene target_organism_taxonomy_id pango_lineage who_label]
92+
%i[batch_number concentration replicate virus_lineage isolate_name]
9393
end
9494

9595
# Returns true if a sample attribute should be blinded for the current box.

app/models/sample.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def self.institution_is_required
1515
belongs_to :batch
1616
belongs_to :box
1717
belongs_to :qc_info
18+
belongs_to :original_batch, class_name: "Batch", optional: true
1819

1920
has_many :sample_identifiers, inverse_of: :sample, dependent: :destroy
2021
has_many :test_results, through: :sample_identifiers
@@ -58,11 +59,7 @@ def self.entity_scope
5859
:concentration,
5960
:replicate,
6061
:media,
61-
:measured_signal,
62-
:reference_gene,
63-
:target_organism_taxonomy_id,
64-
:pango_lineage,
65-
:who_label
62+
:measured_signal
6663

6764
def self.find_by_entity_id(entity_id, opts)
6865
query = joins(:sample_identifiers).where(sample_identifiers: {entity_id: entity_id.to_s}, institution_id: opts.fetch(:institution_id))
@@ -187,4 +184,8 @@ def self.sort_columns
187184
def self.sort_column?(attr_name)
188185
sort_columns.include?(attr_name)
189186
end
187+
188+
def original_batch
189+
Batch.find_by_id(original_batch_id)
190+
end
190191
end

app/models/sample_form.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ def self.shared_attributes
2222
:measured_signal,
2323
:distractor,
2424
:instruction,
25-
:qc_info,
26-
:reference_gene,
27-
:target_organism_taxonomy_id,
28-
:pango_lineage,
29-
:who_label ]
25+
:qc_info]
3026
end
3127

3228
def self.model_name

app/models/samples_report.rb

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SamplesReport < ApplicationRecord
88
has_many :samples_report_samples, dependent: :destroy
99
has_many :samples, through: :samples_report_samples
1010
has_many :boxes, through: :samples
11+
has_many :original_batches, through: :samples
1112

1213
def self.entity_scope
1314
"samples_report"

app/views/batches/_form.haml

+30-12
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,36 @@
3737
= f.number_field :volume, min: 0, step: :any, :class => "input-small", readonly: !@can_update
3838
.span.unit (μl)
3939

40-
= f.form_field :reference_gene do
41-
= autocomplete_field(f, "batch[reference_gene]", :reference_gene, @navigation_context.institution, class: "input-x-large")
42-
43-
= f.form_field :target_organism_taxonomy_id do
44-
= autocomplete_field(f, "batch[target_organism_taxonomy_id]", :target_organism_taxonomy_id, @navigation_context.institution, class: "input-x-large")
45-
46-
= f.form_field :pango_lineage do
47-
= autocomplete_field(f, "batch[pango_lineage]", :pango_lineage, @navigation_context.institution, class: "input-x-large")
48-
49-
= f.form_field :who_label do
50-
= autocomplete_field(f, "batch[who_label]", :who_label, @navigation_context.institution, class: "input-x-large")
51-
40+
:ruby
41+
field_names = [
42+
'virus_shortname',
43+
'reference_gene',
44+
'target_organism_taxonomy_id',
45+
'target_organism_name',
46+
'pango_lineage',
47+
'who_label',
48+
'gisaid_id',
49+
'gisaid_clade',
50+
'nucleotide_db_id',
51+
'virus_sample_source',
52+
'virus_sample_source_url',
53+
'virus_source',
54+
'virus_location',
55+
'virus_sample_type',
56+
'virus_sample_formulation',
57+
'virus_sample_concentration',
58+
'virus_sample_concentration_unit',
59+
'virus_sample_genome_equivalents',
60+
'virus_sample_genome_equivalents_unit',
61+
'virus_sample_genome_equivalents_reference_gene',
62+
'virus_preinactivation_tcid50',
63+
'virus_preinactivation_tcid50_unit',
64+
'virus_sample_grow_cell_line'
65+
]
66+
- field_names.each do |field|
67+
= f.form_field field.to_sym do
68+
= autocomplete_field(f, "batch[#{field}]", field.to_sym, @navigation_context.institution, class: "input-x-large")
69+
5270
- if @can_edit_sample_quantity
5371
= f.form_field :samples_quantity do
5472
= f.number_field :samples_quantity, min: 0, :class => "input-small"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
csv << [
2+
'virus_batch_number',
3+
'virus_shortname',
4+
'target_organism_name',
5+
'target_organism_taxonomy_id',
6+
'isolate_name',
7+
'gisaid_id',
8+
'nucleotide_db_id',
9+
'pango_lineage',
10+
'who_label',
11+
'gisaid_clade',
12+
'virus_sample_source',
13+
'virus_sample_source_url',
14+
'virus_source',
15+
'virus_location',
16+
'virus_sample_type',
17+
'virus_sample_inactivation_method',
18+
'virus_sample_formulation',
19+
'virus_sample_concentration',
20+
'virus_sample_concentration_unit',
21+
'virus_sample_concentration_reference_gene',
22+
'virus_sample_genome_equivalents',
23+
'virus_sample_genome_equivalents_unit',
24+
'virus_sample_genome_equivalents_reference_gene',
25+
'virus_preinactivation_tcid50',
26+
'virus_preinactivation_tcid50_unit',
27+
'virus_sample_grow_cell_line'
28+
]
29+
30+
@target_batches.each do |batch|
31+
csv << [
32+
batch.batch_number,
33+
batch.virus_shortname,
34+
batch.target_organism_name,
35+
batch.target_organism_taxonomy_id,
36+
batch.isolate_name,
37+
batch.gisaid_id,
38+
batch.nucleotide_db_id,
39+
batch.pango_lineage,
40+
batch.who_label,
41+
batch.gisaid_clade,
42+
batch.virus_sample_source,
43+
batch.virus_sample_source_url,
44+
batch.virus_source,
45+
batch.virus_location,
46+
batch.virus_sample_type,
47+
batch.inactivation_method,
48+
batch.virus_sample_formulation,
49+
batch.virus_sample_concentration,
50+
batch.virus_sample_concentration_unit,
51+
batch.reference_gene,
52+
batch.virus_sample_genome_equivalents,
53+
batch.virus_sample_genome_equivalents_unit,
54+
batch.virus_sample_genome_equivalents_reference_gene,
55+
batch.virus_preinactivation_tcid50,
56+
batch.virus_preinactivation_tcid50_unit,
57+
batch.virus_sample_grow_cell_line
58+
]
59+
end

app/views/nih_tables/nih_challenge.csv.csvbuilder

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ csv << [
3232
"#{@target_box.purpose}-panel",
3333
'inactivated virus',
3434
'SARS-CoV-2',
35-
@target_sample.target_organism_taxonomy_id,
36-
@target_sample.pango_lineage,
37-
@target_sample.who_label,
35+
@target_sample.original_batch.target_organism_taxonomy_id,
36+
@target_sample.original_batch.pango_lineage,
37+
@target_sample.original_batch.who_label,
3838
params[:threshold],
3939
'copies/mL',
4040
params[:true_positives],

app/views/nih_tables/nih_lod.csv.csvbuilder

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ csv << [
2727
"#{@target_box.purpose}-panel",
2828
'inactivated virus',
2929
'SARS-CoV-2',
30-
@target_sample.target_organism_taxonomy_id,
31-
@target_sample.pango_lineage,
32-
@target_sample.who_label,
30+
@target_sample.original_batch.target_organism_taxonomy_id,
31+
@target_sample.original_batch.pango_lineage,
32+
@target_sample.original_batch.who_label,
3333
@samples_report.lob,
3434
nil,
3535
@samples_report.lod,
36-
@target_sample.reference_gene,
36+
@target_sample.original_batch.reference_gene,
3737
nil,
3838
nil,
3939
"90",

0 commit comments

Comments
 (0)