From 9d6b77277737e99c5fe298c043459237029771df Mon Sep 17 00:00:00 2001 From: "oleg.vodyanov91@gmail.com" Date: Tue, 22 Jul 2025 00:54:29 +0400 Subject: [PATCH] add consultation handler --- .../handlers/patients/consultation_handler.py | 125 ++++++++++++++++++ src/docbot/main.py | 2 + 2 files changed, 127 insertions(+) create mode 100644 src/docbot/handlers/patients/consultation_handler.py diff --git a/src/docbot/handlers/patients/consultation_handler.py b/src/docbot/handlers/patients/consultation_handler.py new file mode 100644 index 0000000..e9964ff --- /dev/null +++ b/src/docbot/handlers/patients/consultation_handler.py @@ -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, # если используете хранение состояний + ) diff --git a/src/docbot/main.py b/src/docbot/main.py index 227f182..25aec2f 100644 --- a/src/docbot/main.py +++ b/src/docbot/main.py @@ -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())