Skip to main content
POST
/
api
/
correlation
/
metrics
/
:hospitalId
Performance Correlation Analysis
curl --request POST \
  --url https://api.example.com/api/correlation/metrics/:hospitalId \
  --header 'Content-Type: application/json' \
  --data '
{
  "year": 123,
  "month": 123
}
'
{
  "success": true,
  "data.metrics": [
    {}
  ],
  "data.report": {
    "period": "<string>",
    "hospitalId": "<string>",
    "generatedAt": "<string>",
    "metrics": {},
    "strategicAnalysis": "<string>",
    "keyInsights": [
      {}
    ],
    "recommendations": [
      {}
    ]
  },
  "data.dashboard": {
    "currentPeriod": {},
    "metrics": {},
    "trends": {
      "motivation": 123,
      "satisfaction": 123,
      "flightRisk": 123
    },
    "keyAlerts": [
      {}
    ],
    "lastUpdated": "<string>"
  }
}

Overview

The correlation analysis system automatically analyzes the relationship between human resource metrics (motivation, satisfaction, training) and hospital performance indicators (patient satisfaction, clinical errors, wait times). It uses AI to generate strategic insights and recommendations.

Authentication

This endpoint requires authentication and admin role only.
Authorization: Bearer YOUR_JWT_TOKEN

Generate Monthly Metrics

Calculate correlation metrics for a specific hospital and time period.

Endpoint

POST /api/correlation/metrics/:hospitalId

Path Parameters

hospitalId
string
required
The unique identifier of the hospital

Request Body

year
number
required
Year for the metrics period (e.g., 2024)
month
number
required
Month for the metrics period (1-12)

Response

success
boolean
Indicates if metrics were generated successfully
data.metrics
object
Complete metrics object with HR data, hospital data, and correlations

Example Request

curl -X POST https://api.cuido.com/api/correlation/metrics/HOSPITAL_001 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "year": 2024,
    "month": 1
  }'

Response Example

{
  "success": true,
  "message": "Métricas mensuales generadas",
  "data": {
    "metrics": {
      "_id": "65a1b2c3d4e5f6a7b8c9d0e1",
      "hospitalId": "HOSPITAL_001",
      "period": {
        "year": 2024,
        "month": 1
      },
      "hrMetrics": {
        "totalEmployees": 85,
        "avgMotivation": 6.8,
        "avgSatisfaction": 7.2,
        "flightRiskEmployees": 12,
        "trainingHours": 340,
        "recognitionsGiven": 45,
        "surveyParticipation": 78
      },
      "hospitalMetrics": {
        "patientSatisfaction": 7.5,
        "clinicalErrors": 3,
        "readmissionRate": 8.5,
        "averageWaitTime": 35,
        "consultationsPerDay": 125,
        "absenteeismRate": 5.2,
        "bedOccupancy": 82.5,
        "emergencyResponseTime": 8
      },
      "correlations": [
        {
          "hrVariable": "avgSatisfaction",
          "hospitalVariable": "patientSatisfaction",
          "correlation": 0.8,
          "significance": "alta",
          "impact": "Personal satisfecho mejora la experiencia del paciente"
        }
      ],
      "calculatedAt": "2024-01-15T10:30:00.000Z"
    }
  }
}

Get Historical Metrics

Retrieve historical metrics for trend analysis.

Endpoint

GET /api/correlation/metrics/:hospitalId/history

Query Parameters

months
number
Number of months of history to retrieve. Default: 6

Response

data.metrics
array
Array of monthly metrics objects, sorted by most recent first

Example Request

curl -X GET "https://api.cuido.com/api/correlation/metrics/HOSPITAL_001/history?months=6" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Generate Strategic Report

Generate an AI-powered strategic report with insights and recommendations.

Endpoint

GET /api/correlation/report/:hospitalId

Query Parameters

year
number
required
Year for the report
month
number
required
Month for the report (1-12)

Response

data.report
object
AI-generated strategic report

Example Request

curl -X GET "https://api.cuido.com/api/correlation/report/HOSPITAL_001?year=2024&month=1" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response Example

{
  "success": true,
  "message": "Reporte estratégico generado",
  "data": {
    "report": {
      "period": "1/2024",
      "hospitalId": "HOSPITAL_001",
      "generatedAt": "2024-01-15T10:30:00.000Z",
      "metrics": { /* full metrics object */ },
      "strategicAnalysis": "ESTADO GENERAL DEL HOSPITAL:\n\nEl Hospital 001 muestra un desempeño sólido con indicadores positivos en satisfacción del personal (7.2/10) y satisfacción del paciente (7.5/10). La correlación positiva entre estos factores (0.8) confirma que el bienestar del personal impacta directamente en la experiencia del paciente.\n\nÁREAS DE RIESGO INMEDIATO:\n\n1. Riesgo de fuga de talento: 12 empleados (14% del personal) identificados en alto riesgo\n2. Participación en encuestas: Aunque 78% es aceptable, el 22% restante representa voces no escuchadas\n3. Errores clínicos: 3 errores reportados requieren análisis de causa raíz\n\nOPORTUNIDADES DE MEJORA:\n\n1. Capitalizar la alta satisfacción del personal para programas de referidos\n2. Incrementar horas de capacitación (actualmente 340h/mes) en áreas de alto riesgo\n3. Replicar prácticas del sistema de reconocimiento (45 otorgados) en otros departamentos\n\nRECOMENDACIONES PRIORITARIAS:\n\n1. Plan de retención: Entrevistas 1-a-1 con los 12 empleados en riesgo de fuga para identificar causas y soluciones personalizadas\n2. Programa de capacitación: Aumentar 20% las horas de formación enfocadas en prevención de errores clínicos\n3. Sistema de escucha activa: Implementar encuestas breves semanales para aumentar participación al 90%\n\nINDICADORES A MONITOREAR EL PRÓXIMO MES:\n\n- Reducción de empleados en riesgo de fuga (meta: <10)\n- Incremento en participación de encuestas (meta: 85%)\n- Mantenimiento de cero errores clínicos graves\n- Satisfacción del paciente (mantener >7.5)",
      "keyInsights": [
        "La correlación positiva entre estos factores (0.8) confirma que el bienestar del personal impacta directamente en la experiencia del paciente.",
        "Riesgo de fuga de talento: 12 empleados (14% del personal) identificados en alto riesgo",
        "3 errores reportados requieren análisis de causa raíz"
      ],
      "recommendations": [
        "Plan de retención: Entrevistas 1-a-1 con los 12 empleados en riesgo de fuga para identificar causas y soluciones personalizadas",
        "Programa de capacitación: Aumentar 20% las horas de formación enfocadas en prevención de errores clínicos",
        "Sistema de escucha activa: Implementar encuestas breves semanales para aumentar participación al 90%"
      ]
    }
  }
}

Get Executive Dashboard

Get a summary dashboard with current metrics and trends.

Endpoint

GET /api/correlation/dashboard/:hospitalId

Response

data.dashboard
object
Executive dashboard with current period, metrics, trends, and alerts

Example Request

curl -X GET https://api.cuido.com/api/correlation/dashboard/HOSPITAL_001 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Correlation Detection Algorithm

The system (src/services/correlationService.js:131) detects basic correlations:
  1. Motivation vs Clinical Errors (inverse correlation)
    • If avgMotivation < 5 AND clinicalErrors > 5
    • Correlation: -0.7 (high significance)
  2. Satisfaction vs Patient Satisfaction (positive correlation)
    • If avgSatisfaction > 7 AND patientSatisfaction > 7
    • Correlation: 0.8 (high significance)
  3. Flight Risk vs Wait Time (positive correlation)
    • If flightRiskEmployees > 20% of total employees
    • Correlation: 0.6 (medium significance)

AI Integration

Strategic reports use Claude AI (src/services/correlationService.js:173) with:
  • Temperature: 0.4 (factual, less creative)
  • Max Tokens: 1500
  • System Prompt: Senior hospital management consultant
  • Output: Strategic analysis with 5 sections

Source Code References

  • Routes: src/routes/correlationRoutes.js:16-19
  • Controllers: src/controllers/correlationController.js
  • Service: src/services/correlationService.js:15
  • Correlation Logic: src/services/correlationService.js:131
  • AI Report: src/services/correlationService.js:173
  • Model: src/models/PerformanceMetric.js

Build docs developers (and LLMs) love