Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create barcodes for exisiting kits #99

Closed

Conversation

ayobi
Copy link
Contributor

@ayobi ayobi commented Mar 8, 2024

Taking from task description, this PR covers part 1:

Add a barcode to an existing kit (new feature). In this scenario, there already exists a kit in the database with one or more barcodes. The user will log into microsetta-admin and add barcodes to one or more kits, and it needs to provide the following options:

  • Add barcodes to a single kit. The user would enter a Kit ID into a text field, then have the option to either enter a barcode to add to the kit OR dynamically generate a new barcode to add to the kit (using the existing barcode generation function). If it's a generated barcode, the output should inform the user of the newly created barcode. Otherwise, the output should be a success/failure message.

  • Add barcodes to several kits. The user would upload a CSV file with Kit IDs in the first column. They would then have the option to either add a dynamically generated barcode to each kit OR put a barcode in the second column of the CSV file. In either case, the tool should return a CSV file with the Kit IDs and the newly added barcodes.

API PR can be found here.

@ayobi ayobi marked this pull request as ready for review March 8, 2024 21:34
@ayobi
Copy link
Contributor Author

ayobi commented Mar 25, 2024

Added part 2:

The user can now provide their own barcode(s) if needed when they're creating a kit. This can be done either by providing the barcode(s) in the field(s) OR they can upload a list of barcodes via a csv file.

microsetta_admin/templates/add_barcode_to_kit.html Outdated Show resolved Hide resolved
microsetta_admin/templates/add_barcode_to_kit.html Outdated Show resolved Hide resolved
microsetta_admin/templates/create_kits.html Outdated Show resolved Hide resolved
microsetta_admin/server.py Show resolved Hide resolved
microsetta_admin/templates/create_kits.html Outdated Show resolved Hide resolved
microsetta_admin/server.py Outdated Show resolved Hide resolved
microsetta_admin/server.py Outdated Show resolved Hide resolved
@ayobi ayobi marked this pull request as draft August 7, 2024 17:21
@ayobi ayobi marked this pull request as ready for review August 15, 2024 04:44
microsetta_admin/server.py Outdated Show resolved Hide resolved
microsetta_admin/server.py Outdated Show resolved Hide resolved
microsetta_admin/server.py Outdated Show resolved Hide resolved
microsetta_admin/server.py Outdated Show resolved Hide resolved
microsetta_admin/server.py Outdated Show resolved Hide resolved
microsetta_admin/tests/test_routes.py Show resolved Hide resolved
microsetta_admin/templates/add_barcode_to_kit.html Outdated Show resolved Hide resolved
microsetta_admin/server.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@cassidysymons cassidysymons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't thoroughly reviewed this, but noted a couple of things that jumped out at me. Given the fact that there's still some work to do on the Private API portion, and potential for change here, I'm going to defer on further review until those changes have been addressed.

microsetta_admin/server.py Outdated Show resolved Hide resolved
microsetta_admin/server.py Outdated Show resolved Hide resolved
Comment on lines +668 to +690
if 'kit_ids' in request.form:
kit_ids = request.form['kit_ids']

if 'user_barcode' in request.form:
user_barcode = request.form['user_barcode']
barcodes.append(user_barcode)
else:
user_barcode = None

generate_barcode_single = \
request.form.get('generate_barcode_single')
generate_barcodes_multiple = \
request.form.get('generate_barcodes_multiple')

if 'kit_ids' in request.files:
kit_ids_file = request.files['kit_ids']
kit_ids = _read_csv_file(kit_ids_file)

if 'barcodes_file' in request.files:
barcodes_file = request.files['barcodes_file']
barcodes = _read_csv_file(barcodes_file)

if generate_barcode_single or user_barcode:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feels like there's a lot of redundancy here. For example, we know that if the user selects Add Barcode to Single Kit, kit_ids should be present as a string and either user_barcode or generate_barcode_single should be present. Is it necessary to check for each of those individually?

Comment on lines +691 to +742
if not user_barcode:
payload = {
'action': 'create',
'kit_ids': kit_ids,
'generate_barcode_single': generate_barcode_single
}
barcodes = _handle_add_barcodes_api_request(payload)
if isinstance(barcodes, tuple):
return barcodes

payload = {
"action": "insert",
"barcodes": barcodes,
"kit_ids": kit_ids
}
result = _handle_add_barcodes_api_request(payload)
if isinstance(result, tuple):
return result

return render_template('add_barcode_to_kit.html',
barcodes=barcodes,
kit_id=kit_ids,
**build_login_variables())

if generate_barcodes_multiple:
payload = {
'action': 'create',
'kit_ids': kit_ids,
'generate_barcodes_multiple': generate_barcodes_multiple
}
barcodes = _handle_add_barcodes_api_request(payload)
if isinstance(barcodes, tuple):
return barcodes

if len(kit_ids) != len(barcodes):
error_message = f'The number of kit IDs ({len(kit_ids)}) '\
f'does not match the number of barcodes '\
f'({len(barcodes)}).'
return render_template('add_barcode_to_kit.html',
error_message=error_message,
**build_login_variables()), 400

payload = {
"action": "insert",
"barcodes": barcodes,
"kit_ids": kit_ids
}
result = _handle_add_barcodes_api_request(payload)
if isinstance(result, tuple):
return result

return _save_and_send_csv(kit_ids, barcodes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code would be considerably more readable if it was an if/elif block, rather than cascading through conditional return statements that require cross-referencing which variable is being used.

Comment on lines +555 to +570
total_provided_samples += len(new_barcodes)

# Calculate remaining samples to be generated
total_needed_samples = num_kits * num_samples
remaining_samples_to_generate = total_needed_samples - \
total_provided_samples

if remaining_samples_to_generate < 0:
error_message = (f'Too many samples provided '
f'({total_provided_samples}) '
f'for the specified number of kits and samples '
f'({total_needed_samples}).')
return render_template('create_kits.html',
error_message=error_message,
projects=projects,
**build_login_variables())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the fact that the code should be enforcing the number of provided samples on a per-slot basis, does this block still serve a purpose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants