[PROP-CORE-004] feat: Adapt AI roles for medical clinic domain
- Roles: ADMIN, DOCTOR, RECEPCIONISTA, PACIENTE - Clinical data restricted to DOCTOR only - Compliance: NOM-024-SSA3-2012, LFPDPPP - Medical terminology and privacy restrictions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
297720cdf2
commit
07877410d3
@ -1,17 +1,20 @@
|
|||||||
/**
|
/**
|
||||||
* ERP Roles Configuration
|
* ERP Clínicas - Roles Configuration
|
||||||
*
|
*
|
||||||
* Define roles, tools permitidos, y system prompts para cada rol en el ERP.
|
* Roles específicos para operaciones de clínicas médicas.
|
||||||
* Basado en: michangarrito MCH-012/MCH-013 (role-based chatbot)
|
* Adaptado desde erp-core v1.5.0 (PROP-CORE-004)
|
||||||
*
|
*
|
||||||
* Roles disponibles:
|
* IMPORTANTE: Datos clínicos restringidos solo a DOCTOR.
|
||||||
* - ADMIN: Acceso completo a todas las operaciones
|
* Cumplimiento: NOM-024-SSA3-2012, LFPDPPP
|
||||||
* - SUPERVISOR: Gestión de equipos y reportes de sucursal
|
*
|
||||||
* - OPERATOR: Operaciones de punto de venta
|
* Roles:
|
||||||
* - CUSTOMER: Acceso limitado para clientes (si se expone chatbot)
|
* - ADMIN: Director de clínica - acceso administrativo completo
|
||||||
|
* - DOCTOR: Médico - acceso a expedientes de sus pacientes
|
||||||
|
* - RECEPCIONISTA: Citas, pagos, agenda (sin acceso a expedientes)
|
||||||
|
* - PACIENTE: Solo sus citas y expediente propio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type ERPRole = 'ADMIN' | 'SUPERVISOR' | 'OPERATOR' | 'CUSTOMER';
|
export type ERPRole = 'ADMIN' | 'DOCTOR' | 'RECEPCIONISTA' | 'PACIENTE';
|
||||||
|
|
||||||
export interface ERPRoleConfig {
|
export interface ERPRoleConfig {
|
||||||
name: string;
|
name: string;
|
||||||
@ -19,234 +22,126 @@ export interface ERPRoleConfig {
|
|||||||
tools: string[];
|
tools: string[];
|
||||||
systemPromptFile: string;
|
systemPromptFile: string;
|
||||||
maxConversationHistory: number;
|
maxConversationHistory: number;
|
||||||
allowedModels?: string[]; // Si vacío, usa el default del tenant
|
allowedModels?: string[];
|
||||||
rateLimit: {
|
rateLimit: {
|
||||||
requestsPerMinute: number;
|
requestsPerMinute: number;
|
||||||
tokensPerMinute: number;
|
tokensPerMinute: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuración de roles ERP
|
|
||||||
*/
|
|
||||||
export const ERP_ROLES: Record<ERPRole, ERPRoleConfig> = {
|
export const ERP_ROLES: Record<ERPRole, ERPRoleConfig> = {
|
||||||
ADMIN: {
|
ADMIN: {
|
||||||
name: 'Administrador',
|
name: 'Director de Clínica',
|
||||||
description: 'Acceso completo a todas las operaciones del sistema ERP',
|
description: 'Director o administrador con acceso completo excepto expedientes clínicos',
|
||||||
tools: [
|
tools: [
|
||||||
// Ventas
|
|
||||||
'get_sales_summary',
|
|
||||||
'get_sales_report',
|
|
||||||
'get_top_products',
|
|
||||||
'get_top_customers',
|
|
||||||
'get_sales_by_branch',
|
|
||||||
'create_sale',
|
|
||||||
'void_sale',
|
|
||||||
|
|
||||||
// Inventario
|
|
||||||
'get_inventory_status',
|
|
||||||
'get_low_stock_products',
|
|
||||||
'get_inventory_value',
|
|
||||||
'adjust_inventory',
|
|
||||||
'transfer_inventory',
|
|
||||||
|
|
||||||
// Compras
|
|
||||||
'get_pending_orders',
|
|
||||||
'get_supplier_info',
|
|
||||||
'create_purchase_order',
|
|
||||||
'approve_purchase',
|
|
||||||
|
|
||||||
// Finanzas
|
// Finanzas
|
||||||
'get_financial_report',
|
'get_financial_report', 'get_accounts_receivable', 'get_kpis', 'get_cash_flow',
|
||||||
'get_accounts_receivable',
|
// Configuración
|
||||||
'get_accounts_payable',
|
'manage_users', 'view_audit_logs', 'update_settings',
|
||||||
'get_cash_flow',
|
'get_branch_info', 'manage_branches',
|
||||||
|
// Agenda (sin datos clínicos)
|
||||||
// Usuarios y configuración
|
'get_appointments_summary', 'get_doctor_schedules', 'manage_schedules',
|
||||||
'manage_users',
|
// Reportes administrativos
|
||||||
'view_audit_logs',
|
'generate_report', 'export_data',
|
||||||
'update_settings',
|
// Inventario (insumos)
|
||||||
'get_branch_info',
|
'get_inventory_status', 'get_low_stock_products', 'create_purchase_order',
|
||||||
'manage_branches',
|
// TPV
|
||||||
|
'configure_terminal', 'get_payment_history', 'process_refund',
|
||||||
// Reportes avanzados
|
|
||||||
'generate_report',
|
|
||||||
'export_data',
|
|
||||||
'get_kpis',
|
|
||||||
],
|
],
|
||||||
systemPromptFile: 'admin-system-prompt',
|
systemPromptFile: 'admin-system-prompt',
|
||||||
maxConversationHistory: 50,
|
maxConversationHistory: 50,
|
||||||
rateLimit: {
|
rateLimit: { requestsPerMinute: 100, tokensPerMinute: 50000 },
|
||||||
requestsPerMinute: 100,
|
|
||||||
tokensPerMinute: 50000,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
SUPERVISOR: {
|
DOCTOR: {
|
||||||
name: 'Supervisor',
|
name: 'Médico',
|
||||||
description: 'Gestión de equipos, reportes de sucursal y aprobaciones',
|
description: 'Médico con acceso a expedientes de sus pacientes asignados',
|
||||||
tools: [
|
tools: [
|
||||||
// Ventas (lectura + acciones limitadas)
|
// Expedientes (SOLO sus pacientes)
|
||||||
'get_sales_summary',
|
'get_patient_history', 'get_patient_vitals', 'add_consultation_note',
|
||||||
'get_sales_report',
|
'get_patient_prescriptions', 'create_prescription',
|
||||||
'get_top_products',
|
'get_patient_labs', 'order_lab_test',
|
||||||
'get_sales_by_branch',
|
// Diagnósticos
|
||||||
'create_sale',
|
'search_cie10', 'get_drug_interactions', 'get_treatment_guidelines',
|
||||||
|
// Agenda
|
||||||
// Inventario (lectura + ajustes)
|
'get_my_appointments', 'get_my_schedule', 'complete_appointment',
|
||||||
'get_inventory_status',
|
|
||||||
'get_low_stock_products',
|
|
||||||
'adjust_inventory',
|
|
||||||
|
|
||||||
// Equipo
|
|
||||||
'get_team_performance',
|
|
||||||
'get_employee_schedule',
|
|
||||||
'manage_schedules',
|
|
||||||
|
|
||||||
// Aprobaciones
|
|
||||||
'approve_discounts',
|
|
||||||
'approve_voids',
|
|
||||||
'approve_refunds',
|
|
||||||
|
|
||||||
// Sucursal
|
// Sucursal
|
||||||
'get_branch_info',
|
'get_branch_info', 'get_branch_hours',
|
||||||
'get_branch_report',
|
|
||||||
|
|
||||||
// Clientes
|
|
||||||
'get_customer_info',
|
|
||||||
'get_customer_balance',
|
|
||||||
],
|
],
|
||||||
systemPromptFile: 'supervisor-system-prompt',
|
systemPromptFile: 'supervisor-system-prompt',
|
||||||
maxConversationHistory: 30,
|
maxConversationHistory: 30,
|
||||||
rateLimit: {
|
rateLimit: { requestsPerMinute: 60, tokensPerMinute: 30000 },
|
||||||
requestsPerMinute: 60,
|
|
||||||
tokensPerMinute: 30000,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
OPERATOR: {
|
RECEPCIONISTA: {
|
||||||
name: 'Operador',
|
name: 'Recepcionista',
|
||||||
description: 'Operaciones de punto de venta y consultas básicas',
|
description: 'Recepción con gestión de citas, pagos y agenda (sin acceso a expedientes)',
|
||||||
tools: [
|
tools: [
|
||||||
// Productos
|
// Agenda
|
||||||
'search_products',
|
'search_patients', 'create_appointment', 'reschedule_appointment',
|
||||||
'get_product_price',
|
'cancel_appointment', 'get_available_slots', 'confirm_appointment',
|
||||||
'check_product_availability',
|
// Pagos
|
||||||
|
'register_payment', 'get_patient_balance', 'create_invoice',
|
||||||
// Ventas
|
'process_card_payment', 'process_cash_payment', 'print_receipt',
|
||||||
'create_sale',
|
|
||||||
'get_my_sales',
|
|
||||||
'apply_discount', // Con límite
|
|
||||||
|
|
||||||
// Clientes
|
|
||||||
'search_customers',
|
|
||||||
'get_customer_balance',
|
|
||||||
'register_payment',
|
|
||||||
|
|
||||||
// Inventario (solo lectura)
|
|
||||||
'check_stock',
|
|
||||||
|
|
||||||
// Información
|
// Información
|
||||||
'get_branch_hours',
|
'get_branch_hours', 'get_doctor_schedules', 'get_services_catalog',
|
||||||
'get_promotions',
|
// Comunicación
|
||||||
|
'send_appointment_reminder',
|
||||||
],
|
],
|
||||||
systemPromptFile: 'operator-system-prompt',
|
systemPromptFile: 'operator-system-prompt',
|
||||||
maxConversationHistory: 20,
|
maxConversationHistory: 20,
|
||||||
rateLimit: {
|
rateLimit: { requestsPerMinute: 30, tokensPerMinute: 15000 },
|
||||||
requestsPerMinute: 30,
|
|
||||||
tokensPerMinute: 15000,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
CUSTOMER: {
|
PACIENTE: {
|
||||||
name: 'Cliente',
|
name: 'Paciente',
|
||||||
description: 'Acceso limitado para clientes externos',
|
description: 'Paciente con acceso solo a sus citas y expediente propio',
|
||||||
tools: [
|
tools: [
|
||||||
// Catálogo
|
// Sus citas
|
||||||
'view_catalog',
|
'get_my_appointments', 'request_appointment', 'cancel_my_appointment',
|
||||||
'search_products',
|
// Su expediente (solo lectura)
|
||||||
'check_availability',
|
'get_my_history', 'get_my_prescriptions', 'get_my_results',
|
||||||
|
|
||||||
// Pedidos
|
|
||||||
'get_my_orders',
|
|
||||||
'track_order',
|
|
||||||
|
|
||||||
// Cuenta
|
// Cuenta
|
||||||
'get_my_balance',
|
'get_my_balance', 'get_my_invoices',
|
||||||
'get_my_history',
|
|
||||||
|
|
||||||
// Soporte
|
// Soporte
|
||||||
'contact_support',
|
'contact_support', 'get_clinic_info', 'get_doctor_info',
|
||||||
'get_store_info',
|
|
||||||
'get_promotions',
|
|
||||||
],
|
],
|
||||||
systemPromptFile: 'customer-system-prompt',
|
systemPromptFile: 'customer-system-prompt',
|
||||||
maxConversationHistory: 10,
|
maxConversationHistory: 10,
|
||||||
rateLimit: {
|
rateLimit: { requestsPerMinute: 10, tokensPerMinute: 5000 },
|
||||||
requestsPerMinute: 10,
|
|
||||||
tokensPerMinute: 5000,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Mapeo de rol de base de datos a ERPRole
|
|
||||||
*/
|
|
||||||
export const DB_ROLE_MAPPING: Record<string, ERPRole> = {
|
export const DB_ROLE_MAPPING: Record<string, ERPRole> = {
|
||||||
// Roles típicos de sistema
|
// Administradores
|
||||||
admin: 'ADMIN',
|
admin: 'ADMIN', administrator: 'ADMIN', director: 'ADMIN', owner: 'ADMIN',
|
||||||
administrator: 'ADMIN',
|
// Doctores
|
||||||
superadmin: 'ADMIN',
|
doctor: 'DOCTOR', medico: 'DOCTOR', physician: 'DOCTOR',
|
||||||
owner: 'ADMIN',
|
especialista: 'DOCTOR', dentista: 'DOCTOR', veterinario: 'DOCTOR',
|
||||||
|
// Recepcionistas
|
||||||
// Supervisores
|
recepcionista: 'RECEPCIONISTA', receptionist: 'RECEPCIONISTA',
|
||||||
supervisor: 'SUPERVISOR',
|
asistente: 'RECEPCIONISTA', secretary: 'RECEPCIONISTA', operator: 'RECEPCIONISTA',
|
||||||
manager: 'SUPERVISOR',
|
// Pacientes
|
||||||
branch_manager: 'SUPERVISOR',
|
paciente: 'PACIENTE', patient: 'PACIENTE', customer: 'PACIENTE', client: 'PACIENTE',
|
||||||
store_manager: 'SUPERVISOR',
|
|
||||||
|
|
||||||
// Operadores
|
|
||||||
operator: 'OPERATOR',
|
|
||||||
cashier: 'OPERATOR',
|
|
||||||
sales: 'OPERATOR',
|
|
||||||
employee: 'OPERATOR',
|
|
||||||
staff: 'OPERATOR',
|
|
||||||
|
|
||||||
// Clientes
|
|
||||||
customer: 'CUSTOMER',
|
|
||||||
client: 'CUSTOMER',
|
|
||||||
guest: 'CUSTOMER',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtener rol ERP desde rol de base de datos
|
|
||||||
*/
|
|
||||||
export function getERPRole(dbRole: string | undefined): ERPRole {
|
export function getERPRole(dbRole: string | undefined): ERPRole {
|
||||||
if (!dbRole) return 'CUSTOMER'; // Default para roles no mapeados
|
if (!dbRole) return 'PACIENTE';
|
||||||
const normalized = dbRole.toLowerCase().trim();
|
const normalized = dbRole.toLowerCase().trim();
|
||||||
return DB_ROLE_MAPPING[normalized] || 'CUSTOMER';
|
return DB_ROLE_MAPPING[normalized] || 'PACIENTE';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verificar si un rol tiene acceso a un tool
|
|
||||||
*/
|
|
||||||
export function hasToolAccess(role: ERPRole, toolName: string): boolean {
|
export function hasToolAccess(role: ERPRole, toolName: string): boolean {
|
||||||
const roleConfig = ERP_ROLES[role];
|
const roleConfig = ERP_ROLES[role];
|
||||||
if (!roleConfig) return false;
|
if (!roleConfig) return false;
|
||||||
return roleConfig.tools.includes(toolName);
|
return roleConfig.tools.includes(toolName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtener todos los tools para un rol
|
|
||||||
*/
|
|
||||||
export function getToolsForRole(role: ERPRole): string[] {
|
export function getToolsForRole(role: ERPRole): string[] {
|
||||||
const roleConfig = ERP_ROLES[role];
|
const roleConfig = ERP_ROLES[role];
|
||||||
return roleConfig?.tools || [];
|
return roleConfig?.tools || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtener configuración completa de un rol
|
|
||||||
*/
|
|
||||||
export function getRoleConfig(role: ERPRole): ERPRoleConfig | null {
|
export function getRoleConfig(role: ERPRole): ERPRoleConfig | null {
|
||||||
return ERP_ROLES[role] || null;
|
return ERP_ROLES[role] || null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user