84 lines
2.6 KiB
Markdown
84 lines
2.6 KiB
Markdown
# Base de Datos - ERP Clínicas
|
|
|
|
## Resumen
|
|
|
|
| Aspecto | Valor |
|
|
|---------|-------|
|
|
| **Schema principal** | `clinica` |
|
|
| **Tablas específicas** | 13 |
|
|
| **ENUMs** | 4 |
|
|
| **Hereda de ERP-Core** | 144 tablas (12 schemas) |
|
|
|
|
## Prerequisitos
|
|
|
|
1. **ERP-Core instalado** con todos sus schemas:
|
|
- auth, core, financial, inventory, purchase, sales, projects, analytics, system, billing, crm, hr
|
|
|
|
2. **Extensiones PostgreSQL**:
|
|
- pgcrypto (encriptación)
|
|
- pg_trgm (búsqueda de texto)
|
|
|
|
## Orden de Ejecución DDL
|
|
|
|
```bash
|
|
# 1. Instalar ERP-Core primero
|
|
cd apps/erp-core/database
|
|
./scripts/reset-database.sh
|
|
|
|
# 2. Instalar extensión Clínicas
|
|
cd apps/verticales/clinicas/database
|
|
psql $DATABASE_URL -f init/00-extensions.sql
|
|
psql $DATABASE_URL -f init/01-create-schemas.sql
|
|
psql $DATABASE_URL -f init/02-rls-functions.sql
|
|
psql $DATABASE_URL -f init/03-clinical-tables.sql
|
|
psql $DATABASE_URL -f init/04-seed-data.sql
|
|
```
|
|
|
|
## Tablas Implementadas
|
|
|
|
### Schema: clinica (13 tablas)
|
|
|
|
| Tabla | Módulo | Descripción |
|
|
|-------|--------|-------------|
|
|
| specialties | CL-002 | Catálogo de especialidades médicas |
|
|
| doctors | CL-002 | Médicos (extiende hr.employees) |
|
|
| patients | CL-001 | Pacientes (extiende core.partners) |
|
|
| patient_contacts | CL-001 | Contactos de emergencia |
|
|
| patient_insurance | CL-001 | Información de seguros |
|
|
| appointment_slots | CL-002 | Horarios disponibles |
|
|
| appointments | CL-002 | Citas médicas |
|
|
| medical_records | CL-003 | Expediente clínico electrónico |
|
|
| consultations | CL-003 | Consultas realizadas |
|
|
| vital_signs | CL-003 | Signos vitales |
|
|
| diagnoses | CL-003 | Diagnósticos (CIE-10) |
|
|
| prescriptions | CL-003 | Recetas médicas |
|
|
| prescription_items | CL-003 | Medicamentos en receta |
|
|
|
|
## ENUMs
|
|
|
|
| Enum | Valores |
|
|
|------|---------|
|
|
| appointment_status | scheduled, confirmed, in_progress, completed, cancelled, no_show |
|
|
| patient_gender | male, female, other, prefer_not_to_say |
|
|
| blood_type | A+, A-, B+, B-, AB+, AB-, O+, O-, unknown |
|
|
| consultation_status | draft, in_progress, completed, cancelled |
|
|
|
|
## Row Level Security
|
|
|
|
Todas las tablas tienen RLS habilitado con aislamiento por tenant:
|
|
|
|
```sql
|
|
tenant_id = current_setting('app.current_tenant_id', true)::UUID
|
|
```
|
|
|
|
## Consideraciones de Seguridad
|
|
|
|
- **NOM-024-SSA3-2012**: Expediente clínico electrónico
|
|
- **Datos sensibles**: medical_records, consultations requieren encriptación
|
|
- **Auditoría completa**: Todas las tablas tienen campos de auditoría
|
|
|
|
## Referencias
|
|
|
|
- [HERENCIA-ERP-CORE.md](./HERENCIA-ERP-CORE.md)
|
|
- [DATABASE_INVENTORY.yml](../orchestration/inventarios/DATABASE_INVENTORY.yml)
|