elevenlabs-webhook-nodejs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +27 -0
- package/.dockerignore +6 -0
- package/.env.example +43 -0
- package/BEFORE-PRODUCTION.md +32 -0
- package/Dockerfile +23 -0
- package/SYSTEM_OVERVIEW.md +942 -0
- package/SYSTEM_STATUS.md +332 -0
- package/backup_script/main.py +146 -0
- package/baileys/.dockerignore +7 -0
- package/baileys/Dockerfile +13 -0
- package/baileys/README.md +412 -0
- package/baileys/index.js +499 -0
- package/baileys/package-lock.json +2532 -0
- package/baileys/package.json +25 -0
- package/baileys/server.js +96 -0
- package/baileys/src/config.js +55 -0
- package/baileys/src/middleware/api-key.js +16 -0
- package/baileys/src/routes/accounts.js +51 -0
- package/baileys/src/routes/chats.js +103 -0
- package/baileys/src/routes/webhooks.js +34 -0
- package/baileys/src/services/account-store.js +259 -0
- package/baileys/src/services/webhook-dispatcher.js +161 -0
- package/baileys/src/services/worker-manager.js +597 -0
- package/baileys/src/utils/jid.js +79 -0
- package/baileys/src/utils/logger.js +16 -0
- package/baileys/src/utils/use-mongodb-auth-state.js +122 -0
- package/baileys/worker.js +721 -0
- package/dist/app.d.ts +1 -0
- package/dist/app.js +84 -0
- package/dist/app.js.map +1 -0
- package/dist/config/agentPrompts.json +19 -0
- package/dist/config/database.d.ts +1 -0
- package/dist/config/database.js +26 -0
- package/dist/config/database.js.map +1 -0
- package/dist/config/env.d.ts +41 -0
- package/dist/config/env.js +81 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +73 -0
- package/dist/config/index.js.map +1 -0
- package/dist/controllers/webhook.controller.d.ts +10 -0
- package/dist/controllers/webhook.controller.js +128 -0
- package/dist/controllers/webhook.controller.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +13 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/hooks/webhookValidator.d.ts +2 -0
- package/dist/hooks/webhookValidator.js +47 -0
- package/dist/hooks/webhookValidator.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/001_session-architecture.d.ts +3 -0
- package/dist/migrations/001_session-architecture.js +119 -0
- package/dist/migrations/001_session-architecture.js.map +1 -0
- package/dist/migrations/002_agent-ref.d.ts +3 -0
- package/dist/migrations/002_agent-ref.js +55 -0
- package/dist/migrations/002_agent-ref.js.map +1 -0
- package/dist/migrations/003_shift-schedule.d.ts +3 -0
- package/dist/migrations/003_shift-schedule.js +48 -0
- package/dist/migrations/003_shift-schedule.js.map +1 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.d.ts +3 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.js +27 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.js.map +1 -0
- package/dist/migrations/005_composite-baileys-chat-ids.d.ts +3 -0
- package/dist/migrations/005_composite-baileys-chat-ids.js +47 -0
- package/dist/migrations/005_composite-baileys-chat-ids.js.map +1 -0
- package/dist/migrations/migration.model.d.ts +18 -0
- package/dist/migrations/migration.model.js +45 -0
- package/dist/migrations/migration.model.js.map +1 -0
- package/dist/migrations/migration.routes.d.ts +2 -0
- package/dist/migrations/migration.routes.js +37 -0
- package/dist/migrations/migration.routes.js.map +1 -0
- package/dist/migrations/migration.runner.d.ts +19 -0
- package/dist/migrations/migration.runner.js +74 -0
- package/dist/migrations/migration.runner.js.map +1 -0
- package/dist/models/ConversationClaim.d.ts +13 -0
- package/dist/models/ConversationClaim.js +44 -0
- package/dist/models/ConversationClaim.js.map +1 -0
- package/dist/models/ConversationEvaluation.d.ts +23 -0
- package/dist/models/ConversationEvaluation.js +92 -0
- package/dist/models/ConversationEvaluation.js.map +1 -0
- package/dist/models/Summary.d.ts +37 -0
- package/dist/models/Summary.js +78 -0
- package/dist/models/Summary.js.map +1 -0
- package/dist/models/Transcription.d.ts +34 -0
- package/dist/models/Transcription.js +71 -0
- package/dist/models/Transcription.js.map +1 -0
- package/dist/models/WhatsAppRecipient.d.ts +23 -0
- package/dist/models/WhatsAppRecipient.js +53 -0
- package/dist/models/WhatsAppRecipient.js.map +1 -0
- package/dist/modules/admin/admin.routes.d.ts +2 -0
- package/dist/modules/admin/admin.routes.js +1966 -0
- package/dist/modules/admin/admin.routes.js.map +1 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.d.ts +2 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.js +158 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.js.map +1 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.d.ts +2 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.js +204 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.js.map +1 -0
- package/dist/modules/agents/agent.model.d.ts +38 -0
- package/dist/modules/agents/agent.model.js +92 -0
- package/dist/modules/agents/agent.model.js.map +1 -0
- package/dist/modules/agents/agent.routes.d.ts +2 -0
- package/dist/modules/agents/agent.routes.js +61 -0
- package/dist/modules/agents/agent.routes.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.model.d.ts +76 -0
- package/dist/modules/appointment-validation/appointment-validation.model.js +118 -0
- package/dist/modules/appointment-validation/appointment-validation.model.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.d.ts +2 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.js +202 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.service.d.ts +53 -0
- package/dist/modules/appointment-validation/appointment-validation.service.js +827 -0
- package/dist/modules/appointment-validation/appointment-validation.service.js.map +1 -0
- package/dist/modules/auth/auth.model.d.ts +17 -0
- package/dist/modules/auth/auth.model.js +64 -0
- package/dist/modules/auth/auth.model.js.map +1 -0
- package/dist/modules/auth/auth.routes.d.ts +2 -0
- package/dist/modules/auth/auth.routes.js +202 -0
- package/dist/modules/auth/auth.routes.js.map +1 -0
- package/dist/modules/auth/auth.service.d.ts +28 -0
- package/dist/modules/auth/auth.service.js +183 -0
- package/dist/modules/auth/auth.service.js.map +1 -0
- package/dist/modules/auth/refresh-token.model.d.ts +13 -0
- package/dist/modules/auth/refresh-token.model.js +52 -0
- package/dist/modules/auth/refresh-token.model.js.map +1 -0
- package/dist/modules/billing/billing-alert.model.d.ts +16 -0
- package/dist/modules/billing/billing-alert.model.js +47 -0
- package/dist/modules/billing/billing-alert.model.js.map +1 -0
- package/dist/modules/billing/billing-period-snapshot.model.d.ts +35 -0
- package/dist/modules/billing/billing-period-snapshot.model.js +68 -0
- package/dist/modules/billing/billing-period-snapshot.model.js.map +1 -0
- package/dist/modules/billing/billing.model.d.ts +18 -0
- package/dist/modules/billing/billing.model.js +62 -0
- package/dist/modules/billing/billing.model.js.map +1 -0
- package/dist/modules/billing/billing.routes.d.ts +2 -0
- package/dist/modules/billing/billing.routes.js +63 -0
- package/dist/modules/billing/billing.routes.js.map +1 -0
- package/dist/modules/billing/billing.service.d.ts +69 -0
- package/dist/modules/billing/billing.service.js +498 -0
- package/dist/modules/billing/billing.service.js.map +1 -0
- package/dist/modules/billing/payment.model.d.ts +24 -0
- package/dist/modules/billing/payment.model.js +57 -0
- package/dist/modules/billing/payment.model.js.map +1 -0
- package/dist/modules/calls/call.model.d.ts +41 -0
- package/dist/modules/calls/call.model.js +97 -0
- package/dist/modules/calls/call.model.js.map +1 -0
- package/dist/modules/calls/call.routes.d.ts +2 -0
- package/dist/modules/calls/call.routes.js +103 -0
- package/dist/modules/calls/call.routes.js.map +1 -0
- package/dist/modules/campaigns/campaign.model.d.ts +45 -0
- package/dist/modules/campaigns/campaign.model.js +98 -0
- package/dist/modules/campaigns/campaign.model.js.map +1 -0
- package/dist/modules/campaigns/campaign.routes.d.ts +2 -0
- package/dist/modules/campaigns/campaign.routes.js +323 -0
- package/dist/modules/campaigns/campaign.routes.js.map +1 -0
- package/dist/modules/campaigns/campaign.service.d.ts +11 -0
- package/dist/modules/campaigns/campaign.service.js +86 -0
- package/dist/modules/campaigns/campaign.service.js.map +1 -0
- package/dist/modules/google-calendar/google-calendar.routes.d.ts +2 -0
- package/dist/modules/google-calendar/google-calendar.routes.js +32 -0
- package/dist/modules/google-calendar/google-calendar.routes.js.map +1 -0
- package/dist/modules/inbound-call/inbound-call-config.model.d.ts +20 -0
- package/dist/modules/inbound-call/inbound-call-config.model.js +68 -0
- package/dist/modules/inbound-call/inbound-call-config.model.js.map +1 -0
- package/dist/modules/inbound-call/inbound-call.routes.d.ts +2 -0
- package/dist/modules/inbound-call/inbound-call.routes.js +243 -0
- package/dist/modules/inbound-call/inbound-call.routes.js.map +1 -0
- package/dist/modules/leads/lead.model.d.ts +24 -0
- package/dist/modules/leads/lead.model.js +54 -0
- package/dist/modules/leads/lead.model.js.map +1 -0
- package/dist/modules/leads/lead.routes.d.ts +2 -0
- package/dist/modules/leads/lead.routes.js +201 -0
- package/dist/modules/leads/lead.routes.js.map +1 -0
- package/dist/modules/plans/plan.model.d.ts +25 -0
- package/dist/modules/plans/plan.model.js +59 -0
- package/dist/modules/plans/plan.model.js.map +1 -0
- package/dist/modules/surveys/survey.model.d.ts +30 -0
- package/dist/modules/surveys/survey.model.js +75 -0
- package/dist/modules/surveys/survey.model.js.map +1 -0
- package/dist/modules/surveys/survey.routes.d.ts +2 -0
- package/dist/modules/surveys/survey.routes.js +153 -0
- package/dist/modules/surveys/survey.routes.js.map +1 -0
- package/dist/modules/tenants/tenant.model.d.ts +86 -0
- package/dist/modules/tenants/tenant.model.js +127 -0
- package/dist/modules/tenants/tenant.model.js.map +1 -0
- package/dist/modules/tenants/tenant.routes.d.ts +2 -0
- package/dist/modules/tenants/tenant.routes.js +65 -0
- package/dist/modules/tenants/tenant.routes.js.map +1 -0
- package/dist/modules/users/user.routes.d.ts +2 -0
- package/dist/modules/users/user.routes.js +106 -0
- package/dist/modules/users/user.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.d.ts +20 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.js +85 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.d.ts +11 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.js +360 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs.routes.d.ts +2 -0
- package/dist/modules/webhooks/elevenlabs.routes.js +34 -0
- package/dist/modules/webhooks/elevenlabs.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs.service.d.ts +6 -0
- package/dist/modules/webhooks/elevenlabs.service.js +512 -0
- package/dist/modules/webhooks/elevenlabs.service.js.map +1 -0
- package/dist/modules/webhooks/unipile.routes.d.ts +2 -0
- package/dist/modules/webhooks/unipile.routes.js +780 -0
- package/dist/modules/webhooks/unipile.routes.js.map +1 -0
- package/dist/modules/whatsapp/appointment.model.d.ts +27 -0
- package/dist/modules/whatsapp/appointment.model.js +58 -0
- package/dist/modules/whatsapp/appointment.model.js.map +1 -0
- package/dist/modules/whatsapp/operator-request.model.d.ts +29 -0
- package/dist/modules/whatsapp/operator-request.model.js +65 -0
- package/dist/modules/whatsapp/operator-request.model.js.map +1 -0
- package/dist/modules/whatsapp/stt-usage.model.d.ts +16 -0
- package/dist/modules/whatsapp/stt-usage.model.js +53 -0
- package/dist/modules/whatsapp/stt-usage.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.d.ts +23 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.js +55 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.d.ts +23 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.js +54 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-message.model.d.ts +30 -0
- package/dist/modules/whatsapp/whatsapp-message.model.js +52 -0
- package/dist/modules/whatsapp/whatsapp-message.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-session.model.d.ts +33 -0
- package/dist/modules/whatsapp/whatsapp-session.model.js +65 -0
- package/dist/modules/whatsapp/whatsapp-session.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp.routes.d.ts +2 -0
- package/dist/modules/whatsapp/whatsapp.routes.js +1237 -0
- package/dist/modules/whatsapp/whatsapp.routes.js.map +1 -0
- package/dist/plugins/cors.d.ts +3 -0
- package/dist/plugins/cors.js +11 -0
- package/dist/plugins/cors.js.map +1 -0
- package/dist/plugins/jwt.d.ts +3 -0
- package/dist/plugins/jwt.js +22 -0
- package/dist/plugins/jwt.js.map +1 -0
- package/dist/plugins/rawBody.d.ts +3 -0
- package/dist/plugins/rawBody.js +16 -0
- package/dist/plugins/rawBody.js.map +1 -0
- package/dist/plugins/rbac.d.ts +5 -0
- package/dist/plugins/rbac.js +29 -0
- package/dist/plugins/rbac.js.map +1 -0
- package/dist/routes/admin.routes.d.ts +2 -0
- package/dist/routes/admin.routes.js +169 -0
- package/dist/routes/admin.routes.js.map +1 -0
- package/dist/routes/health.routes.d.ts +2 -0
- package/dist/routes/health.routes.js +16 -0
- package/dist/routes/health.routes.js.map +1 -0
- package/dist/routes/webhook.routes.d.ts +2 -0
- package/dist/routes/webhook.routes.js +17 -0
- package/dist/routes/webhook.routes.js.map +1 -0
- package/dist/services/ai/base.ai.d.ts +19 -0
- package/dist/services/ai/base.ai.js +120 -0
- package/dist/services/ai/base.ai.js.map +1 -0
- package/dist/services/ai/gemini.service.d.ts +11 -0
- package/dist/services/ai/gemini.service.js +43 -0
- package/dist/services/ai/gemini.service.js.map +1 -0
- package/dist/services/ai/index.d.ts +2 -0
- package/dist/services/ai/index.js +26 -0
- package/dist/services/ai/index.js.map +1 -0
- package/dist/services/ai/openai.service.d.ts +11 -0
- package/dist/services/ai/openai.service.js +50 -0
- package/dist/services/ai/openai.service.js.map +1 -0
- package/dist/services/elevenlabs.service.d.ts +52 -0
- package/dist/services/elevenlabs.service.js +447 -0
- package/dist/services/elevenlabs.service.js.map +1 -0
- package/dist/services/google-calendar.service.d.ts +60 -0
- package/dist/services/google-calendar.service.js +494 -0
- package/dist/services/google-calendar.service.js.map +1 -0
- package/dist/services/inbound-call-schedule.service.d.ts +11 -0
- package/dist/services/inbound-call-schedule.service.js +162 -0
- package/dist/services/inbound-call-schedule.service.js.map +1 -0
- package/dist/services/netgsm.service.d.ts +41 -0
- package/dist/services/netgsm.service.js +89 -0
- package/dist/services/netgsm.service.js.map +1 -0
- package/dist/services/unipile.service.d.ts +41 -0
- package/dist/services/unipile.service.js +149 -0
- package/dist/services/unipile.service.js.map +1 -0
- package/dist/services/whatsapp-agent.service.d.ts +139 -0
- package/dist/services/whatsapp-agent.service.js +2055 -0
- package/dist/services/whatsapp-agent.service.js.map +1 -0
- package/dist/services/whatsapp.service.d.ts +26 -0
- package/dist/services/whatsapp.service.js +206 -0
- package/dist/services/whatsapp.service.js.map +1 -0
- package/dist/templates/index.d.ts +39 -0
- package/dist/templates/index.js +35 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/receptionist.d.ts +2 -0
- package/dist/templates/receptionist.js +39 -0
- package/dist/templates/receptionist.js.map +1 -0
- package/dist/templates/survey.d.ts +2 -0
- package/dist/templates/survey.js +41 -0
- package/dist/templates/survey.js.map +1 -0
- package/dist/types/index.d.ts +173 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.js +105 -0
- package/dist/utils/logger.js.map +1 -0
- package/docker-compose.nestjs.yml +89 -0
- package/docker-compose.yml +78 -0
- package/docs/AI_AGENT_ENHANCEMENT_PLAN.md +164 -0
- package/docs/API.md +1193 -0
- package/docs/API_ENDPOINTS.md +344 -0
- package/docs/ARCHITECTURE.md +305 -0
- package/docs/AUTH_API.md +252 -0
- package/docs/BILLING_SMS_ALERTS.md +94 -0
- package/docs/CHAT_ASSIGNMENT_SYSTEM.md +118 -0
- package/docs/CLIENT_TOOLS_AND_FEATURES.md +337 -0
- package/docs/ELEVENLABS_WEBHOOK_TOOLS.md +644 -0
- package/docs/FRONTEND_CHECKLIST.md +227 -0
- package/docs/IMPLEMENTATION_STATUS.md +470 -0
- package/docs/MIGRATION_GUIDE.md +96 -0
- package/docs/MISSINGS_REPORT.md +507 -0
- package/docs/NESTJS_MIGRATION_REFERENCE.md +5136 -0
- package/docs/PROJECT_DESCRIPTION.md +1038 -0
- package/docs/SCALING.md +148 -0
- package/docs/SESSION_SUMMARY_2026_03_17.md +135 -0
- package/docs/WHATSAPP_AGENT.md +1086 -0
- package/docs/architecture/00-SYSTEM-OVERVIEW.md +318 -0
- package/docs/architecture/01-DATABASE-SCHEMA.md +2564 -0
- package/docs/architecture/02-AUTHENTICATION.md +1040 -0
- package/docs/architecture/03-MULTI-CLINIC.md +742 -0
- package/docs/architecture/04-WHATSAPP-AGENT.md +608 -0
- package/docs/architecture/05-OPERATOR-WORKFLOW.md +444 -0
- package/docs/architecture/06-BAILEYS-MICROSERVICE.md +616 -0
- package/docs/architecture/07-APPOINTMENTS.md +849 -0
- package/docs/architecture/08-VOICE-CALLS.md +470 -0
- package/docs/architecture/09-OUTBOUND-CAMPAIGNS.md +542 -0
- package/docs/architecture/10-CLIENT-TOOLS.md +665 -0
- package/docs/architecture/11-BILLING.md +458 -0
- package/docs/architecture/12-SECURITY.md +216 -0
- package/docs/architecture/13-LOGGING-AUDIT.md +549 -0
- package/docs/architecture/14-META-BUSINESS-API.md +454 -0
- package/docs/architecture/15-AI-MODULE.md +479 -0
- package/docs/architecture/16-BACKGROUND-JOBS.md +469 -0
- package/docs/architecture/17-REALTIME-LIVECHAT.md +447 -0
- package/docs/architecture/18-FILE-STORAGE.md +410 -0
- package/docs/architecture/19-PATIENTS.md +1034 -0
- package/docs/architecture/20-TREATMENTS-AND-PLANS.md +774 -0
- package/docs/architecture/21-BEFORE-AFTER-PHOTOS.md +519 -0
- package/docs/database.md +456 -0
- package/docs/ornek-randevu-onay.csv +3 -0
- package/ecosystem.config.js +16 -0
- package/elevenlabs-convai-api-reference.md +1171 -0
- package/frontend/.dockerignore +2 -0
- package/frontend/Dockerfile +24 -0
- package/frontend/README.md +75 -0
- package/frontend/components.json +25 -0
- package/frontend/eslint.config.js +23 -0
- package/frontend/index.html +13 -0
- package/frontend/nginx.conf +37 -0
- package/frontend/package-lock.json +8709 -0
- package/frontend/package.json +71 -0
- package/frontend/public/favicon.svg +1 -0
- package/frontend/public/icons.svg +24 -0
- package/frontend/src/App.tsx +125 -0
- package/frontend/src/components/error-boundary.tsx +50 -0
- package/frontend/src/components/shared/activity-timeline.tsx +66 -0
- package/frontend/src/components/shared/appointment-calendar.css +80 -0
- package/frontend/src/components/shared/appointment-calendar.tsx +245 -0
- package/frontend/src/components/shared/chat-bubble.tsx +72 -0
- package/frontend/src/components/shared/combobox.tsx +119 -0
- package/frontend/src/components/shared/confirm-dialog.tsx +57 -0
- package/frontend/src/components/shared/data-table-pagination.tsx +97 -0
- package/frontend/src/components/shared/data-table-toolbar.tsx +39 -0
- package/frontend/src/components/shared/empty-state.tsx +27 -0
- package/frontend/src/components/shared/file-upload.tsx +140 -0
- package/frontend/src/components/shared/index.ts +20 -0
- package/frontend/src/components/shared/language-switcher.tsx +29 -0
- package/frontend/src/components/shared/notification-dropdown.tsx +115 -0
- package/frontend/src/components/shared/page-header.tsx +23 -0
- package/frontend/src/components/shared/stat-card.tsx +37 -0
- package/frontend/src/components/shared/status-badge.tsx +70 -0
- package/frontend/src/components/shared/status-dot.tsx +43 -0
- package/frontend/src/components/ui/alert-dialog.tsx +187 -0
- package/frontend/src/components/ui/alert.tsx +76 -0
- package/frontend/src/components/ui/avatar.tsx +109 -0
- package/frontend/src/components/ui/badge.tsx +52 -0
- package/frontend/src/components/ui/breadcrumb.tsx +125 -0
- package/frontend/src/components/ui/button.tsx +60 -0
- package/frontend/src/components/ui/calendar.tsx +219 -0
- package/frontend/src/components/ui/card.tsx +103 -0
- package/frontend/src/components/ui/chart.tsx +371 -0
- package/frontend/src/components/ui/checkbox.tsx +29 -0
- package/frontend/src/components/ui/collapsible.tsx +19 -0
- package/frontend/src/components/ui/command.tsx +194 -0
- package/frontend/src/components/ui/dialog.tsx +158 -0
- package/frontend/src/components/ui/dropdown-menu.tsx +268 -0
- package/frontend/src/components/ui/input-group.tsx +156 -0
- package/frontend/src/components/ui/input.tsx +20 -0
- package/frontend/src/components/ui/label.tsx +20 -0
- package/frontend/src/components/ui/pagination.tsx +130 -0
- package/frontend/src/components/ui/popover.tsx +90 -0
- package/frontend/src/components/ui/progress.tsx +83 -0
- package/frontend/src/components/ui/radio-group.tsx +36 -0
- package/frontend/src/components/ui/scroll-area.tsx +54 -0
- package/frontend/src/components/ui/select.tsx +199 -0
- package/frontend/src/components/ui/separator.tsx +23 -0
- package/frontend/src/components/ui/sheet.tsx +138 -0
- package/frontend/src/components/ui/sidebar.tsx +723 -0
- package/frontend/src/components/ui/skeleton.tsx +13 -0
- package/frontend/src/components/ui/sonner.tsx +47 -0
- package/frontend/src/components/ui/switch.tsx +30 -0
- package/frontend/src/components/ui/table.tsx +114 -0
- package/frontend/src/components/ui/tabs.tsx +82 -0
- package/frontend/src/components/ui/textarea.tsx +18 -0
- package/frontend/src/components/ui/toggle-group.tsx +89 -0
- package/frontend/src/components/ui/toggle.tsx +43 -0
- package/frontend/src/components/ui/tooltip.tsx +64 -0
- package/frontend/src/hooks/use-mobile.ts +19 -0
- package/frontend/src/i18n/index.ts +20 -0
- package/frontend/src/i18n/locales/en.json +786 -0
- package/frontend/src/i18n/locales/tr.json +786 -0
- package/frontend/src/index.css +134 -0
- package/frontend/src/layouts/admin-layout.tsx +111 -0
- package/frontend/src/layouts/app-header.tsx +130 -0
- package/frontend/src/layouts/app-layout.tsx +19 -0
- package/frontend/src/layouts/app-sidebar.tsx +212 -0
- package/frontend/src/layouts/auth-guard.tsx +31 -0
- package/frontend/src/layouts/mobile-sidebar.tsx +120 -0
- package/frontend/src/lib/api.ts +68 -0
- package/frontend/src/lib/hooks/use-appointments.ts +224 -0
- package/frontend/src/lib/hooks/use-availability-blocks.ts +83 -0
- package/frontend/src/lib/hooks/use-chats.ts +236 -0
- package/frontend/src/lib/hooks/use-clinic-detail.ts +171 -0
- package/frontend/src/lib/hooks/use-clinics.ts +37 -0
- package/frontend/src/lib/hooks/use-doctor-calendar.ts +80 -0
- package/frontend/src/lib/hooks/use-examinations.ts +89 -0
- package/frontend/src/lib/hooks/use-medical-history.ts +52 -0
- package/frontend/src/lib/hooks/use-patients.ts +296 -0
- package/frontend/src/lib/hooks/use-photo-sets.ts +118 -0
- package/frontend/src/lib/hooks/use-treatment-plans.ts +152 -0
- package/frontend/src/lib/hooks/use-treatments.ts +125 -0
- package/frontend/src/lib/hooks/use-users.ts +172 -0
- package/frontend/src/lib/utils.ts +6 -0
- package/frontend/src/main.tsx +17 -0
- package/frontend/src/pages/admin/agents/detail.tsx +774 -0
- package/frontend/src/pages/admin/agents/import.tsx +280 -0
- package/frontend/src/pages/admin/agents/index.tsx +245 -0
- package/frontend/src/pages/admin/ai-playground.tsx +543 -0
- package/frontend/src/pages/appointments/create-appointment-dialog.tsx +390 -0
- package/frontend/src/pages/appointments/index.tsx +860 -0
- package/frontend/src/pages/audit/index.tsx +24 -0
- package/frontend/src/pages/auth/login.tsx +194 -0
- package/frontend/src/pages/billing/index.tsx +24 -0
- package/frontend/src/pages/calendar/index.tsx +704 -0
- package/frontend/src/pages/calendar-connections/index.tsx +295 -0
- package/frontend/src/pages/calls/index.tsx +24 -0
- package/frontend/src/pages/campaigns/index.tsx +24 -0
- package/frontend/src/pages/chats/index.tsx +981 -0
- package/frontend/src/pages/clinics/index.tsx +224 -0
- package/frontend/src/pages/clinics/settings.tsx +412 -0
- package/frontend/src/pages/components-showcase.tsx +773 -0
- package/frontend/src/pages/connections/index.tsx +328 -0
- package/frontend/src/pages/dashboard.tsx +50 -0
- package/frontend/src/pages/leads/index.tsx +24 -0
- package/frontend/src/pages/my-schedule/index.tsx +496 -0
- package/frontend/src/pages/patients/create-patient-dialog.tsx +358 -0
- package/frontend/src/pages/patients/detail.tsx +1195 -0
- package/frontend/src/pages/patients/edit-patient-dialog.tsx +387 -0
- package/frontend/src/pages/patients/examinations-tab.tsx +460 -0
- package/frontend/src/pages/patients/index.tsx +381 -0
- package/frontend/src/pages/patients/medical-history-dialog.tsx +207 -0
- package/frontend/src/pages/patients/photo-sets-tab.tsx +616 -0
- package/frontend/src/pages/patients/timeline-tab.tsx +164 -0
- package/frontend/src/pages/patients/treatment-plans-tab.tsx +598 -0
- package/frontend/src/pages/phone-numbers/detail.tsx +427 -0
- package/frontend/src/pages/phone-numbers/index.tsx +455 -0
- package/frontend/src/pages/platform/index.tsx +454 -0
- package/frontend/src/pages/settings/index.tsx +126 -0
- package/frontend/src/pages/treatments/index.tsx +487 -0
- package/frontend/src/pages/users/doctor-profile.tsx +672 -0
- package/frontend/src/pages/users/edit.tsx +329 -0
- package/frontend/src/pages/users/index.tsx +407 -0
- package/frontend/src/pages/validation/index.tsx +24 -0
- package/frontend/src/stores/auth.store.ts +108 -0
- package/frontend/src/stores/ui.store.ts +41 -0
- package/frontend/tsconfig.app.json +32 -0
- package/frontend/tsconfig.json +13 -0
- package/frontend/tsconfig.node.json +26 -0
- package/frontend/vite.config.ts +29 -0
- package/nestjs/.dockerignore +5 -0
- package/nestjs/.env.docker +64 -0
- package/nestjs/.prettierrc +4 -0
- package/nestjs/Dockerfile +36 -0
- package/nestjs/README.md +98 -0
- package/nestjs/eslint.config.mjs +35 -0
- package/nestjs/nest-cli.json +8 -0
- package/nestjs/package-lock.json +13390 -0
- package/nestjs/package.json +114 -0
- package/nestjs/prisma/migrations/20260409161536_add_message_metadata_fields/migration.sql +1746 -0
- package/nestjs/prisma/migrations/20260410140436_add_agent_ai_fields/migration.sql +36 -0
- package/nestjs/prisma/migrations/20260410175519_add_agent_clinic_assignments/migration.sql +21 -0
- package/nestjs/prisma/migrations/20260412094344_make_agent_tenant_optional/migration.sql +2 -0
- package/nestjs/prisma/migrations/20260412110008_add_admin_chat_sessions/migration.sql +47 -0
- package/nestjs/prisma/migrations/migration_lock.toml +3 -0
- package/nestjs/prisma/schema.prisma +1843 -0
- package/nestjs/prisma/seed.ts +375 -0
- package/nestjs/prisma.config.ts +14 -0
- package/nestjs/src/admin/admin.controller.ts +27 -0
- package/nestjs/src/admin/admin.module.ts +16 -0
- package/nestjs/src/admin/admin.service.ts +91 -0
- package/nestjs/src/admin/ai-chat-session.service.ts +454 -0
- package/nestjs/src/admin/ai-test.controller.ts +191 -0
- package/nestjs/src/admin/superadmin.controller.ts +106 -0
- package/nestjs/src/agents/agents.controller.ts +262 -0
- package/nestjs/src/agents/agents.module.ts +13 -0
- package/nestjs/src/agents/agents.service.ts +733 -0
- package/nestjs/src/agents/dto/create-agent.dto.ts +99 -0
- package/nestjs/src/agents/dto/index.ts +2 -0
- package/nestjs/src/agents/dto/update-agent.dto.ts +148 -0
- package/nestjs/src/app.module.ts +115 -0
- package/nestjs/src/appointment-validation/appointment-validation.controller.ts +194 -0
- package/nestjs/src/appointment-validation/appointment-validation.module.ts +16 -0
- package/nestjs/src/appointment-validation/appointment-validation.service.ts +450 -0
- package/nestjs/src/appointment-validation/dto/create-batch.dto.ts +105 -0
- package/nestjs/src/appointment-validation/dto/index.ts +1 -0
- package/nestjs/src/appointment-validation/processors/validation-dispatch.processor.ts +26 -0
- package/nestjs/src/appointment-validation/processors/validation-sync.processor.ts +23 -0
- package/nestjs/src/appointments/appointments.controller.ts +268 -0
- package/nestjs/src/appointments/appointments.module.ts +13 -0
- package/nestjs/src/appointments/appointments.service.ts +773 -0
- package/nestjs/src/appointments/dto/create-appointment.dto.ts +72 -0
- package/nestjs/src/appointments/dto/index.ts +4 -0
- package/nestjs/src/appointments/dto/query-appointments.dto.ts +60 -0
- package/nestjs/src/appointments/dto/update-appointment.dto.ts +43 -0
- package/nestjs/src/appointments/dto/update-status.dto.ts +18 -0
- package/nestjs/src/appointments/processors/reminder.processor.ts +243 -0
- package/nestjs/src/audit/audit.controller.ts +84 -0
- package/nestjs/src/audit/audit.decorator.ts +20 -0
- package/nestjs/src/audit/audit.interceptor.ts +67 -0
- package/nestjs/src/audit/audit.interfaces.ts +15 -0
- package/nestjs/src/audit/audit.module.ts +12 -0
- package/nestjs/src/audit/audit.service.ts +177 -0
- package/nestjs/src/auth/auth.controller.ts +116 -0
- package/nestjs/src/auth/auth.module.ts +25 -0
- package/nestjs/src/auth/auth.service.ts +612 -0
- package/nestjs/src/auth/dto/change-password.dto.ts +13 -0
- package/nestjs/src/auth/dto/forgot-password.dto.ts +8 -0
- package/nestjs/src/auth/dto/index.ts +6 -0
- package/nestjs/src/auth/dto/login.dto.ts +13 -0
- package/nestjs/src/auth/dto/refresh.dto.ts +8 -0
- package/nestjs/src/auth/dto/register.dto.ts +28 -0
- package/nestjs/src/auth/dto/reset-password.dto.ts +13 -0
- package/nestjs/src/auth/permissions.config.ts +85 -0
- package/nestjs/src/availability-blocks/availability-blocks.controller.ts +83 -0
- package/nestjs/src/availability-blocks/availability-blocks.module.ts +10 -0
- package/nestjs/src/availability-blocks/availability-blocks.service.ts +202 -0
- package/nestjs/src/billing/billing.controller.ts +104 -0
- package/nestjs/src/billing/billing.module.ts +12 -0
- package/nestjs/src/billing/billing.service.ts +398 -0
- package/nestjs/src/billing/dto/index.ts +2 -0
- package/nestjs/src/billing/dto/query-billing.dto.ts +29 -0
- package/nestjs/src/billing/dto/record-payment.dto.ts +60 -0
- package/nestjs/src/billing/processors/alerts.processor.ts +216 -0
- package/nestjs/src/billing/processors/snapshot.processor.ts +181 -0
- package/nestjs/src/calls/calls.controller.ts +92 -0
- package/nestjs/src/calls/calls.module.ts +10 -0
- package/nestjs/src/calls/calls.service.ts +359 -0
- package/nestjs/src/calls/dto/index.ts +1 -0
- package/nestjs/src/calls/dto/query-calls.dto.ts +46 -0
- package/nestjs/src/clinics/clinics.controller.ts +226 -0
- package/nestjs/src/clinics/clinics.module.ts +11 -0
- package/nestjs/src/clinics/clinics.service.ts +203 -0
- package/nestjs/src/clinics/dto/create-clinic.dto.ts +40 -0
- package/nestjs/src/clinics/dto/create-meta-connection.dto.ts +44 -0
- package/nestjs/src/clinics/dto/index.ts +4 -0
- package/nestjs/src/clinics/dto/update-clinic.dto.ts +133 -0
- package/nestjs/src/clinics/dto/update-meta-connection.dto.ts +22 -0
- package/nestjs/src/clinics/meta-connections.service.ts +210 -0
- package/nestjs/src/common/decorators/accessible-clinics.decorator.ts +9 -0
- package/nestjs/src/common/decorators/current-user.decorator.ts +10 -0
- package/nestjs/src/common/decorators/features.decorator.ts +7 -0
- package/nestjs/src/common/decorators/index.ts +4 -0
- package/nestjs/src/common/decorators/permissions.decorator.ts +13 -0
- package/nestjs/src/common/gateways/events.gateway.ts +157 -0
- package/nestjs/src/common/guards/clinic-access.guard.ts +40 -0
- package/nestjs/src/common/guards/features.guard.ts +38 -0
- package/nestjs/src/common/guards/index.ts +5 -0
- package/nestjs/src/common/guards/jwt-auth.guard.ts +54 -0
- package/nestjs/src/common/guards/permissions.guard.ts +50 -0
- package/nestjs/src/common/guards/superadmin.guard.ts +35 -0
- package/nestjs/src/common/interceptors/request-context.interceptor.ts +32 -0
- package/nestjs/src/common/interceptors/superadmin-tenant.interceptor.ts +42 -0
- package/nestjs/src/common/interfaces/jwt-payload.interface.ts +11 -0
- package/nestjs/src/config/config.module.ts +13 -0
- package/nestjs/src/database/database.module.ts +9 -0
- package/nestjs/src/database/prisma.service.ts +20 -0
- package/nestjs/src/database/tenant-context.ts +27 -0
- package/nestjs/src/google-calendar/google-calendar.controller.ts +259 -0
- package/nestjs/src/google-calendar/google-calendar.module.ts +10 -0
- package/nestjs/src/google-calendar/google-calendar.service.ts +811 -0
- package/nestjs/src/integrations/ai/ai.interface.ts +74 -0
- package/nestjs/src/integrations/ai/ai.module.ts +11 -0
- package/nestjs/src/integrations/ai/ai.service.ts +148 -0
- package/nestjs/src/integrations/ai/providers/anthropic.provider.ts +146 -0
- package/nestjs/src/integrations/ai/providers/openai.provider.ts +158 -0
- package/nestjs/src/integrations/elevenlabs/elevenlabs.module.ts +8 -0
- package/nestjs/src/integrations/elevenlabs/elevenlabs.service.ts +226 -0
- package/nestjs/src/integrations/encryption/encryption.module.ts +9 -0
- package/nestjs/src/integrations/encryption/encryption.service.ts +31 -0
- package/nestjs/src/integrations/image/image.module.ts +9 -0
- package/nestjs/src/integrations/image/image.service.ts +61 -0
- package/nestjs/src/integrations/meta-business/meta-business.module.ts +10 -0
- package/nestjs/src/integrations/meta-business/meta-instagram.service.ts +94 -0
- package/nestjs/src/integrations/meta-business/meta-webhook.service.ts +52 -0
- package/nestjs/src/integrations/meta-business/meta-whatsapp.service.ts +254 -0
- package/nestjs/src/integrations/minio/minio.module.ts +9 -0
- package/nestjs/src/integrations/minio/minio.service.ts +88 -0
- package/nestjs/src/integrations/netgsm/netgsm.module.ts +8 -0
- package/nestjs/src/integrations/netgsm/netgsm.service.ts +17 -0
- package/nestjs/src/integrations/tektippay/tektippay.module.ts +8 -0
- package/nestjs/src/integrations/tektippay/tektippay.service.ts +23 -0
- package/nestjs/src/leads/dto/index.ts +2 -0
- package/nestjs/src/leads/dto/query-leads.dto.ts +50 -0
- package/nestjs/src/leads/dto/update-lead.dto.ts +26 -0
- package/nestjs/src/leads/leads.controller.ts +184 -0
- package/nestjs/src/leads/leads.module.ts +10 -0
- package/nestjs/src/leads/leads.service.ts +375 -0
- package/nestjs/src/logging/logging.controller.ts +82 -0
- package/nestjs/src/logging/logging.module.ts +11 -0
- package/nestjs/src/logging/logging.service.ts +180 -0
- package/nestjs/src/main.ts +86 -0
- package/nestjs/src/outbound-campaigns/dto/create-campaign.dto.ts +47 -0
- package/nestjs/src/outbound-campaigns/dto/index.ts +3 -0
- package/nestjs/src/outbound-campaigns/dto/update-campaign.dto.ts +31 -0
- package/nestjs/src/outbound-campaigns/dto/upload-entries.dto.ts +35 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.controller.ts +307 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.module.ts +13 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.service.ts +471 -0
- package/nestjs/src/outbound-campaigns/processors/campaign-dispatch.processor.ts +366 -0
- package/nestjs/src/patients/documents.service.ts +231 -0
- package/nestjs/src/patients/dto/create-examination.dto.ts +34 -0
- package/nestjs/src/patients/dto/create-note.dto.ts +14 -0
- package/nestjs/src/patients/dto/create-patient.dto.ts +86 -0
- package/nestjs/src/patients/dto/create-photo-set.dto.ts +32 -0
- package/nestjs/src/patients/dto/index.ts +10 -0
- package/nestjs/src/patients/dto/update-examination.dto.ts +29 -0
- package/nestjs/src/patients/dto/update-medical-history.dto.ts +47 -0
- package/nestjs/src/patients/dto/update-patient.dto.ts +87 -0
- package/nestjs/src/patients/dto/update-photo-set.dto.ts +28 -0
- package/nestjs/src/patients/dto/upload-document.dto.ts +31 -0
- package/nestjs/src/patients/dto/upload-photo.dto.ts +27 -0
- package/nestjs/src/patients/examinations.service.ts +271 -0
- package/nestjs/src/patients/medical-history.service.ts +149 -0
- package/nestjs/src/patients/notes.service.ts +172 -0
- package/nestjs/src/patients/patients.controller.ts +485 -0
- package/nestjs/src/patients/patients.module.ts +22 -0
- package/nestjs/src/patients/patients.service.ts +412 -0
- package/nestjs/src/patients/photo-sets.service.ts +389 -0
- package/nestjs/src/phone-numbers/dto/create-phone-number.dto.ts +57 -0
- package/nestjs/src/phone-numbers/dto/index.ts +3 -0
- package/nestjs/src/phone-numbers/dto/update-phone-number.dto.ts +38 -0
- package/nestjs/src/phone-numbers/dto/update-schedule.dto.ts +39 -0
- package/nestjs/src/phone-numbers/phone-numbers.controller.ts +125 -0
- package/nestjs/src/phone-numbers/phone-numbers.module.ts +10 -0
- package/nestjs/src/phone-numbers/phone-numbers.service.ts +209 -0
- package/nestjs/src/plans/dto/create-plan.dto.ts +70 -0
- package/nestjs/src/plans/dto/index.ts +2 -0
- package/nestjs/src/plans/dto/update-plan.dto.ts +80 -0
- package/nestjs/src/plans/plans.controller.ts +50 -0
- package/nestjs/src/plans/plans.module.ts +10 -0
- package/nestjs/src/plans/plans.service.ts +115 -0
- package/nestjs/src/platform/dto/create-tenant.dto.ts +36 -0
- package/nestjs/src/platform/dto/index.ts +2 -0
- package/nestjs/src/platform/dto/update-tenant-platform.dto.ts +44 -0
- package/nestjs/src/platform/platform.controller.ts +79 -0
- package/nestjs/src/platform/platform.module.ts +10 -0
- package/nestjs/src/platform/platform.service.ts +301 -0
- package/nestjs/src/queue/queue.module.ts +56 -0
- package/nestjs/src/redis/redis.module.ts +20 -0
- package/nestjs/src/tenants/dto/index.ts +1 -0
- package/nestjs/src/tenants/dto/update-tenant.dto.ts +15 -0
- package/nestjs/src/tenants/tenants.controller.ts +45 -0
- package/nestjs/src/tenants/tenants.module.ts +10 -0
- package/nestjs/src/tenants/tenants.service.ts +41 -0
- package/nestjs/src/tools/adapters/elevenlabs-http.adapter.ts +51 -0
- package/nestjs/src/tools/adapters/elevenlabs-ws.adapter.ts +59 -0
- package/nestjs/src/tools/handlers/calendar.tools.ts +441 -0
- package/nestjs/src/tools/handlers/notification.tools.ts +34 -0
- package/nestjs/src/tools/handlers/operator.tools.ts +303 -0
- package/nestjs/src/tools/handlers/patient.tools.ts +242 -0
- package/nestjs/src/tools/handlers/payment.tools.ts +43 -0
- package/nestjs/src/tools/handlers/validation.tools.ts +152 -0
- package/nestjs/src/tools/tool-registry.service.ts +221 -0
- package/nestjs/src/tools/tool.decorator.ts +16 -0
- package/nestjs/src/tools/tool.interfaces.ts +26 -0
- package/nestjs/src/tools/tools.module.ts +50 -0
- package/nestjs/src/treatments/dto/create-plan-item.dto.ts +27 -0
- package/nestjs/src/treatments/dto/create-treatment-plan.dto.ts +69 -0
- package/nestjs/src/treatments/dto/create-treatment.dto.ts +59 -0
- package/nestjs/src/treatments/dto/index.ts +6 -0
- package/nestjs/src/treatments/dto/update-plan-item.dto.ts +23 -0
- package/nestjs/src/treatments/dto/update-treatment-plan.dto.ts +22 -0
- package/nestjs/src/treatments/dto/update-treatment.dto.ts +70 -0
- package/nestjs/src/treatments/treatment-plans.service.ts +362 -0
- package/nestjs/src/treatments/treatments.controller.ts +265 -0
- package/nestjs/src/treatments/treatments.module.ts +14 -0
- package/nestjs/src/treatments/treatments.service.ts +165 -0
- package/nestjs/src/users/doctor-profiles.service.ts +202 -0
- package/nestjs/src/users/dto/index.ts +4 -0
- package/nestjs/src/users/dto/invite-user.dto.ts +52 -0
- package/nestjs/src/users/dto/update-clinic-assignments.dto.ts +9 -0
- package/nestjs/src/users/dto/update-doctor-profile.dto.ts +49 -0
- package/nestjs/src/users/dto/update-user.dto.ts +41 -0
- package/nestjs/src/users/users.controller.ts +142 -0
- package/nestjs/src/users/users.module.ts +11 -0
- package/nestjs/src/users/users.service.ts +250 -0
- package/nestjs/src/webhooks/elevenlabs-tool.controller.ts +66 -0
- package/nestjs/src/webhooks/elevenlabs-webhook.controller.ts +60 -0
- package/nestjs/src/webhooks/meta-webhook.controller.ts +178 -0
- package/nestjs/src/webhooks/processors/elevenlabs-webhook.processor.ts +28 -0
- package/nestjs/src/webhooks/webhooks.module.ts +17 -0
- package/nestjs/src/whatsapp/chat-context.service.ts +281 -0
- package/nestjs/src/whatsapp/dto/add-blacklist.dto.ts +13 -0
- package/nestjs/src/whatsapp/dto/index.ts +2 -0
- package/nestjs/src/whatsapp/dto/send-message.dto.ts +14 -0
- package/nestjs/src/whatsapp/listeners/meta-message.listener.ts +579 -0
- package/nestjs/src/whatsapp/meta-auth.controller.ts +268 -0
- package/nestjs/src/whatsapp/meta-instagram-auth.controller.ts +244 -0
- package/nestjs/src/whatsapp/operator.service.ts +692 -0
- package/nestjs/src/whatsapp/processors/cost-sweep.processor.ts +130 -0
- package/nestjs/src/whatsapp/processors/grace.processor.ts +191 -0
- package/nestjs/src/whatsapp/processors/message-buffer.processor.ts +138 -0
- package/nestjs/src/whatsapp/processors/message-cleanup.processor.ts +148 -0
- package/nestjs/src/whatsapp/processors/meta-token-refresh.processor.ts +114 -0
- package/nestjs/src/whatsapp/processors/operator-expiry.processor.ts +105 -0
- package/nestjs/src/whatsapp/processors/profile-update.processor.ts +234 -0
- package/nestjs/src/whatsapp/processors/session-cleanup.processor.ts +178 -0
- package/nestjs/src/whatsapp/processors/session-labels.processor.ts +248 -0
- package/nestjs/src/whatsapp/whatsapp-agent.service.ts +2506 -0
- package/nestjs/src/whatsapp/whatsapp-recovery.service.ts +117 -0
- package/nestjs/src/whatsapp/whatsapp.controller.ts +398 -0
- package/nestjs/src/whatsapp/whatsapp.module.ts +51 -0
- package/nestjs/src/whatsapp/whatsapp.service.ts +592 -0
- package/nestjs/test/app.e2e-spec.ts +25 -0
- package/nestjs/test/jest-e2e.json +9 -0
- package/nestjs/tsconfig.build.json +4 -0
- package/nestjs/tsconfig.json +25 -0
- package/nginx.example.conf +18 -0
- package/package.json +47 -0
- package/scripts/addRecipient.ts +48 -0
- package/scripts/listRecipients.ts +31 -0
- package/scripts/migrate-agent-ref.ts +86 -0
- package/scripts/migrate-sessions.ts +183 -0
- package/scripts/promote.ts +27 -0
- package/scripts/retrigger.ts +84 -0
- package/scripts/seed.ts +435 -0
- package/scripts/testSend.ts +63 -0
- package/src/app.ts +85 -0
- package/src/config/agentPrompts.json +19 -0
- package/src/config/database.ts +21 -0
- package/src/config/env.ts +94 -0
- package/src/config/index.ts +86 -0
- package/src/controllers/webhook.controller.ts +150 -0
- package/src/errors/index.ts +9 -0
- package/src/hooks/webhookValidator.ts +55 -0
- package/src/index.ts +68 -0
- package/src/migrations/001_session-architecture.ts +138 -0
- package/src/migrations/002_agent-ref.ts +65 -0
- package/src/migrations/003_shift-schedule.ts +55 -0
- package/src/migrations/004_invert-shift-to-clinic-hours.ts +30 -0
- package/src/migrations/005_composite-baileys-chat-ids.ts +60 -0
- package/src/migrations/migration.model.ts +27 -0
- package/src/migrations/migration.routes.ts +40 -0
- package/src/migrations/migration.runner.ts +112 -0
- package/src/models/ConversationClaim.ts +17 -0
- package/src/models/ConversationEvaluation.ts +91 -0
- package/src/models/Summary.ts +77 -0
- package/src/models/Transcription.ts +68 -0
- package/src/models/WhatsAppRecipient.ts +37 -0
- package/src/modules/admin/admin.routes.ts +2385 -0
- package/src/modules/admin/elevenlabs-test-chat.routes.ts +193 -0
- package/src/modules/admin/whatsapp-test-chat.routes.ts +244 -0
- package/src/modules/agents/agent.model.ts +93 -0
- package/src/modules/agents/agent.routes.ts +65 -0
- package/src/modules/appointment-validation/appointment-validation.model.ts +163 -0
- package/src/modules/appointment-validation/appointment-validation.routes.ts +275 -0
- package/src/modules/appointment-validation/appointment-validation.service.ts +1028 -0
- package/src/modules/auth/auth.model.ts +42 -0
- package/src/modules/auth/auth.routes.ts +199 -0
- package/src/modules/auth/auth.service.ts +210 -0
- package/src/modules/auth/refresh-token.model.ts +26 -0
- package/src/modules/billing/billing-alert.model.ts +28 -0
- package/src/modules/billing/billing-period-snapshot.model.ts +68 -0
- package/src/modules/billing/billing.model.ts +42 -0
- package/src/modules/billing/billing.routes.ts +67 -0
- package/src/modules/billing/billing.service.ts +562 -0
- package/src/modules/billing/payment.model.ts +42 -0
- package/src/modules/calls/call.model.ts +102 -0
- package/src/modules/calls/call.routes.ts +118 -0
- package/src/modules/campaigns/campaign.model.ts +111 -0
- package/src/modules/campaigns/campaign.routes.ts +402 -0
- package/src/modules/campaigns/campaign.service.ts +99 -0
- package/src/modules/google-calendar/google-calendar.routes.ts +31 -0
- package/src/modules/inbound-call/inbound-call-config.model.ts +49 -0
- package/src/modules/inbound-call/inbound-call.routes.ts +289 -0
- package/src/modules/leads/lead.model.ts +40 -0
- package/src/modules/leads/lead.routes.ts +246 -0
- package/src/modules/logs/log.model.ts +27 -0
- package/src/modules/logs/log.routes.ts +102 -0
- package/src/modules/plans/plan.model.ts +45 -0
- package/src/modules/surveys/survey.model.ts +70 -0
- package/src/modules/surveys/survey.routes.ts +187 -0
- package/src/modules/tenants/tenant.model.ts +181 -0
- package/src/modules/tenants/tenant.routes.ts +78 -0
- package/src/modules/users/user.routes.ts +126 -0
- package/src/modules/webhooks/elevenlabs-tool.routes.ts +94 -0
- package/src/modules/webhooks/elevenlabs-tool.service.ts +491 -0
- package/src/modules/webhooks/elevenlabs.routes.ts +34 -0
- package/src/modules/webhooks/elevenlabs.service.ts +565 -0
- package/src/modules/webhooks/unipile.routes.ts +917 -0
- package/src/modules/whatsapp/appointment.model.ts +47 -0
- package/src/modules/whatsapp/operator-request.model.ts +58 -0
- package/src/modules/whatsapp/stt-usage.model.ts +30 -0
- package/src/modules/whatsapp/whatsapp-chat.model.ts +39 -0
- package/src/modules/whatsapp/whatsapp-contact-profile.model.ts +41 -0
- package/src/modules/whatsapp/whatsapp-message.model.ts +41 -0
- package/src/modules/whatsapp/whatsapp-session.model.ts +60 -0
- package/src/modules/whatsapp/whatsapp.routes.ts +1435 -0
- package/src/plugins/cors.ts +7 -0
- package/src/plugins/jwt.ts +18 -0
- package/src/plugins/rawBody.ts +12 -0
- package/src/plugins/rbac.ts +24 -0
- package/src/routes/admin.routes.ts +208 -0
- package/src/routes/health.routes.ts +12 -0
- package/src/routes/webhook.routes.ts +12 -0
- package/src/services/ai/base.ai.ts +132 -0
- package/src/services/ai/gemini.service.ts +41 -0
- package/src/services/ai/index.ts +24 -0
- package/src/services/ai/openai.service.ts +48 -0
- package/src/services/elevenlabs.service.ts +532 -0
- package/src/services/google-calendar.service.ts +656 -0
- package/src/services/inbound-call-schedule.service.ts +174 -0
- package/src/services/netgsm.service.ts +128 -0
- package/src/services/unipile.service.ts +200 -0
- package/src/services/whatsapp-agent.service.ts +2479 -0
- package/src/services/whatsapp.service.ts +245 -0
- package/src/templates/index.ts +71 -0
- package/src/templates/receptionist.ts +44 -0
- package/src/templates/survey.ts +44 -0
- package/src/types/index.ts +218 -0
- package/src/utils/logger.ts +83 -0
- package/tsconfig.json +19 -0
- package/web/.dockerignore +4 -0
- package/web/Dockerfile +18 -0
- package/web/README.md +73 -0
- package/web/components.json +23 -0
- package/web/eslint.config.js +23 -0
- package/web/index.html +14 -0
- package/web/nginx.conf +18 -0
- package/web/package-lock.json +10292 -0
- package/web/package.json +48 -0
- package/web/public/favicon.ico +0 -0
- package/web/public/vite.svg +1 -0
- package/web/src/App.tsx +191 -0
- package/web/src/assets/react.svg +1 -0
- package/web/src/components/Layout.tsx +261 -0
- package/web/src/components/LeadConversation.tsx +251 -0
- package/web/src/components/ProtectedRoute.tsx +20 -0
- package/web/src/components/conversation-review/CardAudioPlayer.tsx +200 -0
- package/web/src/components/conversation-review/CardEvaluation.tsx +351 -0
- package/web/src/components/conversation-review/CardMetadata.tsx +44 -0
- package/web/src/components/conversation-review/ConversationCard.tsx +95 -0
- package/web/src/components/conversation-review/ReviewContainer.tsx +120 -0
- package/web/src/components/conversation-review/ReviewFilters.tsx +88 -0
- package/web/src/components/empty-state.tsx +15 -0
- package/web/src/components/page-header.tsx +19 -0
- package/web/src/components/page-loader.tsx +32 -0
- package/web/src/components/pagination.tsx +38 -0
- package/web/src/components/stat-card.tsx +27 -0
- package/web/src/components/status-badge.tsx +125 -0
- package/web/src/components/ui/alert.tsx +66 -0
- package/web/src/components/ui/badge.tsx +48 -0
- package/web/src/components/ui/button.tsx +64 -0
- package/web/src/components/ui/card.tsx +92 -0
- package/web/src/components/ui/checkbox.tsx +32 -0
- package/web/src/components/ui/dialog.tsx +158 -0
- package/web/src/components/ui/dropdown-menu.tsx +255 -0
- package/web/src/components/ui/input.tsx +21 -0
- package/web/src/components/ui/label.tsx +22 -0
- package/web/src/components/ui/progress.tsx +29 -0
- package/web/src/components/ui/select.tsx +188 -0
- package/web/src/components/ui/separator.tsx +28 -0
- package/web/src/components/ui/sheet.tsx +123 -0
- package/web/src/components/ui/skeleton.tsx +13 -0
- package/web/src/components/ui/sonner.tsx +35 -0
- package/web/src/components/ui/table.tsx +116 -0
- package/web/src/components/ui/tabs.tsx +89 -0
- package/web/src/components/ui/textarea.tsx +18 -0
- package/web/src/components/ui/tooltip.tsx +57 -0
- package/web/src/components/whatsapp/ChatDetail.tsx +417 -0
- package/web/src/components/whatsapp/ChatHeader.tsx +78 -0
- package/web/src/components/whatsapp/ChatList.tsx +107 -0
- package/web/src/components/whatsapp/ChatListItem.tsx +60 -0
- package/web/src/components/whatsapp/MessageBubble.tsx +46 -0
- package/web/src/components/whatsapp/MessageInput.tsx +63 -0
- package/web/src/components/whatsapp/MessageStream.tsx +135 -0
- package/web/src/components/whatsapp/SessionDivider.tsx +65 -0
- package/web/src/components/whatsapp/SessionHistory.tsx +119 -0
- package/web/src/components/whatsapp/settings/AiSettingsTab.tsx +268 -0
- package/web/src/components/whatsapp/settings/CalendarTab.tsx +339 -0
- package/web/src/components/whatsapp/settings/ConnectionTab.tsx +236 -0
- package/web/src/components/whatsapp/settings/NotificationsTab.tsx +109 -0
- package/web/src/components/whatsapp/settings/OperatorTab.tsx +303 -0
- package/web/src/contexts/AuthContext.tsx +103 -0
- package/web/src/index.css +130 -0
- package/web/src/lib/api.ts +92 -0
- package/web/src/lib/utils.ts +6 -0
- package/web/src/main.tsx +10 -0
- package/web/src/pages/AppointmentDetail.tsx +206 -0
- package/web/src/pages/AppointmentValidation.tsx +157 -0
- package/web/src/pages/AppointmentValidationDetail.tsx +617 -0
- package/web/src/pages/AppointmentValidationNew.tsx +1005 -0
- package/web/src/pages/Appointments.tsx +283 -0
- package/web/src/pages/Billing.tsx +126 -0
- package/web/src/pages/CallDetail.tsx +293 -0
- package/web/src/pages/CallSettings.tsx +313 -0
- package/web/src/pages/Calls.tsx +188 -0
- package/web/src/pages/CampaignDetail.tsx +216 -0
- package/web/src/pages/CampaignNew.tsx +277 -0
- package/web/src/pages/CampaignResults.tsx +185 -0
- package/web/src/pages/Campaigns.tsx +171 -0
- package/web/src/pages/Dashboard.tsx +336 -0
- package/web/src/pages/InboundSchedule.tsx +246 -0
- package/web/src/pages/LeadDetail.tsx +183 -0
- package/web/src/pages/Leads.tsx +258 -0
- package/web/src/pages/Login.tsx +99 -0
- package/web/src/pages/Register.tsx +129 -0
- package/web/src/pages/Settings.tsx +133 -0
- package/web/src/pages/SurveyDetail.tsx +232 -0
- package/web/src/pages/SurveyPreview.tsx +179 -0
- package/web/src/pages/Surveys.tsx +207 -0
- package/web/src/pages/Users.tsx +199 -0
- package/web/src/pages/WhatsApp.tsx +147 -0
- package/web/src/pages/WhatsAppSettings.tsx +215 -0
- package/web/src/pages/admin/AdminBaileysMessageLog.tsx +331 -0
- package/web/src/pages/admin/AdminBaileysRawMessages.tsx +318 -0
- package/web/src/pages/admin/AdminConversationReview.tsx +116 -0
- package/web/src/pages/admin/AdminCredits.tsx +467 -0
- package/web/src/pages/admin/AdminElevenLabsAgentDetail.tsx +332 -0
- package/web/src/pages/admin/AdminElevenLabsAgents.tsx +164 -0
- package/web/src/pages/admin/AdminElevenLabsBatchCallDetail.tsx +214 -0
- package/web/src/pages/admin/AdminElevenLabsBatchCalls.tsx +293 -0
- package/web/src/pages/admin/AdminElevenLabsConversationDetail.tsx +230 -0
- package/web/src/pages/admin/AdminElevenLabsConversations.tsx +228 -0
- package/web/src/pages/admin/AdminElevenLabsInboundCalls.tsx +293 -0
- package/web/src/pages/admin/AdminElevenLabsPhoneNumbers.tsx +506 -0
- package/web/src/pages/admin/AdminElevenLabsTestChat.tsx +258 -0
- package/web/src/pages/admin/AdminElevenLabsWebhooks.tsx +289 -0
- package/web/src/pages/admin/AdminEvaluationDashboard.tsx +520 -0
- package/web/src/pages/admin/AdminLeads.tsx +339 -0
- package/web/src/pages/admin/AdminLogs.tsx +283 -0
- package/web/src/pages/admin/AdminMigrations.tsx +247 -0
- package/web/src/pages/admin/AdminPlans.tsx +313 -0
- package/web/src/pages/admin/AdminSystem.tsx +391 -0
- package/web/src/pages/admin/AdminTenantBillableItems.tsx +464 -0
- package/web/src/pages/admin/AdminTenantDetail.tsx +1317 -0
- package/web/src/pages/admin/AdminTenants.tsx +274 -0
- package/web/src/pages/admin/AdminWhatsApp.tsx +618 -0
- package/web/src/pages/admin/AdminWhatsAppTestChat.tsx +328 -0
- package/web/src/types/index.ts +242 -0
- package/web/tsconfig.app.json +32 -0
- package/web/tsconfig.json +13 -0
- package/web/tsconfig.node.json +26 -0
- package/web/vite.config.ts +23 -0
|
@@ -0,0 +1,1746 @@
|
|
|
1
|
+
-- CreateEnum
|
|
2
|
+
CREATE TYPE "UserRole" AS ENUM ('superadmin', 'sales', 'owner', 'admin', 'doctor', 'receptionist');
|
|
3
|
+
|
|
4
|
+
-- CreateEnum
|
|
5
|
+
CREATE TYPE "PostCallStrategy" AS ENUM ('summarize', 'none');
|
|
6
|
+
|
|
7
|
+
-- CreateEnum
|
|
8
|
+
CREATE TYPE "CallDirection" AS ENUM ('inbound', 'outbound');
|
|
9
|
+
|
|
10
|
+
-- CreateEnum
|
|
11
|
+
CREATE TYPE "CallStatus" AS ENUM ('completed', 'failed', 'no_answer', 'voicemail', 'transferred');
|
|
12
|
+
|
|
13
|
+
-- CreateEnum
|
|
14
|
+
CREATE TYPE "Sentiment" AS ENUM ('positive', 'neutral', 'negative');
|
|
15
|
+
|
|
16
|
+
-- CreateEnum
|
|
17
|
+
CREATE TYPE "OutboundCampaignStatus" AS ENUM ('draft', 'scheduled', 'running', 'paused', 'completed');
|
|
18
|
+
|
|
19
|
+
-- CreateEnum
|
|
20
|
+
CREATE TYPE "CampaignEntryStatus" AS ENUM ('pending', 'calling', 'completed', 'failed', 'no_answer', 'voicemail');
|
|
21
|
+
|
|
22
|
+
-- CreateEnum
|
|
23
|
+
CREATE TYPE "SessionStatus" AS ENUM ('waiting', 'active', 'resolved');
|
|
24
|
+
|
|
25
|
+
-- CreateEnum
|
|
26
|
+
CREATE TYPE "SessionResolvedBy" AS ENUM ('human', 'ai_timeout', 'timeout', 'manual');
|
|
27
|
+
|
|
28
|
+
-- CreateEnum
|
|
29
|
+
CREATE TYPE "MessageSender" AS ENUM ('contact', 'ai', 'human', 'system');
|
|
30
|
+
|
|
31
|
+
-- CreateEnum
|
|
32
|
+
CREATE TYPE "OperatorRequestStatus" AS ENUM ('pending', 'responded', 'expired', 'cancelled');
|
|
33
|
+
|
|
34
|
+
-- CreateEnum
|
|
35
|
+
CREATE TYPE "LeadStatus" AS ENUM ('new_lead', 'contacted', 'appointment_scheduled', 'completed', 'lost', 'expired');
|
|
36
|
+
|
|
37
|
+
-- CreateEnum
|
|
38
|
+
CREATE TYPE "AppointmentStatus" AS ENUM ('scheduled', 'confirmed', 'in_progress', 'completed', 'cancelled', 'no_show');
|
|
39
|
+
|
|
40
|
+
-- CreateEnum
|
|
41
|
+
CREATE TYPE "AppointmentSource" AS ENUM ('whatsapp', 'voice_call', 'dashboard', 'walk_in');
|
|
42
|
+
|
|
43
|
+
-- CreateEnum
|
|
44
|
+
CREATE TYPE "AppointmentType" AS ENUM ('appointment', 'walk_in', 'follow_up', 'consultation');
|
|
45
|
+
|
|
46
|
+
-- CreateEnum
|
|
47
|
+
CREATE TYPE "BatchStatus" AS ENUM ('draft', 'submitted', 'in_progress', 'completed', 'cancelled');
|
|
48
|
+
|
|
49
|
+
-- CreateEnum
|
|
50
|
+
CREATE TYPE "EntryCallStatus" AS ENUM ('pending', 'calling', 'completed', 'failed', 'no_answer', 'voicemail');
|
|
51
|
+
|
|
52
|
+
-- CreateEnum
|
|
53
|
+
CREATE TYPE "ValidationResult" AS ENUM ('confirmed', 'cancelled', 'reschedule', 'unresolved');
|
|
54
|
+
|
|
55
|
+
-- CreateEnum
|
|
56
|
+
CREATE TYPE "BillingEventType" AS ENUM ('call_charge', 'subscription', 'top_up', 'refund');
|
|
57
|
+
|
|
58
|
+
-- CreateEnum
|
|
59
|
+
CREATE TYPE "PaymentType" AS ENUM ('subscription', 'top_up');
|
|
60
|
+
|
|
61
|
+
-- CreateEnum
|
|
62
|
+
CREATE TYPE "PaymentMethod" AS ENUM ('cash', 'bank_transfer', 'other');
|
|
63
|
+
|
|
64
|
+
-- CreateEnum
|
|
65
|
+
CREATE TYPE "AlertType" AS ENUM ('usage_75', 'usage_90', 'usage_100', 'period_expiring');
|
|
66
|
+
|
|
67
|
+
-- CreateEnum
|
|
68
|
+
CREATE TYPE "AlertService" AS ENUM ('inbound_minutes', 'inbound_calls', 'wa_chats', 'billing_period');
|
|
69
|
+
|
|
70
|
+
-- CreateEnum
|
|
71
|
+
CREATE TYPE "ChatChannel" AS ENUM ('whatsapp', 'instagram');
|
|
72
|
+
|
|
73
|
+
-- CreateEnum
|
|
74
|
+
CREATE TYPE "PhoneNumberPurpose" AS ENUM ('whatsapp', 'inbound_call', 'outbound_call');
|
|
75
|
+
|
|
76
|
+
-- CreateEnum
|
|
77
|
+
CREATE TYPE "PhoneNumberProvider" AS ENUM ('meta_business', 'elevenlabs');
|
|
78
|
+
|
|
79
|
+
-- CreateEnum
|
|
80
|
+
CREATE TYPE "MigrationStatus" AS ENUM ('success', 'failed');
|
|
81
|
+
|
|
82
|
+
-- CreateEnum
|
|
83
|
+
CREATE TYPE "NotificationDeliveryStatus" AS ENUM ('pending', 'sending', 'sent', 'failed');
|
|
84
|
+
|
|
85
|
+
-- CreateEnum
|
|
86
|
+
CREATE TYPE "TranscriptionProcessingStatus" AS ENUM ('pending', 'summarizing', 'summarized', 'notified', 'failed');
|
|
87
|
+
|
|
88
|
+
-- CreateEnum
|
|
89
|
+
CREATE TYPE "AvailabilityBlockType" AS ENUM ('holiday', 'leave', 'break_time', 'other');
|
|
90
|
+
|
|
91
|
+
-- CreateEnum
|
|
92
|
+
CREATE TYPE "TreatmentPlanStatus" AS ENUM ('active', 'completed', 'cancelled');
|
|
93
|
+
|
|
94
|
+
-- CreateEnum
|
|
95
|
+
CREATE TYPE "TreatmentPlanItemStatus" AS ENUM ('planned', 'scheduled', 'in_progress', 'completed', 'cancelled');
|
|
96
|
+
|
|
97
|
+
-- CreateTable
|
|
98
|
+
CREATE TABLE "tenants" (
|
|
99
|
+
"tenant_id" TEXT NOT NULL,
|
|
100
|
+
"tenant_name" TEXT NOT NULL,
|
|
101
|
+
"tenant_plan_id" TEXT,
|
|
102
|
+
"tenant_enabled_features" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
103
|
+
"tenant_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
104
|
+
"tenant_deleted_at" TIMESTAMP(3),
|
|
105
|
+
"tenant_kvkk_consent" BOOLEAN NOT NULL DEFAULT false,
|
|
106
|
+
"tenant_max_clinics" INTEGER NOT NULL DEFAULT 1,
|
|
107
|
+
"tenant_max_users" INTEGER NOT NULL DEFAULT 5,
|
|
108
|
+
"tenant_max_doctors" INTEGER NOT NULL DEFAULT 2,
|
|
109
|
+
"tenant_max_patients" INTEGER NOT NULL DEFAULT 500,
|
|
110
|
+
"tenant_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
111
|
+
"tenant_updated_at" TIMESTAMP(3) NOT NULL,
|
|
112
|
+
|
|
113
|
+
CONSTRAINT "tenants_pkey" PRIMARY KEY ("tenant_id")
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
-- CreateTable
|
|
117
|
+
CREATE TABLE "clinics" (
|
|
118
|
+
"clinic_id" TEXT NOT NULL,
|
|
119
|
+
"clinic_tenant_id" TEXT NOT NULL,
|
|
120
|
+
"clinic_name" TEXT NOT NULL,
|
|
121
|
+
"clinic_slug" TEXT NOT NULL,
|
|
122
|
+
"clinic_address" TEXT NOT NULL DEFAULT '',
|
|
123
|
+
"clinic_phone" TEXT NOT NULL DEFAULT '',
|
|
124
|
+
"clinic_email" TEXT NOT NULL DEFAULT '',
|
|
125
|
+
"clinic_timezone" TEXT NOT NULL DEFAULT 'Europe/Istanbul',
|
|
126
|
+
"clinic_is_default" BOOLEAN NOT NULL DEFAULT false,
|
|
127
|
+
"clinic_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
128
|
+
"clinic_language" TEXT NOT NULL DEFAULT 'tr',
|
|
129
|
+
"clinic_ai_provider" TEXT NOT NULL DEFAULT 'openai',
|
|
130
|
+
"clinic_ai_model" TEXT NOT NULL DEFAULT '',
|
|
131
|
+
"clinic_grace_period_seconds" INTEGER NOT NULL DEFAULT 180,
|
|
132
|
+
"clinic_operator_phone" TEXT,
|
|
133
|
+
"clinic_operator_prefix" TEXT NOT NULL DEFAULT 'R',
|
|
134
|
+
"clinic_operator_timeout_hours" INTEGER NOT NULL DEFAULT 24,
|
|
135
|
+
"clinic_ai_shift_enabled" BOOLEAN NOT NULL DEFAULT false,
|
|
136
|
+
"clinic_ai_shift_schedule" JSONB NOT NULL DEFAULT '[]',
|
|
137
|
+
"clinic_blacklisted_numbers" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
138
|
+
"clinic_fixed_first_message" TEXT,
|
|
139
|
+
"clinic_sms_enabled" BOOLEAN NOT NULL DEFAULT false,
|
|
140
|
+
"clinic_sms_phones" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
141
|
+
"clinic_notification_phones" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
142
|
+
"clinic_message_retention_days" INTEGER NOT NULL DEFAULT 7,
|
|
143
|
+
"clinic_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
144
|
+
"clinic_updated_at" TIMESTAMP(3) NOT NULL,
|
|
145
|
+
|
|
146
|
+
CONSTRAINT "clinics_pkey" PRIMARY KEY ("clinic_id")
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
-- CreateTable
|
|
150
|
+
CREATE TABLE "clinic_calendar_connections" (
|
|
151
|
+
"calcn_id" TEXT NOT NULL,
|
|
152
|
+
"calcn_clinic_id" TEXT NOT NULL,
|
|
153
|
+
"calcn_google_email" TEXT,
|
|
154
|
+
"calcn_encrypted_refresh_token" TEXT,
|
|
155
|
+
"calcn_calendar_id" TEXT,
|
|
156
|
+
"calcn_calendar_name" TEXT,
|
|
157
|
+
"calcn_appointment_duration" INTEGER NOT NULL DEFAULT 30,
|
|
158
|
+
"calcn_working_hours" JSONB NOT NULL DEFAULT '[]',
|
|
159
|
+
"calcn_blocked_dates" JSONB NOT NULL DEFAULT '[]',
|
|
160
|
+
"calcn_connected_at" TIMESTAMP(3),
|
|
161
|
+
"calcn_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
162
|
+
"calcn_updated_at" TIMESTAMP(3) NOT NULL,
|
|
163
|
+
|
|
164
|
+
CONSTRAINT "clinic_calendar_connections_pkey" PRIMARY KEY ("calcn_id")
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
-- CreateTable
|
|
168
|
+
CREATE TABLE "clinic_meta_connections" (
|
|
169
|
+
"meta_id" TEXT NOT NULL,
|
|
170
|
+
"meta_clinic_id" TEXT NOT NULL,
|
|
171
|
+
"meta_type" TEXT NOT NULL,
|
|
172
|
+
"meta_label" TEXT NOT NULL DEFAULT '',
|
|
173
|
+
"meta_waba_id" TEXT,
|
|
174
|
+
"meta_phone_number_id" TEXT,
|
|
175
|
+
"meta_display_phone" TEXT,
|
|
176
|
+
"meta_instagram_page_id" TEXT,
|
|
177
|
+
"meta_facebook_page_id" TEXT,
|
|
178
|
+
"meta_encrypted_access_token" TEXT,
|
|
179
|
+
"meta_token_expires_at" TIMESTAMP(3),
|
|
180
|
+
"meta_token_refreshed_at" TIMESTAMP(3),
|
|
181
|
+
"meta_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
182
|
+
"meta_connected_at" TIMESTAMP(3),
|
|
183
|
+
"meta_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
184
|
+
"meta_updated_at" TIMESTAMP(3) NOT NULL,
|
|
185
|
+
|
|
186
|
+
CONSTRAINT "clinic_meta_connections_pkey" PRIMARY KEY ("meta_id")
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
-- CreateTable
|
|
190
|
+
CREATE TABLE "phone_numbers" (
|
|
191
|
+
"phone_id" TEXT NOT NULL,
|
|
192
|
+
"phone_tenant_id" TEXT NOT NULL,
|
|
193
|
+
"phone_clinic_id" TEXT,
|
|
194
|
+
"phone_number" TEXT NOT NULL,
|
|
195
|
+
"phone_label" TEXT NOT NULL DEFAULT '',
|
|
196
|
+
"phone_purpose" "PhoneNumberPurpose" NOT NULL,
|
|
197
|
+
"phone_provider" "PhoneNumberProvider" NOT NULL,
|
|
198
|
+
"phone_external_account_id" TEXT,
|
|
199
|
+
"phone_elevenlabs_phone_id" TEXT,
|
|
200
|
+
"phone_elevenlabs_agent_id" TEXT,
|
|
201
|
+
"phone_agent_id" TEXT,
|
|
202
|
+
"phone_wa_connected" BOOLEAN NOT NULL DEFAULT false,
|
|
203
|
+
"phone_wa_connected_at" TIMESTAMP(3),
|
|
204
|
+
"phone_wa_bridge_provider" TEXT,
|
|
205
|
+
"phone_schedule_enabled" BOOLEAN NOT NULL DEFAULT false,
|
|
206
|
+
"phone_schedule_mode" TEXT NOT NULL DEFAULT 'active_hours',
|
|
207
|
+
"phone_schedule" JSONB NOT NULL DEFAULT '[]',
|
|
208
|
+
"phone_agent_assigned" BOOLEAN NOT NULL DEFAULT false,
|
|
209
|
+
"phone_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
210
|
+
"phone_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
211
|
+
"phone_updated_at" TIMESTAMP(3) NOT NULL,
|
|
212
|
+
|
|
213
|
+
CONSTRAINT "phone_numbers_pkey" PRIMARY KEY ("phone_id")
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
-- CreateTable
|
|
217
|
+
CREATE TABLE "users" (
|
|
218
|
+
"user_id" TEXT NOT NULL,
|
|
219
|
+
"user_tenant_id" TEXT,
|
|
220
|
+
"user_email" TEXT NOT NULL,
|
|
221
|
+
"user_password_hash" TEXT NOT NULL,
|
|
222
|
+
"user_role" "UserRole" NOT NULL DEFAULT 'receptionist',
|
|
223
|
+
"user_first_name" TEXT NOT NULL,
|
|
224
|
+
"user_last_name" TEXT NOT NULL,
|
|
225
|
+
"user_phone" TEXT,
|
|
226
|
+
"user_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
227
|
+
"user_custom_permissions" JSONB NOT NULL DEFAULT '[]',
|
|
228
|
+
"user_last_login_at" TIMESTAMP(3),
|
|
229
|
+
"user_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
230
|
+
"user_updated_at" TIMESTAMP(3) NOT NULL,
|
|
231
|
+
|
|
232
|
+
CONSTRAINT "users_pkey" PRIMARY KEY ("user_id")
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
-- CreateTable
|
|
236
|
+
CREATE TABLE "user_clinic_assignments" (
|
|
237
|
+
"assign_id" TEXT NOT NULL,
|
|
238
|
+
"assign_user_id" TEXT NOT NULL,
|
|
239
|
+
"assign_clinic_id" TEXT NOT NULL,
|
|
240
|
+
"assign_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
241
|
+
|
|
242
|
+
CONSTRAINT "user_clinic_assignments_pkey" PRIMARY KEY ("assign_id")
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
-- CreateTable
|
|
246
|
+
CREATE TABLE "refresh_tokens" (
|
|
247
|
+
"token_id" TEXT NOT NULL,
|
|
248
|
+
"token_user_id" TEXT NOT NULL,
|
|
249
|
+
"token_value" TEXT NOT NULL,
|
|
250
|
+
"token_expires_at" TIMESTAMP(3) NOT NULL,
|
|
251
|
+
"token_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
252
|
+
|
|
253
|
+
CONSTRAINT "refresh_tokens_pkey" PRIMARY KEY ("token_id")
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
-- CreateTable
|
|
257
|
+
CREATE TABLE "plans" (
|
|
258
|
+
"plan_id" TEXT NOT NULL,
|
|
259
|
+
"plan_name" TEXT NOT NULL,
|
|
260
|
+
"plan_slug" TEXT NOT NULL,
|
|
261
|
+
"plan_price" DECIMAL(65,30) NOT NULL,
|
|
262
|
+
"plan_overage_rate" DECIMAL(65,30) NOT NULL,
|
|
263
|
+
"plan_included_inbound_minutes" INTEGER NOT NULL DEFAULT 0,
|
|
264
|
+
"plan_included_inbound_calls" INTEGER NOT NULL DEFAULT 0,
|
|
265
|
+
"plan_included_outbound_minutes" INTEGER NOT NULL DEFAULT 0,
|
|
266
|
+
"plan_included_outbound_calls" INTEGER NOT NULL DEFAULT 0,
|
|
267
|
+
"plan_included_wa_chats" INTEGER NOT NULL DEFAULT 0,
|
|
268
|
+
"plan_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
269
|
+
"plan_sort_order" INTEGER NOT NULL DEFAULT 0,
|
|
270
|
+
"plan_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
271
|
+
"plan_updated_at" TIMESTAMP(3) NOT NULL,
|
|
272
|
+
|
|
273
|
+
CONSTRAINT "plans_pkey" PRIMARY KEY ("plan_id")
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
-- CreateTable
|
|
277
|
+
CREATE TABLE "agents" (
|
|
278
|
+
"agent_id" TEXT NOT NULL,
|
|
279
|
+
"agent_tenant_id" TEXT NOT NULL,
|
|
280
|
+
"agent_clinic_id" TEXT,
|
|
281
|
+
"agent_elevenlabs_id" TEXT NOT NULL,
|
|
282
|
+
"agent_name" TEXT NOT NULL DEFAULT '',
|
|
283
|
+
"agent_description" TEXT NOT NULL DEFAULT '',
|
|
284
|
+
"agent_voice_id" TEXT NOT NULL DEFAULT '',
|
|
285
|
+
"agent_language" TEXT NOT NULL DEFAULT 'tr',
|
|
286
|
+
"agent_greeting" TEXT NOT NULL DEFAULT '',
|
|
287
|
+
"agent_system_prompt" TEXT NOT NULL DEFAULT '',
|
|
288
|
+
"agent_ai_provider" TEXT,
|
|
289
|
+
"agent_ai_model" TEXT,
|
|
290
|
+
"agent_post_call_strategy" "PostCallStrategy" NOT NULL DEFAULT 'summarize',
|
|
291
|
+
"agent_post_call_wa_notify" BOOLEAN NOT NULL DEFAULT true,
|
|
292
|
+
"agent_post_call_sms_notify" BOOLEAN NOT NULL DEFAULT false,
|
|
293
|
+
"agent_summary_prompt" TEXT NOT NULL DEFAULT '',
|
|
294
|
+
"agent_wa_message_template" TEXT NOT NULL DEFAULT '',
|
|
295
|
+
"agent_extra_config" JSONB NOT NULL DEFAULT '{}',
|
|
296
|
+
"agent_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
297
|
+
"agent_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
298
|
+
"agent_updated_at" TIMESTAMP(3) NOT NULL,
|
|
299
|
+
|
|
300
|
+
CONSTRAINT "agents_pkey" PRIMARY KEY ("agent_id")
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
-- CreateTable
|
|
304
|
+
CREATE TABLE "calls" (
|
|
305
|
+
"call_id" TEXT NOT NULL,
|
|
306
|
+
"call_tenant_id" TEXT NOT NULL,
|
|
307
|
+
"call_clinic_id" TEXT NOT NULL,
|
|
308
|
+
"call_patient_id" TEXT,
|
|
309
|
+
"call_agent_id" TEXT NOT NULL,
|
|
310
|
+
"call_campaign_id" TEXT,
|
|
311
|
+
"call_conversation_id" TEXT,
|
|
312
|
+
"call_direction" "CallDirection" NOT NULL,
|
|
313
|
+
"call_caller_number" TEXT NOT NULL,
|
|
314
|
+
"call_callee_number" TEXT NOT NULL,
|
|
315
|
+
"call_duration_seconds" INTEGER NOT NULL DEFAULT 0,
|
|
316
|
+
"call_start_time" TIMESTAMP(3),
|
|
317
|
+
"call_end_time" TIMESTAMP(3),
|
|
318
|
+
"call_termination_reason" TEXT,
|
|
319
|
+
"call_cost" DECIMAL(65,30),
|
|
320
|
+
"call_language" TEXT,
|
|
321
|
+
"call_elevenlabs_status" TEXT,
|
|
322
|
+
"call_status" "CallStatus" NOT NULL,
|
|
323
|
+
"call_sentiment" "Sentiment",
|
|
324
|
+
"call_categories" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
325
|
+
"call_wa_notification_sent" BOOLEAN NOT NULL DEFAULT false,
|
|
326
|
+
"call_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
327
|
+
"call_updated_at" TIMESTAMP(3) NOT NULL,
|
|
328
|
+
|
|
329
|
+
CONSTRAINT "calls_pkey" PRIMARY KEY ("call_id")
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
-- CreateTable
|
|
333
|
+
CREATE TABLE "call_details" (
|
|
334
|
+
"detail_id" TEXT NOT NULL,
|
|
335
|
+
"detail_call_id" TEXT NOT NULL,
|
|
336
|
+
"detail_transcript" TEXT NOT NULL DEFAULT '',
|
|
337
|
+
"detail_llm_summary" TEXT,
|
|
338
|
+
"detail_extracted_data" JSONB,
|
|
339
|
+
"detail_recording_url" TEXT,
|
|
340
|
+
"detail_recording_key" TEXT,
|
|
341
|
+
"detail_analysis" JSONB,
|
|
342
|
+
"detail_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
343
|
+
"detail_updated_at" TIMESTAMP(3) NOT NULL,
|
|
344
|
+
|
|
345
|
+
CONSTRAINT "call_details_pkey" PRIMARY KEY ("detail_id")
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
-- CreateTable
|
|
349
|
+
CREATE TABLE "leads" (
|
|
350
|
+
"lead_id" TEXT NOT NULL,
|
|
351
|
+
"lead_tenant_id" TEXT NOT NULL,
|
|
352
|
+
"lead_clinic_id" TEXT NOT NULL,
|
|
353
|
+
"lead_patient_id" TEXT,
|
|
354
|
+
"lead_call_id" TEXT,
|
|
355
|
+
"lead_session_id" TEXT,
|
|
356
|
+
"lead_chat_id" TEXT,
|
|
357
|
+
"lead_name" TEXT,
|
|
358
|
+
"lead_phone" TEXT NOT NULL,
|
|
359
|
+
"lead_service_of_interest" TEXT,
|
|
360
|
+
"lead_status" "LeadStatus" NOT NULL DEFAULT 'new_lead',
|
|
361
|
+
"lead_categories" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
362
|
+
"lead_summary" TEXT,
|
|
363
|
+
"lead_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
364
|
+
"lead_updated_at" TIMESTAMP(3) NOT NULL,
|
|
365
|
+
|
|
366
|
+
CONSTRAINT "leads_pkey" PRIMARY KEY ("lead_id")
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
-- CreateTable
|
|
370
|
+
CREATE TABLE "outbound_campaigns" (
|
|
371
|
+
"campaign_id" TEXT NOT NULL,
|
|
372
|
+
"campaign_tenant_id" TEXT NOT NULL,
|
|
373
|
+
"campaign_clinic_id" TEXT NOT NULL,
|
|
374
|
+
"campaign_agent_id" TEXT NOT NULL,
|
|
375
|
+
"campaign_name" TEXT NOT NULL,
|
|
376
|
+
"campaign_description" TEXT NOT NULL DEFAULT '',
|
|
377
|
+
"campaign_status" "OutboundCampaignStatus" NOT NULL DEFAULT 'draft',
|
|
378
|
+
"campaign_agent_config" JSONB NOT NULL DEFAULT '{}',
|
|
379
|
+
"campaign_schedule" JSONB NOT NULL,
|
|
380
|
+
"campaign_phone_id" TEXT,
|
|
381
|
+
"campaign_stats" JSONB NOT NULL DEFAULT '{}',
|
|
382
|
+
"campaign_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
383
|
+
"campaign_updated_at" TIMESTAMP(3) NOT NULL,
|
|
384
|
+
|
|
385
|
+
CONSTRAINT "outbound_campaigns_pkey" PRIMARY KEY ("campaign_id")
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
-- CreateTable
|
|
389
|
+
CREATE TABLE "outbound_campaign_entries" (
|
|
390
|
+
"centry_id" TEXT NOT NULL,
|
|
391
|
+
"centry_campaign_id" TEXT NOT NULL,
|
|
392
|
+
"centry_phone" TEXT NOT NULL,
|
|
393
|
+
"centry_contact_name" TEXT NOT NULL DEFAULT '',
|
|
394
|
+
"centry_custom_data" JSONB NOT NULL DEFAULT '{}',
|
|
395
|
+
"centry_status" "CampaignEntryStatus" NOT NULL DEFAULT 'pending',
|
|
396
|
+
"centry_attempts" INTEGER NOT NULL DEFAULT 0,
|
|
397
|
+
"centry_max_attempts" INTEGER NOT NULL DEFAULT 3,
|
|
398
|
+
"centry_last_attempt_at" TIMESTAMP(3),
|
|
399
|
+
"centry_conversation_id" TEXT,
|
|
400
|
+
"centry_call_id" TEXT,
|
|
401
|
+
"centry_call_duration_secs" INTEGER NOT NULL DEFAULT 0,
|
|
402
|
+
"centry_extracted_data" JSONB,
|
|
403
|
+
"centry_summary" TEXT,
|
|
404
|
+
"centry_called_at" TIMESTAMP(3),
|
|
405
|
+
"centry_completed_at" TIMESTAMP(3),
|
|
406
|
+
"centry_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
407
|
+
"centry_updated_at" TIMESTAMP(3) NOT NULL,
|
|
408
|
+
|
|
409
|
+
CONSTRAINT "outbound_campaign_entries_pkey" PRIMARY KEY ("centry_id")
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
-- CreateTable
|
|
413
|
+
CREATE TABLE "whatsapp_chats" (
|
|
414
|
+
"chat_id" TEXT NOT NULL,
|
|
415
|
+
"chat_tenant_id" TEXT NOT NULL,
|
|
416
|
+
"chat_clinic_id" TEXT NOT NULL,
|
|
417
|
+
"chat_patient_id" TEXT,
|
|
418
|
+
"chat_channel" "ChatChannel" NOT NULL DEFAULT 'whatsapp',
|
|
419
|
+
"chat_external_id" TEXT NOT NULL,
|
|
420
|
+
"chat_phone_id" TEXT,
|
|
421
|
+
"chat_contact_name" TEXT NOT NULL DEFAULT 'Bilinmiyor',
|
|
422
|
+
"chat_contact_phone" TEXT NOT NULL DEFAULT '',
|
|
423
|
+
"chat_is_closed" BOOLEAN NOT NULL DEFAULT false,
|
|
424
|
+
"chat_active_session_id" TEXT,
|
|
425
|
+
"chat_last_message_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
426
|
+
"chat_last_message_preview" TEXT NOT NULL DEFAULT '',
|
|
427
|
+
"chat_message_count" INTEGER NOT NULL DEFAULT 0,
|
|
428
|
+
"chat_assigned_to_id" TEXT,
|
|
429
|
+
"chat_assigned_by_id" TEXT,
|
|
430
|
+
"chat_assigned_at" TIMESTAMP(3),
|
|
431
|
+
"chat_deleted_at" TIMESTAMP(3),
|
|
432
|
+
"chat_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
433
|
+
"chat_updated_at" TIMESTAMP(3) NOT NULL,
|
|
434
|
+
|
|
435
|
+
CONSTRAINT "whatsapp_chats_pkey" PRIMARY KEY ("chat_id")
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
-- CreateTable
|
|
439
|
+
CREATE TABLE "whatsapp_sessions" (
|
|
440
|
+
"session_id" TEXT NOT NULL,
|
|
441
|
+
"session_chat_id" TEXT NOT NULL,
|
|
442
|
+
"session_tenant_id" TEXT NOT NULL,
|
|
443
|
+
"session_clinic_id" TEXT NOT NULL,
|
|
444
|
+
"session_status" "SessionStatus" NOT NULL DEFAULT 'waiting',
|
|
445
|
+
"session_resolved_by" "SessionResolvedBy",
|
|
446
|
+
"session_started_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
447
|
+
"session_resolved_at" TIMESTAMP(3),
|
|
448
|
+
"session_grace_deadline" TIMESTAMP(3),
|
|
449
|
+
"session_taken_over_by_id" TEXT,
|
|
450
|
+
"session_taken_over_at" TIMESTAMP(3),
|
|
451
|
+
"session_el_conversation_id" TEXT,
|
|
452
|
+
"session_el_prev_conversation_ids" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
453
|
+
"session_el_conversation_created" TIMESTAMP(3),
|
|
454
|
+
"session_el_last_interaction" TIMESTAMP(3),
|
|
455
|
+
"session_el_cost" DECIMAL(65,30),
|
|
456
|
+
"session_ref_code" TEXT,
|
|
457
|
+
"session_awaiting_operator" BOOLEAN NOT NULL DEFAULT false,
|
|
458
|
+
"session_message_count" INTEGER NOT NULL DEFAULT 0,
|
|
459
|
+
"session_llm_summary" TEXT,
|
|
460
|
+
"session_sentiment" "Sentiment",
|
|
461
|
+
"session_categories" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
462
|
+
"session_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
463
|
+
"session_updated_at" TIMESTAMP(3) NOT NULL,
|
|
464
|
+
|
|
465
|
+
CONSTRAINT "whatsapp_sessions_pkey" PRIMARY KEY ("session_id")
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
-- CreateTable
|
|
469
|
+
CREATE TABLE "whatsapp_messages" (
|
|
470
|
+
"msg_id" TEXT NOT NULL,
|
|
471
|
+
"msg_chat_id" TEXT NOT NULL,
|
|
472
|
+
"msg_session_id" TEXT,
|
|
473
|
+
"msg_tenant_id" TEXT NOT NULL,
|
|
474
|
+
"msg_external_id" TEXT,
|
|
475
|
+
"msg_sender" "MessageSender" NOT NULL,
|
|
476
|
+
"msg_sender_name" TEXT NOT NULL DEFAULT '',
|
|
477
|
+
"msg_sender_user_id" TEXT,
|
|
478
|
+
"msg_text" TEXT NOT NULL,
|
|
479
|
+
"msg_media_type" TEXT,
|
|
480
|
+
"msg_media_key" TEXT,
|
|
481
|
+
"msg_media_url" TEXT,
|
|
482
|
+
"msg_media_mime" TEXT,
|
|
483
|
+
"msg_media_filename" TEXT,
|
|
484
|
+
"msg_ad_context" JSONB,
|
|
485
|
+
"msg_metadata" JSONB,
|
|
486
|
+
"msg_sent_via_bridge" BOOLEAN NOT NULL DEFAULT false,
|
|
487
|
+
"msg_quoted_text" TEXT,
|
|
488
|
+
"msg_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
489
|
+
|
|
490
|
+
CONSTRAINT "whatsapp_messages_pkey" PRIMARY KEY ("msg_id")
|
|
491
|
+
);
|
|
492
|
+
|
|
493
|
+
-- CreateTable
|
|
494
|
+
CREATE TABLE "operator_requests" (
|
|
495
|
+
"opreq_id" TEXT NOT NULL,
|
|
496
|
+
"opreq_tenant_id" TEXT NOT NULL,
|
|
497
|
+
"opreq_clinic_id" TEXT NOT NULL,
|
|
498
|
+
"opreq_session_id" TEXT NOT NULL,
|
|
499
|
+
"opreq_chat_id" TEXT NOT NULL,
|
|
500
|
+
"opreq_ref_code" TEXT NOT NULL,
|
|
501
|
+
"opreq_request_type" TEXT NOT NULL DEFAULT 'general',
|
|
502
|
+
"opreq_request_message" TEXT,
|
|
503
|
+
"opreq_status" "OperatorRequestStatus" NOT NULL DEFAULT 'pending',
|
|
504
|
+
"opreq_forwarded_media_types" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
505
|
+
"opreq_forwarded_count" INTEGER NOT NULL DEFAULT 0,
|
|
506
|
+
"opreq_failed_count" INTEGER NOT NULL DEFAULT 0,
|
|
507
|
+
"opreq_forwarded_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
508
|
+
"opreq_forwarded_to_phone" TEXT NOT NULL,
|
|
509
|
+
"opreq_operator_response" TEXT,
|
|
510
|
+
"opreq_response_media_type" TEXT,
|
|
511
|
+
"opreq_response_message_id" TEXT,
|
|
512
|
+
"opreq_responded_at" TIMESTAMP(3),
|
|
513
|
+
"opreq_patient_message_ids" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
514
|
+
"opreq_expires_at" TIMESTAMP(3) NOT NULL,
|
|
515
|
+
"opreq_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
516
|
+
"opreq_updated_at" TIMESTAMP(3) NOT NULL,
|
|
517
|
+
|
|
518
|
+
CONSTRAINT "operator_requests_pkey" PRIMARY KEY ("opreq_id")
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
-- CreateTable
|
|
522
|
+
CREATE TABLE "appointments" (
|
|
523
|
+
"appt_id" TEXT NOT NULL,
|
|
524
|
+
"appt_tenant_id" TEXT NOT NULL,
|
|
525
|
+
"appt_clinic_id" TEXT NOT NULL,
|
|
526
|
+
"appt_patient_id" TEXT NOT NULL,
|
|
527
|
+
"appt_doctor_id" TEXT,
|
|
528
|
+
"appt_treatment_id" TEXT,
|
|
529
|
+
"appt_treatment_plan_item_id" TEXT,
|
|
530
|
+
"appt_chat_id" TEXT,
|
|
531
|
+
"appt_session_id" TEXT,
|
|
532
|
+
"appt_google_event_id" TEXT,
|
|
533
|
+
"appt_patient_name" TEXT NOT NULL,
|
|
534
|
+
"appt_patient_phone" TEXT NOT NULL,
|
|
535
|
+
"appt_start_time" TIMESTAMP(3) NOT NULL,
|
|
536
|
+
"appt_end_time" TIMESTAMP(3) NOT NULL,
|
|
537
|
+
"appt_duration_minutes" INTEGER NOT NULL,
|
|
538
|
+
"appt_type" "AppointmentType" NOT NULL DEFAULT 'appointment',
|
|
539
|
+
"appt_status" "AppointmentStatus" NOT NULL DEFAULT 'scheduled',
|
|
540
|
+
"appt_source" "AppointmentSource" NOT NULL DEFAULT 'dashboard',
|
|
541
|
+
"appt_notes" TEXT NOT NULL DEFAULT '',
|
|
542
|
+
"appt_conversation_id" TEXT,
|
|
543
|
+
"appt_reminder_sent_24h" BOOLEAN NOT NULL DEFAULT false,
|
|
544
|
+
"appt_reminder_sent_2h" BOOLEAN NOT NULL DEFAULT false,
|
|
545
|
+
"appt_cancelled_at" TIMESTAMP(3),
|
|
546
|
+
"appt_completed_at" TIMESTAMP(3),
|
|
547
|
+
"appt_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
548
|
+
"appt_updated_at" TIMESTAMP(3) NOT NULL,
|
|
549
|
+
|
|
550
|
+
CONSTRAINT "appointments_pkey" PRIMARY KEY ("appt_id")
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
-- CreateTable
|
|
554
|
+
CREATE TABLE "appointment_validation_batches" (
|
|
555
|
+
"batch_id" TEXT NOT NULL,
|
|
556
|
+
"batch_tenant_id" TEXT NOT NULL,
|
|
557
|
+
"batch_clinic_id" TEXT NOT NULL,
|
|
558
|
+
"batch_created_by_id" TEXT NOT NULL,
|
|
559
|
+
"batch_name" TEXT NOT NULL,
|
|
560
|
+
"batch_status" "BatchStatus" NOT NULL DEFAULT 'draft',
|
|
561
|
+
"batch_el_batch_id" TEXT,
|
|
562
|
+
"batch_agent_id" TEXT,
|
|
563
|
+
"batch_phone_id" TEXT,
|
|
564
|
+
"batch_column_mapping" JSONB NOT NULL,
|
|
565
|
+
"batch_call_schedule" JSONB NOT NULL,
|
|
566
|
+
"batch_stats" JSONB NOT NULL DEFAULT '{}',
|
|
567
|
+
"batch_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
568
|
+
"batch_updated_at" TIMESTAMP(3) NOT NULL,
|
|
569
|
+
|
|
570
|
+
CONSTRAINT "appointment_validation_batches_pkey" PRIMARY KEY ("batch_id")
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
-- CreateTable
|
|
574
|
+
CREATE TABLE "appointment_validation_entries" (
|
|
575
|
+
"bentry_id" TEXT NOT NULL,
|
|
576
|
+
"bentry_batch_id" TEXT NOT NULL,
|
|
577
|
+
"bentry_appointment_id" TEXT,
|
|
578
|
+
"bentry_row_index" INTEGER NOT NULL,
|
|
579
|
+
"bentry_external_id" TEXT NOT NULL DEFAULT '',
|
|
580
|
+
"bentry_patient_name" TEXT NOT NULL,
|
|
581
|
+
"bentry_patient_phone" TEXT NOT NULL,
|
|
582
|
+
"bentry_appointment_date" TEXT NOT NULL,
|
|
583
|
+
"bentry_appointment_time" TEXT NOT NULL,
|
|
584
|
+
"bentry_doctor_name" TEXT NOT NULL DEFAULT '',
|
|
585
|
+
"bentry_department" TEXT NOT NULL DEFAULT '',
|
|
586
|
+
"bentry_notes" TEXT NOT NULL DEFAULT '',
|
|
587
|
+
"bentry_raw_data" JSONB NOT NULL DEFAULT '{}',
|
|
588
|
+
"bentry_call_status" "EntryCallStatus" NOT NULL DEFAULT 'pending',
|
|
589
|
+
"bentry_attempts" INTEGER NOT NULL DEFAULT 0,
|
|
590
|
+
"bentry_conversation_id" TEXT,
|
|
591
|
+
"bentry_validation_result" "ValidationResult",
|
|
592
|
+
"bentry_reschedule_request" TEXT,
|
|
593
|
+
"bentry_patient_message" TEXT,
|
|
594
|
+
"bentry_call_duration_secs" INTEGER NOT NULL DEFAULT 0,
|
|
595
|
+
"bentry_called_at" TIMESTAMP(3),
|
|
596
|
+
"bentry_result_at" TIMESTAMP(3),
|
|
597
|
+
"bentry_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
598
|
+
"bentry_updated_at" TIMESTAMP(3) NOT NULL,
|
|
599
|
+
|
|
600
|
+
CONSTRAINT "appointment_validation_entries_pkey" PRIMARY KEY ("bentry_id")
|
|
601
|
+
);
|
|
602
|
+
|
|
603
|
+
-- CreateTable
|
|
604
|
+
CREATE TABLE "billing_events" (
|
|
605
|
+
"billing_id" TEXT NOT NULL,
|
|
606
|
+
"billing_tenant_id" TEXT NOT NULL,
|
|
607
|
+
"billing_clinic_id" TEXT,
|
|
608
|
+
"billing_type" "BillingEventType" NOT NULL,
|
|
609
|
+
"billing_amount" DECIMAL(65,30) NOT NULL,
|
|
610
|
+
"billing_currency" TEXT NOT NULL DEFAULT 'TRY',
|
|
611
|
+
"billing_call_id" TEXT,
|
|
612
|
+
"billing_description" TEXT NOT NULL DEFAULT '',
|
|
613
|
+
"billing_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
614
|
+
|
|
615
|
+
CONSTRAINT "billing_events_pkey" PRIMARY KEY ("billing_id")
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
-- CreateTable
|
|
619
|
+
CREATE TABLE "payments" (
|
|
620
|
+
"payment_id" TEXT NOT NULL,
|
|
621
|
+
"payment_tenant_id" TEXT NOT NULL,
|
|
622
|
+
"payment_type" "PaymentType" NOT NULL DEFAULT 'subscription',
|
|
623
|
+
"payment_plan_slug" TEXT NOT NULL,
|
|
624
|
+
"payment_plan_name" TEXT NOT NULL,
|
|
625
|
+
"payment_amount" DECIMAL(65,30) NOT NULL,
|
|
626
|
+
"payment_extra_minutes" INTEGER NOT NULL DEFAULT 0,
|
|
627
|
+
"payment_period_start" TIMESTAMP(3) NOT NULL,
|
|
628
|
+
"payment_period_end" TIMESTAMP(3) NOT NULL,
|
|
629
|
+
"payment_method" "PaymentMethod" NOT NULL DEFAULT 'cash',
|
|
630
|
+
"payment_notes" TEXT NOT NULL DEFAULT '',
|
|
631
|
+
"payment_recorded_by_id" TEXT NOT NULL,
|
|
632
|
+
"payment_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
633
|
+
"payment_updated_at" TIMESTAMP(3) NOT NULL,
|
|
634
|
+
|
|
635
|
+
CONSTRAINT "payments_pkey" PRIMARY KEY ("payment_id")
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
-- CreateTable
|
|
639
|
+
CREATE TABLE "billing_period_snapshots" (
|
|
640
|
+
"snapshot_id" TEXT NOT NULL,
|
|
641
|
+
"snapshot_tenant_id" TEXT NOT NULL,
|
|
642
|
+
"snapshot_payment_id" TEXT NOT NULL,
|
|
643
|
+
"snapshot_plan_id" TEXT,
|
|
644
|
+
"snapshot_period_start" TIMESTAMP(3) NOT NULL,
|
|
645
|
+
"snapshot_period_end" TIMESTAMP(3) NOT NULL,
|
|
646
|
+
"snapshot_total_calls" INTEGER NOT NULL DEFAULT 0,
|
|
647
|
+
"snapshot_inbound_calls" INTEGER NOT NULL DEFAULT 0,
|
|
648
|
+
"snapshot_inbound_minutes" DECIMAL(65,30) NOT NULL DEFAULT 0,
|
|
649
|
+
"snapshot_outbound_calls" INTEGER NOT NULL DEFAULT 0,
|
|
650
|
+
"snapshot_outbound_minutes" DECIMAL(65,30) NOT NULL DEFAULT 0,
|
|
651
|
+
"snapshot_total_charges" DECIMAL(65,30) NOT NULL DEFAULT 0,
|
|
652
|
+
"snapshot_wa_billable_chats" INTEGER NOT NULL DEFAULT 0,
|
|
653
|
+
"snapshot_wa_total_sessions" INTEGER NOT NULL DEFAULT 0,
|
|
654
|
+
"snapshot_wa_total_messages" INTEGER NOT NULL DEFAULT 0,
|
|
655
|
+
"snapshot_wa_ai_messages" INTEGER NOT NULL DEFAULT 0,
|
|
656
|
+
"snapshot_wa_el_cost" DECIMAL(65,30) NOT NULL DEFAULT 0,
|
|
657
|
+
"snapshot_wa_stt_count" INTEGER NOT NULL DEFAULT 0,
|
|
658
|
+
"snapshot_wa_stt_seconds" DECIMAL(65,30) NOT NULL DEFAULT 0,
|
|
659
|
+
"snapshot_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
660
|
+
|
|
661
|
+
CONSTRAINT "billing_period_snapshots_pkey" PRIMARY KEY ("snapshot_id")
|
|
662
|
+
);
|
|
663
|
+
|
|
664
|
+
-- CreateTable
|
|
665
|
+
CREATE TABLE "billing_alerts" (
|
|
666
|
+
"alert_id" TEXT NOT NULL,
|
|
667
|
+
"alert_tenant_id" TEXT NOT NULL,
|
|
668
|
+
"alert_type" "AlertType" NOT NULL,
|
|
669
|
+
"alert_service" "AlertService" NOT NULL,
|
|
670
|
+
"alert_payment_id" TEXT NOT NULL,
|
|
671
|
+
"alert_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
672
|
+
|
|
673
|
+
CONSTRAINT "billing_alerts_pkey" PRIMARY KEY ("alert_id")
|
|
674
|
+
);
|
|
675
|
+
|
|
676
|
+
-- CreateTable
|
|
677
|
+
CREATE TABLE "stt_usages" (
|
|
678
|
+
"stt_id" TEXT NOT NULL,
|
|
679
|
+
"stt_tenant_id" TEXT NOT NULL,
|
|
680
|
+
"stt_clinic_id" TEXT,
|
|
681
|
+
"stt_chat_id" TEXT NOT NULL DEFAULT '',
|
|
682
|
+
"stt_message_id" TEXT NOT NULL DEFAULT '',
|
|
683
|
+
"stt_duration_seconds" DECIMAL(65,30) NOT NULL,
|
|
684
|
+
"stt_character_count" INTEGER NOT NULL,
|
|
685
|
+
"stt_language" TEXT NOT NULL DEFAULT 'tr',
|
|
686
|
+
"stt_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
687
|
+
|
|
688
|
+
CONSTRAINT "stt_usages_pkey" PRIMARY KEY ("stt_id")
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
-- CreateTable
|
|
692
|
+
CREATE TABLE "logs" (
|
|
693
|
+
"log_id" TEXT NOT NULL,
|
|
694
|
+
"log_level" TEXT NOT NULL,
|
|
695
|
+
"log_message" TEXT NOT NULL,
|
|
696
|
+
"log_service" TEXT NOT NULL DEFAULT 'api',
|
|
697
|
+
"log_meta" JSONB NOT NULL DEFAULT '{}',
|
|
698
|
+
"log_request_id" TEXT,
|
|
699
|
+
"log_tenant_id" TEXT,
|
|
700
|
+
"log_clinic_id" TEXT,
|
|
701
|
+
"log_user_id" TEXT,
|
|
702
|
+
"log_timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
703
|
+
|
|
704
|
+
CONSTRAINT "logs_pkey" PRIMARY KEY ("log_id")
|
|
705
|
+
);
|
|
706
|
+
|
|
707
|
+
-- CreateTable
|
|
708
|
+
CREATE TABLE "audit_logs" (
|
|
709
|
+
"audit_id" TEXT NOT NULL,
|
|
710
|
+
"audit_tenant_id" TEXT,
|
|
711
|
+
"audit_clinic_id" TEXT,
|
|
712
|
+
"audit_user_id" TEXT,
|
|
713
|
+
"audit_user_email" TEXT,
|
|
714
|
+
"audit_user_role" TEXT,
|
|
715
|
+
"audit_action" TEXT NOT NULL,
|
|
716
|
+
"audit_entity" TEXT NOT NULL,
|
|
717
|
+
"audit_entity_id" TEXT NOT NULL,
|
|
718
|
+
"audit_changes" JSONB,
|
|
719
|
+
"audit_metadata" JSONB,
|
|
720
|
+
"audit_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
721
|
+
|
|
722
|
+
CONSTRAINT "audit_logs_pkey" PRIMARY KEY ("audit_id")
|
|
723
|
+
);
|
|
724
|
+
|
|
725
|
+
-- CreateTable
|
|
726
|
+
CREATE TABLE "tool_execution_logs" (
|
|
727
|
+
"toollog_id" TEXT NOT NULL,
|
|
728
|
+
"toollog_tenant_id" TEXT NOT NULL,
|
|
729
|
+
"toollog_clinic_id" TEXT,
|
|
730
|
+
"toollog_tool_name" TEXT NOT NULL,
|
|
731
|
+
"toollog_channel" TEXT NOT NULL,
|
|
732
|
+
"toollog_patient_phone" TEXT NOT NULL DEFAULT '',
|
|
733
|
+
"toollog_conversation_id" TEXT,
|
|
734
|
+
"toollog_parameters" JSONB NOT NULL DEFAULT '{}',
|
|
735
|
+
"toollog_result" JSONB NOT NULL DEFAULT '{}',
|
|
736
|
+
"toollog_is_error" BOOLEAN NOT NULL DEFAULT false,
|
|
737
|
+
"toollog_duration_ms" INTEGER NOT NULL DEFAULT 0,
|
|
738
|
+
"toollog_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
739
|
+
|
|
740
|
+
CONSTRAINT "tool_execution_logs_pkey" PRIMARY KEY ("toollog_id")
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
-- CreateTable
|
|
744
|
+
CREATE TABLE "migrations" (
|
|
745
|
+
"migration_id" TEXT NOT NULL,
|
|
746
|
+
"migration_name" TEXT NOT NULL,
|
|
747
|
+
"migration_ran_at" TIMESTAMP(3) NOT NULL,
|
|
748
|
+
"migration_duration_ms" INTEGER NOT NULL,
|
|
749
|
+
"migration_status" "MigrationStatus" NOT NULL,
|
|
750
|
+
"migration_error" TEXT,
|
|
751
|
+
"migration_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
752
|
+
"migration_updated_at" TIMESTAMP(3) NOT NULL,
|
|
753
|
+
|
|
754
|
+
CONSTRAINT "migrations_pkey" PRIMARY KEY ("migration_id")
|
|
755
|
+
);
|
|
756
|
+
|
|
757
|
+
-- CreateTable
|
|
758
|
+
CREATE TABLE "transcriptions" (
|
|
759
|
+
"tx_id" TEXT NOT NULL,
|
|
760
|
+
"tx_conversation_id" TEXT NOT NULL,
|
|
761
|
+
"tx_agent_id" TEXT NOT NULL,
|
|
762
|
+
"tx_agent_name" TEXT,
|
|
763
|
+
"tx_user_id" TEXT,
|
|
764
|
+
"tx_event_type" TEXT NOT NULL DEFAULT 'post_call_transcription',
|
|
765
|
+
"tx_event_timestamp" INTEGER,
|
|
766
|
+
"tx_status" TEXT NOT NULL DEFAULT 'done',
|
|
767
|
+
"tx_transcript" JSONB NOT NULL DEFAULT '[]',
|
|
768
|
+
"tx_metadata" JSONB,
|
|
769
|
+
"tx_analysis" JSONB,
|
|
770
|
+
"tx_processing_status" "TranscriptionProcessingStatus" NOT NULL DEFAULT 'pending',
|
|
771
|
+
"tx_processing_error" TEXT,
|
|
772
|
+
"tx_raw_payload" JSONB,
|
|
773
|
+
"tx_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
774
|
+
"tx_updated_at" TIMESTAMP(3) NOT NULL,
|
|
775
|
+
|
|
776
|
+
CONSTRAINT "transcriptions_pkey" PRIMARY KEY ("tx_id")
|
|
777
|
+
);
|
|
778
|
+
|
|
779
|
+
-- CreateTable
|
|
780
|
+
CREATE TABLE "summaries" (
|
|
781
|
+
"summary_id" TEXT NOT NULL,
|
|
782
|
+
"summary_transcription_id" TEXT NOT NULL,
|
|
783
|
+
"summary_conversation_id" TEXT NOT NULL,
|
|
784
|
+
"summary_text" TEXT NOT NULL,
|
|
785
|
+
"summary_title" TEXT,
|
|
786
|
+
"summary_key_points" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
787
|
+
"summary_detected_intent" TEXT,
|
|
788
|
+
"summary_sentiment" "Sentiment",
|
|
789
|
+
"summary_ai_provider" TEXT NOT NULL,
|
|
790
|
+
"summary_ai_model" TEXT,
|
|
791
|
+
"summary_token_usage" JSONB,
|
|
792
|
+
"summary_notification_status" "NotificationDeliveryStatus" NOT NULL DEFAULT 'pending',
|
|
793
|
+
"summary_notified_recipients" JSONB NOT NULL DEFAULT '[]',
|
|
794
|
+
"summary_language" TEXT NOT NULL DEFAULT 'tr',
|
|
795
|
+
"summary_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
796
|
+
"summary_updated_at" TIMESTAMP(3) NOT NULL,
|
|
797
|
+
|
|
798
|
+
CONSTRAINT "summaries_pkey" PRIMARY KEY ("summary_id")
|
|
799
|
+
);
|
|
800
|
+
|
|
801
|
+
-- CreateTable
|
|
802
|
+
CREATE TABLE "patients" (
|
|
803
|
+
"patient_id" TEXT NOT NULL,
|
|
804
|
+
"patient_tenant_id" TEXT NOT NULL,
|
|
805
|
+
"patient_clinic_id" TEXT,
|
|
806
|
+
"patient_phone" TEXT NOT NULL,
|
|
807
|
+
"patient_email" TEXT,
|
|
808
|
+
"patient_first_name" TEXT NOT NULL DEFAULT '',
|
|
809
|
+
"patient_last_name" TEXT NOT NULL DEFAULT '',
|
|
810
|
+
"patient_display_name" TEXT NOT NULL DEFAULT '',
|
|
811
|
+
"patient_date_of_birth" TIMESTAMP(3),
|
|
812
|
+
"patient_gender" TEXT,
|
|
813
|
+
"patient_id_number" TEXT,
|
|
814
|
+
"patient_blood_type" TEXT,
|
|
815
|
+
"patient_preferred_language" TEXT NOT NULL DEFAULT 'tr',
|
|
816
|
+
"patient_source" TEXT,
|
|
817
|
+
"patient_source_detail" TEXT,
|
|
818
|
+
"patient_tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
|
|
819
|
+
"patient_ai_summary" TEXT NOT NULL DEFAULT '',
|
|
820
|
+
"patient_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
821
|
+
"patient_first_contact_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
822
|
+
"patient_last_contact_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
823
|
+
"patient_total_sessions" INTEGER NOT NULL DEFAULT 0,
|
|
824
|
+
"patient_total_appointments" INTEGER NOT NULL DEFAULT 0,
|
|
825
|
+
"patient_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
826
|
+
"patient_updated_at" TIMESTAMP(3) NOT NULL,
|
|
827
|
+
|
|
828
|
+
CONSTRAINT "patients_pkey" PRIMARY KEY ("patient_id")
|
|
829
|
+
);
|
|
830
|
+
|
|
831
|
+
-- CreateTable
|
|
832
|
+
CREATE TABLE "patient_medical_histories" (
|
|
833
|
+
"history_id" TEXT NOT NULL,
|
|
834
|
+
"history_patient_id" TEXT NOT NULL,
|
|
835
|
+
"history_allergies" TEXT NOT NULL DEFAULT '',
|
|
836
|
+
"history_chronic_conditions" TEXT NOT NULL DEFAULT '',
|
|
837
|
+
"history_current_medications" TEXT NOT NULL DEFAULT '',
|
|
838
|
+
"history_past_surgeries" TEXT NOT NULL DEFAULT '',
|
|
839
|
+
"history_pregnancy_status" TEXT,
|
|
840
|
+
"history_smoking" BOOLEAN,
|
|
841
|
+
"history_alcohol" BOOLEAN,
|
|
842
|
+
"history_notes" TEXT NOT NULL DEFAULT '',
|
|
843
|
+
"history_anamnesis_completed" BOOLEAN NOT NULL DEFAULT false,
|
|
844
|
+
"history_anamnesis_date" TIMESTAMP(3),
|
|
845
|
+
"history_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
846
|
+
"history_updated_at" TIMESTAMP(3) NOT NULL,
|
|
847
|
+
|
|
848
|
+
CONSTRAINT "patient_medical_histories_pkey" PRIMARY KEY ("history_id")
|
|
849
|
+
);
|
|
850
|
+
|
|
851
|
+
-- CreateTable
|
|
852
|
+
CREATE TABLE "patient_documents" (
|
|
853
|
+
"doc_id" TEXT NOT NULL,
|
|
854
|
+
"doc_patient_id" TEXT NOT NULL,
|
|
855
|
+
"doc_tenant_id" TEXT NOT NULL,
|
|
856
|
+
"doc_clinic_id" TEXT NOT NULL,
|
|
857
|
+
"doc_appointment_id" TEXT,
|
|
858
|
+
"doc_type" TEXT NOT NULL DEFAULT 'other',
|
|
859
|
+
"doc_name" TEXT NOT NULL,
|
|
860
|
+
"doc_media_key" TEXT NOT NULL,
|
|
861
|
+
"doc_content_type" TEXT NOT NULL,
|
|
862
|
+
"doc_size_bytes" INTEGER NOT NULL DEFAULT 0,
|
|
863
|
+
"doc_uploaded_by" TEXT,
|
|
864
|
+
"doc_notes" TEXT NOT NULL DEFAULT '',
|
|
865
|
+
"doc_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
866
|
+
|
|
867
|
+
CONSTRAINT "patient_documents_pkey" PRIMARY KEY ("doc_id")
|
|
868
|
+
);
|
|
869
|
+
|
|
870
|
+
-- CreateTable
|
|
871
|
+
CREATE TABLE "patient_notes" (
|
|
872
|
+
"note_id" TEXT NOT NULL,
|
|
873
|
+
"note_patient_id" TEXT NOT NULL,
|
|
874
|
+
"note_tenant_id" TEXT NOT NULL,
|
|
875
|
+
"note_clinic_id" TEXT NOT NULL,
|
|
876
|
+
"note_author_id" TEXT NOT NULL,
|
|
877
|
+
"note_text" TEXT NOT NULL,
|
|
878
|
+
"note_is_pinned" BOOLEAN NOT NULL DEFAULT false,
|
|
879
|
+
"note_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
880
|
+
"note_updated_at" TIMESTAMP(3) NOT NULL,
|
|
881
|
+
|
|
882
|
+
CONSTRAINT "patient_notes_pkey" PRIMARY KEY ("note_id")
|
|
883
|
+
);
|
|
884
|
+
|
|
885
|
+
-- CreateTable
|
|
886
|
+
CREATE TABLE "treatments" (
|
|
887
|
+
"treatment_id" TEXT NOT NULL,
|
|
888
|
+
"treatment_tenant_id" TEXT NOT NULL,
|
|
889
|
+
"treatment_clinic_id" TEXT,
|
|
890
|
+
"treatment_name" TEXT NOT NULL,
|
|
891
|
+
"treatment_category" TEXT NOT NULL DEFAULT '',
|
|
892
|
+
"treatment_description" TEXT NOT NULL DEFAULT '',
|
|
893
|
+
"treatment_duration_minutes" INTEGER NOT NULL DEFAULT 30,
|
|
894
|
+
"treatment_price" DECIMAL(65,30),
|
|
895
|
+
"treatment_currency" TEXT NOT NULL DEFAULT 'TRY',
|
|
896
|
+
"treatment_is_active" BOOLEAN NOT NULL DEFAULT true,
|
|
897
|
+
"treatment_sort_order" INTEGER NOT NULL DEFAULT 0,
|
|
898
|
+
"treatment_recall_days" INTEGER,
|
|
899
|
+
"treatment_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
900
|
+
"treatment_updated_at" TIMESTAMP(3) NOT NULL,
|
|
901
|
+
|
|
902
|
+
CONSTRAINT "treatments_pkey" PRIMARY KEY ("treatment_id")
|
|
903
|
+
);
|
|
904
|
+
|
|
905
|
+
-- CreateTable
|
|
906
|
+
CREATE TABLE "treatment_plans" (
|
|
907
|
+
"tplan_id" TEXT NOT NULL,
|
|
908
|
+
"tplan_tenant_id" TEXT NOT NULL,
|
|
909
|
+
"tplan_clinic_id" TEXT NOT NULL,
|
|
910
|
+
"tplan_patient_id" TEXT NOT NULL,
|
|
911
|
+
"tplan_doctor_id" TEXT,
|
|
912
|
+
"tplan_name" TEXT NOT NULL,
|
|
913
|
+
"tplan_status" "TreatmentPlanStatus" NOT NULL DEFAULT 'active',
|
|
914
|
+
"tplan_notes" TEXT NOT NULL DEFAULT '',
|
|
915
|
+
"tplan_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
916
|
+
"tplan_updated_at" TIMESTAMP(3) NOT NULL,
|
|
917
|
+
|
|
918
|
+
CONSTRAINT "treatment_plans_pkey" PRIMARY KEY ("tplan_id")
|
|
919
|
+
);
|
|
920
|
+
|
|
921
|
+
-- CreateTable
|
|
922
|
+
CREATE TABLE "treatment_plan_items" (
|
|
923
|
+
"tpitem_id" TEXT NOT NULL,
|
|
924
|
+
"tpitem_plan_id" TEXT NOT NULL,
|
|
925
|
+
"tpitem_treatment_id" TEXT,
|
|
926
|
+
"tpitem_appointment_id" TEXT,
|
|
927
|
+
"tpitem_name" TEXT NOT NULL,
|
|
928
|
+
"tpitem_tooth_number" TEXT,
|
|
929
|
+
"tpitem_status" "TreatmentPlanItemStatus" NOT NULL DEFAULT 'planned',
|
|
930
|
+
"tpitem_notes" TEXT NOT NULL DEFAULT '',
|
|
931
|
+
"tpitem_sort_order" INTEGER NOT NULL DEFAULT 0,
|
|
932
|
+
"tpitem_completed_at" TIMESTAMP(3),
|
|
933
|
+
"tpitem_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
934
|
+
"tpitem_updated_at" TIMESTAMP(3) NOT NULL,
|
|
935
|
+
|
|
936
|
+
CONSTRAINT "treatment_plan_items_pkey" PRIMARY KEY ("tpitem_id")
|
|
937
|
+
);
|
|
938
|
+
|
|
939
|
+
-- CreateTable
|
|
940
|
+
CREATE TABLE "doctor_profiles" (
|
|
941
|
+
"dprofile_id" TEXT NOT NULL,
|
|
942
|
+
"dprofile_user_id" TEXT NOT NULL,
|
|
943
|
+
"dprofile_specialty" TEXT NOT NULL DEFAULT '',
|
|
944
|
+
"dprofile_title" TEXT NOT NULL DEFAULT '',
|
|
945
|
+
"dprofile_bio" TEXT NOT NULL DEFAULT '',
|
|
946
|
+
"dprofile_working_hours" JSONB NOT NULL DEFAULT '[]',
|
|
947
|
+
"dprofile_appointment_duration" INTEGER NOT NULL DEFAULT 30,
|
|
948
|
+
"dprofile_color" TEXT NOT NULL DEFAULT '',
|
|
949
|
+
"dprofile_is_accepting" BOOLEAN NOT NULL DEFAULT true,
|
|
950
|
+
"dprofile_blocked_dates" JSONB NOT NULL DEFAULT '[]',
|
|
951
|
+
"dprofile_google_email" TEXT,
|
|
952
|
+
"dprofile_google_encrypted_token" TEXT,
|
|
953
|
+
"dprofile_google_calendar_id" TEXT,
|
|
954
|
+
"dprofile_google_calendar_name" TEXT,
|
|
955
|
+
"dprofile_google_connected_at" TIMESTAMP(3),
|
|
956
|
+
"dprofile_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
957
|
+
"dprofile_updated_at" TIMESTAMP(3) NOT NULL,
|
|
958
|
+
|
|
959
|
+
CONSTRAINT "doctor_profiles_pkey" PRIMARY KEY ("dprofile_id")
|
|
960
|
+
);
|
|
961
|
+
|
|
962
|
+
-- CreateTable
|
|
963
|
+
CREATE TABLE "patient_photo_sets" (
|
|
964
|
+
"photoset_id" TEXT NOT NULL,
|
|
965
|
+
"photoset_patient_id" TEXT NOT NULL,
|
|
966
|
+
"photoset_tenant_id" TEXT NOT NULL,
|
|
967
|
+
"photoset_clinic_id" TEXT NOT NULL,
|
|
968
|
+
"photoset_treatment_plan_id" TEXT,
|
|
969
|
+
"photoset_type" TEXT NOT NULL,
|
|
970
|
+
"photoset_label" TEXT NOT NULL DEFAULT '',
|
|
971
|
+
"photoset_taken_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
972
|
+
"photoset_taken_by" TEXT,
|
|
973
|
+
"photoset_notes" TEXT NOT NULL DEFAULT '',
|
|
974
|
+
"photoset_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
975
|
+
"photoset_updated_at" TIMESTAMP(3) NOT NULL,
|
|
976
|
+
|
|
977
|
+
CONSTRAINT "patient_photo_sets_pkey" PRIMARY KEY ("photoset_id")
|
|
978
|
+
);
|
|
979
|
+
|
|
980
|
+
-- CreateTable
|
|
981
|
+
CREATE TABLE "patient_photos" (
|
|
982
|
+
"photo_id" TEXT NOT NULL,
|
|
983
|
+
"photo_set_id" TEXT NOT NULL,
|
|
984
|
+
"photo_angle" TEXT NOT NULL DEFAULT '',
|
|
985
|
+
"photo_media_key" TEXT NOT NULL,
|
|
986
|
+
"photo_thumbnail_key" TEXT,
|
|
987
|
+
"photo_caption" TEXT NOT NULL DEFAULT '',
|
|
988
|
+
"photo_sort_order" INTEGER NOT NULL DEFAULT 0,
|
|
989
|
+
"photo_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
990
|
+
|
|
991
|
+
CONSTRAINT "patient_photos_pkey" PRIMARY KEY ("photo_id")
|
|
992
|
+
);
|
|
993
|
+
|
|
994
|
+
-- CreateTable
|
|
995
|
+
CREATE TABLE "examination_records" (
|
|
996
|
+
"exam_id" TEXT NOT NULL,
|
|
997
|
+
"exam_appointment_id" TEXT,
|
|
998
|
+
"exam_patient_id" TEXT NOT NULL,
|
|
999
|
+
"exam_doctor_id" TEXT NOT NULL,
|
|
1000
|
+
"exam_clinic_id" TEXT NOT NULL,
|
|
1001
|
+
"exam_tenant_id" TEXT NOT NULL,
|
|
1002
|
+
"exam_findings" TEXT NOT NULL DEFAULT '',
|
|
1003
|
+
"exam_diagnosis" TEXT NOT NULL DEFAULT '',
|
|
1004
|
+
"exam_procedure_notes" TEXT NOT NULL DEFAULT '',
|
|
1005
|
+
"exam_prescription" TEXT NOT NULL DEFAULT '',
|
|
1006
|
+
"exam_instructions" TEXT NOT NULL DEFAULT '',
|
|
1007
|
+
"exam_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
1008
|
+
"exam_updated_at" TIMESTAMP(3) NOT NULL,
|
|
1009
|
+
|
|
1010
|
+
CONSTRAINT "examination_records_pkey" PRIMARY KEY ("exam_id")
|
|
1011
|
+
);
|
|
1012
|
+
|
|
1013
|
+
-- CreateTable
|
|
1014
|
+
CREATE TABLE "availability_blocks" (
|
|
1015
|
+
"block_id" TEXT NOT NULL,
|
|
1016
|
+
"block_tenant_id" TEXT NOT NULL,
|
|
1017
|
+
"block_clinic_id" TEXT NOT NULL,
|
|
1018
|
+
"block_doctor_id" TEXT,
|
|
1019
|
+
"block_title" TEXT NOT NULL,
|
|
1020
|
+
"block_type" "AvailabilityBlockType" NOT NULL DEFAULT 'holiday',
|
|
1021
|
+
"block_start_date" DATE NOT NULL,
|
|
1022
|
+
"block_end_date" DATE NOT NULL,
|
|
1023
|
+
"block_all_day" BOOLEAN NOT NULL DEFAULT true,
|
|
1024
|
+
"block_start_time" TEXT,
|
|
1025
|
+
"block_end_time" TEXT,
|
|
1026
|
+
"block_recurring" BOOLEAN NOT NULL DEFAULT false,
|
|
1027
|
+
"block_notes" TEXT NOT NULL DEFAULT '',
|
|
1028
|
+
"block_created_by" TEXT,
|
|
1029
|
+
"block_created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
1030
|
+
|
|
1031
|
+
CONSTRAINT "availability_blocks_pkey" PRIMARY KEY ("block_id")
|
|
1032
|
+
);
|
|
1033
|
+
|
|
1034
|
+
-- CreateIndex
|
|
1035
|
+
CREATE INDEX "idx_tenants_plan" ON "tenants"("tenant_plan_id");
|
|
1036
|
+
|
|
1037
|
+
-- CreateIndex
|
|
1038
|
+
CREATE INDEX "idx_clinics_tenant" ON "clinics"("clinic_tenant_id");
|
|
1039
|
+
|
|
1040
|
+
-- CreateIndex
|
|
1041
|
+
CREATE INDEX "idx_clinics_operator" ON "clinics"("clinic_tenant_id", "clinic_operator_phone");
|
|
1042
|
+
|
|
1043
|
+
-- CreateIndex
|
|
1044
|
+
CREATE UNIQUE INDEX "clinics_clinic_tenant_id_clinic_slug_key" ON "clinics"("clinic_tenant_id", "clinic_slug");
|
|
1045
|
+
|
|
1046
|
+
-- CreateIndex
|
|
1047
|
+
CREATE UNIQUE INDEX "clinic_calendar_connections_calcn_clinic_id_key" ON "clinic_calendar_connections"("calcn_clinic_id");
|
|
1048
|
+
|
|
1049
|
+
-- CreateIndex
|
|
1050
|
+
CREATE INDEX "idx_meta_clinic" ON "clinic_meta_connections"("meta_clinic_id");
|
|
1051
|
+
|
|
1052
|
+
-- CreateIndex
|
|
1053
|
+
CREATE INDEX "idx_meta_clinic_type" ON "clinic_meta_connections"("meta_clinic_id", "meta_type");
|
|
1054
|
+
|
|
1055
|
+
-- CreateIndex
|
|
1056
|
+
CREATE INDEX "idx_meta_phone_number" ON "clinic_meta_connections"("meta_phone_number_id");
|
|
1057
|
+
|
|
1058
|
+
-- CreateIndex
|
|
1059
|
+
CREATE INDEX "idx_meta_instagram_page" ON "clinic_meta_connections"("meta_instagram_page_id");
|
|
1060
|
+
|
|
1061
|
+
-- CreateIndex
|
|
1062
|
+
CREATE INDEX "idx_phones_tenant_purpose" ON "phone_numbers"("phone_tenant_id", "phone_purpose");
|
|
1063
|
+
|
|
1064
|
+
-- CreateIndex
|
|
1065
|
+
CREATE INDEX "idx_phones_clinic" ON "phone_numbers"("phone_clinic_id");
|
|
1066
|
+
|
|
1067
|
+
-- CreateIndex
|
|
1068
|
+
CREATE INDEX "idx_phones_provider_external" ON "phone_numbers"("phone_provider", "phone_external_account_id");
|
|
1069
|
+
|
|
1070
|
+
-- CreateIndex
|
|
1071
|
+
CREATE UNIQUE INDEX "phone_numbers_phone_tenant_id_phone_number_phone_purpose_key" ON "phone_numbers"("phone_tenant_id", "phone_number", "phone_purpose");
|
|
1072
|
+
|
|
1073
|
+
-- CreateIndex
|
|
1074
|
+
CREATE UNIQUE INDEX "users_user_email_key" ON "users"("user_email");
|
|
1075
|
+
|
|
1076
|
+
-- CreateIndex
|
|
1077
|
+
CREATE INDEX "idx_users_tenant" ON "users"("user_tenant_id");
|
|
1078
|
+
|
|
1079
|
+
-- CreateIndex
|
|
1080
|
+
CREATE INDEX "idx_assign_user" ON "user_clinic_assignments"("assign_user_id");
|
|
1081
|
+
|
|
1082
|
+
-- CreateIndex
|
|
1083
|
+
CREATE INDEX "idx_assign_clinic" ON "user_clinic_assignments"("assign_clinic_id");
|
|
1084
|
+
|
|
1085
|
+
-- CreateIndex
|
|
1086
|
+
CREATE UNIQUE INDEX "user_clinic_assignments_assign_user_id_assign_clinic_id_key" ON "user_clinic_assignments"("assign_user_id", "assign_clinic_id");
|
|
1087
|
+
|
|
1088
|
+
-- CreateIndex
|
|
1089
|
+
CREATE UNIQUE INDEX "refresh_tokens_token_value_key" ON "refresh_tokens"("token_value");
|
|
1090
|
+
|
|
1091
|
+
-- CreateIndex
|
|
1092
|
+
CREATE INDEX "idx_tokens_user" ON "refresh_tokens"("token_user_id");
|
|
1093
|
+
|
|
1094
|
+
-- CreateIndex
|
|
1095
|
+
CREATE INDEX "idx_tokens_expires" ON "refresh_tokens"("token_expires_at");
|
|
1096
|
+
|
|
1097
|
+
-- CreateIndex
|
|
1098
|
+
CREATE UNIQUE INDEX "plans_plan_slug_key" ON "plans"("plan_slug");
|
|
1099
|
+
|
|
1100
|
+
-- CreateIndex
|
|
1101
|
+
CREATE INDEX "idx_agents_tenant" ON "agents"("agent_tenant_id");
|
|
1102
|
+
|
|
1103
|
+
-- CreateIndex
|
|
1104
|
+
CREATE INDEX "idx_agents_clinic" ON "agents"("agent_clinic_id");
|
|
1105
|
+
|
|
1106
|
+
-- CreateIndex
|
|
1107
|
+
CREATE INDEX "idx_agents_elevenlabs" ON "agents"("agent_elevenlabs_id");
|
|
1108
|
+
|
|
1109
|
+
-- CreateIndex
|
|
1110
|
+
CREATE INDEX "idx_calls_tenant_date" ON "calls"("call_tenant_id", "call_created_at" DESC);
|
|
1111
|
+
|
|
1112
|
+
-- CreateIndex
|
|
1113
|
+
CREATE INDEX "idx_calls_clinic_date" ON "calls"("call_clinic_id", "call_created_at" DESC);
|
|
1114
|
+
|
|
1115
|
+
-- CreateIndex
|
|
1116
|
+
CREATE INDEX "idx_calls_campaign_status" ON "calls"("call_campaign_id", "call_status");
|
|
1117
|
+
|
|
1118
|
+
-- CreateIndex
|
|
1119
|
+
CREATE INDEX "idx_calls_tenant_direction_date" ON "calls"("call_tenant_id", "call_direction", "call_created_at" DESC);
|
|
1120
|
+
|
|
1121
|
+
-- CreateIndex
|
|
1122
|
+
CREATE INDEX "idx_calls_conversation" ON "calls"("call_conversation_id");
|
|
1123
|
+
|
|
1124
|
+
-- CreateIndex
|
|
1125
|
+
CREATE INDEX "idx_calls_tenant_callee" ON "calls"("call_tenant_id", "call_callee_number");
|
|
1126
|
+
|
|
1127
|
+
-- CreateIndex
|
|
1128
|
+
CREATE INDEX "idx_calls_patient_date" ON "calls"("call_patient_id", "call_created_at" DESC);
|
|
1129
|
+
|
|
1130
|
+
-- CreateIndex
|
|
1131
|
+
CREATE UNIQUE INDEX "call_details_detail_call_id_key" ON "call_details"("detail_call_id");
|
|
1132
|
+
|
|
1133
|
+
-- CreateIndex
|
|
1134
|
+
CREATE INDEX "idx_leads_tenant_date" ON "leads"("lead_tenant_id", "lead_created_at" DESC);
|
|
1135
|
+
|
|
1136
|
+
-- CreateIndex
|
|
1137
|
+
CREATE INDEX "idx_leads_tenant_status" ON "leads"("lead_tenant_id", "lead_status");
|
|
1138
|
+
|
|
1139
|
+
-- CreateIndex
|
|
1140
|
+
CREATE INDEX "idx_leads_call" ON "leads"("lead_call_id");
|
|
1141
|
+
|
|
1142
|
+
-- CreateIndex
|
|
1143
|
+
CREATE INDEX "idx_leads_session" ON "leads"("lead_session_id");
|
|
1144
|
+
|
|
1145
|
+
-- CreateIndex
|
|
1146
|
+
CREATE INDEX "idx_leads_patient" ON "leads"("lead_patient_id");
|
|
1147
|
+
|
|
1148
|
+
-- CreateIndex
|
|
1149
|
+
CREATE INDEX "idx_campaigns_tenant_status" ON "outbound_campaigns"("campaign_tenant_id", "campaign_status");
|
|
1150
|
+
|
|
1151
|
+
-- CreateIndex
|
|
1152
|
+
CREATE INDEX "idx_campaigns_clinic" ON "outbound_campaigns"("campaign_clinic_id");
|
|
1153
|
+
|
|
1154
|
+
-- CreateIndex
|
|
1155
|
+
CREATE INDEX "idx_centries_campaign_status" ON "outbound_campaign_entries"("centry_campaign_id", "centry_status");
|
|
1156
|
+
|
|
1157
|
+
-- CreateIndex
|
|
1158
|
+
CREATE INDEX "idx_centries_conversation" ON "outbound_campaign_entries"("centry_conversation_id");
|
|
1159
|
+
|
|
1160
|
+
-- CreateIndex
|
|
1161
|
+
CREATE INDEX "idx_chats_tenant_clinic" ON "whatsapp_chats"("chat_tenant_id", "chat_clinic_id");
|
|
1162
|
+
|
|
1163
|
+
-- CreateIndex
|
|
1164
|
+
CREATE INDEX "idx_chats_tenant_lastmsg" ON "whatsapp_chats"("chat_tenant_id", "chat_last_message_at" DESC);
|
|
1165
|
+
|
|
1166
|
+
-- CreateIndex
|
|
1167
|
+
CREATE INDEX "idx_chats_tenant_phone" ON "whatsapp_chats"("chat_tenant_id", "chat_contact_phone");
|
|
1168
|
+
|
|
1169
|
+
-- CreateIndex
|
|
1170
|
+
CREATE UNIQUE INDEX "whatsapp_chats_chat_tenant_id_chat_external_id_key" ON "whatsapp_chats"("chat_tenant_id", "chat_external_id");
|
|
1171
|
+
|
|
1172
|
+
-- CreateIndex
|
|
1173
|
+
CREATE INDEX "idx_sessions_chat_status" ON "whatsapp_sessions"("session_chat_id", "session_status");
|
|
1174
|
+
|
|
1175
|
+
-- CreateIndex
|
|
1176
|
+
CREATE INDEX "idx_sessions_status_grace" ON "whatsapp_sessions"("session_status", "session_grace_deadline");
|
|
1177
|
+
|
|
1178
|
+
-- CreateIndex
|
|
1179
|
+
CREATE INDEX "idx_sessions_tenant_status" ON "whatsapp_sessions"("session_tenant_id", "session_status");
|
|
1180
|
+
|
|
1181
|
+
-- CreateIndex
|
|
1182
|
+
CREATE INDEX "idx_sessions_clinic_status" ON "whatsapp_sessions"("session_clinic_id", "session_status");
|
|
1183
|
+
|
|
1184
|
+
-- CreateIndex
|
|
1185
|
+
CREATE INDEX "idx_sessions_status_updated" ON "whatsapp_sessions"("session_status", "session_updated_at");
|
|
1186
|
+
|
|
1187
|
+
-- CreateIndex
|
|
1188
|
+
CREATE INDEX "idx_sessions_ref_tenant" ON "whatsapp_sessions"("session_ref_code", "session_tenant_id");
|
|
1189
|
+
|
|
1190
|
+
-- CreateIndex
|
|
1191
|
+
CREATE INDEX "idx_msgs_chat_date" ON "whatsapp_messages"("msg_chat_id", "msg_created_at");
|
|
1192
|
+
|
|
1193
|
+
-- CreateIndex
|
|
1194
|
+
CREATE INDEX "idx_msgs_session_date" ON "whatsapp_messages"("msg_session_id", "msg_created_at");
|
|
1195
|
+
|
|
1196
|
+
-- CreateIndex
|
|
1197
|
+
CREATE INDEX "idx_msgs_tenant_date" ON "whatsapp_messages"("msg_tenant_id", "msg_created_at" DESC);
|
|
1198
|
+
|
|
1199
|
+
-- CreateIndex
|
|
1200
|
+
CREATE INDEX "idx_opreqs_session_status" ON "operator_requests"("opreq_session_id", "opreq_status");
|
|
1201
|
+
|
|
1202
|
+
-- CreateIndex
|
|
1203
|
+
CREATE INDEX "idx_opreqs_status_expires" ON "operator_requests"("opreq_status", "opreq_expires_at");
|
|
1204
|
+
|
|
1205
|
+
-- CreateIndex
|
|
1206
|
+
CREATE UNIQUE INDEX "operator_requests_opreq_tenant_id_opreq_ref_code_key" ON "operator_requests"("opreq_tenant_id", "opreq_ref_code");
|
|
1207
|
+
|
|
1208
|
+
-- CreateIndex
|
|
1209
|
+
CREATE INDEX "idx_appts_tenant_start" ON "appointments"("appt_tenant_id", "appt_start_time");
|
|
1210
|
+
|
|
1211
|
+
-- CreateIndex
|
|
1212
|
+
CREATE INDEX "idx_appts_clinic_start" ON "appointments"("appt_clinic_id", "appt_start_time");
|
|
1213
|
+
|
|
1214
|
+
-- CreateIndex
|
|
1215
|
+
CREATE INDEX "idx_appts_patient_start" ON "appointments"("appt_patient_id", "appt_start_time");
|
|
1216
|
+
|
|
1217
|
+
-- CreateIndex
|
|
1218
|
+
CREATE INDEX "idx_appts_doctor_start" ON "appointments"("appt_doctor_id", "appt_start_time");
|
|
1219
|
+
|
|
1220
|
+
-- CreateIndex
|
|
1221
|
+
CREATE INDEX "idx_appts_tenant_status" ON "appointments"("appt_tenant_id", "appt_status");
|
|
1222
|
+
|
|
1223
|
+
-- CreateIndex
|
|
1224
|
+
CREATE INDEX "idx_appts_google_event" ON "appointments"("appt_google_event_id");
|
|
1225
|
+
|
|
1226
|
+
-- CreateIndex
|
|
1227
|
+
CREATE INDEX "idx_batches_tenant_date" ON "appointment_validation_batches"("batch_tenant_id", "batch_created_at" DESC);
|
|
1228
|
+
|
|
1229
|
+
-- CreateIndex
|
|
1230
|
+
CREATE INDEX "idx_batches_el" ON "appointment_validation_batches"("batch_el_batch_id");
|
|
1231
|
+
|
|
1232
|
+
-- CreateIndex
|
|
1233
|
+
CREATE INDEX "idx_batches_clinic" ON "appointment_validation_batches"("batch_clinic_id");
|
|
1234
|
+
|
|
1235
|
+
-- CreateIndex
|
|
1236
|
+
CREATE INDEX "idx_bentries_batch_status" ON "appointment_validation_entries"("bentry_batch_id", "bentry_call_status");
|
|
1237
|
+
|
|
1238
|
+
-- CreateIndex
|
|
1239
|
+
CREATE INDEX "idx_bentries_conversation" ON "appointment_validation_entries"("bentry_conversation_id");
|
|
1240
|
+
|
|
1241
|
+
-- CreateIndex
|
|
1242
|
+
CREATE INDEX "idx_billing_tenant_date" ON "billing_events"("billing_tenant_id", "billing_created_at" DESC);
|
|
1243
|
+
|
|
1244
|
+
-- CreateIndex
|
|
1245
|
+
CREATE INDEX "idx_payments_tenant" ON "payments"("payment_tenant_id");
|
|
1246
|
+
|
|
1247
|
+
-- CreateIndex
|
|
1248
|
+
CREATE INDEX "idx_payments_tenant_period" ON "payments"("payment_tenant_id", "payment_period_end" DESC);
|
|
1249
|
+
|
|
1250
|
+
-- CreateIndex
|
|
1251
|
+
CREATE INDEX "idx_snapshots_tenant_period" ON "billing_period_snapshots"("snapshot_tenant_id", "snapshot_period_start" DESC);
|
|
1252
|
+
|
|
1253
|
+
-- CreateIndex
|
|
1254
|
+
CREATE UNIQUE INDEX "billing_alerts_alert_tenant_id_alert_type_alert_service_ale_key" ON "billing_alerts"("alert_tenant_id", "alert_type", "alert_service", "alert_payment_id");
|
|
1255
|
+
|
|
1256
|
+
-- CreateIndex
|
|
1257
|
+
CREATE INDEX "idx_stt_tenant_date" ON "stt_usages"("stt_tenant_id", "stt_created_at" DESC);
|
|
1258
|
+
|
|
1259
|
+
-- CreateIndex
|
|
1260
|
+
CREATE INDEX "idx_logs_level" ON "logs"("log_level");
|
|
1261
|
+
|
|
1262
|
+
-- CreateIndex
|
|
1263
|
+
CREATE INDEX "idx_logs_timestamp" ON "logs"("log_timestamp");
|
|
1264
|
+
|
|
1265
|
+
-- CreateIndex
|
|
1266
|
+
CREATE INDEX "idx_logs_level_timestamp" ON "logs"("log_level", "log_timestamp" DESC);
|
|
1267
|
+
|
|
1268
|
+
-- CreateIndex
|
|
1269
|
+
CREATE INDEX "idx_logs_tenant_timestamp" ON "logs"("log_tenant_id", "log_timestamp" DESC);
|
|
1270
|
+
|
|
1271
|
+
-- CreateIndex
|
|
1272
|
+
CREATE INDEX "idx_logs_request" ON "logs"("log_request_id");
|
|
1273
|
+
|
|
1274
|
+
-- CreateIndex
|
|
1275
|
+
CREATE INDEX "idx_logs_service_timestamp" ON "logs"("log_service", "log_timestamp" DESC);
|
|
1276
|
+
|
|
1277
|
+
-- CreateIndex
|
|
1278
|
+
CREATE INDEX "idx_audit_tenant_date" ON "audit_logs"("audit_tenant_id", "audit_created_at" DESC);
|
|
1279
|
+
|
|
1280
|
+
-- CreateIndex
|
|
1281
|
+
CREATE INDEX "idx_audit_clinic_date" ON "audit_logs"("audit_clinic_id", "audit_created_at" DESC);
|
|
1282
|
+
|
|
1283
|
+
-- CreateIndex
|
|
1284
|
+
CREATE INDEX "idx_audit_entity" ON "audit_logs"("audit_entity", "audit_entity_id");
|
|
1285
|
+
|
|
1286
|
+
-- CreateIndex
|
|
1287
|
+
CREATE INDEX "idx_audit_user_date" ON "audit_logs"("audit_user_id", "audit_created_at" DESC);
|
|
1288
|
+
|
|
1289
|
+
-- CreateIndex
|
|
1290
|
+
CREATE INDEX "idx_audit_action_date" ON "audit_logs"("audit_action", "audit_created_at" DESC);
|
|
1291
|
+
|
|
1292
|
+
-- CreateIndex
|
|
1293
|
+
CREATE INDEX "idx_toollog_tenant_date" ON "tool_execution_logs"("toollog_tenant_id", "toollog_created_at" DESC);
|
|
1294
|
+
|
|
1295
|
+
-- CreateIndex
|
|
1296
|
+
CREATE INDEX "idx_toollog_tool_date" ON "tool_execution_logs"("toollog_tool_name", "toollog_created_at" DESC);
|
|
1297
|
+
|
|
1298
|
+
-- CreateIndex
|
|
1299
|
+
CREATE INDEX "idx_toollog_conversation" ON "tool_execution_logs"("toollog_conversation_id");
|
|
1300
|
+
|
|
1301
|
+
-- CreateIndex
|
|
1302
|
+
CREATE UNIQUE INDEX "migrations_migration_name_key" ON "migrations"("migration_name");
|
|
1303
|
+
|
|
1304
|
+
-- CreateIndex
|
|
1305
|
+
CREATE UNIQUE INDEX "transcriptions_tx_conversation_id_key" ON "transcriptions"("tx_conversation_id");
|
|
1306
|
+
|
|
1307
|
+
-- CreateIndex
|
|
1308
|
+
CREATE INDEX "idx_tx_agent" ON "transcriptions"("tx_agent_id");
|
|
1309
|
+
|
|
1310
|
+
-- CreateIndex
|
|
1311
|
+
CREATE INDEX "idx_tx_user" ON "transcriptions"("tx_user_id");
|
|
1312
|
+
|
|
1313
|
+
-- CreateIndex
|
|
1314
|
+
CREATE INDEX "idx_tx_processing" ON "transcriptions"("tx_processing_status");
|
|
1315
|
+
|
|
1316
|
+
-- CreateIndex
|
|
1317
|
+
CREATE INDEX "idx_tx_date" ON "transcriptions"("tx_created_at" DESC);
|
|
1318
|
+
|
|
1319
|
+
-- CreateIndex
|
|
1320
|
+
CREATE UNIQUE INDEX "summaries_summary_transcription_id_key" ON "summaries"("summary_transcription_id");
|
|
1321
|
+
|
|
1322
|
+
-- CreateIndex
|
|
1323
|
+
CREATE INDEX "idx_summary_conversation" ON "summaries"("summary_conversation_id");
|
|
1324
|
+
|
|
1325
|
+
-- CreateIndex
|
|
1326
|
+
CREATE INDEX "idx_patients_tenant_lastcontact" ON "patients"("patient_tenant_id", "patient_last_contact_at" DESC);
|
|
1327
|
+
|
|
1328
|
+
-- CreateIndex
|
|
1329
|
+
CREATE INDEX "idx_patients_clinic" ON "patients"("patient_clinic_id");
|
|
1330
|
+
|
|
1331
|
+
-- CreateIndex
|
|
1332
|
+
CREATE INDEX "idx_patients_tenant_name" ON "patients"("patient_tenant_id", "patient_last_name", "patient_first_name");
|
|
1333
|
+
|
|
1334
|
+
-- CreateIndex
|
|
1335
|
+
CREATE UNIQUE INDEX "patients_patient_tenant_id_patient_phone_key" ON "patients"("patient_tenant_id", "patient_phone");
|
|
1336
|
+
|
|
1337
|
+
-- CreateIndex
|
|
1338
|
+
CREATE UNIQUE INDEX "patient_medical_histories_history_patient_id_key" ON "patient_medical_histories"("history_patient_id");
|
|
1339
|
+
|
|
1340
|
+
-- CreateIndex
|
|
1341
|
+
CREATE INDEX "idx_docs_patient_date" ON "patient_documents"("doc_patient_id", "doc_created_at" DESC);
|
|
1342
|
+
|
|
1343
|
+
-- CreateIndex
|
|
1344
|
+
CREATE INDEX "idx_docs_tenant_type" ON "patient_documents"("doc_tenant_id", "doc_type");
|
|
1345
|
+
|
|
1346
|
+
-- CreateIndex
|
|
1347
|
+
CREATE INDEX "idx_notes_patient_date" ON "patient_notes"("note_patient_id", "note_created_at" DESC);
|
|
1348
|
+
|
|
1349
|
+
-- CreateIndex
|
|
1350
|
+
CREATE INDEX "idx_treatments_tenant_active" ON "treatments"("treatment_tenant_id", "treatment_is_active");
|
|
1351
|
+
|
|
1352
|
+
-- CreateIndex
|
|
1353
|
+
CREATE INDEX "idx_treatments_tenant_category" ON "treatments"("treatment_tenant_id", "treatment_category");
|
|
1354
|
+
|
|
1355
|
+
-- CreateIndex
|
|
1356
|
+
CREATE INDEX "idx_treatments_clinic" ON "treatments"("treatment_clinic_id");
|
|
1357
|
+
|
|
1358
|
+
-- CreateIndex
|
|
1359
|
+
CREATE INDEX "idx_tplans_patient_status" ON "treatment_plans"("tplan_patient_id", "tplan_status");
|
|
1360
|
+
|
|
1361
|
+
-- CreateIndex
|
|
1362
|
+
CREATE INDEX "idx_tplans_tenant_status" ON "treatment_plans"("tplan_tenant_id", "tplan_status");
|
|
1363
|
+
|
|
1364
|
+
-- CreateIndex
|
|
1365
|
+
CREATE INDEX "idx_tplans_doctor" ON "treatment_plans"("tplan_doctor_id");
|
|
1366
|
+
|
|
1367
|
+
-- CreateIndex
|
|
1368
|
+
CREATE INDEX "idx_tplans_clinic" ON "treatment_plans"("tplan_clinic_id");
|
|
1369
|
+
|
|
1370
|
+
-- CreateIndex
|
|
1371
|
+
CREATE INDEX "idx_tpitems_plan_order" ON "treatment_plan_items"("tpitem_plan_id", "tpitem_sort_order");
|
|
1372
|
+
|
|
1373
|
+
-- CreateIndex
|
|
1374
|
+
CREATE INDEX "idx_tpitems_appointment" ON "treatment_plan_items"("tpitem_appointment_id");
|
|
1375
|
+
|
|
1376
|
+
-- CreateIndex
|
|
1377
|
+
CREATE UNIQUE INDEX "doctor_profiles_dprofile_user_id_key" ON "doctor_profiles"("dprofile_user_id");
|
|
1378
|
+
|
|
1379
|
+
-- CreateIndex
|
|
1380
|
+
CREATE INDEX "idx_photosets_patient_date" ON "patient_photo_sets"("photoset_patient_id", "photoset_taken_at" DESC);
|
|
1381
|
+
|
|
1382
|
+
-- CreateIndex
|
|
1383
|
+
CREATE INDEX "idx_photosets_plan" ON "patient_photo_sets"("photoset_treatment_plan_id");
|
|
1384
|
+
|
|
1385
|
+
-- CreateIndex
|
|
1386
|
+
CREATE INDEX "idx_photosets_tenant_type" ON "patient_photo_sets"("photoset_tenant_id", "photoset_type");
|
|
1387
|
+
|
|
1388
|
+
-- CreateIndex
|
|
1389
|
+
CREATE INDEX "idx_photos_set_order" ON "patient_photos"("photo_set_id", "photo_sort_order");
|
|
1390
|
+
|
|
1391
|
+
-- CreateIndex
|
|
1392
|
+
CREATE UNIQUE INDEX "examination_records_exam_appointment_id_key" ON "examination_records"("exam_appointment_id");
|
|
1393
|
+
|
|
1394
|
+
-- CreateIndex
|
|
1395
|
+
CREATE INDEX "idx_exam_patient_date" ON "examination_records"("exam_patient_id", "exam_created_at" DESC);
|
|
1396
|
+
|
|
1397
|
+
-- CreateIndex
|
|
1398
|
+
CREATE INDEX "idx_exam_doctor_date" ON "examination_records"("exam_doctor_id", "exam_created_at" DESC);
|
|
1399
|
+
|
|
1400
|
+
-- CreateIndex
|
|
1401
|
+
CREATE INDEX "idx_blocks_clinic_date" ON "availability_blocks"("block_tenant_id", "block_clinic_id", "block_start_date");
|
|
1402
|
+
|
|
1403
|
+
-- CreateIndex
|
|
1404
|
+
CREATE INDEX "idx_blocks_doctor_date" ON "availability_blocks"("block_doctor_id", "block_start_date");
|
|
1405
|
+
|
|
1406
|
+
-- AddForeignKey
|
|
1407
|
+
ALTER TABLE "tenants" ADD CONSTRAINT "tenants_tenant_plan_id_fkey" FOREIGN KEY ("tenant_plan_id") REFERENCES "plans"("plan_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1408
|
+
|
|
1409
|
+
-- AddForeignKey
|
|
1410
|
+
ALTER TABLE "clinics" ADD CONSTRAINT "clinics_clinic_tenant_id_fkey" FOREIGN KEY ("clinic_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1411
|
+
|
|
1412
|
+
-- AddForeignKey
|
|
1413
|
+
ALTER TABLE "clinic_calendar_connections" ADD CONSTRAINT "clinic_calendar_connections_calcn_clinic_id_fkey" FOREIGN KEY ("calcn_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1414
|
+
|
|
1415
|
+
-- AddForeignKey
|
|
1416
|
+
ALTER TABLE "clinic_meta_connections" ADD CONSTRAINT "clinic_meta_connections_meta_clinic_id_fkey" FOREIGN KEY ("meta_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1417
|
+
|
|
1418
|
+
-- AddForeignKey
|
|
1419
|
+
ALTER TABLE "phone_numbers" ADD CONSTRAINT "phone_numbers_phone_tenant_id_fkey" FOREIGN KEY ("phone_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1420
|
+
|
|
1421
|
+
-- AddForeignKey
|
|
1422
|
+
ALTER TABLE "phone_numbers" ADD CONSTRAINT "phone_numbers_phone_clinic_id_fkey" FOREIGN KEY ("phone_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1423
|
+
|
|
1424
|
+
-- AddForeignKey
|
|
1425
|
+
ALTER TABLE "phone_numbers" ADD CONSTRAINT "phone_numbers_phone_agent_id_fkey" FOREIGN KEY ("phone_agent_id") REFERENCES "agents"("agent_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1426
|
+
|
|
1427
|
+
-- AddForeignKey
|
|
1428
|
+
ALTER TABLE "users" ADD CONSTRAINT "users_user_tenant_id_fkey" FOREIGN KEY ("user_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1429
|
+
|
|
1430
|
+
-- AddForeignKey
|
|
1431
|
+
ALTER TABLE "user_clinic_assignments" ADD CONSTRAINT "user_clinic_assignments_assign_user_id_fkey" FOREIGN KEY ("assign_user_id") REFERENCES "users"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1432
|
+
|
|
1433
|
+
-- AddForeignKey
|
|
1434
|
+
ALTER TABLE "user_clinic_assignments" ADD CONSTRAINT "user_clinic_assignments_assign_clinic_id_fkey" FOREIGN KEY ("assign_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1435
|
+
|
|
1436
|
+
-- AddForeignKey
|
|
1437
|
+
ALTER TABLE "refresh_tokens" ADD CONSTRAINT "refresh_tokens_token_user_id_fkey" FOREIGN KEY ("token_user_id") REFERENCES "users"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1438
|
+
|
|
1439
|
+
-- AddForeignKey
|
|
1440
|
+
ALTER TABLE "agents" ADD CONSTRAINT "agents_agent_tenant_id_fkey" FOREIGN KEY ("agent_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1441
|
+
|
|
1442
|
+
-- AddForeignKey
|
|
1443
|
+
ALTER TABLE "agents" ADD CONSTRAINT "agents_agent_clinic_id_fkey" FOREIGN KEY ("agent_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1444
|
+
|
|
1445
|
+
-- AddForeignKey
|
|
1446
|
+
ALTER TABLE "calls" ADD CONSTRAINT "calls_call_tenant_id_fkey" FOREIGN KEY ("call_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1447
|
+
|
|
1448
|
+
-- AddForeignKey
|
|
1449
|
+
ALTER TABLE "calls" ADD CONSTRAINT "calls_call_clinic_id_fkey" FOREIGN KEY ("call_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1450
|
+
|
|
1451
|
+
-- AddForeignKey
|
|
1452
|
+
ALTER TABLE "calls" ADD CONSTRAINT "calls_call_patient_id_fkey" FOREIGN KEY ("call_patient_id") REFERENCES "patients"("patient_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1453
|
+
|
|
1454
|
+
-- AddForeignKey
|
|
1455
|
+
ALTER TABLE "calls" ADD CONSTRAINT "calls_call_agent_id_fkey" FOREIGN KEY ("call_agent_id") REFERENCES "agents"("agent_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1456
|
+
|
|
1457
|
+
-- AddForeignKey
|
|
1458
|
+
ALTER TABLE "calls" ADD CONSTRAINT "calls_call_campaign_id_fkey" FOREIGN KEY ("call_campaign_id") REFERENCES "outbound_campaigns"("campaign_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1459
|
+
|
|
1460
|
+
-- AddForeignKey
|
|
1461
|
+
ALTER TABLE "call_details" ADD CONSTRAINT "call_details_detail_call_id_fkey" FOREIGN KEY ("detail_call_id") REFERENCES "calls"("call_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1462
|
+
|
|
1463
|
+
-- AddForeignKey
|
|
1464
|
+
ALTER TABLE "leads" ADD CONSTRAINT "leads_lead_tenant_id_fkey" FOREIGN KEY ("lead_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1465
|
+
|
|
1466
|
+
-- AddForeignKey
|
|
1467
|
+
ALTER TABLE "leads" ADD CONSTRAINT "leads_lead_clinic_id_fkey" FOREIGN KEY ("lead_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1468
|
+
|
|
1469
|
+
-- AddForeignKey
|
|
1470
|
+
ALTER TABLE "leads" ADD CONSTRAINT "leads_lead_patient_id_fkey" FOREIGN KEY ("lead_patient_id") REFERENCES "patients"("patient_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1471
|
+
|
|
1472
|
+
-- AddForeignKey
|
|
1473
|
+
ALTER TABLE "leads" ADD CONSTRAINT "leads_lead_call_id_fkey" FOREIGN KEY ("lead_call_id") REFERENCES "calls"("call_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1474
|
+
|
|
1475
|
+
-- AddForeignKey
|
|
1476
|
+
ALTER TABLE "leads" ADD CONSTRAINT "leads_lead_session_id_fkey" FOREIGN KEY ("lead_session_id") REFERENCES "whatsapp_sessions"("session_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1477
|
+
|
|
1478
|
+
-- AddForeignKey
|
|
1479
|
+
ALTER TABLE "leads" ADD CONSTRAINT "leads_lead_chat_id_fkey" FOREIGN KEY ("lead_chat_id") REFERENCES "whatsapp_chats"("chat_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1480
|
+
|
|
1481
|
+
-- AddForeignKey
|
|
1482
|
+
ALTER TABLE "outbound_campaigns" ADD CONSTRAINT "outbound_campaigns_campaign_tenant_id_fkey" FOREIGN KEY ("campaign_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1483
|
+
|
|
1484
|
+
-- AddForeignKey
|
|
1485
|
+
ALTER TABLE "outbound_campaigns" ADD CONSTRAINT "outbound_campaigns_campaign_clinic_id_fkey" FOREIGN KEY ("campaign_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1486
|
+
|
|
1487
|
+
-- AddForeignKey
|
|
1488
|
+
ALTER TABLE "outbound_campaigns" ADD CONSTRAINT "outbound_campaigns_campaign_agent_id_fkey" FOREIGN KEY ("campaign_agent_id") REFERENCES "agents"("agent_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1489
|
+
|
|
1490
|
+
-- AddForeignKey
|
|
1491
|
+
ALTER TABLE "outbound_campaigns" ADD CONSTRAINT "outbound_campaigns_campaign_phone_id_fkey" FOREIGN KEY ("campaign_phone_id") REFERENCES "phone_numbers"("phone_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1492
|
+
|
|
1493
|
+
-- AddForeignKey
|
|
1494
|
+
ALTER TABLE "outbound_campaign_entries" ADD CONSTRAINT "outbound_campaign_entries_centry_campaign_id_fkey" FOREIGN KEY ("centry_campaign_id") REFERENCES "outbound_campaigns"("campaign_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1495
|
+
|
|
1496
|
+
-- AddForeignKey
|
|
1497
|
+
ALTER TABLE "outbound_campaign_entries" ADD CONSTRAINT "outbound_campaign_entries_centry_call_id_fkey" FOREIGN KEY ("centry_call_id") REFERENCES "calls"("call_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1498
|
+
|
|
1499
|
+
-- AddForeignKey
|
|
1500
|
+
ALTER TABLE "whatsapp_chats" ADD CONSTRAINT "whatsapp_chats_chat_tenant_id_fkey" FOREIGN KEY ("chat_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1501
|
+
|
|
1502
|
+
-- AddForeignKey
|
|
1503
|
+
ALTER TABLE "whatsapp_chats" ADD CONSTRAINT "whatsapp_chats_chat_clinic_id_fkey" FOREIGN KEY ("chat_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1504
|
+
|
|
1505
|
+
-- AddForeignKey
|
|
1506
|
+
ALTER TABLE "whatsapp_chats" ADD CONSTRAINT "whatsapp_chats_chat_patient_id_fkey" FOREIGN KEY ("chat_patient_id") REFERENCES "patients"("patient_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1507
|
+
|
|
1508
|
+
-- AddForeignKey
|
|
1509
|
+
ALTER TABLE "whatsapp_chats" ADD CONSTRAINT "whatsapp_chats_chat_phone_id_fkey" FOREIGN KEY ("chat_phone_id") REFERENCES "phone_numbers"("phone_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1510
|
+
|
|
1511
|
+
-- AddForeignKey
|
|
1512
|
+
ALTER TABLE "whatsapp_chats" ADD CONSTRAINT "whatsapp_chats_chat_assigned_to_id_fkey" FOREIGN KEY ("chat_assigned_to_id") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1513
|
+
|
|
1514
|
+
-- AddForeignKey
|
|
1515
|
+
ALTER TABLE "whatsapp_chats" ADD CONSTRAINT "whatsapp_chats_chat_assigned_by_id_fkey" FOREIGN KEY ("chat_assigned_by_id") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1516
|
+
|
|
1517
|
+
-- AddForeignKey
|
|
1518
|
+
ALTER TABLE "whatsapp_sessions" ADD CONSTRAINT "whatsapp_sessions_session_tenant_id_fkey" FOREIGN KEY ("session_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1519
|
+
|
|
1520
|
+
-- AddForeignKey
|
|
1521
|
+
ALTER TABLE "whatsapp_sessions" ADD CONSTRAINT "whatsapp_sessions_session_clinic_id_fkey" FOREIGN KEY ("session_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1522
|
+
|
|
1523
|
+
-- AddForeignKey
|
|
1524
|
+
ALTER TABLE "whatsapp_sessions" ADD CONSTRAINT "whatsapp_sessions_session_chat_id_fkey" FOREIGN KEY ("session_chat_id") REFERENCES "whatsapp_chats"("chat_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1525
|
+
|
|
1526
|
+
-- AddForeignKey
|
|
1527
|
+
ALTER TABLE "whatsapp_sessions" ADD CONSTRAINT "whatsapp_sessions_session_taken_over_by_id_fkey" FOREIGN KEY ("session_taken_over_by_id") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1528
|
+
|
|
1529
|
+
-- AddForeignKey
|
|
1530
|
+
ALTER TABLE "whatsapp_messages" ADD CONSTRAINT "whatsapp_messages_msg_tenant_id_fkey" FOREIGN KEY ("msg_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1531
|
+
|
|
1532
|
+
-- AddForeignKey
|
|
1533
|
+
ALTER TABLE "whatsapp_messages" ADD CONSTRAINT "whatsapp_messages_msg_chat_id_fkey" FOREIGN KEY ("msg_chat_id") REFERENCES "whatsapp_chats"("chat_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1534
|
+
|
|
1535
|
+
-- AddForeignKey
|
|
1536
|
+
ALTER TABLE "whatsapp_messages" ADD CONSTRAINT "whatsapp_messages_msg_session_id_fkey" FOREIGN KEY ("msg_session_id") REFERENCES "whatsapp_sessions"("session_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1537
|
+
|
|
1538
|
+
-- AddForeignKey
|
|
1539
|
+
ALTER TABLE "whatsapp_messages" ADD CONSTRAINT "whatsapp_messages_msg_sender_user_id_fkey" FOREIGN KEY ("msg_sender_user_id") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1540
|
+
|
|
1541
|
+
-- AddForeignKey
|
|
1542
|
+
ALTER TABLE "operator_requests" ADD CONSTRAINT "operator_requests_opreq_tenant_id_fkey" FOREIGN KEY ("opreq_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1543
|
+
|
|
1544
|
+
-- AddForeignKey
|
|
1545
|
+
ALTER TABLE "operator_requests" ADD CONSTRAINT "operator_requests_opreq_clinic_id_fkey" FOREIGN KEY ("opreq_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1546
|
+
|
|
1547
|
+
-- AddForeignKey
|
|
1548
|
+
ALTER TABLE "operator_requests" ADD CONSTRAINT "operator_requests_opreq_session_id_fkey" FOREIGN KEY ("opreq_session_id") REFERENCES "whatsapp_sessions"("session_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1549
|
+
|
|
1550
|
+
-- AddForeignKey
|
|
1551
|
+
ALTER TABLE "operator_requests" ADD CONSTRAINT "operator_requests_opreq_chat_id_fkey" FOREIGN KEY ("opreq_chat_id") REFERENCES "whatsapp_chats"("chat_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1552
|
+
|
|
1553
|
+
-- AddForeignKey
|
|
1554
|
+
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_appt_tenant_id_fkey" FOREIGN KEY ("appt_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1555
|
+
|
|
1556
|
+
-- AddForeignKey
|
|
1557
|
+
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_appt_clinic_id_fkey" FOREIGN KEY ("appt_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1558
|
+
|
|
1559
|
+
-- AddForeignKey
|
|
1560
|
+
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_appt_patient_id_fkey" FOREIGN KEY ("appt_patient_id") REFERENCES "patients"("patient_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1561
|
+
|
|
1562
|
+
-- AddForeignKey
|
|
1563
|
+
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_appt_doctor_id_fkey" FOREIGN KEY ("appt_doctor_id") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1564
|
+
|
|
1565
|
+
-- AddForeignKey
|
|
1566
|
+
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_appt_treatment_id_fkey" FOREIGN KEY ("appt_treatment_id") REFERENCES "treatments"("treatment_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1567
|
+
|
|
1568
|
+
-- AddForeignKey
|
|
1569
|
+
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_appt_treatment_plan_item_id_fkey" FOREIGN KEY ("appt_treatment_plan_item_id") REFERENCES "treatment_plan_items"("tpitem_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1570
|
+
|
|
1571
|
+
-- AddForeignKey
|
|
1572
|
+
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_appt_chat_id_fkey" FOREIGN KEY ("appt_chat_id") REFERENCES "whatsapp_chats"("chat_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1573
|
+
|
|
1574
|
+
-- AddForeignKey
|
|
1575
|
+
ALTER TABLE "appointments" ADD CONSTRAINT "appointments_appt_session_id_fkey" FOREIGN KEY ("appt_session_id") REFERENCES "whatsapp_sessions"("session_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1576
|
+
|
|
1577
|
+
-- AddForeignKey
|
|
1578
|
+
ALTER TABLE "appointment_validation_batches" ADD CONSTRAINT "appointment_validation_batches_batch_tenant_id_fkey" FOREIGN KEY ("batch_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1579
|
+
|
|
1580
|
+
-- AddForeignKey
|
|
1581
|
+
ALTER TABLE "appointment_validation_batches" ADD CONSTRAINT "appointment_validation_batches_batch_clinic_id_fkey" FOREIGN KEY ("batch_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1582
|
+
|
|
1583
|
+
-- AddForeignKey
|
|
1584
|
+
ALTER TABLE "appointment_validation_batches" ADD CONSTRAINT "appointment_validation_batches_batch_created_by_id_fkey" FOREIGN KEY ("batch_created_by_id") REFERENCES "users"("user_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1585
|
+
|
|
1586
|
+
-- AddForeignKey
|
|
1587
|
+
ALTER TABLE "appointment_validation_batches" ADD CONSTRAINT "appointment_validation_batches_batch_agent_id_fkey" FOREIGN KEY ("batch_agent_id") REFERENCES "agents"("agent_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1588
|
+
|
|
1589
|
+
-- AddForeignKey
|
|
1590
|
+
ALTER TABLE "appointment_validation_batches" ADD CONSTRAINT "appointment_validation_batches_batch_phone_id_fkey" FOREIGN KEY ("batch_phone_id") REFERENCES "phone_numbers"("phone_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1591
|
+
|
|
1592
|
+
-- AddForeignKey
|
|
1593
|
+
ALTER TABLE "appointment_validation_entries" ADD CONSTRAINT "appointment_validation_entries_bentry_batch_id_fkey" FOREIGN KEY ("bentry_batch_id") REFERENCES "appointment_validation_batches"("batch_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1594
|
+
|
|
1595
|
+
-- AddForeignKey
|
|
1596
|
+
ALTER TABLE "appointment_validation_entries" ADD CONSTRAINT "appointment_validation_entries_bentry_appointment_id_fkey" FOREIGN KEY ("bentry_appointment_id") REFERENCES "appointments"("appt_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1597
|
+
|
|
1598
|
+
-- AddForeignKey
|
|
1599
|
+
ALTER TABLE "billing_events" ADD CONSTRAINT "billing_events_billing_tenant_id_fkey" FOREIGN KEY ("billing_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1600
|
+
|
|
1601
|
+
-- AddForeignKey
|
|
1602
|
+
ALTER TABLE "billing_events" ADD CONSTRAINT "billing_events_billing_clinic_id_fkey" FOREIGN KEY ("billing_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1603
|
+
|
|
1604
|
+
-- AddForeignKey
|
|
1605
|
+
ALTER TABLE "billing_events" ADD CONSTRAINT "billing_events_billing_call_id_fkey" FOREIGN KEY ("billing_call_id") REFERENCES "calls"("call_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1606
|
+
|
|
1607
|
+
-- AddForeignKey
|
|
1608
|
+
ALTER TABLE "payments" ADD CONSTRAINT "payments_payment_tenant_id_fkey" FOREIGN KEY ("payment_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1609
|
+
|
|
1610
|
+
-- AddForeignKey
|
|
1611
|
+
ALTER TABLE "payments" ADD CONSTRAINT "payments_payment_recorded_by_id_fkey" FOREIGN KEY ("payment_recorded_by_id") REFERENCES "users"("user_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1612
|
+
|
|
1613
|
+
-- AddForeignKey
|
|
1614
|
+
ALTER TABLE "billing_period_snapshots" ADD CONSTRAINT "billing_period_snapshots_snapshot_tenant_id_fkey" FOREIGN KEY ("snapshot_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1615
|
+
|
|
1616
|
+
-- AddForeignKey
|
|
1617
|
+
ALTER TABLE "billing_period_snapshots" ADD CONSTRAINT "billing_period_snapshots_snapshot_payment_id_fkey" FOREIGN KEY ("snapshot_payment_id") REFERENCES "payments"("payment_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1618
|
+
|
|
1619
|
+
-- AddForeignKey
|
|
1620
|
+
ALTER TABLE "billing_period_snapshots" ADD CONSTRAINT "billing_period_snapshots_snapshot_plan_id_fkey" FOREIGN KEY ("snapshot_plan_id") REFERENCES "plans"("plan_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1621
|
+
|
|
1622
|
+
-- AddForeignKey
|
|
1623
|
+
ALTER TABLE "billing_alerts" ADD CONSTRAINT "billing_alerts_alert_tenant_id_fkey" FOREIGN KEY ("alert_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1624
|
+
|
|
1625
|
+
-- AddForeignKey
|
|
1626
|
+
ALTER TABLE "billing_alerts" ADD CONSTRAINT "billing_alerts_alert_payment_id_fkey" FOREIGN KEY ("alert_payment_id") REFERENCES "payments"("payment_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1627
|
+
|
|
1628
|
+
-- AddForeignKey
|
|
1629
|
+
ALTER TABLE "stt_usages" ADD CONSTRAINT "stt_usages_stt_tenant_id_fkey" FOREIGN KEY ("stt_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1630
|
+
|
|
1631
|
+
-- AddForeignKey
|
|
1632
|
+
ALTER TABLE "stt_usages" ADD CONSTRAINT "stt_usages_stt_clinic_id_fkey" FOREIGN KEY ("stt_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1633
|
+
|
|
1634
|
+
-- AddForeignKey
|
|
1635
|
+
ALTER TABLE "summaries" ADD CONSTRAINT "summaries_summary_transcription_id_fkey" FOREIGN KEY ("summary_transcription_id") REFERENCES "transcriptions"("tx_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1636
|
+
|
|
1637
|
+
-- AddForeignKey
|
|
1638
|
+
ALTER TABLE "patients" ADD CONSTRAINT "patients_patient_tenant_id_fkey" FOREIGN KEY ("patient_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1639
|
+
|
|
1640
|
+
-- AddForeignKey
|
|
1641
|
+
ALTER TABLE "patients" ADD CONSTRAINT "patients_patient_clinic_id_fkey" FOREIGN KEY ("patient_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1642
|
+
|
|
1643
|
+
-- AddForeignKey
|
|
1644
|
+
ALTER TABLE "patient_medical_histories" ADD CONSTRAINT "patient_medical_histories_history_patient_id_fkey" FOREIGN KEY ("history_patient_id") REFERENCES "patients"("patient_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1645
|
+
|
|
1646
|
+
-- AddForeignKey
|
|
1647
|
+
ALTER TABLE "patient_documents" ADD CONSTRAINT "patient_documents_doc_patient_id_fkey" FOREIGN KEY ("doc_patient_id") REFERENCES "patients"("patient_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1648
|
+
|
|
1649
|
+
-- AddForeignKey
|
|
1650
|
+
ALTER TABLE "patient_documents" ADD CONSTRAINT "patient_documents_doc_tenant_id_fkey" FOREIGN KEY ("doc_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1651
|
+
|
|
1652
|
+
-- AddForeignKey
|
|
1653
|
+
ALTER TABLE "patient_documents" ADD CONSTRAINT "patient_documents_doc_clinic_id_fkey" FOREIGN KEY ("doc_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1654
|
+
|
|
1655
|
+
-- AddForeignKey
|
|
1656
|
+
ALTER TABLE "patient_documents" ADD CONSTRAINT "patient_documents_doc_appointment_id_fkey" FOREIGN KEY ("doc_appointment_id") REFERENCES "appointments"("appt_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1657
|
+
|
|
1658
|
+
-- AddForeignKey
|
|
1659
|
+
ALTER TABLE "patient_documents" ADD CONSTRAINT "patient_documents_doc_uploaded_by_fkey" FOREIGN KEY ("doc_uploaded_by") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1660
|
+
|
|
1661
|
+
-- AddForeignKey
|
|
1662
|
+
ALTER TABLE "patient_notes" ADD CONSTRAINT "patient_notes_note_patient_id_fkey" FOREIGN KEY ("note_patient_id") REFERENCES "patients"("patient_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1663
|
+
|
|
1664
|
+
-- AddForeignKey
|
|
1665
|
+
ALTER TABLE "patient_notes" ADD CONSTRAINT "patient_notes_note_tenant_id_fkey" FOREIGN KEY ("note_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1666
|
+
|
|
1667
|
+
-- AddForeignKey
|
|
1668
|
+
ALTER TABLE "patient_notes" ADD CONSTRAINT "patient_notes_note_clinic_id_fkey" FOREIGN KEY ("note_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1669
|
+
|
|
1670
|
+
-- AddForeignKey
|
|
1671
|
+
ALTER TABLE "patient_notes" ADD CONSTRAINT "patient_notes_note_author_id_fkey" FOREIGN KEY ("note_author_id") REFERENCES "users"("user_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1672
|
+
|
|
1673
|
+
-- AddForeignKey
|
|
1674
|
+
ALTER TABLE "treatments" ADD CONSTRAINT "treatments_treatment_tenant_id_fkey" FOREIGN KEY ("treatment_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1675
|
+
|
|
1676
|
+
-- AddForeignKey
|
|
1677
|
+
ALTER TABLE "treatments" ADD CONSTRAINT "treatments_treatment_clinic_id_fkey" FOREIGN KEY ("treatment_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1678
|
+
|
|
1679
|
+
-- AddForeignKey
|
|
1680
|
+
ALTER TABLE "treatment_plans" ADD CONSTRAINT "treatment_plans_tplan_tenant_id_fkey" FOREIGN KEY ("tplan_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1681
|
+
|
|
1682
|
+
-- AddForeignKey
|
|
1683
|
+
ALTER TABLE "treatment_plans" ADD CONSTRAINT "treatment_plans_tplan_clinic_id_fkey" FOREIGN KEY ("tplan_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1684
|
+
|
|
1685
|
+
-- AddForeignKey
|
|
1686
|
+
ALTER TABLE "treatment_plans" ADD CONSTRAINT "treatment_plans_tplan_patient_id_fkey" FOREIGN KEY ("tplan_patient_id") REFERENCES "patients"("patient_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1687
|
+
|
|
1688
|
+
-- AddForeignKey
|
|
1689
|
+
ALTER TABLE "treatment_plans" ADD CONSTRAINT "treatment_plans_tplan_doctor_id_fkey" FOREIGN KEY ("tplan_doctor_id") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1690
|
+
|
|
1691
|
+
-- AddForeignKey
|
|
1692
|
+
ALTER TABLE "treatment_plan_items" ADD CONSTRAINT "treatment_plan_items_tpitem_plan_id_fkey" FOREIGN KEY ("tpitem_plan_id") REFERENCES "treatment_plans"("tplan_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1693
|
+
|
|
1694
|
+
-- AddForeignKey
|
|
1695
|
+
ALTER TABLE "treatment_plan_items" ADD CONSTRAINT "treatment_plan_items_tpitem_treatment_id_fkey" FOREIGN KEY ("tpitem_treatment_id") REFERENCES "treatments"("treatment_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1696
|
+
|
|
1697
|
+
-- AddForeignKey
|
|
1698
|
+
ALTER TABLE "treatment_plan_items" ADD CONSTRAINT "treatment_plan_items_tpitem_appointment_id_fkey" FOREIGN KEY ("tpitem_appointment_id") REFERENCES "appointments"("appt_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1699
|
+
|
|
1700
|
+
-- AddForeignKey
|
|
1701
|
+
ALTER TABLE "doctor_profiles" ADD CONSTRAINT "doctor_profiles_dprofile_user_id_fkey" FOREIGN KEY ("dprofile_user_id") REFERENCES "users"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1702
|
+
|
|
1703
|
+
-- AddForeignKey
|
|
1704
|
+
ALTER TABLE "patient_photo_sets" ADD CONSTRAINT "patient_photo_sets_photoset_patient_id_fkey" FOREIGN KEY ("photoset_patient_id") REFERENCES "patients"("patient_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1705
|
+
|
|
1706
|
+
-- AddForeignKey
|
|
1707
|
+
ALTER TABLE "patient_photo_sets" ADD CONSTRAINT "patient_photo_sets_photoset_tenant_id_fkey" FOREIGN KEY ("photoset_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1708
|
+
|
|
1709
|
+
-- AddForeignKey
|
|
1710
|
+
ALTER TABLE "patient_photo_sets" ADD CONSTRAINT "patient_photo_sets_photoset_clinic_id_fkey" FOREIGN KEY ("photoset_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1711
|
+
|
|
1712
|
+
-- AddForeignKey
|
|
1713
|
+
ALTER TABLE "patient_photo_sets" ADD CONSTRAINT "patient_photo_sets_photoset_treatment_plan_id_fkey" FOREIGN KEY ("photoset_treatment_plan_id") REFERENCES "treatment_plans"("tplan_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1714
|
+
|
|
1715
|
+
-- AddForeignKey
|
|
1716
|
+
ALTER TABLE "patient_photo_sets" ADD CONSTRAINT "patient_photo_sets_photoset_taken_by_fkey" FOREIGN KEY ("photoset_taken_by") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1717
|
+
|
|
1718
|
+
-- AddForeignKey
|
|
1719
|
+
ALTER TABLE "patient_photos" ADD CONSTRAINT "patient_photos_photo_set_id_fkey" FOREIGN KEY ("photo_set_id") REFERENCES "patient_photo_sets"("photoset_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1720
|
+
|
|
1721
|
+
-- AddForeignKey
|
|
1722
|
+
ALTER TABLE "examination_records" ADD CONSTRAINT "examination_records_exam_appointment_id_fkey" FOREIGN KEY ("exam_appointment_id") REFERENCES "appointments"("appt_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1723
|
+
|
|
1724
|
+
-- AddForeignKey
|
|
1725
|
+
ALTER TABLE "examination_records" ADD CONSTRAINT "examination_records_exam_patient_id_fkey" FOREIGN KEY ("exam_patient_id") REFERENCES "patients"("patient_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1726
|
+
|
|
1727
|
+
-- AddForeignKey
|
|
1728
|
+
ALTER TABLE "examination_records" ADD CONSTRAINT "examination_records_exam_doctor_id_fkey" FOREIGN KEY ("exam_doctor_id") REFERENCES "users"("user_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1729
|
+
|
|
1730
|
+
-- AddForeignKey
|
|
1731
|
+
ALTER TABLE "examination_records" ADD CONSTRAINT "examination_records_exam_clinic_id_fkey" FOREIGN KEY ("exam_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1732
|
+
|
|
1733
|
+
-- AddForeignKey
|
|
1734
|
+
ALTER TABLE "examination_records" ADD CONSTRAINT "examination_records_exam_tenant_id_fkey" FOREIGN KEY ("exam_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1735
|
+
|
|
1736
|
+
-- AddForeignKey
|
|
1737
|
+
ALTER TABLE "availability_blocks" ADD CONSTRAINT "availability_blocks_block_tenant_id_fkey" FOREIGN KEY ("block_tenant_id") REFERENCES "tenants"("tenant_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
1738
|
+
|
|
1739
|
+
-- AddForeignKey
|
|
1740
|
+
ALTER TABLE "availability_blocks" ADD CONSTRAINT "availability_blocks_block_clinic_id_fkey" FOREIGN KEY ("block_clinic_id") REFERENCES "clinics"("clinic_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
1741
|
+
|
|
1742
|
+
-- AddForeignKey
|
|
1743
|
+
ALTER TABLE "availability_blocks" ADD CONSTRAINT "availability_blocks_block_doctor_id_fkey" FOREIGN KEY ("block_doctor_id") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
1744
|
+
|
|
1745
|
+
-- AddForeignKey
|
|
1746
|
+
ALTER TABLE "availability_blocks" ADD CONSTRAINT "availability_blocks_block_created_by_fkey" FOREIGN KEY ("block_created_by") REFERENCES "users"("user_id") ON DELETE SET NULL ON UPDATE CASCADE;
|