workspace-v1/projects/erp-suite/apps/verticales/clinicas/database/init/02-rls-functions.sql
Adrian Flores Cortes 967ab360bb Initial commit: Workspace v1 with 3-layer architecture
Structure:
- control-plane/: Registries, SIMCO directives, CI/CD templates
- projects/: Gamilit, ERP-Suite, Trading-Platform, Betting-Analytics
- shared/: Libs catalog, knowledge-base

Key features:
- Centralized port, domain, database, and service registries
- 23 SIMCO directives + 6 fundamental principles
- NEXUS agent profiles with delegation rules
- Validation scripts for workspace integrity
- Dockerfiles for all services
- Path aliases for quick reference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 00:35:19 -06:00

38 lines
1.4 KiB
PL/PgSQL

-- ============================================================================
-- FUNCIONES RLS - ERP Clínicas
-- ============================================================================
-- Versión: 1.0.0
-- Fecha: 2025-12-09
-- Nota: Usa las funciones de contexto de ERP-Core (auth schema)
-- ============================================================================
-- Las funciones principales están en ERP-Core:
-- auth.get_current_tenant_id()
-- auth.get_current_user_id()
-- auth.get_current_company_id()
-- Función auxiliar para verificar acceso a expediente médico
CREATE OR REPLACE FUNCTION clinica.can_access_medical_record(
p_patient_id UUID,
p_user_id UUID DEFAULT NULL
)
RETURNS BOOLEAN AS $$
DECLARE
v_user_id UUID;
v_has_access BOOLEAN := FALSE;
BEGIN
v_user_id := COALESCE(p_user_id, current_setting('app.current_user_id', true)::UUID);
-- TODO: Implementar lógica de permisos específicos
-- Por ahora, cualquier usuario del tenant puede acceder
RETURN TRUE;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
COMMENT ON FUNCTION clinica.can_access_medical_record IS
'Verifica si el usuario tiene permiso para acceder al expediente médico del paciente';
-- ============================================================================
-- FIN FUNCIONES RLS
-- ============================================================================