mirror of
https://github.com/sartography/uva-covid19-testing-communicator.git
synced 2025-02-23 20:38:13 +00:00
Adding code that will properly pull in the full bar code from IVY,
and a script that will fix previously incorrect pairings of data.
This commit is contained in:
parent
5dc0e72662
commit
aa526b4c07
@ -31,6 +31,18 @@ paths:
|
||||
text/plain:
|
||||
schema:
|
||||
type: string
|
||||
/merge_similar_records:
|
||||
get:
|
||||
operationId: communicator.api.admin.merge_similar_records
|
||||
summary: Checks the local file system and firecloud for data and loads it into the db.
|
||||
security: [] # Disable security for this endpoint only.
|
||||
responses:
|
||||
'200':
|
||||
description: Status indicator that the app is up and alive.
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
type: string
|
||||
/notify_by_email:
|
||||
get:
|
||||
operationId: communicator.api.admin.notify_by_email
|
||||
|
@ -39,6 +39,10 @@ def update_data():
|
||||
SampleService().add_or_update_records(samples)
|
||||
db.session.commit()
|
||||
|
||||
def merge_similar_records():
|
||||
sample_service = SampleService()
|
||||
sample_service.merge_similar_records()
|
||||
|
||||
|
||||
def notify_by_email():
|
||||
"""Sends out notifications via email"""
|
||||
|
@ -66,7 +66,7 @@ class IvyService(object):
|
||||
"""Creates a Test Result from a record read in from the IVY CSV File"""
|
||||
sample = Sample()
|
||||
try:
|
||||
sample.barcode = f"{dictionary['Student ID']}-{dictionary['Test Date Time']}-{dictionary['Test Kiosk Loc']}"
|
||||
sample.barcode = dictionary['Test Bar Code']
|
||||
sample.student_id = dictionary["Student ID"]
|
||||
sample.phone = dictionary["Student Cellphone"]
|
||||
sample.email = dictionary["Student Email"]
|
||||
|
@ -13,3 +13,26 @@ class SampleService(object):
|
||||
else:
|
||||
db.session.add(sample)
|
||||
db.session.commit()
|
||||
|
||||
def merge_similar_records(self):
|
||||
"""We have samples that are duplicates of each other because of the way the data was coming in
|
||||
earlier on. This is a onetime fix that will compare all records based on the studient id, location
|
||||
and date, and merge them together using the new and correct bar code."""
|
||||
|
||||
# Get all samples that do not contain an email (these were added via the api call)
|
||||
samples = db.session.query(Sample).filter(Sample.email == None).all()
|
||||
for sample in samples:
|
||||
sample2 = db.session.query(Sample).\
|
||||
filter(Sample.email != None).\
|
||||
filter(Sample.student_id == sample.student_id).\
|
||||
filter(Sample.date == sample.date).\
|
||||
filter(Sample.location == sample.location).\
|
||||
first()
|
||||
if sample2:
|
||||
sample.merge(sample2)
|
||||
db.session.add(sample)
|
||||
db.session.delete(sample2)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[
|
||||
{"id": "000000111-202009091449-4321", "locationId": "4321", "createdAt": "2020-09-09T14:49:00+0000", "barcodeId": "000000111"},
|
||||
{"id": "000000222-202009091449-4321", "locationId": "4321", "createdAt": "2020-09-09T14:49:00+0000", "barcodeId": "000000222"},
|
||||
{"id": "000000333-202009091449-4321", "locationId": "4321", "createdAt": "2020-09-09T14:49:00+0000", "barcodeId": "000000333"},
|
||||
{"id": "000000444-202009091449-4321", "locationId": "4321", "createdAt": "2020-09-09T14:49:00+0000", "barcodeId": "000000444"}
|
||||
{"id": "000000111-RKC-202009091449-4321", "locationId": "4321", "createdAt": "2020-09-09T14:49:00+0000", "barcodeId": "000000111"},
|
||||
{"id": "000000222-TP-202009091449-4321", "locationId": "4321", "createdAt": "2020-09-09T14:49:00+0000", "barcodeId": "000000222"},
|
||||
{"id": "000000333-TN-202009091449-4321", "locationId": "4321", "createdAt": "2020-09-09T14:49:00+0000", "barcodeId": "000000333"},
|
||||
{"id": "000000444-XX-202009091449-4321", "locationId": "4321", "createdAt": "2020-09-09T14:49:00+0000", "barcodeId": "000000444"}
|
||||
]
|
@ -1,2 +1,2 @@
|
||||
Student ID|Student Cellphone|Student Email|Test Date Time|Test Kiosk Loc|Test Result Code
|
||||
987654321|555/555-5555|rkc7h@virginia.edu|202009030809|4321|8726520277
|
||||
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
|
||||
|
|
@ -1,3 +1,3 @@
|
||||
Student ID|Student Cellphone|Student Email|Test Date Time|Test Kiosk Loc|Test Result Code
|
||||
987655321|555/555-5558|testnegetive@virginia.edu|202009070719|4321|1142270225
|
||||
Student ID|Student Cellphone|Student Email|Test Date Time|Test Kiosk Loc|Test Result Code|Test Bar Code
|
||||
987654321|555/555-5555|testnegetive@virginia.edu|202009070719|4321|1142270225|987654321-RKC-202009070719-4321
|
||||
|
||||
|
|
@ -1,3 +1,3 @@
|
||||
Student ID|Student Cellphone|Student Email|Test Date Time|Test Kiosk Loc|Test Result Code
|
||||
000000222|555/555-5556|testpositive@virginia.edu|202009091449|4321|8269722523
|
||||
000000333|555/555-5558|testnegetive@virginia.edu|202009091449|4321|1142270225
|
||||
Student ID|Student Cellphone|Student Email|Test Date Time|Test Kiosk Loc|Test Result Code|Test Bar Code
|
||||
000000222|555/555-5556|testpositive@virginia.edu|202009091449|4321|8269722523|000000222-TP-202009091449-4321
|
||||
000000333|555/555-5558|testnegetive@virginia.edu|202009091449|4321|1142270225|000000333-TN-202009091449-4321
|
||||
|
|
@ -1,4 +1,5 @@
|
||||
Student ID|Student Cellphone|Student Email|Test Date Time|Test Kiosk Loc|Test Result Code
|
||||
987654321|555/555-5555|rkc7h@virginia.edu|202009030809|4321|8726520277
|
||||
987654322|555/555-5556|testpositive@virginia.edu|202009060919|4321|8269722523
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
||||
Student ID|Student Cellphone|Student Email|Test Date Time|Test Kiosk Loc|Test Result Code
|
||||
987654321|555/555-5555|rkc7h@virginia.edu|202009030809|4321|8726520277
|
||||
987654322|555/555-5556|testpositive@virginia.edu|202009060919|4321|8269722523
|
||||
987655321|555/555-5558|testnegetive@virginia.edu|202009070719|4321|1142270225
|
||||
000000111|555/555-5555|rkc7h@virginia.edu|202009091449|4321|8726520277
|
||||
000000222|555/555-5556|testpositive@virginia.edu|202009091449|4321|8269722523
|
||||
000000333|555/555-5558|testnegetive@virginia.edu|202009091449|4321|1142270225
|
||||
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|testnegetive@virginia.edu|202009070719|4321|1142270225|987655321-TN-202009070719-4321
|
||||
000000111|555/555-5555|rkc7h@virginia.edu|202009091449|4321|8726520277|000000111-RKC-202009091449-4321
|
||||
000000222|555/555-5556|testpositive@virginia.edu|202009091449|4321|8269722523|000000222-TP-202009091449-4321
|
||||
000000333|555/555-5558|testnegetive@virginia.edu|202009091449|4321|1142270225|000000333-TN-202009091449-4321
|
||||
|
|
@ -1,11 +1,9 @@
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from dateutil import parser
|
||||
|
||||
from tests.base_test import BaseTest
|
||||
from communicator import db, app
|
||||
from communicator import db
|
||||
from communicator.models.sample import Sample
|
||||
from communicator.services.ivy_service import IvyService
|
||||
from communicator.services.sample_service import SampleService
|
||||
@ -13,7 +11,6 @@ from communicator.services.sample_service import SampleService
|
||||
|
||||
class IvyServiceTest(BaseTest):
|
||||
|
||||
|
||||
def get_firebase_records(self):
|
||||
with open(self.firebase_file, 'r') as fb_file:
|
||||
raw_data = json.load(fb_file)
|
||||
@ -69,3 +66,43 @@ class IvyServiceTest(BaseTest):
|
||||
.filter(Sample.in_ivy == True).all()))
|
||||
self.assertEqual(7, len(db.session.query(Sample).all()))
|
||||
|
||||
|
||||
def test_merge_similar_records(self):
|
||||
service = SampleService()
|
||||
# 511908685 - 202010051136 - 0202
|
||||
db.session.add(Sample(barcode="111111111-AAA-202010050000-0000",
|
||||
student_id=111111111,
|
||||
date = parser.parse("202010050000"),
|
||||
location=0))
|
||||
db.session.add(Sample(barcode="111111111-202010050000-0000",
|
||||
student_id=111111111,
|
||||
date = parser.parse("202010050000"),
|
||||
location=0,
|
||||
email="dan@sartography.com",
|
||||
phone="555-555-5555"))
|
||||
db.session.commit()
|
||||
self.assertEquals(2, len(db.session.query(Sample).all()))
|
||||
service.merge_similar_records()
|
||||
self.assertEquals(1, len(db.session.query(Sample).all()))
|
||||
sample = db.session.query(Sample).first()
|
||||
self.assertEquals("dan@sartography.com", sample.email)
|
||||
self.assertEquals("111111111-AAA-202010050000-0000", sample.barcode)
|
||||
|
||||
def test_merge_non_similar_records(self):
|
||||
service = SampleService()
|
||||
db.session.add(Sample(barcode="222222222-AAA-202010050000-0000",
|
||||
student_id=222222222,
|
||||
date = parser.parse("202010050000"),
|
||||
location=0))
|
||||
db.session.add(Sample(barcode="111111111-202010050000-0000",
|
||||
student_id=111111111,
|
||||
date = parser.parse("202010050000"),
|
||||
location=0,
|
||||
email="dan@sartography.com",
|
||||
phone="555-555-5555"))
|
||||
service.merge_similar_records()
|
||||
self.assertEquals(2, len(db.session.query(Sample).all()))
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user