-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
155 changed files
with
74,210 additions
and
1,050 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ before_script: | |
script: | ||
- make lint | ||
- make test-cov | ||
- make test-install | ||
|
||
after_success: | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ flake8 | |
psycopg2 | ||
flask | ||
natsort | ||
pycryptodome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
882 changes: 585 additions & 297 deletions
882
microsetta_private_api/LEGACY/locale_data/english_gut.py
Large diffs are not rendered by default.
Oops, something went wrong.
198 changes: 198 additions & 0 deletions
198
microsetta_private_api/LEGACY/locale_data/spanish_gut.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import string | ||
import random | ||
import datetime | ||
import uuid | ||
from microsetta_private_api.repo.transaction import Transaction | ||
from microsetta_private_api.api.tests.test_integration import \ | ||
_create_mock_kit | ||
|
||
|
||
def make_test_kits(output_filename=None, num_kits=100, | ||
samples_lower_limit=1, samples_upper_limit=5): | ||
|
||
if output_filename is None: | ||
output_filename = "test_kit_ids_" + datetime.datetime.now().strftime( | ||
"%Y%m%d%H%M%S") + ".csv" | ||
|
||
# right now I don't want to deal with the complication of how to ensure | ||
# that as we increment the base barcode, we don't go into >9 digits, so | ||
# I am putting this arbitrary and low limit on it for now. | ||
if num_kits > 1000: | ||
raise ValueError("make_test_kits is not able to create more than 1000" | ||
"test kits") | ||
base_barcode = 999010000 | ||
curr_barcode = base_barcode | ||
|
||
external_kit_ids = [] | ||
|
||
with Transaction() as t: | ||
for curr_kit_num in range(0, num_kits): | ||
# generate a mock internal kit id and a mock human-readable kit id | ||
curr_kit_id = str(uuid.uuid4()) | ||
curr_external_kit_id = generate_random_kit_name() | ||
external_kit_ids.append(curr_external_kit_id) | ||
|
||
# select a random number of swabs to add to this kit; | ||
# upper limit is plus 1 bc randrange stop argument is exclusive | ||
curr_num_samples = random.randrange(samples_lower_limit, | ||
samples_upper_limit+1) | ||
|
||
# make barcodes/sample ids for swabs to be added to this mock kit | ||
barcodes = [] | ||
mock_sample_ids = [] | ||
for curr_sample_index in range(0, curr_num_samples): | ||
mock_sample_ids.append(str(uuid.uuid4())) | ||
barcodes.append(curr_barcode) | ||
curr_barcode += 1 | ||
# next barcode/sample to create ids for | ||
|
||
# create the mock kit with all the specified mock barcodes/ | ||
# samples | ||
_create_mock_kit(t, barcodes, mock_sample_ids, | ||
curr_kit_id, curr_external_kit_id) | ||
# next kit to create | ||
|
||
t.commit() | ||
# end transaction | ||
|
||
# create a file of the kit names | ||
with open(output_filename, 'w') as filehandle: | ||
filehandle.write('%s\n' % "kit_id") | ||
for curr_external_kit_id in external_kit_ids: | ||
filehandle.write('%s\n' % curr_external_kit_id) | ||
|
||
print("created {0} test kits with {1}-{2} samples each".format( | ||
num_kits, samples_lower_limit, samples_upper_limit)) | ||
print("kit names in {0}".format(output_filename)) | ||
|
||
|
||
def generate_random_kit_name(name_length=8, name_base="test"): | ||
letters_and_digits = string.ascii_letters + string.digits | ||
rand_name = ''.join(random.choice(letters_and_digits) | ||
for i in range(name_length)) | ||
return rand_name + name_base | ||
|
||
|
||
make_test_kits() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import flask | ||
from flask import jsonify | ||
|
||
from microsetta_private_api.repo.account_repo import AccountRepo | ||
from microsetta_private_api.repo.transaction import Transaction | ||
from microsetta_private_api.repo.admin_repo import AdminRepo | ||
from werkzeug.exceptions import Unauthorized | ||
|
||
|
||
def search_barcode(token_info, sample_barcode): | ||
validate_admin_access(token_info) | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
diag = admin_repo.retrieve_diagnostics_by_barcode(sample_barcode) | ||
if diag is None: | ||
return jsonify(code=404, message="Barcode not found"), 404 | ||
return jsonify(diag), 200 | ||
|
||
|
||
def search_kit_id(token_info, kit_id): | ||
validate_admin_access(token_info) | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
diag = admin_repo.retrieve_diagnostics_by_kit_id(kit_id) | ||
if diag is None: | ||
return jsonify(code=404, message="Kit ID not found"), 404 | ||
return jsonify(diag), 200 | ||
|
||
|
||
def search_email(token_info, email): | ||
validate_admin_access(token_info) | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
diag = admin_repo.retrieve_diagnostics_by_email(email) | ||
if diag is None: | ||
return jsonify(code=404, message="Email not found"), 404 | ||
return jsonify(diag), 200 | ||
|
||
|
||
def scan_barcode(token_info, sample_barcode, body): | ||
validate_admin_access(token_info) | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
admin_repo.scan_barcode(sample_barcode, body) | ||
t.commit() | ||
|
||
response = flask.Response() | ||
response.status_code = 201 | ||
response.headers['Location'] = '/api/admin/search/samples/%s' % \ | ||
sample_barcode | ||
return response | ||
|
||
|
||
def sample_pulldown_single_survey(token_info, | ||
sample_barcode, | ||
survey_template_id): | ||
validate_admin_access(token_info) | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
sample_pulldown = admin_repo.get_survey_metadata( | ||
sample_barcode, | ||
survey_template_id=survey_template_id) | ||
return jsonify(sample_pulldown), 200 | ||
|
||
|
||
def sample_pulldown_multiple_survey(token_info, | ||
sample_barcode): | ||
validate_admin_access(token_info) | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
sample_pulldown = admin_repo.get_survey_metadata(sample_barcode) | ||
return jsonify(sample_pulldown), 200 | ||
|
||
|
||
def project_statistics_summary(token_info): | ||
validate_admin_access(token_info) | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
summary = admin_repo.get_project_summary_statistics() | ||
return jsonify(summary), 200 | ||
|
||
|
||
def project_statistics_detailed(token_info, project_id): | ||
validate_admin_access(token_info) | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
summary = admin_repo.get_project_detailed_statistics(project_id) | ||
return jsonify(summary), 200 | ||
|
||
|
||
def validate_admin_access(token_info): | ||
with Transaction() as t: | ||
account_repo = AccountRepo(t) | ||
account = account_repo.find_linked_account(token_info['iss'], | ||
token_info['sub']) | ||
if account is None or account.account_type != 'admin': | ||
raise Unauthorized() | ||
|
||
|
||
def create_project(body, token_info): | ||
validate_admin_access(token_info) | ||
|
||
project_name = body['project_name'] | ||
is_microsetta = body['is_microsetta'] | ||
|
||
if len(project_name) == 0: | ||
return jsonify(code=400, message="No project name provided"), 400 | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
admin_repo.create_project(project_name, is_microsetta) | ||
t.commit() | ||
|
||
return {}, 201 | ||
|
||
|
||
def create_kits(body, token_info): | ||
validate_admin_access(token_info) | ||
|
||
number_of_kits = body['number_of_kits'] | ||
number_of_samples = body['number_of_samples'] | ||
kit_prefix = body.get('kit_id_prefix', None) | ||
projects = body['projects'] | ||
|
||
with Transaction() as t: | ||
admin_repo = AdminRepo(t) | ||
|
||
try: | ||
kits = admin_repo.create_kits(number_of_kits, number_of_samples, | ||
kit_prefix, projects) | ||
except KeyError: | ||
return jsonify(code=422, message="Unable to create kits"), 422 | ||
else: | ||
t.commit() | ||
|
||
return jsonify(kits), 201 |
Empty file.
Oops, something went wrong.