Skip to content

Commit

Permalink
Merge pull request #589 from biocore/csymons_sample_summary_updates
Browse files Browse the repository at this point in the history
Sample Summary Report Adjustments
  • Loading branch information
cassidysymons authored Dec 2, 2024
2 parents ea6cd51 + c17313a commit 9f5fb2c
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 18 deletions.
6 changes: 5 additions & 1 deletion microsetta_private_api/admin/admin_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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
get_barcodes_by_inbound_tracking_numbers, get_barcodes_by_dak_order_ids
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 @@ -521,6 +521,10 @@ def query_barcode_stats(body, token_info, strip_sampleid):
barcodes = get_barcodes_by_inbound_tracking_numbers(
body["inbound_tracking_numbers"]
)
elif 'dak_order_ids' in body:
barcodes = get_barcodes_by_dak_order_ids(
body['dak_order_ids']
)
elif 'project_id' in body:
project_id = body["project_id"]
barcodes = get_barcodes_by_project_id(project_id)
Expand Down
14 changes: 14 additions & 0 deletions microsetta_private_api/admin/sample_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def get_barcodes_by_inbound_tracking_numbers(inbound_tracking_numbers):
inbound_tracking_numbers=inbound_tracking_numbers)


def get_barcodes_by_dak_order_ids(dak_order_ids):
with Transaction() as t:
return AdminRepo(t).get_barcodes_filter(
dak_order_ids=dak_order_ids
)


def per_sample(project, barcodes, strip_sampleid):
summaries = []
with Transaction() as t:
Expand Down Expand Up @@ -73,6 +80,8 @@ def per_sample(project, barcodes, strip_sampleid):
latest_scan_status = None

account_email = None if account is None else account.email
account_fname = None if account is None else account.first_name
account_lname = None if account is None else account.last_name
source_type = None if source is None else source.source_type
vio_id = None

Expand Down Expand Up @@ -135,10 +144,12 @@ def per_sample(project, barcodes, strip_sampleid):
kit_id_name = info['kit_id']
outbound_fedex_tracking = info['outbound_tracking']
inbound_fedex_tracking = info['inbound_tracking']
daklapack_order_id = info['dak_order_id']
else:
kit_id_name = None
outbound_fedex_tracking = None
inbound_fedex_tracking = None
daklapack_order_id = None

summary = {
"sampleid": None if strip_sampleid else barcode,
Expand All @@ -148,6 +159,8 @@ def per_sample(project, barcodes, strip_sampleid):
"sample-date": sample_date,
"sample-time": sample_time,
"account-email": account_email,
"account-first-name": account_fname,
"account-last-name": account_lname,
"vioscreen_username": vio_id,
"ffq-taken": ffq_taken,
"ffq-complete": ffq_complete,
Expand All @@ -160,6 +173,7 @@ def per_sample(project, barcodes, strip_sampleid):
"kit-id": kit_id_name,
"outbound-tracking": outbound_fedex_tracking,
"inbound-tracking": inbound_fedex_tracking,
"daklapack-order-id": daklapack_order_id
}

for status in ["sample-is-valid",
Expand Down
116 changes: 103 additions & 13 deletions microsetta_private_api/admin/tests/test_admin_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,26 +1593,116 @@ def test_get_barcodes_filter_inbound_tracking_failure(self):
inbound_tracking_numbers=['99999'])
self.assertEqual(barcodes, [])

def test_get_kit_by_barcode_success(self):
def test_get_barcodes_filter_dak_order_ids_success(self):
dak_order_id = 'd77e111e-ded2-4817-9240-7e94c6712102'
kit_id = 'test1'
kit_uuid = '2fd79f11-f377-4fa8-99f3-cc184192180b'
outbound_tracking = 'FEDEX_OUT_1234'
inbound_tracking = 'FEDEX_IN_5678'
barcode = '00001234'

with Transaction() as t:
setup_sql = """
INSERT INTO barcodes.kit (kit_id, box_id)
VALUES ('test1', '0001e15f-4170-4b28-b111-191cd567c348');
with t.cursor() as cur:
# Insert Daklapack order
cur.execute(
"INSERT INTO barcodes.daklapack_order "
"(dak_order_id, submitter_acct_id, order_json) "
"VALUES (%s, %s, '{}')",
(dak_order_id, ADMIN_ACCT_ID)
)

INSERT INTO barcodes.barcode (barcode, kit_id)
VALUES ('00001234', 'test1');
"""
# Insert Kit
cur.execute(
"INSERT INTO barcodes.kit "
"(kit_uuid, kit_id, box_id, outbound_fedex_tracking, "
"inbound_fedex_tracking) "
"VALUES (%s, %s, '0001e15f-4170-4b28-b111-191cd567c348', "
"%s, %s)",
(kit_uuid, kit_id, outbound_tracking, inbound_tracking)
)

# Insert Daklapack order to kit record
cur.execute(
"INSERT INTO barcodes.daklapack_order_to_kit "
"(dak_order_id, kit_uuid) "
"VALUES (%s, %s)",
(dak_order_id, kit_uuid)
)

# Insert barcode
cur.execute(
"INSERT INTO barcodes.barcode (barcode, kit_id) "
"VALUES (%s, %s)",
(barcode, kit_id)
)

admin_repo = AdminRepo(t)
barcodes = admin_repo.get_barcodes_filter(
dak_order_ids=[dak_order_id]
)
self.assertEqual(barcodes, [barcode])

def test_get_barcodes_filter_dak_order_ids_failure(self):
dak_order_id = 'd77e111e-ded2-4817-9240-7e94c6712102'
with Transaction() as t:
admin_repo = AdminRepo(t)
barcodes = admin_repo.get_barcodes_filter(
dak_order_ids=[dak_order_id]
)
self.assertEqual(barcodes, [])

def test_get_kit_by_barcode_success(self):
dak_order_id = 'd77e111e-ded2-4817-9240-7e94c6712102'
kit_id = 'test1'
kit_uuid = '2fd79f11-f377-4fa8-99f3-cc184192180b'
outbound_tracking = 'FEDEX_OUT_1234'
inbound_tracking = 'FEDEX_IN_5678'
barcode = '00001234'

with Transaction() as t:
with t.cursor() as cur:
cur.execute(setup_sql)
# Insert Daklapack order
cur.execute(
"INSERT INTO barcodes.daklapack_order "
"(dak_order_id, submitter_acct_id, order_json) "
"VALUES (%s, %s, '{}')",
(dak_order_id, ADMIN_ACCT_ID)
)

# Insert Kit
cur.execute(
"INSERT INTO barcodes.kit "
"(kit_uuid, kit_id, box_id, outbound_fedex_tracking, "
"inbound_fedex_tracking) "
"VALUES (%s, %s, '0001e15f-4170-4b28-b111-191cd567c348', "
"%s, %s)",
(kit_uuid, kit_id, outbound_tracking, inbound_tracking)
)

# Insert Daklapack order to kit record
cur.execute(
"INSERT INTO barcodes.daklapack_order_to_kit "
"(dak_order_id, kit_uuid) "
"VALUES (%s, %s)",
(dak_order_id, kit_uuid)
)

# Insert barcode
cur.execute(
"INSERT INTO barcodes.barcode (barcode, kit_id) "
"VALUES (%s, %s)",
(barcode, kit_id)
)

admin_repo = AdminRepo(t)

kit_info = admin_repo.get_kit_by_barcode(['00001234'])
kit_info = admin_repo.get_kit_by_barcode([barcode])
expected = [{
'barcode': '00001234',
'outbound_tracking': None,
'inbound_tracking': None,
'kit_id': 'test1'
'barcode': barcode,
'outbound_tracking': outbound_tracking,
'inbound_tracking': inbound_tracking,
'kit_id': kit_id,
'dak_order_id': dak_order_id
}]
self.assertEqual(kit_info, expected)

Expand Down
4 changes: 4 additions & 0 deletions microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3014,6 +3014,10 @@ paths:
type: array
items:
type: string
'dak_order_ids':
type: array
items:
type: string
responses:
'200':
description: Return an object containing a list of dictionaries of sample status for requested accounts
Expand Down
25 changes: 21 additions & 4 deletions microsetta_private_api/repo/admin_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ def get_project_barcodes(self, project_id):

def get_barcodes_filter(self, kit_ids=None, emails=None,
outbound_tracking_numbers=None,
inbound_tracking_numbers=None):
inbound_tracking_numbers=None,
dak_order_ids=None):
"""Obtain the barcodes based on different filtering criteria.
Parameters
Expand All @@ -568,6 +569,8 @@ def get_barcodes_filter(self, kit_ids=None, emails=None,
List of outbound tracking numbers to obtain barcodes for.
inbound_tracking_numbers : list, optional
List of inbound tracking numbers to obtain barcodes for.
dak_order_ids : list, optional
List of Daklapack order IDs to obtain barcodes for
Returns
-------
Expand Down Expand Up @@ -604,6 +607,14 @@ def get_barcodes_filter(self, kit_ids=None, emails=None,
conditions.append("k.inbound_fedex_tracking IN %s")
params.append(tuple(inbound_tracking_numbers))

if dak_order_ids:
query += """
JOIN barcodes.daklapack_order_to_kit dotk
ON dotk.kit_uuid = k.kit_uuid
"""
conditions.append("dotk.dak_order_id IN %s")
params.append(tuple(dak_order_ids))

if conditions:
query += " WHERE " + " AND ".join(conditions)

Expand All @@ -615,7 +626,7 @@ def get_barcodes_filter(self, kit_ids=None, emails=None,

def get_kit_by_barcode(self, barcodes):
"""Obtain the outbound tracking, inbound tracking numbers,
and kit ID associated with a list of barcodes.
kit ID, and Daklapack order ID associated with a list of barcodes.
Parameters
----------
Expand All @@ -633,13 +644,18 @@ def get_kit_by_barcode(self, barcodes):
b.barcode,
k.outbound_fedex_tracking,
k.inbound_fedex_tracking,
k.kit_id
k.kit_id,
dotk.dak_order_id
FROM
barcodes.barcode b
JOIN
barcodes.kit k
ON
b.kit_id = k.kit_id
LEFT JOIN
barcodes.daklapack_order_to_kit dotk
ON
dotk.kit_uuid = k.kit_uuid
WHERE
b.barcode IN %s
"""
Expand All @@ -657,7 +673,8 @@ def get_kit_by_barcode(self, barcodes):
"barcode": row[0],
"outbound_tracking": row[1],
"inbound_tracking": row[2],
"kit_id": row[3]
"kit_id": row[3],
"dak_order_id": row[4]
}
for row in rows
]
Expand Down

0 comments on commit 9f5fb2c

Please sign in to comment.