Skip to content

Commit

Permalink
Merge pull request #464 from biocore/master
Browse files Browse the repository at this point in the history
Get master-overhaul current with bugfixes, changes, and Spain locale
  • Loading branch information
cassidysymons authored Oct 4, 2022
2 parents d80ae23 + 579cee5 commit c781acc
Show file tree
Hide file tree
Showing 33 changed files with 2,343 additions and 971 deletions.
2 changes: 1 addition & 1 deletion microsetta_private_api/LEGACY/locale_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


available_locales = set([
'american_gut', 'british_gut', 'spanish_gut'])
'american_gut', 'british_gut', 'spanish_gut', 'spain_spanish_gut'])


media_locale = {
Expand Down
1,087 changes: 432 additions & 655 deletions microsetta_private_api/LEGACY/locale_data/english_gut.py

Large diffs are not rendered by default.

322 changes: 322 additions & 0 deletions microsetta_private_api/LEGACY/locale_data/spain_spanish_gut.py

Large diffs are not rendered by default.

275 changes: 176 additions & 99 deletions microsetta_private_api/LEGACY/locale_data/spanish_gut.py

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions microsetta_private_api/admin/admin_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from microsetta_private_api.repo.kit_repo import KitRepo
from microsetta_private_api.repo.sample_repo import SampleRepo
from microsetta_private_api.repo.survey_answers_repo import SurveyAnswersRepo
from microsetta_private_api.repo.survey_template_repo import SurveyTemplateRepo
from microsetta_private_api.repo.source_repo import SourceRepo
from microsetta_private_api.repo.transaction import Transaction
from microsetta_private_api.repo.admin_repo import AdminRepo
Expand Down Expand Up @@ -591,15 +592,15 @@ def search_activation(token_info, email_query=None, code_query=None):
return jsonify([i.to_api() for i in infos]), 200


def address_verification(address_1=None, address_2=None,
def address_verification(address_1=None, address_2=None, address_3=None,
city=None, state=None, postal=None, country=None):
if address_1 is None or len(address_1) < 1 or \
postal is None or len(postal) < 1 or \
country is None or len(country) < 1:
raise Exception("Must include address_1, postal, and country")

melissa_response = verify_address(address_1, address_2, city, state,
postal, country)
melissa_response = verify_address(address_1, address_2, address_3, city,
state, postal, country)

return jsonify(melissa_response), 200

Expand Down Expand Up @@ -841,3 +842,11 @@ def delete_account(account_id, token_info):
t.commit()

return None, 204


def get_vioscreen_sample_to_user(token_info):
validate_admin_access(token_info)
with Transaction() as t:
st_repo = SurveyTemplateRepo(t)
data = st_repo.get_vioscreen_sample_to_user()
return jsonify(data), 200
137 changes: 107 additions & 30 deletions microsetta_private_api/admin/daklapack_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
ERROR_STATUS = "Error"
ARCHIVE_STATUS = "Archived"
CODE_ERROR = "Code Error"
BARCODE_KEY = "barcode"
CONTAINER_KEY = "Container-content"
CONTAINER_ITEMS_KEY = "containerItems"
TYPE_KEY = "type"
SINGLE_KIT_TYPES = [BOX_TYPE, REGISTRATION_CARD_TYPE]
SINGLE_KIT_TYPES.extend(COLLECTION_DEVICE_TYPES)
MULTI_ITEM_ERR_MSG = "Found multi-item content in a single-kit item"


@celery.task(ignore_result=False)
Expand Down Expand Up @@ -124,8 +131,7 @@ def process_order_articles(admin_repo, order_id, status, create_date):
order_proj_ids = admin_repo.get_projects_for_dak_order(order_id)

# call daklapack api to get detailed info on this single order
dak_orders_response = dc.get_daklapack_order_details(
order_id)
dak_orders_response = dc.get_daklapack_order_details(order_id)

# loop over each kind of "daklapack article" in this order;
# NOTE that although the daklapack api allows >1 type of article (i.e.,
Expand All @@ -140,41 +146,88 @@ def process_order_articles(admin_repo, order_id, status, create_date):
# for each instance of this article kind in the order
for curr_article_instance in article_instances:
if status == SENT_STATUS:
# (Per Daniel 2021-07-01, each instance of a daklapack article
# represents exactly one kit, no more or less.)
curr_output = _store_single_sent_kit(
admin_repo, order_proj_ids, curr_article_instance)

# able to assume there is only one kit uuid bc
# _store_single_sent_kit stores a single kit, by definition
kit_uuid = curr_output["created"][0]["kit_uuid"]
admin_repo.set_kit_uuids_for_dak_order(order_id, [kit_uuid])
curr_output = _store_sent_kits_for_article(
admin_repo, order_proj_ids, order_id,
curr_article_instance)
elif status == ERROR_STATUS:
curr_output = _gather_article_error_info(
single_output = _gather_article_error_info(
order_id, create_date, curr_article_instance)
curr_output = [single_output]
else:
raise ValueError(f"Order {order_id} has an unexpected status: "
f"{status}")

per_article_outputs.append(curr_output)
per_article_outputs.extend(curr_output)
# next article instance
# next article type

return per_article_outputs


def _prevent_overwrite(old_val, new_val, val_type):
if old_val is not None:
raise ValueError(f"For type '{val_type}, cannot overwrite first value "
f"found ('{old_val}') with additional value "
f"'{new_val}'")
return new_val
def _store_sent_kits_for_article(
admin_repo, order_proj_ids, order_id, single_article_dict):

created_kits = []
is_multi_item = None

def _store_single_sent_kit(admin_repo, order_proj_ids, single_article_dict):
device_barcodes = []
kit_name = box_id = None
outbound_fedex_code, inbound_fedex_code, address_dict = _get_article_info(
single_article_dict)

# for each "thing" in a kit
# for each "scannable item" (i.e., barcoded thing) in a kit
scannable_kit_items = single_article_dict["scannableKitItems"]
for curr_scannable in scannable_kit_items:
# figure out what *kind* of barcoded thing this is and capture
# its barcode to the right field if it is a kind we care about
curr_scannable_type = curr_scannable[TYPE_KEY]

if curr_scannable_type == CONTAINER_KEY:
curr_barcode = curr_scannable[BARCODE_KEY]
if curr_barcode != "NoLabel":
raise ValueError(f"Unexpected barcode for {CONTAINER_KEY}: "
f"{curr_barcode}")

# DON'T change this to "is_multi_item" bc False != None here
if is_multi_item is False:
raise ValueError(MULTI_ITEM_ERR_MSG)
else:
is_multi_item = True

curr_items = curr_scannable[CONTAINER_ITEMS_KEY]
for curr_item in curr_items:
curr_item_details = curr_item["containerItemDetails"]
# ok, NOW we should be at the level of a single kit
curr_kit_info = _store_single_sent_kit(
admin_repo, order_proj_ids, order_id, outbound_fedex_code,
inbound_fedex_code, address_dict, curr_item_details)
created_kits.append(curr_kit_info)

elif curr_scannable_type in SINGLE_KIT_TYPES:
is_multi_item = False

# in theory, at this point I could break from the loop, but I'm
# continuing to loop over all the kit items so I can detect if
# single-item and multi-item info are both present (which is Bad)
# end if
# next scannable kit item

# if we found out above that this scannable_kit_items is for only one kit;
# DON'T change this to "is_multi_item" bc False != None here
if is_multi_item is False:
curr_kit_info = _store_single_sent_kit(
admin_repo, order_proj_ids, order_id, outbound_fedex_code,
inbound_fedex_code, address_dict, scannable_kit_items)
created_kits.append(curr_kit_info)

if len(created_kits) == 0:
raise ValueError(f"Unable to find any kits in order {order_id}, "
f"article internal id "
f"{single_article_dict['internalId']}")

return created_kits


def _get_article_info(single_article_dict):
# Gather info on address and outbound/inbound fedex tracking
# numbers for this particular article instance (i.e., kit).
# Per Edgar and Daniel, some kits:
Expand All @@ -197,28 +250,40 @@ def _store_single_sent_kit(admin_repo, order_proj_ids, single_article_dict):

address_dict = single_article_dict["sendInformation"]

# for each "scannable item" (i.e., barcoded thing) in a kit
scannable_kit_items = single_article_dict["scannableKitItems"]
for curr_scannable in scannable_kit_items:
return outbound_fedex_code, inbound_fedex_code, address_dict


def _store_single_sent_kit(admin_repo, order_proj_ids, order_id,
outbound_fedex_code, inbound_fedex_code,
address_dict, items_list):

device_barcodes = []
kit_name = box_id = None

for curr_scannable in items_list:
# NB: the scannable item can theoretically have a lot of internal
# complexity, like a populated containerItems list that itself
# contains scannable items, on to infinity. HOWEVER, microsetta
# has defined each article to equal exactly one kit, so it should
# not be necessary to dig into that.
# DOES NOT support that level of nesting, so if it is present, error.
curr_subitems = curr_scannable.get(CONTAINER_ITEMS_KEY)
if curr_subitems and len(curr_subitems) > 0:
raise ValueError(MULTI_ITEM_ERR_MSG)

# figure out what *kind* of barcoded thing this is and capture
# its barcode to the right field if it is a kind we care about
curr_scannable_type = curr_scannable["type"]
curr_barcode = curr_scannable["barcode"]
curr_scannable_type = curr_scannable[TYPE_KEY]
curr_barcode = curr_scannable[BARCODE_KEY]
if curr_scannable_type in COLLECTION_DEVICE_TYPES:
device_barcodes.append(curr_barcode)
elif curr_scannable_type == BOX_TYPE:
box_id = _prevent_overwrite(box_id, curr_barcode, BOX_TYPE)
elif curr_scannable_type == REGISTRATION_CARD_TYPE:
kit_name = _prevent_overwrite(kit_name, curr_barcode,
REGISTRATION_CARD_TYPE)
elif curr_scannable_type == CONTAINER_KEY:
raise ValueError(MULTI_ITEM_ERR_MSG)
else:
# Daklapack barcodes this thing but we don't care about it
# Something we don't care about it
continue # to next scannable kit item
# next scannable item

Expand All @@ -238,9 +303,21 @@ def _store_single_sent_kit(admin_repo, order_proj_ids, single_article_dict):
raise ValueError(f"Expected exactly one kit created, "
f"found {len(created_kit_info['created'])}")

# can do [0] since just verified we created ONLY ONE KIT
kit_uuid = created_kit_info["created"][0]["kit_uuid"]
admin_repo.set_kit_uuids_for_dak_order(order_id, [kit_uuid])

return created_kit_info


def _prevent_overwrite(old_val, new_val, val_type):
if old_val is not None:
raise ValueError(f"For type '{val_type}, cannot overwrite first value "
f"found ('{old_val}') with additional value "
f"'{new_val}'")
return new_val


def _gather_article_error_info(order_id, create_date, curr_article_instance):
# dig the info for an error report out of the article instance
curr_error_info = {"order_id": order_id,
Expand Down
10 changes: 10 additions & 0 deletions microsetta_private_api/admin/tests/test_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ def tearDown(self):
self.client.__exit__(None, None, None)
teardown_test_data()

def test_vioscreen_samples_to_barcodes(self):
response = self.client.get(
'/api/admin/vioscreen/username_to_barcode',
headers=MOCK_HEADERS
)
self.assertEqual(200, response.status_code)
response_obj = json.loads(response.data)
self.assertEqual(response_obj['000031536'],
'b98c5ac966b754ff')

def _test_project_create_success(self, project_info):
input_json = json.dumps(project_info)

Expand Down
Loading

0 comments on commit c781acc

Please sign in to comment.