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

sample summary report expansion #585

Merged
merged 13 commits into from
Oct 29, 2024
22 changes: 19 additions & 3 deletions microsetta_private_api/admin/admin_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
post_daklapack_orders
from microsetta_private_api import localization
from microsetta_private_api.admin.sample_summary import per_sample
from microsetta_private_api.admin.sample_summary import get_barcodes_for
from microsetta_private_api.admin.sample_summary import \
get_barcodes_by_project_id,\
get_barcodes_by_kit_ids, get_barcodes_by_emails,\
get_barcodes_by_outbound_tracking_numbers,\
get_barcodes_by_inbound_tracking_numbers
from microsetta_private_api.util.melissa import verify_address
from microsetta_private_api.util.query_builder_to_sql import build_condition
from werkzeug.exceptions import Unauthorized
Expand Down Expand Up @@ -500,12 +504,24 @@ def query_project_barcode_stats(body, token_info, strip_sampleid):

def query_barcode_stats(body, token_info, strip_sampleid):
validate_admin_access(token_info)

project_id = None

if 'sample_barcodes' in body:
project_id = None
barcodes = body["sample_barcodes"]
elif 'kit_ids' in body:
barcodes = get_barcodes_by_kit_ids(body["kit_ids"])
elif 'emails' in body:
barcodes = get_barcodes_by_emails(body["emails"])
elif 'outbound_tracking_numbers' in body:
barcodes = get_barcodes_by_outbound_tracking_numbers
(body["outbound_tracking_numbers"])
elif 'inbound_tracking_numbers' in body:
barcodes = get_barcodes_by_inbound_tracking_numbers
(body["inbound_tracking_numbers"])
cassidysymons marked this conversation as resolved.
Show resolved Hide resolved
elif 'project_id' in body:
project_id = body["project_id"]
barcodes = get_barcodes_for(project_id)
barcodes = get_barcodes_by_project_id(project_id)

unprocessed_barcodes = None

Expand Down
44 changes: 39 additions & 5 deletions microsetta_private_api/admin/sample_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,33 @@
from werkzeug.exceptions import NotFound


def get_barcodes_for(project_id):
if project_id is None:
raise ValueError("project_id must be defined.")

def get_barcodes_by_project_id(project_id):
with Transaction() as t:
return AdminRepo(t).get_project_barcodes(project_id)


def get_barcodes_by_kit_ids(kit_ids):
with Transaction() as t:
return AdminRepo(t).get_kit_barcodes(kit_ids)


def get_barcodes_by_emails(emails):
with Transaction() as t:
return AdminRepo(t).get_email_barcodes(emails)


def get_barcodes_by_outbound_tracking_numbers(outbound_tracking_numbers):
with Transaction() as t:
return AdminRepo(t).get_outbound_tracking_barcodes
(outbound_tracking_numbers)


def get_barcodes_by_inbound_tracking_numbers(inbound_tracking_numbers):
with Transaction() as t:
return AdminRepo(t).get_inbound_tracking_barcodes
(inbound_tracking_numbers)


def per_sample(project, barcodes, strip_sampleid):
summaries = []
with Transaction() as t:
Expand Down Expand Up @@ -84,6 +103,16 @@ def per_sample(project, barcodes, strip_sampleid):
sample.id
)

kit_id_name = sample_repo._get_supplied_kit_id_by_sample(barcode)
outbound_fedex_tracking = \
admin_repo.get_outbound_tracking_by_barcodes(barcode)
inbound_fedex_tracking = \
admin_repo.get_inbound_tracking_by_barcodes(barcode)
ayobi marked this conversation as resolved.
Show resolved Hide resolved
first_scan_timestamp_status = \
admin_repo.get_first_scan_timestamp_by_barcodes(barcode)
last_scan_timestamp_status = \
admin_repo.get_last_scan_timestamp_by_barcodes(barcode)

ayobi marked this conversation as resolved.
Show resolved Hide resolved
summary = {
"sampleid": None if strip_sampleid else barcode,
"project": barcode_project,
Expand All @@ -96,7 +125,12 @@ def per_sample(project, barcodes, strip_sampleid):
"ffq-taken": ffq_taken,
"ffq-complete": ffq_complete,
"sample-status": sample_status,
"sample-received": sample_status is not None
"sample-received": sample_status is not None,
"kit-id": kit_id_name,
"outbound-tracking": outbound_fedex_tracking,
"inbound-tracking": inbound_fedex_tracking,
"first-scan-timestamp-status": first_scan_timestamp_status,
"last-scan-timestamp-status": last_scan_timestamp_status
}

for status in ["sample-is-valid",
Expand Down
16 changes: 16 additions & 0 deletions microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2998,6 +2998,22 @@ paths:
# not using the defined schema for sample_barcode as it is
# readOnly
type: string
'kit_ids':
type: array
items:
type: string
'emails':
type: array
items:
type: string
'outbound_tracking_numbers':
type: array
items:
type: string
'inbound_tracking_numbers':
type: array
items:
type: string
responses:
'200':
description: Return an object containing a list of dictionaries of sample status for requested accounts
Expand Down
Loading
Loading