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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 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,28 @@ def query_project_barcode_stats(body, token_info, strip_sampleid):

def query_barcode_stats(body, token_info, strip_sampleid):
validate_admin_access(token_info)
print("body", body)
if 'sample_barcodes' in body:
project_id = None
barcodes = body["sample_barcodes"]
elif 'kit_ids' in body:
project_id = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since all but one condition set project_id = None, it would be more efficient to move that statement to above the if block and only change it for the project_id condition.

barcodes = get_barcodes_by_kit_ids(body["kit_ids"])
print("kit id barcodes", barcodes)
elif 'emails' in body:
project_id = None
barcodes = get_barcodes_by_emails(body["emails"])
elif 'outbound_tracking_numbers' in body:
project_id = None
barcodes = get_barcodes_by_outbound_tracking_numbers
(body["outbound_tracking_numbers"])
elif 'inbound_tracking_numbers' in body:
project_id = None
barcodes = get_barcodes_by_inbound_tracking_numbers
(body["inbound_tracking_numbers"])
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
55 changes: 53 additions & 2 deletions microsetta_private_api/admin/sample_summary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from microsetta_private_api.model.source import Source
from microsetta_private_api.repo.kit_repo import KitRepo
from microsetta_private_api.repo.sample_repo import SampleRepo
from microsetta_private_api.repo.transaction import Transaction
from microsetta_private_api.repo.admin_repo import AdminRepo
Expand All @@ -7,20 +8,55 @@
from werkzeug.exceptions import NotFound


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

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


def get_barcodes_by_kit_ids(kit_ids):
if kit_ids is None:
raise ValueError("kit_id must be defined.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be helpful for the API layer to catch these ValueErrors and return a useful error to microsetta-admin


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


def get_barcodes_by_emails(emails):
if emails is None:
raise ValueError("email must be defined.")

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


def get_barcodes_by_outbound_tracking_numbers(outbound_tracking_numbers):
if outbound_tracking_numbers is None:
raise ValueError("outbound_tracking_numbers must be defined.")

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


def get_barcodes_by_inbound_tracking_numbers(inbound_tracking_numbers):
if inbound_tracking_numbers is None:
raise ValueError("inbound_tracking_numbers must be defined.")

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:
admin_repo = AdminRepo(t)
sample_repo = SampleRepo(t)
template_repo = SurveyTemplateRepo(t)
kit_repo = KitRepo(t)
vs_repo = VioscreenSessionRepo(t)

# all associated projects returned for each barcode,
Expand Down Expand Up @@ -84,6 +120,16 @@ def per_sample(project, barcodes, strip_sampleid):
sample.id
)

kit_id_name = kit_repo.get_kit_id_name_by_barcode(barcode)
outbound_fedex_tracking = \
admin_repo.get_outbound_tracking_by_barcodes(barcode)
inbound_fedex_tracking = \
admin_repo.get_inbound_tracking_by_barcodes(barcode)
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)

Comment on lines +123 to +132
Copy link
Collaborator

Choose a reason for hiding this comment

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

Many of these values are already being exposed here from admin_repo.get_diagnostics_by_barcode() - is there a reason you're re-retrieving them?

summary = {
"sampleid": None if strip_sampleid else barcode,
"project": barcode_project,
Expand All @@ -96,7 +142,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