Skip to content
Snippets Groups Projects
Commit 7da7b31b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

import of the new format from tns

parent 937213c3
No related branches found
No related tags found
1 merge request!238Tns update
Pipeline #25228 passed
# coding=utf-8
import csv
import datetime
import logging
......@@ -56,7 +57,9 @@ class TnsCsvVisitImportReader:
else:
study_subject = study_subjects[0]
date = self.extract_date(data['dateofvisit'])
location = self.extract_location(data['adressofvisit'])
location = self.extract_location(data)
visit_number = data['visit_id']
visit_number = int(visit_number) + 1
......@@ -125,9 +128,18 @@ class TnsCsvVisitImportReader:
logger.warn("Invalid date: " + text)
return result
def extract_location(self, text):
# type: (unicode) -> Location
def extract_location(self, data):
# type: (dict) -> Location
text = data.get('adressofvisit', None)
if text is None:
text = data['lab_id']
if text.startswith('lab-reunis'):
text = u"Laboratoires réunis"
if text.startswith('lab-ketterthill'):
text = u"Ketterthill"
if text.startswith('lab-bionex'):
text = u"BioneXt"
locations = Location.objects.filter(name=text)
if len(locations) > 0:
return locations[0]
......
donor_id;visit_id;dateofvisit;lab_id
cov-000111;0;20200410;lab-reunis-15
cov-222333;0;20200410;lab-ketterthill-18
cov-444444;0;20200410;lab-bionextpd-17
......@@ -132,6 +132,25 @@ class TestTnsCsvSubjectReader(TestCase):
self.assertEquals(1, self.get_warnings_count())
def test_load_data_with_lab_id(self):
filename = get_resource_path('tns_vouchers_lab_id_import.csv')
visits = TnsCsvVisitImportReader().load_data(filename)
self.assertEqual(3, len(visits))
visit = Visit.objects.filter(id=visits[0].id)[0]
appointment = Appointment.objects.filter(visit=visit)[0]
self.assertEqual(u"Laboratoires réunis", appointment.location.name)
visit = Visit.objects.filter(id=visits[1].id)[0]
appointment = Appointment.objects.filter(visit=visit)[0]
self.assertEqual(u"Ketterthill", appointment.location.name)
visit = Visit.objects.filter(id=visits[2].id)[0]
appointment = Appointment.objects.filter(visit=visit)[0]
self.assertEqual(u"BioneXt", appointment.location.name)
self.assertEquals(3, self.get_warnings_count())
def get_warnings_count(self):
if "WARNING" in self.warning_counter.level2count:
return self.warning_counter.level2count["WARNING"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment