Advertisement
Mochinov

Untitled

Aug 28th, 2020
299
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. subject = 'Запись на приём к врачу'
  35. entrance = request.POST.get('entrance')
  36. intercom_code = request.POST.get('intercom_code')
  37. floor = request.POST.get('floor')
  38. flat = request.POST.get('flat')
  39. SNILS = request.POST.get('SNILS')
  40. C_M_O_policy = request.POST.get('C_M_O_policy')
  41. polyclinic = request.POST.get('polyclinic')
  42. 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)
  43. send_mail(subject,message,from_email,to_email,fail_silently=False,)
  44.  
  45. create_actions(request, Activity.CHOICES_OPTION[0][0], fio)
  46. return redirect('/')
  47. else:
  48. messages.error(request, 'Данная запись уже существует !')
  49. return redirect('/new-write/%s/%s/' % (str(id),address))
  50. else:
  51. messages.error(request, 'Не правильно заполнены поля !')
  52. return redirect('/new-write/%s/%s/' % (str(id),address))
  53. else:
  54. form = SetNoteForm(initial={'address': address})
  55.  
  56.  
  57. context['form'] = form
  58. return render(request,'registration/patient/person_set_form.html',context)
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement