Advertisement
Mochinov

Untitled

Nov 19th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.11 KB | None | 0 0
  1. def set_pacietn_in_elena(request):
  2.     context = dict()
  3.     polyclinic = Polyclinic.objects.filter(town__name = 'Самара')
  4.     id_pol = [x.id for x in polyclinic]
  5.     DERECTORY = module_path() + '/../media/'
  6.     logging.info(str(DERECTORY) +  "Full path")
  7.     if request.method == 'POST':
  8.         logging.info('Document start parse !')
  9.         form = AddLocation(request.POST)
  10.         if form.is_valid():
  11.             try:
  12.                 # Получение файла из запроса
  13.                 files = request.FILES['document_address']
  14.  
  15.                 fs = FileSystemStorage()
  16.                 # Сохранение файла для парсинга
  17.                 filename = fs.save(files.name, files)
  18.                 uploaded_file_url = fs.url(filename)
  19.                 logging.info('Save document as %s' % (uploaded_file_url))
  20.             except Exception as e:
  21.                 logging.error('Error parse document - %s' % (e))
  22.                 files = None
  23.             FILE = DERECTORY + '{}'.format(files)
  24.             logging.info(str(FILE) + '   FILE')
  25.             pacient_list = parse_data_exel(FILE)
  26.             # logging.info('PACIENT LIST ---------- %s' % (pacient_list))
  27.             path = os.path.join(DERECTORY, FILE)
  28.             logging.info('Path rm %s' % (str(FILE)))
  29.             os.remove(FILE)
  30.             context['pacient_list'] = pacient_list
  31.             polyclinic_id = request.POST.get('polyclinic_id')
  32.             polyclinic_id = Polyclinic.objects.get(id = polyclinic_id)
  33.        
  34.         print(len(pacient_list))
  35.         try:
  36.             for i in pacient_list:
  37.                 now = datetime.now()
  38.                 data_birth = i['date_birth'].split('-')
  39.                 address = i['address'].split(',')
  40.                 print(data_birth)
  41.                 print(address)
  42.                 if len(address) > 3:
  43.                     date_of_birth = int(now.year) - int(data_birth[0])
  44.                     print(str(now.year) +' - '+ str(data_birth[0]) +'  =  ' + str(date_of_birth))
  45.                     if (int(now.year) - int(data_birth[0])) > 18:
  46.                         branch_name = 'Взрослая поликлиника'
  47.                     else:
  48.                         branch_name = 'Детская поликлиника'
  49.                     print(branch_name)
  50.                     try:
  51.                         logging.warning(address)
  52.                         print(address[1].capitalize())
  53.                         print(address[2])
  54.                         get_address = Location.objects.get(
  55.                             street = address[1].capitalize(),
  56.                             building = address[2],
  57.                             subdivision_polyclinics__branch=branch_name                        
  58.                         )
  59.                         print('Полученный адресс %s' % (get_address))
  60.                     except Exception as e:
  61.                         logging.error('==== set_pacietn_in_elena ==== %s'%(e))
  62.                         try:
  63.                             get_address = Location.objects.filter(
  64.                                 polyclinic__in = id_pol,
  65.                                 street__icontains =  address[1].capitalize(),
  66.                                 building__icontains = address[2],
  67.                                 subdivision_polyclinics__branch=branch_name    
  68.                             )
  69.                             logging.warning(get_address)
  70.                            
  71.                             if get_address == None:
  72.                                 get_address = None
  73.                             else:
  74.                                 get_address = get_address[0]
  75.                                 logging.info(get_address)
  76.                         except Exception as e:
  77.                             logging.info(e)
  78.                 else:
  79.                     get_address = None
  80.                 print('==========================================')
  81.                 pacient_create = Patient_registration.objects.create(
  82.                     fio = i['FIO'],
  83.                     recording_time = get_time_to_city(polyclinic_id.town.time_shifting),
  84.                     operator = request.user ,
  85.                     polyclinic = get_address.polyclinic if get_address else polyclinic[0],
  86.                     address = i['address'],
  87.                     date_of_birth = i['date_birth'],
  88.                     entrance = 0,
  89.                     intercom_code = 0,
  90.                     flat = re.findall('(\d+)', address[-1])[0],
  91.                     floor = 0,
  92.                     phone = i['phone'],
  93.                     reason_for_calling = i['reason'],
  94.                     temperature = 0,
  95.                     address_fk = get_address if get_address else None
  96.                 )
  97.                 logging.info('PASIENT IS CREATE')
  98.             mess  = 'Complite'
  99.         except Exception as e :
  100.             mess = 'Error data: %s' % (e)
  101.         context['mess'] = mess
  102.     else:
  103.         form = AddLocation()
  104.     context['form'] = form
  105.     context['polyclinic'] = polyclinic
  106.     return render(request, 'registration/set_pacient.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement