Advertisement
Mochinov

Untitled

Aug 28th, 2020
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1.  
  2. @login_required
  3. def set_write_pasient(request, id, address):
  4. context ={}
  5. id_polyclinic = Polyclinic.objects.get(id = id)
  6. if request.method == 'POST':
  7. form = SetNoteForm(request.POST, initial={'address': address})
  8. if form.is_valid():
  9. fio = request.POST.get('fio')
  10. phone = request.POST.get('phone')
  11. date_of_birth = request.POST.get('date_of_birth')
  12. reason_for_calling = request.POST.get('reason_for_calling')
  13. address_form = request.POST.get('address')
  14. try:
  15. person = Patient_registration.objects.get(fio=fio,phone=phone,date_of_birth=date_of_birth,address=address_form)
  16. except Patient_registration.DoesNotExist:
  17. person = None
  18.  
  19. if person != None:
  20. if person.recording_time.date() == datetime.datetime.today().date():
  21. messages.error(request, 'Данная запись уже существует !')
  22. return redirect('/new-write/%s/%s/' % (str(id),address))
  23. else:
  24. form = form.save(commit=False)
  25. form.polyclinic = id_polyclinic
  26. form.operator = request.user
  27. form.recording_time = get_time_to_city()
  28. form.save()
  29.  
  30. from_email = settings.EMAIL_HOST_USER
  31. if id_polyclinic.email:
  32. to_email = [id_polyclinic.email]
  33. else:
  34. to_email = ['fora11@yandex.ru','fora11@yandex.ru',]
  35. subject = 'Запись на приём к врачу'
  36. entrance = request.POST.get('entrance')
  37. intercom_code = request.POST.get('intercom_code')
  38. floor = request.POST.get('floor')
  39. flat = request.POST.get('flat')
  40. SNILS = request.POST.get('SNILS')
  41. C_M_O_policy = request.POST.get('C_M_O_policy')
  42. polyclinic = request.POST.get('polyclinic')
  43. message = 'ФИО: %s,Год рождения: %s,Адрес проживания %s %s,Подъезд: %s, Этаж дома: %s,Код домофона: %s , Телефон: %s,Снилс: %s,Полис: %s,Причина вызова : %s' % (fio,date_of_birth,address_form,flat,entrance, intercom_code,floor,phone,SNILS,C_M_O_policy,reason_for_calling)
  44. send_mail(subject,message,from_email,to_email,fail_silently=False,)
  45.  
  46. create_actions(request, Activity.CHOICES_OPTION[0][0], fio)
  47. return redirect('/')
  48. else:
  49. messages.error(request, 'Данная запись уже существует !')
  50. return redirect('/new-write/%s/%s/' % (str(id),address))
  51. else:
  52. messages.error(request, 'Не правильно заполнены поля !')
  53. return redirect('/new-write/%s/%s/' % (str(id),address))
  54. else:
  55. form = SetNoteForm(initial={'address': address})
  56.  
  57.  
  58. context['form'] = form
  59. return render(request,'registration/patient/person_set_form.html',context)
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement