Add a field to sample that contains the moment the sample was added to the database, and make it possible to retrieve records on this date.

This commit is contained in:
Dan 2021-01-29 14:18:44 -05:00
parent 22026e2ed7
commit 5ac5cfdc5d
3 changed files with 20 additions and 1 deletions

View File

@ -1,7 +1,9 @@
import csv
from datetime import datetime
from parser import ParserError
import globus_sdk
import sentry_sdk
from dateutil import parser
from communicator import app, db
@ -66,11 +68,16 @@ class IvyService(object):
"""Creates a Test Result from a record read in from the IVY CSV File"""
sample = Sample()
try:
try:
sample.date = parser.parse(dictionary["Test Date Time"])
except Exception as pe:
sentry_sdk.capture_message(f"Failed to parse date for barcode '{dictionary['Test Bar Code']}', '{pe}'")
sample.date = datetime.now()
sample.barcode = dictionary['Test Bar Code']
sample.student_id = dictionary["Student ID"]
sample.phone = dictionary["Student Cellphone"]
sample.email = dictionary["Student Email"]
sample.date = parser.parse(dictionary["Test Date Time"])
sample.location = dictionary["Test Kiosk Loc"]
sample.result_code = dictionary["Test Result Code"]
sample.ivy_file = file_name

View File

@ -0,0 +1,5 @@
Student ID|Student Cellphone|Student Email|Test Date Time|Test Kiosk Loc|Test Result Code|Test Bar Code
987654321|555/555-5555|rkc7h@virginia.edu|202009030809|4321|8726520277|987654321-RKC-202009030809-4321
987654322|555/555-5556|testpositive@virginia.edu|202009060919|4321|8269722523|987654322-TP-202009060919-4321
987655321|555/555-5558|badDate@virginia.edu|20212719|4321|1142270225|987655321-TN-20212719-4321
987655321|555/555-5558|testnegetive@virginia.edu|202009070719|4321|1142270225|987655321-TN-202009070719-4321
1 Student ID Student Cellphone Student Email Test Date Time Test Kiosk Loc Test Result Code Test Bar Code
2 987654321 555/555-5555 rkc7h@virginia.edu 202009030809 4321 8726520277 987654321-RKC-202009030809-4321
3 987654322 555/555-5556 testpositive@virginia.edu 202009060919 4321 8269722523 987654322-TP-202009060919-4321
4 987655321 555/555-5558 badDate@virginia.edu 20212719 4321 1142270225 987655321-TN-20212719-4321
5 987655321 555/555-5558 testnegetive@virginia.edu 202009070719 4321 1142270225 987655321-TN-202009070719-4321

View File

@ -24,6 +24,13 @@ class IvyServiceTest(BaseTest):
ivy_incorrect_file = os.path.join(app.root_path, '..', 'tests', 'data', 'incorrect.csv')
IvyService.samples_from_ivy_file(ivy_incorrect_file)
def test_invalid_date(self):
"""If a record with an unparssable date comes through, use today's date in the date field."""
ivy_incorrect_file = os.path.join(app.root_path, '..', 'tests', 'data', 'incorrect_date.csv')
records = IvyService.samples_from_ivy_file(ivy_incorrect_file)
self.assertEquals(4, len(records))
self.assertEquals('987655321-TN-20212719-4321', records[2].barcode)
def test_load_directory(self):
self.assertEqual(0, db.session.query(IvyFile).count())
app.config['IVY_IMPORT_DIR'] = os.path.join(app.root_path, '..', 'tests', 'data', 'import_directory')