-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
392 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...efault_records/submission_templates/010_rvi_bait_capture_library_submission_templates.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# This submission template is associated with the Limber Bait Capture Library preparation pipeline. | ||
# To create this run WIP=010_bait_capture_library_submission_templates rake record_loader:all | ||
--- | ||
Limber-Htp - RVI - Bait Capture Library: | ||
Limber-Htp - RVI Bait Capture Library - NovaSeq 6000 Paired end sequencing: | ||
submission_class_name: "LinearSubmission" | ||
related_records: | ||
request_type_keys: ["limber_bait_capture_library_prep", "limber_multiplexing"] | ||
request_type_keys: | ||
["limber_bait_capture_library_prep", "limber_multiplexing", "illumina_htp_novaseq_6000_paired_end_sequencing"] | ||
project_name: Respiratory Virus and Microbiome Initiative | ||
product_line_name: Illumina-HTP | ||
product_catalogue_name: Bait Capture Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# frozen_string_literal: true | ||
|
||
# Rails task to add missing asset audit records from a CSV file | ||
namespace :asset_audit do | ||
# This rake task is used to add missing asset audit records from a CSV file. | ||
# If there are any errors in the CSV file, no records will be inserted. | ||
# Usage: rails asset_audit:add_missing_records['/path/to/file.csv'] | ||
# The CSV file should have the following headers: | ||
# barcode, message, created_by, created_at | ||
# The message column should have one of the following values: | ||
# 'Destroying location', 'Destroying labware' | ||
|
||
desc 'Add missing asset audit records' | ||
task :add_missing_records, [:file_path] => :environment do |_, args| | ||
required_csv_headers = %w[barcode message created_by created_at] | ||
|
||
# Check if the file path is provided and valid | ||
file_path = args[:file_path] == 'nil' ? nil : args[:file_path] | ||
raise 'Please provide a valid file path' if file_path.nil? || !File.exist?(file_path) | ||
|
||
# Read the CSV file and validate the headers | ||
begin | ||
csv_data = CSV.read(file_path, headers: true) | ||
rescue StandardError => e | ||
raise "Failed to read CSV file: #{e.message}" | ||
end | ||
|
||
unless csv_data.headers.length == required_csv_headers.length | ||
raise 'Failed to read CSV file: Invalid number of header columns.' | ||
end | ||
|
||
# Process the CSV data and create asset audit records data array to insert | ||
asset_audit_data = [] | ||
csv_data.each do |row| | ||
missing_columns = required_csv_headers.select { |header| row[header].nil? } | ||
|
||
# Check if any of the required columns are missing | ||
raise 'Failed to read CSV file: Missing columns.' unless missing_columns.empty? | ||
|
||
# Find the asset by barcode | ||
asset = Labware.find_by_barcode(row['barcode'].strip) | ||
raise "Asset with barcode #{row['barcode']} not found." if asset.nil? | ||
|
||
# Check if the message is valid | ||
key = | ||
case row['message'] | ||
when 'Destroying location' | ||
'destroy_location' | ||
when 'Destroying labware' | ||
'destroy_labware' | ||
end | ||
|
||
raise "Invalid message for asset with barcode #{row['barcode']}." if key.nil? | ||
|
||
# Create the asset audit record data | ||
data = { | ||
asset_id: asset.id, | ||
created_by: row['created_by'], | ||
created_at: row['created_at'], | ||
message: "Process '#{row['message']}' performed on instrument Destroying instrument", | ||
key: key | ||
} | ||
asset_audit_data << data | ||
end | ||
|
||
# Insert the asset audit records | ||
ActiveRecord::Base.transaction do | ||
asset_audit_data.each do |data| | ||
AssetAudit.create!( | ||
message: data[:message], | ||
created_by: data[:created_by], | ||
created_at: data[:created_at], | ||
asset_id: data[:asset_id], | ||
key: data[:key] | ||
) | ||
end | ||
puts 'All records successfully inserted.' | ||
rescue ActiveRecord::ActiveRecordError => e | ||
puts "Failed to insert records: #{e.message}" | ||
raise ActiveRecord::Rollback | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
barcode,message,created_by,created_at | ||
SQPD-9002;"Destroying location;User1,2021-01-01 12:00:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
barcode,message,created_by,created_at | ||
SQPD-1,Destroying test,User1,2021-01-01 12:00:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
barcode,message,created_by,created_at | ||
SQPD-1,Destroying location,2021-01-01 12:00:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
barcode,created_by,created_at | ||
SQPD-1,Destroying location,2021-01-01 12:00:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
barcode,message,created_by,created_at | ||
SQPD-1,Destroying location,User1,2021-01-01 12:00:00 | ||
SQPD-2,Destroying labware,User2,2021-01-02 12:00:00 |
4 changes: 4 additions & 0 deletions
4
spec/data/record_loader/application_record_loader/example.wip.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Test record loader records | ||
--- | ||
Test Record: | ||
test_attribute: "A Value" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.