Skip to content

Commit

Permalink
add new patch to correct two problems in patch 0067.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
AmandaBirmingham committed Aug 12, 2020
1 parent ced7e31 commit f44ff57
Showing 1 changed file with 28 additions and 0 deletions.
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 f44ff57

Please sign in to comment.