Skip to content

Commit

Permalink
Merge 39e646e into d4a9661
Browse files Browse the repository at this point in the history
  • Loading branch information
AmandaBirmingham committed Aug 12, 2020
2 parents d4a9661 + 39e646e commit bb575a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion microsetta_private_api/api/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ def _test_edit_sample_info(self, source_type):
cur.execute("INSERT INTO barcode_scans "
"(barcode, scan_timestamp, sample_status) "
"VALUES "
"(%s, %s, 'valid')",
"(%s, %s, 'sample-is-valid')",
(BARCODE, datetime.datetime.now()))
t.commit()

Expand Down
6 changes: 1 addition & 5 deletions microsetta_private_api/db/patches/0067.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
-- put into barcode
--
-- case 1: (happy path) scanned barcode belongs to AGP, is linked to an
-- account by way of a source, and has collection info. Note that
-- collection date is used as a proxy for collection info
-- because all kinds of sources require collection_date for
-- a sample (whereas, e.g., environmental sources don't require
-- site_sampled, etc).
-- account by way of a source, and has collection info.
UPDATE barcodes.barcode
SET sample_status = 'valid'
FROM ag.ag_kit_barcodes, ag.source, ag.account
Expand Down
28 changes: 28 additions & 0 deletions microsetta_private_api/db/patches/0068.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Correct two problems in the population of barcode_scans in 0067.sql:

-- Problem 1: valid sample status should be 'sample-is-valid' rather than 'valid'
-- per request from wet lab to revert to original terminology. Change ALL instances
-- of 'valid' to 'sample-is-valid'.
UPDATE barcodes.barcode_scans
SET sample_status = 'sample-is-valid'
WHERE sample_status = 'valid';

-- Problem 2: filled site_sampled was used as a proxy for having collection info,
-- but environmental sources don't have site_sampled filled in when they
-- are collected. Identify all scans of barcodes that are part of American Gut,
-- are associated with a source, are for a sample of the type "environmental", and
-- have been collected by the participant (as evidenced by the sample_date field
-- being filled). Additionally, look only at scans meeting the above criteria
-- that additionally were done AFTER the participant-reported sample_date (so after
-- the sample was collected) AND that have a sample_status of "no-collection-info".
-- Given the foregoing conditions, this status is incorrect as the sample is valid;
-- change sample_status in these cases to 'sample-is-valid'.
UPDATE barcodes.barcode_scans
SET sample_status = 'sample-is-valid'
FROM ag.ag_kit_barcodes, ag.source
WHERE barcode_scans.barcode = ag_kit_barcodes.barcode
AND ag_kit_barcodes.source_id = source.id
AND source.source_type = 'environmental'
AND ag_kit_barcodes.sample_date IS not null
AND barcode_scans.scan_timestamp >= ag_kit_barcodes.sample_date
AND barcode_scans.sample_status = 'no-collection-info';

0 comments on commit bb575a3

Please sign in to comment.