From bc8f4c6c3d24feed86fea019482c17f40380f8d8 Mon Sep 17 00:00:00 2001 From: Carlos Vega <carlos.vega@uni.lu> Date: Fri, 9 Nov 2018 18:18:55 +0100 Subject: [PATCH] Issue #268 added a worker to appointments and typelink --- smash/import_file.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/smash/import_file.py b/smash/import_file.py index f274d8f2..227e2c1e 100644 --- a/smash/import_file.py +++ b/smash/import_file.py @@ -310,7 +310,7 @@ def create_appointment_types(assessments): return appointmentTypes -def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): +def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_worker): # Languages if len(row['LANGUAGES']) == 0 and len(row['PREFERED WRITEN LANGUAGE']) == 0: logging.warn('No Languages available') @@ -473,8 +473,10 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): ''' If there are two Vx with the same date we put together the appointment types in the same appointment ''' + starting_hour = 9 for visit_date in set(visit_dates): - datetime_when = visit_date.strftime('%Y-%m-%d') + datetime_when = visit_date.replace(hour=starting_hour, minute=0, second=0, microsecond=0) + starting_hour+=1 # get the indices of each occurrence of the date and use them to get # the appointment types @@ -483,17 +485,17 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): # creatre appointment appointment, _ = Appointment.objects.update_or_create( - visit=visit, length=sum( - [a.default_duration for a in appointment_types]), + visit=visit, length=sum([a.default_duration for a in appointment_types]), flying_team=ft, location=location, - status=Appointment.APPOINTMENT_STATUS_FINISHED, datetime_when=datetime_when) + status=Appointment.APPOINTMENT_STATUS_SCHEDULED, datetime_when=datetime_when, + worker_assigned=lcsb_worker) date_when = visit_date.replace( hour=9, minute=0, second=0, microsecond=0) for appointment_type in appointment_types: app_type_link = AppointmentTypeLink( - appointment=appointment, date_when=date_when, - appointment_type=appointment_type) + appointment=appointment, date_when=date_when, + appointment_type=appointment_type, worker=lcsb_worker) date_when += datetime.timedelta( minutes=appointment_type.default_duration) app_type_link.save() @@ -527,7 +529,9 @@ def createWorker(password, email='', username='admin', first_name='LCSB', last_n # create workerStudyRole workerStudyRole, _ = WorkerStudyRole.objects.update_or_create(worker=worker, study_id=GLOBAL_STUDY_ID, role=ROLE_CHOICES_TECHNICIAN) + workerStudyRole.save() logging.info('SuperUser and Worker {} created'.format(username)) + return worker if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) -- GitLab