Skip to content
Snippets Groups Projects

Fix/import file

Merged Carlos Vega requested to merge fix/import_file into master
1 unresolved thread
1 file
+ 23
17
Compare changes
  • Side-by-side
  • Inline
+ 23
17
@@ -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,
Please register or sign in to reply
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)
@@ -538,6 +542,17 @@ if __name__ == '__main__':
if not os.path.isfile(file):
logging.warn('Please, execute the program with a valid file path.')
sys.exit(1)
#create worker and super user
pass1 = ''
pass2 = None
while pass1 != pass2:
pass1 = getpass.getpass('Please type a password for the Admin user: ')
pass2 = getpass.getpass('Please type your password again: ')
if pass1 != pass2:
print 'Password mismatch, please try again'
lcsb_worker = createWorker(pass1)
df = pd.read_excel(file, dtype=object)
df = df.fillna('').astype(unicode)
df.columns = [c.upper() for c in df.columns]
@@ -569,13 +584,4 @@ if __name__ == '__main__':
# process each row
for index, row in df.iterrows():
parse_row(index, row, visit_columns, appointmentTypes, voucher_types)
#create worker and super user
pass1 = ''
pass2 = None
while pass1 != pass2:
pass1 = getpass.getpass('Please type a password for the Admin user: ')
pass2 = getpass.getpass('Please type your password again: ')
if pass1 != pass2:
print 'Password mismatch, please try again'
createWorker(pass1)
\ No newline at end of file
parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_worker)
\ No newline at end of file
Loading