Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def set_pacietn_in_elena(request):
- context = dict()
- polyclinic = Polyclinic.objects.filter(town__name = 'Самара')
- id_pol = [x.id for x in polyclinic]
- DERECTORY = module_path() + '/../media/'
- logging.info(str(DERECTORY) + "Full path")
- if request.method == 'POST':
- logging.info('Document start parse !')
- form = AddLocation(request.POST)
- if form.is_valid():
- try:
- # Получение файла из запроса
- files = request.FILES['document_address']
- fs = FileSystemStorage()
- # Сохранение файла для парсинга
- filename = fs.save(files.name, files)
- uploaded_file_url = fs.url(filename)
- logging.info('Save document as %s' % (uploaded_file_url))
- except Exception as e:
- logging.error('Error parse document - %s' % (e))
- files = None
- FILE = DERECTORY + '{}'.format(files)
- logging.info(str(FILE) + ' FILE')
- pacient_list = parse_data_exel(FILE)
- # logging.info('PACIENT LIST ---------- %s' % (pacient_list))
- path = os.path.join(DERECTORY, FILE)
- logging.info('Path rm %s' % (str(FILE)))
- os.remove(FILE)
- context['pacient_list'] = pacient_list
- polyclinic_id = request.POST.get('polyclinic_id')
- polyclinic_id = Polyclinic.objects.get(id = polyclinic_id)
- print(len(pacient_list))
- try:
- for i in pacient_list:
- now = datetime.now()
- data_birth = i['date_birth'].split('-')
- address = i['address'].split(',')
- print(data_birth)
- print(address)
- if len(address) > 3:
- date_of_birth = int(now.year) - int(data_birth[0])
- print(str(now.year) +' - '+ str(data_birth[0]) +' = ' + str(date_of_birth))
- if (int(now.year) - int(data_birth[0])) > 18:
- branch_name = 'Взрослая поликлиника'
- else:
- branch_name = 'Детская поликлиника'
- print(branch_name)
- try:
- logging.warning(address)
- print(address[1].capitalize())
- print(address[2])
- get_address = Location.objects.get(
- street = address[1].capitalize(),
- building = address[2],
- subdivision_polyclinics__branch=branch_name
- )
- print('Полученный адресс %s' % (get_address))
- except Exception as e:
- logging.error('==== set_pacietn_in_elena ==== %s'%(e))
- try:
- get_address = Location.objects.filter(
- polyclinic__in = id_pol,
- street__icontains = address[1].capitalize(),
- building__icontains = address[2],
- subdivision_polyclinics__branch=branch_name
- )
- logging.warning(get_address)
- if get_address == None:
- get_address = None
- else:
- get_address = get_address[0]
- logging.info(get_address)
- except Exception as e:
- logging.info(e)
- else:
- get_address = None
- print('==========================================')
- pacient_create = Patient_registration.objects.create(
- fio = i['FIO'],
- recording_time = get_time_to_city(polyclinic_id.town.time_shifting),
- operator = request.user ,
- polyclinic = get_address.polyclinic if get_address else polyclinic[0],
- address = i['address'],
- date_of_birth = i['date_birth'],
- entrance = 0,
- intercom_code = 0,
- flat = re.findall('(\d+)', address[-1])[0],
- floor = 0,
- phone = i['phone'],
- reason_for_calling = i['reason'],
- temperature = 0,
- address_fk = get_address if get_address else None
- )
- logging.info('PASIENT IS CREATE')
- mess = 'Complite'
- except Exception as e :
- mess = 'Error data: %s' % (e)
- context['mess'] = mess
- else:
- form = AddLocation()
- context['form'] = form
- context['polyclinic'] = polyclinic
- return render(request, 'registration/set_pacient.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement