mirror of
https://github.com/sartography/uva-covid19-testing-communicator.git
synced 2025-02-24 04:48:05 +00:00
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:
parent
22026e2ed7
commit
5ac5cfdc5d
@ -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
|
||||
|
5
tests/data/incorrect_date.csv
Normal file
5
tests/data/incorrect_date.csv
Normal 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
|
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user