Skip to content

Commit 9f5fb2c

Browse files
Merge pull request #589 from biocore/csymons_sample_summary_updates
Sample Summary Report Adjustments
2 parents ea6cd51 + c17313a commit 9f5fb2c

File tree

5 files changed

+147
-18
lines changed

5 files changed

+147
-18
lines changed

microsetta_private_api/admin/admin_impl.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
get_barcodes_by_project_id,\
3434
get_barcodes_by_kit_ids, get_barcodes_by_emails,\
3535
get_barcodes_by_outbound_tracking_numbers,\
36-
get_barcodes_by_inbound_tracking_numbers
36+
get_barcodes_by_inbound_tracking_numbers, get_barcodes_by_dak_order_ids
3737
from microsetta_private_api.util.melissa import verify_address
3838
from microsetta_private_api.util.query_builder_to_sql import build_condition
3939
from werkzeug.exceptions import Unauthorized
@@ -521,6 +521,10 @@ def query_barcode_stats(body, token_info, strip_sampleid):
521521
barcodes = get_barcodes_by_inbound_tracking_numbers(
522522
body["inbound_tracking_numbers"]
523523
)
524+
elif 'dak_order_ids' in body:
525+
barcodes = get_barcodes_by_dak_order_ids(
526+
body['dak_order_ids']
527+
)
524528
elif 'project_id' in body:
525529
project_id = body["project_id"]
526530
barcodes = get_barcodes_by_project_id(project_id)

microsetta_private_api/admin/sample_summary.py

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def get_barcodes_by_inbound_tracking_numbers(inbound_tracking_numbers):
3434
inbound_tracking_numbers=inbound_tracking_numbers)
3535

3636

37+
def get_barcodes_by_dak_order_ids(dak_order_ids):
38+
with Transaction() as t:
39+
return AdminRepo(t).get_barcodes_filter(
40+
dak_order_ids=dak_order_ids
41+
)
42+
43+
3744
def per_sample(project, barcodes, strip_sampleid):
3845
summaries = []
3946
with Transaction() as t:
@@ -73,6 +80,8 @@ def per_sample(project, barcodes, strip_sampleid):
7380
latest_scan_status = None
7481

7582
account_email = None if account is None else account.email
83+
account_fname = None if account is None else account.first_name
84+
account_lname = None if account is None else account.last_name
7685
source_type = None if source is None else source.source_type
7786
vio_id = None
7887

@@ -135,10 +144,12 @@ def per_sample(project, barcodes, strip_sampleid):
135144
kit_id_name = info['kit_id']
136145
outbound_fedex_tracking = info['outbound_tracking']
137146
inbound_fedex_tracking = info['inbound_tracking']
147+
daklapack_order_id = info['dak_order_id']
138148
else:
139149
kit_id_name = None
140150
outbound_fedex_tracking = None
141151
inbound_fedex_tracking = None
152+
daklapack_order_id = None
142153

143154
summary = {
144155
"sampleid": None if strip_sampleid else barcode,
@@ -148,6 +159,8 @@ def per_sample(project, barcodes, strip_sampleid):
148159
"sample-date": sample_date,
149160
"sample-time": sample_time,
150161
"account-email": account_email,
162+
"account-first-name": account_fname,
163+
"account-last-name": account_lname,
151164
"vioscreen_username": vio_id,
152165
"ffq-taken": ffq_taken,
153166
"ffq-complete": ffq_complete,
@@ -160,6 +173,7 @@ def per_sample(project, barcodes, strip_sampleid):
160173
"kit-id": kit_id_name,
161174
"outbound-tracking": outbound_fedex_tracking,
162175
"inbound-tracking": inbound_fedex_tracking,
176+
"daklapack-order-id": daklapack_order_id
163177
}
164178

165179
for status in ["sample-is-valid",

microsetta_private_api/admin/tests/test_admin_repo.py

+103-13
Original file line numberDiff line numberDiff line change
@@ -1593,26 +1593,116 @@ def test_get_barcodes_filter_inbound_tracking_failure(self):
15931593
inbound_tracking_numbers=['99999'])
15941594
self.assertEqual(barcodes, [])
15951595

1596-
def test_get_kit_by_barcode_success(self):
1596+
def test_get_barcodes_filter_dak_order_ids_success(self):
1597+
dak_order_id = 'd77e111e-ded2-4817-9240-7e94c6712102'
1598+
kit_id = 'test1'
1599+
kit_uuid = '2fd79f11-f377-4fa8-99f3-cc184192180b'
1600+
outbound_tracking = 'FEDEX_OUT_1234'
1601+
inbound_tracking = 'FEDEX_IN_5678'
1602+
barcode = '00001234'
1603+
15971604
with Transaction() as t:
1598-
setup_sql = """
1599-
INSERT INTO barcodes.kit (kit_id, box_id)
1600-
VALUES ('test1', '0001e15f-4170-4b28-b111-191cd567c348');
1605+
with t.cursor() as cur:
1606+
# Insert Daklapack order
1607+
cur.execute(
1608+
"INSERT INTO barcodes.daklapack_order "
1609+
"(dak_order_id, submitter_acct_id, order_json) "
1610+
"VALUES (%s, %s, '{}')",
1611+
(dak_order_id, ADMIN_ACCT_ID)
1612+
)
16011613

1602-
INSERT INTO barcodes.barcode (barcode, kit_id)
1603-
VALUES ('00001234', 'test1');
1604-
"""
1614+
# Insert Kit
1615+
cur.execute(
1616+
"INSERT INTO barcodes.kit "
1617+
"(kit_uuid, kit_id, box_id, outbound_fedex_tracking, "
1618+
"inbound_fedex_tracking) "
1619+
"VALUES (%s, %s, '0001e15f-4170-4b28-b111-191cd567c348', "
1620+
"%s, %s)",
1621+
(kit_uuid, kit_id, outbound_tracking, inbound_tracking)
1622+
)
1623+
1624+
# Insert Daklapack order to kit record
1625+
cur.execute(
1626+
"INSERT INTO barcodes.daklapack_order_to_kit "
1627+
"(dak_order_id, kit_uuid) "
1628+
"VALUES (%s, %s)",
1629+
(dak_order_id, kit_uuid)
1630+
)
1631+
1632+
# Insert barcode
1633+
cur.execute(
1634+
"INSERT INTO barcodes.barcode (barcode, kit_id) "
1635+
"VALUES (%s, %s)",
1636+
(barcode, kit_id)
1637+
)
1638+
1639+
admin_repo = AdminRepo(t)
1640+
barcodes = admin_repo.get_barcodes_filter(
1641+
dak_order_ids=[dak_order_id]
1642+
)
1643+
self.assertEqual(barcodes, [barcode])
1644+
1645+
def test_get_barcodes_filter_dak_order_ids_failure(self):
1646+
dak_order_id = 'd77e111e-ded2-4817-9240-7e94c6712102'
1647+
with Transaction() as t:
1648+
admin_repo = AdminRepo(t)
1649+
barcodes = admin_repo.get_barcodes_filter(
1650+
dak_order_ids=[dak_order_id]
1651+
)
1652+
self.assertEqual(barcodes, [])
1653+
1654+
def test_get_kit_by_barcode_success(self):
1655+
dak_order_id = 'd77e111e-ded2-4817-9240-7e94c6712102'
1656+
kit_id = 'test1'
1657+
kit_uuid = '2fd79f11-f377-4fa8-99f3-cc184192180b'
1658+
outbound_tracking = 'FEDEX_OUT_1234'
1659+
inbound_tracking = 'FEDEX_IN_5678'
1660+
barcode = '00001234'
1661+
1662+
with Transaction() as t:
16051663
with t.cursor() as cur:
1606-
cur.execute(setup_sql)
1664+
# Insert Daklapack order
1665+
cur.execute(
1666+
"INSERT INTO barcodes.daklapack_order "
1667+
"(dak_order_id, submitter_acct_id, order_json) "
1668+
"VALUES (%s, %s, '{}')",
1669+
(dak_order_id, ADMIN_ACCT_ID)
1670+
)
1671+
1672+
# Insert Kit
1673+
cur.execute(
1674+
"INSERT INTO barcodes.kit "
1675+
"(kit_uuid, kit_id, box_id, outbound_fedex_tracking, "
1676+
"inbound_fedex_tracking) "
1677+
"VALUES (%s, %s, '0001e15f-4170-4b28-b111-191cd567c348', "
1678+
"%s, %s)",
1679+
(kit_uuid, kit_id, outbound_tracking, inbound_tracking)
1680+
)
1681+
1682+
# Insert Daklapack order to kit record
1683+
cur.execute(
1684+
"INSERT INTO barcodes.daklapack_order_to_kit "
1685+
"(dak_order_id, kit_uuid) "
1686+
"VALUES (%s, %s)",
1687+
(dak_order_id, kit_uuid)
1688+
)
1689+
1690+
# Insert barcode
1691+
cur.execute(
1692+
"INSERT INTO barcodes.barcode (barcode, kit_id) "
1693+
"VALUES (%s, %s)",
1694+
(barcode, kit_id)
1695+
)
16071696

16081697
admin_repo = AdminRepo(t)
16091698

1610-
kit_info = admin_repo.get_kit_by_barcode(['00001234'])
1699+
kit_info = admin_repo.get_kit_by_barcode([barcode])
16111700
expected = [{
1612-
'barcode': '00001234',
1613-
'outbound_tracking': None,
1614-
'inbound_tracking': None,
1615-
'kit_id': 'test1'
1701+
'barcode': barcode,
1702+
'outbound_tracking': outbound_tracking,
1703+
'inbound_tracking': inbound_tracking,
1704+
'kit_id': kit_id,
1705+
'dak_order_id': dak_order_id
16161706
}]
16171707
self.assertEqual(kit_info, expected)
16181708

microsetta_private_api/api/microsetta_private_api.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -3014,6 +3014,10 @@ paths:
30143014
type: array
30153015
items:
30163016
type: string
3017+
'dak_order_ids':
3018+
type: array
3019+
items:
3020+
type: string
30173021
responses:
30183022
'200':
30193023
description: Return an object containing a list of dictionaries of sample status for requested accounts

microsetta_private_api/repo/admin_repo.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ def get_project_barcodes(self, project_id):
555555

556556
def get_barcodes_filter(self, kit_ids=None, emails=None,
557557
outbound_tracking_numbers=None,
558-
inbound_tracking_numbers=None):
558+
inbound_tracking_numbers=None,
559+
dak_order_ids=None):
559560
"""Obtain the barcodes based on different filtering criteria.
560561
561562
Parameters
@@ -568,6 +569,8 @@ def get_barcodes_filter(self, kit_ids=None, emails=None,
568569
List of outbound tracking numbers to obtain barcodes for.
569570
inbound_tracking_numbers : list, optional
570571
List of inbound tracking numbers to obtain barcodes for.
572+
dak_order_ids : list, optional
573+
List of Daklapack order IDs to obtain barcodes for
571574
572575
Returns
573576
-------
@@ -604,6 +607,14 @@ def get_barcodes_filter(self, kit_ids=None, emails=None,
604607
conditions.append("k.inbound_fedex_tracking IN %s")
605608
params.append(tuple(inbound_tracking_numbers))
606609

610+
if dak_order_ids:
611+
query += """
612+
JOIN barcodes.daklapack_order_to_kit dotk
613+
ON dotk.kit_uuid = k.kit_uuid
614+
"""
615+
conditions.append("dotk.dak_order_id IN %s")
616+
params.append(tuple(dak_order_ids))
617+
607618
if conditions:
608619
query += " WHERE " + " AND ".join(conditions)
609620

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

616627
def get_kit_by_barcode(self, barcodes):
617628
"""Obtain the outbound tracking, inbound tracking numbers,
618-
and kit ID associated with a list of barcodes.
629+
kit ID, and Daklapack order ID associated with a list of barcodes.
619630
620631
Parameters
621632
----------
@@ -633,13 +644,18 @@ def get_kit_by_barcode(self, barcodes):
633644
b.barcode,
634645
k.outbound_fedex_tracking,
635646
k.inbound_fedex_tracking,
636-
k.kit_id
647+
k.kit_id,
648+
dotk.dak_order_id
637649
FROM
638650
barcodes.barcode b
639651
JOIN
640652
barcodes.kit k
641653
ON
642654
b.kit_id = k.kit_id
655+
LEFT JOIN
656+
barcodes.daklapack_order_to_kit dotk
657+
ON
658+
dotk.kit_uuid = k.kit_uuid
643659
WHERE
644660
b.barcode IN %s
645661
"""
@@ -657,7 +673,8 @@ def get_kit_by_barcode(self, barcodes):
657673
"barcode": row[0],
658674
"outbound_tracking": row[1],
659675
"inbound_tracking": row[2],
660-
"kit_id": row[3]
676+
"kit_id": row[3],
677+
"dak_order_id": row[4]
661678
}
662679
for row in rows
663680
]

0 commit comments

Comments
 (0)