Skip to content

Commit

Permalink
Merge pull request #558 from ayobi/master
Browse files Browse the repository at this point in the history
added last_update column to ag_kit_barcodes
  • Loading branch information
cassidysymons authored Feb 9, 2024
2 parents d65fa27 + b4d1a6c commit 2096e14
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
7 changes: 7 additions & 0 deletions microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,11 @@ components:
type: string
nullable: true
example: "Oops, I dropped it"
latest_sample_information_update:
type: string
format: date-time
example: "2017-07-21T17:32:28Z"
nullable: true
sample_site:
enum: ["Blood (skin prick)", "Saliva", "Ear wax", "Forehead", "Fur", "Hair", "Left hand", "Left leg", "Mouth", "Nares", "Nasal mucus",
"Right hand", "Right leg", "Stool", "Tears", "Torso", "Vaginal mucus", null]
Expand Down Expand Up @@ -3512,6 +3517,8 @@ components:
$ref: '#/components/schemas/sample_datetime'
sample_notes:
$ref: '#/components/schemas/sample_notes'
latest_sample_information_update:
$ref: '#/components/schemas/latest_sample_information_update'
sample_projects:
$ref: '#/components/schemas/sample_projects'
source_id:
Expand Down
6 changes: 6 additions & 0 deletions microsetta_private_api/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
'sample_edit_locked': False,
'sample_remove_locked': False,
'sample_notes': None,
'sample_latest_sample_information_update': None,
'sample_latest_scan_timestamp': None,
'sample_projects': ['American Gut Project'],
'account_id': None,
'source_id': None,
Expand All @@ -188,6 +190,8 @@
'sample_edit_locked': False,
'sample_remove_locked': False,
'sample_notes': "Oops, I dropped it",
'sample_latest_sample_information_update': "2018-07-21T17:32:28Z",
'sample_latest_scan_timestamp': "2016-07-21T17:32:28Z",
'sample_projects': ['American Gut Project'],
'account_id': 'foobar',
'source_id': 'foobarbaz',
Expand Down Expand Up @@ -588,6 +592,7 @@ def create_dummy_sample_objects(filled=False):
None,
info_dict['source_id'],
info_dict['account_id'],
None,
info_dict["sample_projects"],
None)

Expand Down Expand Up @@ -2652,6 +2657,7 @@ def test_dissociate_sample_from_source_success(self):
# make sure the sample's collection info is wiped
sample_repo = SampleRepo(t)
obs_sample = sample_repo._get_sample_by_id(MOCK_SAMPLE_ID)
obs_sample.latest_sample_information_update = None
self.assertEqual(expected_sample.__dict__, obs_sample.__dict__)

# make sure answered survey no longer associated with any samples
Expand Down
9 changes: 9 additions & 0 deletions microsetta_private_api/db/patches/0135.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Jan 26, 2024
-- Add sample information update timestamp
-- For UI enhancement.
-- We are not nulling the field out, though it may become necessary if used outside of the UI.
ALTER TABLE ag.ag_kit_barcodes
ADD COLUMN latest_sample_information_update timestamp with time zone;

COMMENT ON COLUMN ag.ag_kit_barcodes.latest_sample_information_update
IS 'Sample information update timestamp.';
15 changes: 11 additions & 4 deletions microsetta_private_api/model/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
class Sample(ModelBase):
def __init__(self, sample_id, datetime_collected, site, notes, barcode,
latest_scan_timestamp, source_id, account_id,
sample_projects, latest_scan_status, kit_id=None):
latest_sample_information_update, sample_projects,
latest_scan_status, kit_id=None):
self.id = sample_id
# NB: datetime_collected may be None if sample not yet used
self.datetime_collected = datetime_collected
Expand All @@ -17,6 +18,8 @@ def __init__(self, sample_id, datetime_collected, site, notes, barcode,
# NB: _latest_scan_timestamp may be None if not yet returned to lab
self._latest_scan_timestamp = latest_scan_timestamp
self._latest_scan_status = latest_scan_status
self.latest_sample_information_update \
= latest_sample_information_update
self.sample_projects = sample_projects

self.source_id = source_id
Expand All @@ -43,16 +46,17 @@ def remove_locked(self):
@classmethod
def from_db(cls, sample_id, date_collected, time_collected,
site, notes, barcode, latest_scan_timestamp,
source_id, account_id, sample_projects, latest_scan_status):
latest_sample_information_update, source_id,
account_id, sample_projects, latest_scan_status):
datetime_collected = None
# NB a sample may NOT have date and time collected if it has been sent
# out but not yet used
if date_collected is not None and time_collected is not None:
datetime_collected = datetime.combine(date_collected,
time_collected)
return cls(sample_id, datetime_collected, site, notes, barcode,
latest_scan_timestamp, source_id,
account_id, sample_projects, latest_scan_status)
latest_scan_timestamp, latest_sample_information_update,
source_id, account_id, sample_projects, latest_scan_status)

def to_api(self):
return {
Expand All @@ -62,7 +66,10 @@ def to_api(self):
"sample_edit_locked": self.edit_locked,
"sample_remove_locked": self.remove_locked,
"sample_datetime": self.datetime_collected,
"sample_latest_scan_timestamp": self._latest_scan_timestamp,
"sample_notes": self.notes,
"sample_latest_sample_information_update":
self.latest_sample_information_update,
"source_id": self.source_id,
"account_id": self.account_id,
"sample_projects": list(self.sample_projects),
Expand Down
11 changes: 8 additions & 3 deletions microsetta_private_api/repo/sample_repo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import werkzeug
from werkzeug.exceptions import NotFound

Expand All @@ -19,7 +20,8 @@ class SampleRepo(BaseRepo):
ag.ag_kit_barcodes.barcode,
latest_scan.scan_timestamp,
ag.source.id,
ag.source.account_id
ag.source.account_id,
ag.ag_kit_barcodes.latest_sample_information_update
FROM ag.ag_kit_barcodes
LEFT JOIN (
SELECT barcode, max(scan_timestamp) AS scan_timestamp
Expand All @@ -43,7 +45,8 @@ class SampleRepo(BaseRepo):
ag.ag_kit_barcodes.barcode,
latest_scan.scan_timestamp,
ag.source.id,
ag.source.account_id
ag.source.account_id,
ag.ag_kit_barcodes.latest_sample_information_update
FROM ag.ag_kit_barcodes
LEFT JOIN (
SELECT barcode, max(scan_timestamp) AS scan_timestamp
Expand Down Expand Up @@ -302,14 +305,16 @@ def update_info(self, account_id, source_id, sample_info,
"sample_date = %s, "
"sample_time = %s, "
"site_sampled = %s, "
"notes = %s "
"notes = %s, "
"latest_sample_information_update = %s "
"WHERE "
"ag_kit_barcode_id = %s",
(
sample_date,
sample_time,
sample_info.site,
sample_info.notes,
datetime.datetime.now(),
sample_info.id
))

Expand Down

0 comments on commit 2096e14

Please sign in to comment.