chore: Remove duplicated TRIGGER-COHERENCIA-CAPAS files
- Removed 2 files from _archive/directivas/ - These files should be inherited from workspace, not copied Part of: TASK-2026-02-02-ANALISIS-REESTRUCTURACION-ORCHESTRATION Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a86d26847f
commit
b40303fe08
@ -1,187 +0,0 @@
|
||||
# TRIGGER: Coherencia Entre Capas - Clinica Veterinaria
|
||||
|
||||
**ID:** TRIGGER-VET-COHERENCIA
|
||||
**Version:** 1.0.0
|
||||
**Proyecto:** clinica-veterinaria
|
||||
**Hereda de:** @ERP_TRIGGER_COHERENCIA -> @CLINICAS_TRIGGER_COHERENCIA
|
||||
**Alias:** @VET_TRIGGER_COHERENCIA
|
||||
|
||||
---
|
||||
|
||||
## Proposito
|
||||
|
||||
Validar que cada objeto creado en una capa tenga su correspondiente en las demas capas, manteniendo coherencia DDL - Backend - Frontend, con validaciones especificas para el dominio veterinario.
|
||||
|
||||
## Cadena de Herencia
|
||||
|
||||
```
|
||||
template-saas (PROVIDER)
|
||||
|
|
||||
v
|
||||
erp-core (INTERMEDIATE)
|
||||
|
|
||||
v
|
||||
erp-clinicas (CONSUMER)
|
||||
|
|
||||
v
|
||||
clinica-veterinaria (SUB-VERTICAL) <- ESTE PROYECTO
|
||||
```
|
||||
|
||||
## Activacion
|
||||
|
||||
### Automatica
|
||||
- Creacion/modificacion de tabla DDL en schema `sub_veterinaria`
|
||||
- Creacion/modificacion de entity TypeORM en modulos veterinarios
|
||||
- Creacion/modificacion de endpoint API especifico veterinario
|
||||
|
||||
### Manual
|
||||
- Comando: `@VET_VALIDATE_COHERENCE`
|
||||
- Pre-commit hook
|
||||
|
||||
## Reglas de Validacion
|
||||
|
||||
### DDL -> Backend (OBLIGATORIO)
|
||||
|
||||
```yaml
|
||||
regla_1:
|
||||
condicion: "Nueva tabla DDL creada en sub_veterinaria.*"
|
||||
accion: "Verificar entity correspondiente existe"
|
||||
bloquea: true
|
||||
|
||||
regla_2:
|
||||
condicion: "Columna agregada a tabla veterinaria"
|
||||
accion: "Verificar campo en entity existe"
|
||||
bloquea: true
|
||||
|
||||
regla_3:
|
||||
condicion: "Constraint FK agregado a tabla veterinaria"
|
||||
accion: "Verificar relacion TypeORM existe"
|
||||
bloquea: true
|
||||
```
|
||||
|
||||
### Backend -> Frontend (CONDICIONAL)
|
||||
|
||||
```yaml
|
||||
regla_4:
|
||||
condicion: "Endpoint CRUD veterinario creado"
|
||||
accion: "Verificar hook/servicio frontend existe"
|
||||
bloquea: false # Solo warning
|
||||
|
||||
regla_5:
|
||||
condicion: "DTO veterinario modificado"
|
||||
accion: "Verificar tipos TypeScript frontend"
|
||||
bloquea: false
|
||||
```
|
||||
|
||||
## Validaciones Especificas Clinica Veterinaria
|
||||
|
||||
### Modulos CVT (Clinica Veterinaria)
|
||||
|
||||
| Modulo | DDL Schema | Backend Path | Frontend Path |
|
||||
|--------|------------|--------------|---------------|
|
||||
| CVT-001 Mascotas | sub_veterinaria.pets, pet_owners | modules/mascotas/ | pages/mascotas/ |
|
||||
| CVT-002 Vacunacion | sub_veterinaria.vaccinations | modules/vacunacion/ | pages/vacunacion/ |
|
||||
| CVT-003 Desparasitaciones | sub_veterinaria.dewormings | modules/desparasitaciones/ | pages/desparasitaciones/ |
|
||||
| CVT-004 Hospitalizacion | sub_veterinaria.hospitalizations | modules/hospitalizacion/ | pages/hospitalizacion/ |
|
||||
| CVT-005 Estetica Canina | sub_veterinaria.grooming_* | modules/estetica/ | pages/estetica/ |
|
||||
| CVT-006 Farmacia Veterinaria | sub_veterinaria.vet_medications | modules/farmacia/ | pages/farmacia/ |
|
||||
|
||||
### Coherencia de Nombres
|
||||
|
||||
```
|
||||
DDL: sub_veterinaria.tabla_nombre (snake_case)
|
||||
Entity: TablaNombre (PascalCase)
|
||||
Service: tabla-nombre.service.ts (kebab-case)
|
||||
Controller: tabla-nombre.controller.ts (kebab-case)
|
||||
```
|
||||
|
||||
## Validaciones Normativas (NOM-064-ZOO-2000)
|
||||
|
||||
### Campos Obligatorios para Expediente Veterinario
|
||||
|
||||
```yaml
|
||||
validacion_normativa:
|
||||
condicion: "Entity de expediente veterinario"
|
||||
campos_requeridos:
|
||||
- "especie"
|
||||
- "raza"
|
||||
- "sexo"
|
||||
- "edad_aproximada"
|
||||
- "peso"
|
||||
- "chip_id" # Si aplica
|
||||
- "propietario_id"
|
||||
- "historial_vacunacion"
|
||||
- "historial_desparasitacion"
|
||||
- "alergias_conocidas"
|
||||
- "diagnostico"
|
||||
- "tratamiento"
|
||||
referencia_normativa: "NOM-064-ZOO-2000"
|
||||
bloquea: true
|
||||
```
|
||||
|
||||
### Integridad de Registro de Mascotas
|
||||
|
||||
```yaml
|
||||
validacion_mascotas:
|
||||
condicion: "Tabla pets creada/modificada"
|
||||
reglas:
|
||||
- "Especie obligatoria (catalogo SENASICA)"
|
||||
- "Propietario vinculado obligatorio"
|
||||
- "Historial medico trazable"
|
||||
- "Chip/Identificacion unica"
|
||||
bloquea: true
|
||||
```
|
||||
|
||||
### Control de Vacunacion
|
||||
|
||||
```yaml
|
||||
validacion_vacunas:
|
||||
condicion: "Tabla vaccinations creada/modificada"
|
||||
reglas:
|
||||
- "Lote de vacuna registrado"
|
||||
- "Fecha de aplicacion"
|
||||
- "Fecha de proxima aplicacion"
|
||||
- "Medico veterinario responsable"
|
||||
- "Consentimiento del propietario"
|
||||
referencia_normativa: "SENASICA"
|
||||
bloquea: true
|
||||
```
|
||||
|
||||
## Excepciones Permitidas
|
||||
|
||||
1. **Tablas M:N gestionadas por TypeORM**
|
||||
- Documentar en ENTITIES-CATALOG.md
|
||||
|
||||
2. **Tablas de auditoria/sistema**
|
||||
- Prefijo: `_audit_vet`, `_system_vet`
|
||||
|
||||
3. **Tablas heredadas de erp-clinicas**
|
||||
- No requieren entity local si se usa la del padre (adaptada)
|
||||
|
||||
4. **Vistas para reportes sanitarios**
|
||||
- Documentar en DATABASE-SCHEMA.md
|
||||
|
||||
## Metricas
|
||||
|
||||
| Metrica | Objetivo | Actual |
|
||||
|---------|----------|--------|
|
||||
| Coherencia DDL-Entity | 100% | TBD |
|
||||
| Coherencia Entity-Service | 100% | TBD |
|
||||
| Coherencia API-Frontend | 95% | TBD |
|
||||
| Cumplimiento NOM-064 | 100% | TBD |
|
||||
|
||||
## Referencias
|
||||
|
||||
- `@VET_DEF_DB` - DATABASE-SCHEMA.md
|
||||
- `@VET_DEF_ENTITIES` - ENTITIES-CATALOG.md
|
||||
- `@CLINICAS_TRIGGER_COHERENCIA` - Trigger padre en erp-clinicas
|
||||
- `@ERP_TRIGGER_COHERENCIA` - Trigger abuelo en erp-core
|
||||
- `@WS_TRIGGER_COHERENCIA` - Trigger raiz del workspace
|
||||
|
||||
---
|
||||
|
||||
**Normativa Aplicable:**
|
||||
- NOM-064-ZOO-2000: Requisitos para establecimientos de atencion medica veterinaria
|
||||
- NOM-051-ZOO-1995: Trato humanitario en movilizacion de animales
|
||||
- SENASICA: Servicio Nacional de Sanidad, Inocuidad y Calidad Agroalimentaria
|
||||
- NOM-033-SAG/ZOO-2014: Metodos para dar muerte a animales domesticos y silvestres
|
||||
@ -1,311 +0,0 @@
|
||||
# TRIGGER: COHERENCIA ENTRE CAPAS
|
||||
|
||||
**Versión:** 1.0.0
|
||||
**Fecha:** 2026-01-16
|
||||
**Sistema:** SIMCO v4.0.0
|
||||
**Alias:** @TRIGGER_COHERENCIA
|
||||
|
||||
---
|
||||
|
||||
## RESUMEN EJECUTIVO
|
||||
|
||||
Este trigger OBLIGA a mantener coherencia entre las capas DDL, Backend y Frontend. Se activa automáticamente cuando se crea o modifica cualquier objeto en cualquier capa.
|
||||
|
||||
**PRINCIPIO:** "Ninguna capa puede tener objetos huérfanos. Todo DDL debe tener entity, todo entity que requiera persistencia debe tener DDL."
|
||||
|
||||
---
|
||||
|
||||
## CONDICIONES DE ACTIVACIÓN
|
||||
|
||||
```yaml
|
||||
activar_cuando:
|
||||
DDL:
|
||||
- Se crea nueva tabla (CREATE TABLE)
|
||||
- Se modifica estructura de tabla (ALTER TABLE)
|
||||
- Se crea nuevo schema
|
||||
- Se elimina tabla o schema
|
||||
|
||||
Backend:
|
||||
- Se crea nueva entity
|
||||
- Se modifica entity existente
|
||||
- Se crea nuevo módulo
|
||||
- Se elimina entity o módulo
|
||||
|
||||
Frontend:
|
||||
- Se crea componente que consume endpoint nuevo
|
||||
- Se crea store/hook que requiere datos de API
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## VERIFICACIONES OBLIGATORIAS
|
||||
|
||||
### 1. Al Crear Tabla DDL
|
||||
|
||||
```yaml
|
||||
ANTES_de_completar_tarea:
|
||||
verificar:
|
||||
- "¿Existe entity correspondiente en backend?"
|
||||
- "¿Entity tiene mismos campos que tabla?"
|
||||
- "¿Tipos de datos son compatibles (PostgreSQL ↔ TypeScript)?"
|
||||
- "¿Está documentada en DATABASE_INVENTORY.yml?"
|
||||
- "¿Está documentada en ENTITIES-CATALOG.md?"
|
||||
|
||||
si_no_existe_entity:
|
||||
accion: "BLOQUEAR hasta crear entity"
|
||||
excepcion: "Tablas de relación M:N pueden no tener entity si están documentadas como tal"
|
||||
|
||||
si_no_documentada:
|
||||
accion: "BLOQUEAR hasta documentar en inventarios"
|
||||
```
|
||||
|
||||
### 2. Al Crear Entity
|
||||
|
||||
```yaml
|
||||
ANTES_de_completar_tarea:
|
||||
verificar:
|
||||
- "¿Existe tabla DDL correspondiente?"
|
||||
- "¿Campos coinciden con DDL?"
|
||||
- "¿Decoradores TypeORM son correctos?"
|
||||
- "¿Está documentada en BACKEND_INVENTORY.yml?"
|
||||
- "¿Está documentada en ENTITIES-CATALOG.md?"
|
||||
|
||||
si_no_existe_tabla:
|
||||
accion: "BLOQUEAR hasta crear tabla DDL"
|
||||
excepcion: "Entities de solo lectura (views) deben estar documentadas"
|
||||
|
||||
si_no_documentada:
|
||||
accion: "BLOQUEAR hasta documentar en inventarios"
|
||||
```
|
||||
|
||||
### 3. Al Crear Módulo Backend
|
||||
|
||||
```yaml
|
||||
ANTES_de_completar_tarea:
|
||||
verificar:
|
||||
- "¿Todas las entities del módulo tienen tabla DDL?"
|
||||
- "¿Módulo está documentado en MODULES-CATALOG.md?"
|
||||
- "¿Servicios están documentados en SERVICES-CATALOG.md?"
|
||||
- "¿Endpoints están documentados en QUICK-API.yml?"
|
||||
|
||||
si_incompleto:
|
||||
accion: "BLOQUEAR hasta completar documentación"
|
||||
```
|
||||
|
||||
### 4. Al Crear Schema DDL
|
||||
|
||||
```yaml
|
||||
ANTES_de_completar_tarea:
|
||||
verificar:
|
||||
- "¿Schema tiene al menos un módulo backend correspondiente?"
|
||||
- "¿Schema está documentado en DATABASE-SCHEMA.md?"
|
||||
- "¿Schema está en DATABASE_INVENTORY.yml?"
|
||||
|
||||
si_schema_vacio:
|
||||
accion: "ADVERTIR - Schema sin tablas debe tener plan de uso"
|
||||
|
||||
si_no_documentado:
|
||||
accion: "BLOQUEAR hasta documentar"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## MATRIZ DE COHERENCIA
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ MATRIZ DE COHERENCIA │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ DDL (Schema/Tabla) │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ Tabla │────▶│ Entity │────▶│ Service │ │
|
||||
│ │ DDL │ │ TypeORM │ │ NestJS │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
│ │ │ │ │
|
||||
│ │ │ │ │
|
||||
│ ▼ ▼ ▼ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ DATABASE_ │ │ BACKEND_ │ │ QUICK- │ │
|
||||
│ │ INVENTORY │ │ INVENTORY │ │ API.yml │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
│ │ │ │ │
|
||||
│ └───────────────────┼───────────────────┘ │
|
||||
│ ▼ │
|
||||
│ ┌─────────────────┐ │
|
||||
│ │ ENTITIES-CATALOG│ │
|
||||
│ │ MODULES-CATALOG │ │
|
||||
│ │ SERVICES-CATALOG│ │
|
||||
│ └─────────────────┘ │
|
||||
│ │
|
||||
│ REGLA: Cada flecha representa una DEPENDENCIA OBLIGATORIA │
|
||||
│ No puede existir ningún nodo sin sus dependencias │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## EXCEPCIONES PERMITIDAS
|
||||
|
||||
```yaml
|
||||
excepciones:
|
||||
tablas_sin_entity:
|
||||
- tipo: "Tablas de relación M:N gestionadas por TypeORM"
|
||||
requisito: "Documentar en ENTITIES-CATALOG.md sección 'Relaciones'"
|
||||
ejemplo: "user_roles, permission_roles"
|
||||
|
||||
- tipo: "Tablas de auditoría automática"
|
||||
requisito: "Documentar en DATABASE-SCHEMA.md sección 'Audit'"
|
||||
ejemplo: "audit_logs, activity_logs"
|
||||
|
||||
- tipo: "Tablas de sistema/migración"
|
||||
requisito: "Documentar en DATABASE-SCHEMA.md sección 'System'"
|
||||
ejemplo: "migrations, typeorm_metadata"
|
||||
|
||||
entities_sin_tabla:
|
||||
- tipo: "View entities (solo lectura)"
|
||||
requisito: "Documentar como @ViewEntity con query"
|
||||
ejemplo: "UserStatsView, DashboardSummaryView"
|
||||
|
||||
- tipo: "Entities embebidas"
|
||||
requisito: "Documentar como @Embeddable"
|
||||
ejemplo: "AddressEmbed, MetadataEmbed"
|
||||
|
||||
schemas_sin_modulo:
|
||||
- tipo: "Schemas planificados (FUTURE)"
|
||||
requisito: "Documentar en DATABASE_INVENTORY con estado='PLANNED'"
|
||||
requisito_2: "Crear issue/ticket de implementación"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## FLUJO DE VALIDACIÓN
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ FLUJO DE VALIDACIÓN │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ 1. Agente completa tarea │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ 2. TRIGGER-COHERENCIA-CAPAS se activa │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ 3. Detectar tipo de cambio (DDL/BE/FE) │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ 4. Ejecutar verificaciones según tipo │
|
||||
│ │ │
|
||||
│ ├──── SI PASA ────▶ 5a. Permitir completar tarea │
|
||||
│ │ │
|
||||
│ └──── SI FALLA ───▶ 5b. BLOQUEAR y reportar gaps │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ 6. Agente debe: │
|
||||
│ - Crear objetos faltantes │
|
||||
│ - Documentar en inventarios │
|
||||
│ - Re-ejecutar validación │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## CHECKLIST DE COHERENCIA
|
||||
|
||||
### Para Cambios DDL
|
||||
|
||||
```markdown
|
||||
[ ] Tabla tiene entity correspondiente en backend
|
||||
[ ] Campos de entity coinciden con columnas de tabla
|
||||
[ ] Tipos de datos son compatibles
|
||||
[ ] Tabla documentada en DATABASE_INVENTORY.yml
|
||||
[ ] Schema documentado en DATABASE-SCHEMA.md
|
||||
[ ] Entity documentada en ENTITIES-CATALOG.md
|
||||
```
|
||||
|
||||
### Para Cambios Backend
|
||||
|
||||
```markdown
|
||||
[ ] Entity tiene tabla DDL correspondiente
|
||||
[ ] Campos coinciden con DDL
|
||||
[ ] Módulo documentado en MODULES-CATALOG.md
|
||||
[ ] Servicios documentados en SERVICES-CATALOG.md
|
||||
[ ] Entity documentada en BACKEND_INVENTORY.yml
|
||||
[ ] Endpoints documentados en QUICK-API.yml
|
||||
```
|
||||
|
||||
### Para Nuevo Schema
|
||||
|
||||
```markdown
|
||||
[ ] Schema tiene módulo backend planificado o existente
|
||||
[ ] Schema documentado en DATABASE-SCHEMA.md
|
||||
[ ] Schema en DATABASE_INVENTORY.yml
|
||||
[ ] Si no tiene módulo: documentar como PLANNED con fecha estimada
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## INTEGRACIÓN CON OTROS TRIGGERS
|
||||
|
||||
```yaml
|
||||
secuencia_triggers:
|
||||
1: "TRIGGER-ANTI-DUPLICACION" # Verificar no existe
|
||||
2: "TRIGGER-ANALISIS-DEPENDENCIAS" # Mapear impacto
|
||||
3: "TRIGGER-COHERENCIA-CAPAS" # ← ESTE TRIGGER
|
||||
4: "TRIGGER-DOCUMENTACION-OBLIGATORIA" # Documentar
|
||||
|
||||
orden: "TRIGGER-COHERENCIA-CAPAS se ejecuta ANTES de TRIGGER-DOC"
|
||||
razon: "No se puede documentar algo que no está coherente"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## MENSAJES DE ERROR
|
||||
|
||||
```yaml
|
||||
errores:
|
||||
E-COH-001:
|
||||
mensaje: "Tabla DDL sin entity correspondiente"
|
||||
accion: "Crear entity antes de completar tarea"
|
||||
bloqueante: true
|
||||
|
||||
E-COH-002:
|
||||
mensaje: "Entity sin tabla DDL"
|
||||
accion: "Crear tabla DDL o documentar como excepción"
|
||||
bloqueante: true
|
||||
|
||||
E-COH-003:
|
||||
mensaje: "Schema sin módulo backend"
|
||||
accion: "Crear módulo o documentar como PLANNED"
|
||||
bloqueante: true
|
||||
|
||||
E-COH-004:
|
||||
mensaje: "Objeto no documentado en inventario"
|
||||
accion: "Actualizar inventario correspondiente"
|
||||
bloqueante: true
|
||||
|
||||
E-COH-005:
|
||||
mensaje: "Discrepancia de campos DDL ↔ Entity"
|
||||
accion: "Sincronizar campos entre DDL y Entity"
|
||||
bloqueante: true
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## REFERENCIAS
|
||||
|
||||
| Alias | Descripción |
|
||||
|-------|-------------|
|
||||
| @TRIGGER_COHERENCIA | Este trigger |
|
||||
| @DEF_CHK_POST | Checklist post-tarea |
|
||||
| @TRIGGER-DOC | Documentación obligatoria |
|
||||
| @SIMCO-VALIDAR | Directiva de validación |
|
||||
|
||||
---
|
||||
|
||||
**Versión:** 1.0.0 | **Sistema:** SIMCO v4.0.0 | **Tipo:** Trigger Preventivo
|
||||
Loading…
Reference in New Issue
Block a user