mirror of
https://github.com/olegvodyanov/docbot.git
synced 2025-12-19 23:57:05 +03:00
add consultation handler
This commit is contained in:
parent
c97cf5e0d8
commit
9d6b772777
125
src/docbot/handlers/patients/consultation_handler.py
Normal file
125
src/docbot/handlers/patients/consultation_handler.py
Normal file
@ -0,0 +1,125 @@
|
||||
from telegram import (
|
||||
Update, ReplyKeyboardMarkup, ReplyKeyboardRemove,
|
||||
InlineKeyboardButton, InlineKeyboardMarkup
|
||||
)
|
||||
from telegram.ext import (
|
||||
ContextTypes,
|
||||
ConversationHandler,
|
||||
CommandHandler,
|
||||
MessageHandler,
|
||||
filters,
|
||||
CallbackQueryHandler,
|
||||
)
|
||||
from docbot.handlers.utils.cancel_handler import get_cancel_handler
|
||||
from docbot.handlers.start_handler import get_start_handler
|
||||
from core.enums.dialog_helpers import ConfirmationMessage
|
||||
|
||||
SEND_ACKNOWLEDGEMENT_INFO = 1
|
||||
PROCEED_WITH_CONSULTATION = 2
|
||||
CHOOSE_CONSULTATION_TYPE = 3
|
||||
|
||||
STOPPING = 99
|
||||
|
||||
|
||||
ACCEPT_PERSONAL_DATA_AGREEMENT_TEXT = (
|
||||
"📝 Пожалуйста, подтвердите, что вы согласны с обработкой ваших персональных данных.\n"
|
||||
"Для этого нажмите кнопку ниже."
|
||||
)
|
||||
|
||||
|
||||
async def accept_personal_data_agreement(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
||||
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
ConfirmationMessage.PROCEED.value,
|
||||
callback_data="accepted"
|
||||
),
|
||||
InlineKeyboardButton(
|
||||
ConfirmationMessage.DECLINE.value,
|
||||
callback_data="declined"
|
||||
),
|
||||
]
|
||||
]
|
||||
|
||||
await update.message.reply_text(
|
||||
ACCEPT_PERSONAL_DATA_AGREEMENT_TEXT,
|
||||
parse_mode="Markdown",
|
||||
reply_markup=InlineKeyboardMarkup(keyboard),
|
||||
)
|
||||
return SEND_ACKNOWLEDGEMENT_INFO
|
||||
|
||||
|
||||
async def receive_patient_aceptance(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
||||
# Здесь можно добавить логику обработки согласия пациента
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
"Записаться на консультацию",
|
||||
callback_data="proceed_with_consultation"
|
||||
),
|
||||
InlineKeyboardButton(
|
||||
"Частые вопросы",
|
||||
callback_data="frequent_questions"
|
||||
),
|
||||
]
|
||||
]
|
||||
user_data = context.user_data
|
||||
await update.callback_query.answer()
|
||||
if update.callback_query.data == "accepted":
|
||||
user_data['accepted'] = True
|
||||
await update.callback_query.edit_message_text(
|
||||
text="✅ Спасибо за подтверждение. Вы можете продолжить запись на консультацию.",
|
||||
parse_mode="Markdown",
|
||||
reply_markup=InlineKeyboardMarkup(keyboard),
|
||||
)
|
||||
return PROCEED_WITH_CONSULTATION
|
||||
else:
|
||||
user_data['accepted'] = False
|
||||
await update.callback_query.edit_message_text(
|
||||
text="❌ Вы отказались от обработки персональных данных. Запись на консультацию невозможна.",
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
return STOPPING
|
||||
|
||||
|
||||
async def choose_consultation_type(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
"Первичная консультация",
|
||||
callback_data="initial_reception"
|
||||
),
|
||||
InlineKeyboardButton(
|
||||
"Повторная консультация",
|
||||
callback_data="readmission"
|
||||
),
|
||||
]
|
||||
]
|
||||
|
||||
await update.callback_query.answer()
|
||||
if update.callback_query.data == "proceed_with_consultation":
|
||||
await update.callback_query.edit_message_text(
|
||||
text="Выберите тип консультации:",
|
||||
reply_markup=InlineKeyboardMarkup(keyboard),
|
||||
)
|
||||
return CHOOSE_CONSULTATION_TYPE
|
||||
|
||||
|
||||
def consultation_handler() -> CommandHandler:
|
||||
"""Фабрика для регистрации в Application."""
|
||||
return CommandHandler("consultation", accept_personal_data_agreement)
|
||||
|
||||
|
||||
def get_consultation_handler() -> ConversationHandler:
|
||||
return ConversationHandler(
|
||||
entry_points=[consultation_handler()],
|
||||
states={
|
||||
SEND_ACKNOWLEDGEMENT_INFO: [CallbackQueryHandler(receive_patient_aceptance)],
|
||||
PROCEED_WITH_CONSULTATION: [CallbackQueryHandler(choose_consultation_type)],
|
||||
STOPPING: [get_start_handler()],
|
||||
},
|
||||
fallbacks=[get_cancel_handler()],
|
||||
name="consultation_dialog", # для тестов/логирования
|
||||
persistent=True, # если используете хранение состояний
|
||||
)
|
||||
@ -4,6 +4,7 @@ from telegram.ext import ApplicationBuilder, PicklePersistence, ExtBot
|
||||
from core.config import settings
|
||||
from docbot.handlers.start_handler import get_start_handler
|
||||
from docbot.handlers.patients.send_form_handler import get_send_form_handler
|
||||
from docbot.handlers.patients.consultation_handler import get_consultation_handler
|
||||
from docbot.handlers.admins.doctors_handler import get_doctors_handler
|
||||
from docbot.handlers.doctors.register_handler import get_register_doctor_first_stage_handler
|
||||
from docbot.handlers.admins.generate_ref import get_referral_handlers
|
||||
@ -23,6 +24,7 @@ def main():
|
||||
.concurrent_updates(concurrent_updates=False)
|
||||
.build()
|
||||
)
|
||||
app.add_handler(get_consultation_handler())
|
||||
app.add_handler(get_start_handler())
|
||||
app.add_handler(get_send_form_handler())
|
||||
app.add_handler(get_doctors_handler())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user