This commit is contained in:
Ilya Mukhortov 2025-02-24 17:44:52 +10:00
parent a670fae9eb
commit ea0223e100
6 changed files with 81 additions and 14 deletions

View File

@ -7,6 +7,7 @@ from django.utils import timezone
from constance import config from constance import config
from .models import CallRequest, RequestLog from .models import CallRequest, RequestLog
from appa.call_api import call_status
def auth_request(): def auth_request():
@ -69,8 +70,12 @@ def get_record(call_request: CallRequest, logging=True):
if result['confirmed']: if result['confirmed']:
call_request.status = call_request.Status.APPROVED call_request.status = call_request.Status.APPROVED
elif result['call_result_code'] in [3]: elif result['call_result_code'] in call_status.STATUS_CANCELLED:
call_request.status = call_request.Status.CANCELED call_request.status = call_request.Status.CANCELED
elif result['call_result_code'] in call_status.STATUS_WITHOUT_ANSWER:
call_request.status = call_request.Status.WITHOUT_ANSWER
else:
call_request.status = call_request.Status.OTHER
call_request.save() call_request.save()

View File

View File

@ -0,0 +1,29 @@
STATUS_1 = 1 # Не обработан
STATUS_2 = 2 # Подтверждено
STATUS_3 = 3 # Запись отменена
STATUS_4 = 4 # Перенос записи
STATUS_5 = 5 # Перезвонить
STATUS_6 = 6 # Ошибка обработки
STATUS_7 = 7 # Запись отменена с ошибкой
STATUS_11 = 11 # Неверный номер
STATUS_13 = 13 # Недостаточно средств
STATUS_14 = 14 # Недозвон
STATUS_15 = 15 # Звонок сбросили
STATUS_18 = 18 # Ошибочный звонок
STATUS_19 = 19 # Техническая ошибка
STATUS_20 = 20 # Отменен
STATUS_21 = 21 # Удачный перевод на оператора
STATUS_22 = 22 # Неудачный перевод на оператора
STATUS_CANCELLED = [
STATUS_3,
STATUS_7
]
STATUS_WITHOUT_ANSWER = [
STATUS_11,
STATUS_14,
STATUS_15,
STATUS_18
]

View File

@ -17,6 +17,7 @@ class CallRequest(models.Model):
APPROVED = 'APPROVED', 'Прием подтвержден' APPROVED = 'APPROVED', 'Прием подтвержден'
CANCELED = 'CANCELED', 'Прием отменен' CANCELED = 'CANCELED', 'Прием отменен'
WITHOUT_ANSWER = 'WITHOUT_ANSWER', 'Не дозвонились' WITHOUT_ANSWER = 'WITHOUT_ANSWER', 'Не дозвонились'
OTHER = 'OTHER', 'Другая ошибка'
STATUS_COLOR = { STATUS_COLOR = {
Status.PENDING: '#2D72D2', Status.PENDING: '#2D72D2',
@ -44,6 +45,7 @@ class CallRequest(models.Model):
request_status = models.CharField(max_length=20, choices=RequestStatus.choices, default=RequestStatus.NOT_SENT, request_status = models.CharField(max_length=20, choices=RequestStatus.choices, default=RequestStatus.NOT_SENT,
verbose_name='Статус запроса') verbose_name='Статус запроса')
date = models.DateField(verbose_name='Дата') date = models.DateField(verbose_name='Дата')
booking_id = models.PositiveIntegerField(null=True, verbose_name='ID записи на прием')
patient_id = models.IntegerField(verbose_name='ID пациента') patient_id = models.IntegerField(verbose_name='ID пациента')
patient_first_name = models.CharField(max_length=200, verbose_name='Имя') patient_first_name = models.CharField(max_length=200, verbose_name='Имя')
patient_last_name = models.CharField(max_length=200, verbose_name='Фамилия') patient_last_name = models.CharField(max_length=200, verbose_name='Фамилия')

View File

@ -3,7 +3,6 @@ import requests
from constance import config from constance import config
from appa.celery import app from appa.celery import app
from appa.models import * from appa.models import *
from appa.call_api import add_call_request from appa.call_api import add_call_request
@ -53,21 +52,21 @@ def update_call_requests(self):
response = r.json() response = r.json()
results = response['results'] results = response['results']
for booking in results: for booking in results:
call_request = CallRequest.objects.get_or_create( CallRequest.objects.update_or_create(
defaults={ defaults={
'patient_name': booking['patient']['full_name'], 'date': booking['date'],
'patient_id': booking['patient']['id'],
'patient_first_name': booking['patient']['first_name'],
'patient_last_name': booking['patient']['last_name'],
'patient_middle_name': booking['patient']['middle_name'],
'patient_phone': '7' + booking['patient']['phone_mobile'], 'patient_phone': '7' + booking['patient']['phone_mobile'],
'doctor_name': '',
'doctor_speciality': '',
'service_name': '',
'address': ''
}, },
date=booking_date, booking_id=booking['id'],
patient_id=booking['patient']['id'], )
)[0]
call_request.data.append({
'booking_id': booking['id'],
'time_start': booking['time_start'],
'time_end': booking['time_end'],
'speciality': booking['user']['doctor']['speciality_display'],
})
call_request.save(update_fields=['data'])
if response['next'] is None: if response['next'] is None:
break break

View File

@ -7,6 +7,9 @@ from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse from django.http import JsonResponse
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string
from appa.models import CallRequest
@csrf_exempt @csrf_exempt
def auth_view(request): def auth_view(request):
return JsonResponse({ return JsonResponse({
@ -28,6 +31,35 @@ def add_records_view(request):
}) })
@csrf_exempt
def get_record_view(request, record_id):
call_request = CallRequest.objects.get(id=record_id)
return JsonResponse({
"middle_name": call_request.middle_name,
"call_date": "2020-06-10",
"mp3_file": "",
"text_log": "",
"id": call_request.call_id,
"first_name": call_request.first_name,
"second_name": call_request.last_name,
"phone_number": call_request.phone_number,
"receipt_date": "2020-06-11",
"receipt_time": "22:39",
"doctor_specialisation": "Окулист",
"doctor_fullname": "Петренко",
"filial": "",
"call_result": "Подтверждено с смс",
"confirmed": true,
"call_result_code": 2,
"call_over": true,
"note": ""
})
@csrf_exempt
def delete_record_view(request, record_id):
pass
@csrf_exempt @csrf_exempt
def add_error_view(request): def add_error_view(request):
return JsonResponse({ return JsonResponse({