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

daklapack article changes #429

Merged
merged 4 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 4 additions & 8 deletions microsetta_private_api/admin/tests/test_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
MOCK_HEADERS, ACCT_ID_1, ACCT_MOCK_ISS, ACCT_MOCK_SUB,
extract_last_id_from_location_header)
from microsetta_private_api.admin.tests.test_admin_repo import \
FIRST_DAKLAPACK_ARTICLE, delete_test_scan
FIRST_LIVE_DAK_ARTICLE, delete_test_scan
from microsetta_private_api.model.tests.test_daklapack_order import \
DUMMY_PROJ_ID_LIST, DUMMY_DAK_ARTICLE_CODE, DUMMY_ADDRESSES, \
DUMMY_DAK_ORDER_DESC, DUMMY_PLANNED_SEND_DATE, DUMMY_FEDEX_REFS


DUMMY_PROJ_NAME = "test project"
# although the article code is stored as a string in the json that we
# send to daklapack, it is stored as an int in our db's daklapack_article table
# so our private api expects it to be sent as an int
DUMMY_INT_DAK_ARTICLE_CODE = int(DUMMY_DAK_ARTICLE_CODE)


def teardown_test_data():
Expand Down Expand Up @@ -754,7 +750,7 @@ def test_get_daklapack_articles(self):
first_article.pop("dak_article_id")

self.assertEqual(len(article_dicts_list), len(response_obj))
self.assertEqual(FIRST_DAKLAPACK_ARTICLE, response_obj[0])
self.assertEqual(FIRST_LIVE_DAK_ARTICLE, response_obj[0])

def test_email_stats(self):
with Transaction() as t:
Expand Down Expand Up @@ -921,7 +917,7 @@ def test_post_daklapack_orders_fully_specified(self):
# create post input json
order_info = {
"project_ids": DUMMY_PROJ_ID_LIST,
"article_code": DUMMY_INT_DAK_ARTICLE_CODE,
"article_code": DUMMY_DAK_ARTICLE_CODE,
"addresses": DUMMY_ADDRESSES,
"description": DUMMY_DAK_ORDER_DESC,
"fedex_ref_1": DUMMY_FEDEX_REFS[0],
Expand All @@ -945,7 +941,7 @@ def test_post_daklapack_orders_wo_optionals(self):
# create post input json
order_info = {
"project_ids": DUMMY_PROJ_ID_LIST,
"article_code": DUMMY_INT_DAK_ARTICLE_CODE,
"article_code": DUMMY_DAK_ARTICLE_CODE,
"addresses": DUMMY_ADDRESSES,
"description": None,
"fedex_ref_1": None,
Expand Down
39 changes: 22 additions & 17 deletions microsetta_private_api/admin/tests/test_admin_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@

STANDARD_ACCT_ID = "12345678-bbbb-cccc-dddd-eeeeffffffff"
ADMIN_ACCT_ID = "12345678-1234-1234-1234-123412341234"
FIRST_DAKLAPACK_ARTICLE = {'dak_article_code': 350100,
'short_description': 'TMI 1 tube',
'num_2point5ml_etoh_tubes': 1,
'num_7ml_etoh_tube': 0,
'num_neoteryx_kit': 0,
'outer_sleeve': 'Microsetta',
'box': 'Microsetta',
'return_label': 'Microsetta',
'compartment_bag': 'Microsetta',
'num_stool_collector': 0,
'instructions': 'Fv1',
'registration_card': 'Microsetta',
'swabs': '1x bag of two',
'rigid_safety_bag': 'yes'}
FIRST_LIVE_DAK_ARTICLE = {'dak_article_code': '3510000E',
'short_description': 'TMI 1 tube',
'detailed_description':
'TMI 1 tube, American English'
}
# This is the first one in the db, but it is retired
FIRST_DAK_ARTICLE = {'dak_article_code': '350103',
'short_description': 'TMI 2 tubes',
'detailed_description': 'TMI 2 tubes'
}


def add_dummy_scan(scan_dict):
Expand Down Expand Up @@ -994,14 +990,23 @@ def test_get_projects_inactive_wo_stats(self):
# and is 2nd in (zero-based) list, after project 2
self.assertEqual(updated_dict, output[1].to_api())

def test_get_daklapack_articles(self):
def test_get_daklapack_articles_not_retired(self):
with Transaction() as t:
admin_repo = AdminRepo(t)
articles = admin_repo.get_daklapack_articles()
self.assertEqual(9, len(articles))
self.assertEqual(11, len(articles))
first_article = articles[0]
first_article.pop("dak_article_id")
self.assertEqual(FIRST_DAKLAPACK_ARTICLE, first_article)
self.assertEqual(FIRST_LIVE_DAK_ARTICLE, first_article)

def test_get_daklapack_articles_all(self):
with Transaction() as t:
admin_repo = AdminRepo(t)
articles = admin_repo.get_daklapack_articles(include_retired=True)
self.assertEqual(19, len(articles))
first_article = articles[0]
first_article.pop("dak_article_id")
self.assertEqual(FIRST_DAK_ARTICLE, first_article)

def test_create_daklapack_order(self):
with Transaction() as t:
Expand Down
2 changes: 1 addition & 1 deletion microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@ paths:
items:
type: integer
article_code:
type: integer
type: string
quantity:
type: integer
addresses:
Expand Down
56 changes: 56 additions & 0 deletions microsetta_private_api/db/patches/0097.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- modify campaign.fundrazr_perk_to_daklapack_article
-- to use article UUID as foreign key instead of article code;
-- table is not yet in use so just drop and re-create.
-- (drop should fail if the primary key here is being used as a foreign
-- key anywhere else, so should be safe to do this.)

DROP TABLE campaign.fundrazr_perk_to_daklapack_article;
CREATE TABLE campaign.fundrazr_perk_to_daklapack_article (
perk_id VARCHAR NOT NULL,
dak_article_id uuid NOT NULL,
CONSTRAINT pk_perk_to_dak PRIMARY KEY (perk_id, dak_article_id),
CONSTRAINT fk_perk_to_dak FOREIGN KEY (dak_article_id) REFERENCES barcodes.daklapack_article (dak_article_id)
);

-- modify the daklapack_article table
-- to take out columns not being used and add a new detailed description and a column indicating
-- which articles are retired.
-- mark those being retired now as retired=true and then change the data type of the article code
-- from integer to string since new codes are strings.
-- update and add records to bring article set up to date, including adding the new detailed descriptions,
-- then set the detailed description column not to allow nulls.

ALTER TABLE barcodes.daklapack_article DROP COLUMN num_2point5ml_etoh_tubes;
ALTER TABLE barcodes.daklapack_article DROP COLUMN num_7ml_etoh_tube;
ALTER TABLE barcodes.daklapack_article DROP COLUMN num_neoteryx_kit;
ALTER TABLE barcodes.daklapack_article DROP COLUMN outer_sleeve;
ALTER TABLE barcodes.daklapack_article DROP COLUMN box;
ALTER TABLE barcodes.daklapack_article DROP COLUMN return_label;
ALTER TABLE barcodes.daklapack_article DROP COLUMN compartment_bag;
ALTER TABLE barcodes.daklapack_article DROP COLUMN num_stool_collector;
ALTER TABLE barcodes.daklapack_article DROP COLUMN instructions;
ALTER TABLE barcodes.daklapack_article DROP COLUMN registration_card;
ALTER TABLE barcodes.daklapack_article DROP COLUMN swabs;
ALTER TABLE barcodes.daklapack_article DROP COLUMN rigid_safety_bag;
ALTER TABLE barcodes.daklapack_article ADD COLUMN detailed_description VARCHAR;
ALTER TABLE barcodes.daklapack_article ADD COLUMN retired boolean DEFAULT FALSE;

UPDATE barcodes.daklapack_article SET retired=TRUE, detailed_description=short_description
WHERE dak_article_code IN (350103, 350104, 350109, 350110, 350200, 350201, 350205, 350210);

ALTER TABLE barcodes.daklapack_article ALTER COLUMN dak_article_code TYPE VARCHAR;

UPDATE barcodes.daklapack_article SET dak_article_code='3510000E', short_description='TMI 1 tube', detailed_description='TMI 1 tube, American English' WHERE dak_article_code='350100';

INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3510001E', 'TMI 1 tube', 'TMI 1 tube, American English, no inbound label');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3511000E', 'TMI 1 tube + blood', 'TMI 1 tube + blood, American English');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3541002E', 'TMI 6 tubes + blood', 'TMI 6 tubes + blood , American English');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3512004E', 'TMI 1 tube + urine', 'TMI 1 tube + urine, American English');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3532004E', 'TMI 2 tubes + urine', 'TMI 2 tubes + urine, American English');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3510001M', 'TMI 1 tube', 'TMI 1 tube, Mexican Spanish, no inbound label');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3510001S', 'TMI 1 tube', 'TMI 1 tube, Spanish, no inbound label*');
wasade marked this conversation as resolved.
Show resolved Hide resolved
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3510001J', 'TMI 1 tube', 'TMI 1 tube, Japanese, no inbound label');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3520003E', 'TMI scoop tube', 'TMI 1 scoop tube (6ml EtOH), American English');
INSERT INTO barcodes.daklapack_article (dak_article_code, short_description, detailed_description) VALUES ('3521003E', 'TMI scoop tube + blood', 'TMI 1 scoop tube (6 ml EtOH) + blood, American English');

ALTER TABLE barcodes.daklapack_article ALTER COLUMN detailed_description SET NOT NULL;
17 changes: 7 additions & 10 deletions microsetta_private_api/repo/admin_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,17 +1224,14 @@ def get_survey_metadata(self, sample_barcode, survey_template_id=None):

return pulldown

def get_daklapack_articles(self):
def get_daklapack_articles(self, include_retired=False):
retired_constraint = "" if include_retired else "WHERE retired = False"
cmd = f"SELECT dak_article_id, dak_article_code, short_description, " \
f"detailed_description " \
f"FROM barcodes.daklapack_article {retired_constraint} " \
f"ORDER BY daklapack_article.dak_article_code;"
with self._transaction.dict_cursor() as cur:
cur.execute(
"SELECT dak_article_id, dak_article_code, short_description, "
"num_2point5ml_etoh_tubes, num_7ml_etoh_tube, "
"num_neoteryx_kit, outer_sleeve, box, return_label, "
"compartment_bag, num_stool_collector, instructions, "
"registration_card, swabs, rigid_safety_bag "
"FROM "
"barcodes.daklapack_article "
"ORDER BY daklapack_article.dak_article_code;")
cur.execute(cmd)
rows = cur.fetchall()
return [dict(x) for x in rows]

Expand Down