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

Fix sample summary project output #566

Merged
merged 4 commits into from
Apr 2, 2024
Merged
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
3 changes: 2 additions & 1 deletion microsetta_private_api/admin/admin_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ def query_project_barcode_stats(body, token_info, strip_sampleid):
def query_barcode_stats(body, token_info, strip_sampleid):
validate_admin_access(token_info)
if 'sample_barcodes' in body:
project_id = None
barcodes = body["sample_barcodes"]
elif 'project_id' in body:
project_id = body["project_id"]
Expand All @@ -502,7 +503,7 @@ def query_barcode_stats(body, token_info, strip_sampleid):
unprocessed_barcodes = barcodes[1000:]
barcodes = barcodes[0:1000]

results = {'samples': per_sample(None, barcodes, strip_sampleid)}
results = {'samples': per_sample(project_id, barcodes, strip_sampleid)}

if unprocessed_barcodes:
results['partial_result'] = True
Expand Down
18 changes: 11 additions & 7 deletions microsetta_private_api/admin/sample_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ def per_sample(project, barcodes, strip_sampleid):
template_repo = SurveyTemplateRepo(t)
vs_repo = VioscreenSessionRepo(t)

if project is not None:
project_barcodes = admin_repo.get_project_barcodes(project)
else:
project = 'Unspecified'

# all associated projects returned for each barcode,
# so no universal project needed
if barcodes is None:
barcodes = project_barcodes
if project is None:
return summaries
barcodes = admin_repo.get_project_barcodes(project)

for barcode in barcodes:
diag = admin_repo.retrieve_diagnostics_by_barcode(barcode)
Expand All @@ -44,6 +43,11 @@ def per_sample(project, barcodes, strip_sampleid):
source_type = None if source is None else source.source_type
vio_id = None

# find all projects for barcode
projects_info = diag['projects_info']
all_projects = [proj_obj['project'] for proj_obj in projects_info]
barcode_project = '; '.join(sorted(all_projects))

if source is not None and source_type == Source.SOURCE_TYPE_HUMAN:

vio_id = template_repo.get_vioscreen_id_if_exists(account.id,
Expand Down Expand Up @@ -82,7 +86,7 @@ def per_sample(project, barcodes, strip_sampleid):

summary = {
"sampleid": None if strip_sampleid else barcode,
"project": project,
"project": barcode_project,
"source-type": source_type,
"site-sampled": sample_site,
"sample-date": sample_date,
Expand Down
51 changes: 51 additions & 0 deletions microsetta_private_api/admin/tests/test_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,57 @@ def test_query_barcode_stats_project_barcodes_with_strip(self):
self.assertEqual([v['sample-status'] for v in response_obj],
exp_status)

def test_query_barcode_stats_multiple_projects(self):
barcodes = ['000005059', '000005078', '000005103']
input_json = json.dumps({'sample_barcodes': barcodes})

response = self.client.post(
"api/admin/account_barcode_summary?strip_sampleid=False",
content_type='application/json',
data=input_json,
headers=MOCK_HEADERS
)
# an empty string project should be unknown
self.assertEqual(200, response.status_code)

response_obj = json.loads(response.data)
self.assertIn('samples', response_obj)
response_obj = response_obj['samples']
self.assertEqual(len(response_obj), 3)

self.assertEqual([v['sampleid'] for v in response_obj], barcodes)
response_projects = [v['project'].split('; ') for v in response_obj]
self.assertEqual(len(response_projects[0]), 2)
self.assertEqual(len(response_projects[1]), 3)
self.assertEqual(len(response_projects[2]), 3)
self.assertTrue(all(
projs[0] == 'American Gut Project' for projs in response_projects
))
# content: should have exactly the same projects
self.assertEqual(response_projects[1], response_projects[2])

def test_query_barcode_stats_by_project(self):
input_json = json.dumps({'project_id': 19}) # expect 5 barcodes
exp_barcodes = [
'000035369', '000035370', '000035371',
'000035372', '000035373'
]

response = self.client.post(
"api/admin/account_barcode_summary?strip_sampleid=False",
content_type='application/json',
data=input_json,
headers=MOCK_HEADERS
)
# an empty string project should be unknown
self.assertEqual(200, response.status_code)

response_obj = json.loads(response.data)
self.assertIn('samples', response_obj)
response_obj = response_obj['samples']
self.assertEqual(len(response_obj), 5)
self.assertEqual([v['sampleid'] for v in response_obj], exp_barcodes)

def test_send_email(self):
def mock_func(*args, **kwargs):
pass
Expand Down
Loading