Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a5b5a47
save changes
wendyyang Mar 19, 2026
e446636
save change
wendyyang Mar 23, 2026
99653c3
remove retention instruction param
wendyyang Mar 23, 2026
67bc87f
save changes
wendyyang Mar 25, 2026
fc408a1
save changes
wendyyang Mar 26, 2026
31159ad
refactor
wendyyang Mar 26, 2026
0b1e94f
merge develop in and resolve conflict
wendyyang Mar 27, 2026
77a9e04
add tests
wendyyang Mar 27, 2026
a2a9912
fix the typo
wendyyang Mar 27, 2026
7e4e26f
fix the typo
wendyyang Mar 27, 2026
8a8178f
refactor test
wendyyang Apr 10, 2026
81e643c
update the new column type
wendyyang Apr 10, 2026
ef88f72
fix the test
wendyyang Apr 10, 2026
9b13bb4
fix tests
wendyyang Apr 10, 2026
c010b3d
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang Apr 13, 2026
d767076
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang Apr 13, 2026
f150c6f
merge develop in
wendyyang Apr 29, 2026
de897c4
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang Apr 30, 2026
e973767
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang May 4, 2026
1f63913
move filter in the scope
wendyyang May 5, 2026
bb4db65
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang May 5, 2026
cd2be93
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang May 5, 2026
2b9a0cf
refactor search_for_labware_by_selection
wendyyang May 5, 2026
b572c92
fix the test
wendyyang May 5, 2026
eab5820
fix linting
wendyyang May 5, 2026
9cc102e
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang May 6, 2026
d233cf9
refactor the tests
wendyyang May 7, 2026
1851e07
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang May 7, 2026
b91b6ca
rename the plate_3_return_customer
wendyyang May 7, 2026
4d1e8fb
Merge branch 'develop' into Y26-031---labware-location-report-by-rete…
wendyyang May 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/controllers/location_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def location_report_params # rubocop:todo Metrics/MethodLength
:study_id,
:start_date,
:end_date,
:barcodes,
:barcodes_text,
Comment thread
StephenHulme marked this conversation as resolved.
retention_instructions: [],
faculty_sponsor_ids: [],
plate_purpose_ids: []
)
Expand Down
13 changes: 13 additions & 0 deletions app/models/labware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,21 @@ def receptacle_proxy
}

# Used for location report
def self.map_retention_instructions(values)
return if values.blank?

values.filter_map { |v| Labware.retention_instructions[v] }
end

def self.search_for_labware(params)
with_faculty_sponsor_ids(params[:faculty_sponsor_ids] || nil)
.with_study_id(params[:study_id] || nil)
.with_plate_purpose_ids(params[:plate_purpose_ids] || nil)
.created_between(params[:start_date], params[:end_date])
.filter_by_barcode(params[:barcodes] || nil)
.with_retention_instructions(
map_retention_instructions(params[:retention_instructions])
)
.distinct
end

Expand All @@ -186,6 +195,10 @@ def self.search_for_count_of_labware(params)
scope :with_plate_purpose_ids,
->(plate_purpose_ids) { where(plate_purpose_id: plate_purpose_ids) if plate_purpose_ids.present? }

scope :with_retention_instructions, ->(retention_instructions) {
where(retention_instruction: retention_instructions) if retention_instructions.present?
}

scope :created_between,
->(start_date, end_date) do
where(created_at: (start_date.midnight..(end_date || Time.current).end_of_day)) if start_date.present?
Expand Down
10 changes: 6 additions & 4 deletions app/models/location_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class LocationReport < ApplicationRecord
serialize :faculty_sponsor_ids, type: Array, coder: YAML
serialize :plate_purpose_ids, type: Array, coder: YAML
serialize :barcodes, type: Array, coder: YAML
serialize :retention_instructions, type: Array, coder: YAML
self.per_page = 20
enum :report_type, { type_selection: 0, type_labwhere: 1 }

Expand Down Expand Up @@ -49,7 +50,7 @@ def check_location_barcode
end

def check_any_select_field_present
attr_list = %i[faculty_sponsor_ids study_id start_date end_date plate_purpose_ids barcodes]
attr_list = %i[faculty_sponsor_ids study_id start_date end_date plate_purpose_ids barcodes retention_instructions]
if attr_list.all? { |attr| send(attr).blank? }
errors.add(:base, I18n.t('location_reports.errors.no_selection_fields_filled'))
end
Expand Down Expand Up @@ -119,7 +120,6 @@ def generate_report_rows # rubocop:todo Metrics/MethodLength
end

yield column_headers

labware_list.each do |cur_labware|
if cur_labware.studies.present?
cur_labware.studies.each { |cur_study| yield(generate_report_row(cur_labware, cur_study)) }
Expand Down Expand Up @@ -175,13 +175,15 @@ def generate_study_cols_for_row(cur_study)
cols << (cur_study.study_metadata.faculty_sponsor&.name || 'Unknown')
end

def search_for_labware_by_selection
params = { faculty_sponsor_ids:, study_id:, start_date:, end_date:, plate_purpose_ids:, barcodes: }
def search_for_labware_by_selection # rubocop:todo Metrics/AbcSize
params = { faculty_sponsor_ids:, study_id:, start_date:, end_date:, plate_purpose_ids:, barcodes:,
retention_instructions: }
count = Labware.search_for_count_of_labware(params)
if count > configatron.fetch(:location_reports_fetch_count_max, 25000)
errors.add(:base, I18n.t('location_reports.errors.too_many_labwares_found', count:))
return []
end

# Only plates and tubes are currently supported by this report
Labware.search_for_labware(params).filter { |labware| labware.is_a?(Plate) || labware.is_a?(Tube) }
end
Expand Down
6 changes: 4 additions & 2 deletions app/models/location_report/location_report_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class LocationReport::LocationReportForm
include ActiveModel::AttributeMethods

# Attributes
attr_accessor :user, :report_type, :faculty_sponsor_ids, :study_id, :start_date, :end_date, :plate_purpose_ids
attr_accessor :user, :report_type, :faculty_sponsor_ids, :study_id, :start_date, :end_date, :retention_instructions,
:plate_purpose_ids

attr_accessor :barcodes_text
attr_reader :name, :location_barcode
Expand Down Expand Up @@ -44,7 +45,8 @@ def location_report
start_date: start_date&.to_datetime,
end_date: end_date&.to_datetime,
plate_purpose_ids: plate_purpose_ids,
barcodes: barcodes
barcodes: barcodes,
retention_instructions: retention_instructions
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
</div>
</div>

<div class='form-group'>
<%= f.label 'retention_instructions', 'Retention instructions' %>
<%= f.select :retention_instructions, options_for_select(retention_instruction_option_for_select, location_report_form.retention_instructions), { include_hidden: false }, { class: 'form-control select2', :multiple => true } %>
Comment thread
wendyyang marked this conversation as resolved.
</div>

<div class='form-group'>
<%= f.label 'plate_purpose_ids', 'Labware purposes (can select multiple)' %>
<%= f.select :plate_purpose_ids, options_for_select(Purpose.alphabetical.pluck(:name, :id), location_report_form.plate_purpose_ids), { include_hidden: false }, { class: 'form-control select2', :multiple => true } %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
class AddRetentionInstructionsToLocationReports < ActiveRecord::Migration[7.2]
def change
add_column :location_reports, :retention_instructions, :string
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@
t.string "report_filename"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.string "retention_instructions"
t.index ["study_id"], name: "index_location_reports_on_study_id"
t.index ["user_id"], name: "index_location_reports_on_user_id"
end
Expand Down
Loading
Loading