{
  "openapi": "3.1.0",
  "info": {
    "title": "RiskCare · Conector de consulta para MCP Ingeniería 365",
    "version": "1.0.0",
    "description": "Contrato REST importable de consulta. Conserva autenticación delegada, selección de institución y permisos. La importación requiere configurar la autenticación en el hub; no es un endpoint MCP remoto."
  },
  "servers": [
    {
      "url": "https://gestion.riskcare.ai",
      "description": "Producción RiskCare"
    }
  ],
  "tags": [
    {
      "name": "Cuenta e institución"
    },
    {
      "name": "Analítica e históricos"
    }
  ],
  "paths": {
    "/api/v1/analytics/catalog": {
      "get": {
        "operationId": "catalog_api_v1_analytics_catalog_get",
        "parameters": [
          {
            "in": "header",
            "name": "x-tenant-id",
            "required": true,
            "schema": {
              "format": "uuid",
              "title": "X-Tenant-Id",
              "type": "string"
            },
            "description": "UUID de la institución seleccionada entre las autorizadas devueltas por GET /api/v1/me. El encabezado por sí solo no concede acceso."
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareAnalyticsCatalog"
                }
              }
            },
            "description": "Successful Response"
          },
          "422": {
            "description": "Parámetros o cuerpo no válidos.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "401": {
            "description": "Sesión ausente, inválida o vencida.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "403": {
            "description": "Permiso insuficiente o segundo factor requerido.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "503": {
            "description": "Servicio temporalmente no disponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          }
        },
        "summary": "Consultar catálogo de indicadores",
        "tags": [
          "Analítica e históricos"
        ],
        "security": [
          {
            "RiskCareSession": []
          }
        ],
        "x-riskcare-scope": "tenant",
        "description": "Requiere una sesión válida y una institución autorizada. El servidor valida el rol, el acceso al registro y si la operación está habilitada."
      }
    },
    "/api/v1/analytics/dimensions": {
      "get": {
        "operationId": "dimensions_api_v1_analytics_dimensions_get",
        "parameters": [
          {
            "in": "header",
            "name": "x-tenant-id",
            "required": true,
            "schema": {
              "format": "uuid",
              "title": "X-Tenant-Id",
              "type": "string"
            },
            "description": "UUID de la institución seleccionada entre las autorizadas devueltas por GET /api/v1/me. El encabezado por sí solo no concede acceso."
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareAnalyticsDimensions"
                }
              }
            },
            "description": "Successful Response"
          },
          "422": {
            "description": "Parámetros o cuerpo no válidos.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "401": {
            "description": "Sesión ausente, inválida o vencida.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "403": {
            "description": "Permiso insuficiente o segundo factor requerido.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "503": {
            "description": "Servicio temporalmente no disponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          }
        },
        "summary": "Consultar dimensiones de analítica",
        "tags": [
          "Analítica e históricos"
        ],
        "security": [
          {
            "RiskCareSession": []
          }
        ],
        "x-riskcare-scope": "tenant",
        "description": "Requiere una sesión válida y una institución autorizada. El servidor valida el rol, el acceso al registro y si la operación está habilitada."
      }
    },
    "/api/v1/analytics/reports": {
      "get": {
        "operationId": "reports_api_v1_analytics_reports_get",
        "parameters": [
          {
            "in": "query",
            "name": "from_date",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "format": "date",
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "From Date"
            }
          },
          {
            "in": "query",
            "name": "to_date",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "format": "date",
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "To Date"
            }
          },
          {
            "in": "query",
            "name": "site",
            "required": false,
            "schema": {
              "default": "",
              "maxLength": 240,
              "title": "Site",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "service",
            "required": false,
            "schema": {
              "default": "",
              "maxLength": 240,
              "title": "Service",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "classification",
            "required": false,
            "schema": {
              "default": "",
              "maxLength": 100,
              "title": "Classification",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "default": 9,
              "maximum": 16,
              "minimum": 1,
              "title": "Page",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "calendar_basis",
            "required": false,
            "schema": {
              "default": "native_monthly",
              "enum": [
                "native_monthly",
                "legacy_monthly"
              ],
              "title": "Calendar Basis",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "as_of_date",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "format": "date",
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "As Of Date"
            }
          },
          {
            "in": "header",
            "name": "x-tenant-id",
            "required": true,
            "schema": {
              "format": "uuid",
              "title": "X-Tenant-Id",
              "type": "string"
            },
            "description": "UUID de la institución seleccionada entre las autorizadas devueltas por GET /api/v1/me. El encabezado por sí solo no concede acceso."
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareAnalyticsReport"
                }
              }
            },
            "description": "Successful Response"
          },
          "422": {
            "description": "Parámetros o cuerpo no válidos.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "401": {
            "description": "Sesión ausente, inválida o vencida.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "403": {
            "description": "Permiso insuficiente o segundo factor requerido.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "503": {
            "description": "Servicio temporalmente no disponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          }
        },
        "summary": "Consultar una página de analítica (1–16)",
        "tags": [
          "Analítica e históricos"
        ],
        "security": [
          {
            "RiskCareSession": []
          }
        ],
        "x-riskcare-scope": "tenant",
        "description": "Requiere una sesión válida y una institución autorizada. El servidor valida el rol, el acceso al registro y si la operación está habilitada."
      }
    },
    "/api/v1/dashboard": {
      "get": {
        "operationId": "dashboard_api_v1_dashboard_get",
        "parameters": [
          {
            "in": "header",
            "name": "x-tenant-id",
            "required": true,
            "schema": {
              "format": "uuid",
              "title": "X-Tenant-Id",
              "type": "string"
            },
            "description": "UUID de la institución seleccionada entre las autorizadas devueltas por GET /api/v1/me. El encabezado por sí solo no concede acceso."
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareDashboard"
                }
              }
            },
            "description": "Successful Response"
          },
          "422": {
            "description": "Parámetros o cuerpo no válidos.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "401": {
            "description": "Sesión ausente, inválida o vencida.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "403": {
            "description": "Permiso insuficiente o segundo factor requerido.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "503": {
            "description": "Servicio temporalmente no disponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          }
        },
        "summary": "Consultar resumen de gestión",
        "security": [
          {
            "RiskCareSession": []
          }
        ],
        "tags": [
          "Analítica e históricos"
        ],
        "x-riskcare-scope": "tenant",
        "description": "Requiere una sesión válida y una institución autorizada. El servidor valida el rol, el acceso al registro y si la operación está habilitada."
      }
    },
    "/api/v1/me": {
      "get": {
        "operationId": "me_api_v1_me_get",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareIdentity"
                }
              }
            },
            "description": "Successful Response"
          },
          "401": {
            "description": "Sesión ausente, inválida o vencida.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "403": {
            "description": "Permiso insuficiente o segundo factor requerido.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          },
          "503": {
            "description": "Servicio temporalmente no disponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskCareError"
                }
              }
            }
          }
        },
        "summary": "Consultar mi cuenta e instituciones autorizadas",
        "security": [
          {
            "RiskCareSession": []
          }
        ],
        "tags": [
          "Cuenta e institución"
        ],
        "x-riskcare-scope": "account",
        "description": "Requiere una sesión válida. El alcance y el permiso se comprueban en el servidor."
      }
    }
  },
  "components": {
    "schemas": {
      "RiskCareAnalyticsCatalog": {
        "type": "object",
        "properties": {
          "semanticVersion": {
            "type": "string"
          },
          "dataRowsIncluded": {
            "type": "boolean"
          },
          "measures": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "pages": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "coverage": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "semanticVersion",
          "dataRowsIncluded",
          "measures",
          "pages"
        ],
        "additionalProperties": true
      },
      "RiskCareAnalyticsDimensions": {
        "type": "object",
        "properties": {
          "sites": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "services": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "classifications": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "sites",
          "services",
          "classifications"
        ],
        "additionalProperties": true
      },
      "RiskCareAnalyticsReport": {
        "type": "object",
        "properties": {
          "semantic_version": {
            "type": "string"
          },
          "period": {
            "type": "object",
            "additionalProperties": true
          },
          "filters": {
            "type": "object",
            "additionalProperties": true
          },
          "page": {
            "type": "object",
            "additionalProperties": true
          },
          "metrics": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "all_metrics": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "series": {
            "type": "object",
            "additionalProperties": true
          },
          "coverage": {
            "type": "object",
            "additionalProperties": true
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "semantic_version",
          "period",
          "page",
          "metrics",
          "warnings"
        ],
        "additionalProperties": true
      },
      "RiskCareDashboard": {
        "type": "object",
        "properties": {
          "total_events": {
            "type": "integer",
            "minimum": 0
          },
          "open_events": {
            "type": "integer",
            "minimum": 0
          },
          "closed_events": {
            "type": "integer",
            "minimum": 0
          },
          "total_actions": {
            "type": "integer",
            "minimum": 0
          },
          "overdue_actions": {
            "type": "integer",
            "minimum": 0
          },
          "pending_actions": {
            "type": "integer",
            "minimum": 0
          },
          "by_status": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "value": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "required": [
                "name",
                "value"
              ],
              "additionalProperties": true
            }
          },
          "by_service": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "value": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "required": [
                "name",
                "value"
              ],
              "additionalProperties": true
            }
          },
          "monthly": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "month": {
                  "type": "string"
                },
                "value": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "required": [
                "month",
                "value"
              ],
              "additionalProperties": true
            }
          }
        },
        "required": [
          "total_events",
          "open_events",
          "closed_events",
          "total_actions",
          "overdue_actions",
          "pending_actions",
          "by_status",
          "by_service",
          "monthly"
        ],
        "additionalProperties": true
      },
      "RiskCareError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              },
              "fields": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "code",
              "message"
            ],
            "additionalProperties": true
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": true
      },
      "RiskCareIdentity": {
        "type": "object",
        "properties": {
          "user": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "email": {
                "type": "string"
              },
              "display_name": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "email"
            ],
            "additionalProperties": true
          },
          "tenants": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RiskCareInstitution"
            }
          },
          "is_super_admin": {
            "type": "boolean"
          },
          "can_create_company": {
            "type": "boolean"
          }
        },
        "required": [
          "user",
          "tenants",
          "is_super_admin",
          "can_create_company"
        ],
        "additionalProperties": true
      },
      "RiskCareInstitution": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "clinic_admin",
              "quality_lead",
              "analyst",
              "action_owner",
              "reporter",
              "reader"
            ]
          },
          "write_enabled": {
            "type": "boolean"
          },
          "is_demo": {
            "type": "boolean"
          },
          "historical_modules_available": {
            "type": "boolean"
          },
          "logo_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "is_company_admin": {
            "type": "boolean"
          },
          "can_delegate_clinic_admin": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "name",
          "role",
          "write_enabled"
        ],
        "additionalProperties": true
      }
    },
    "securitySchemes": {
      "RiskCareSession": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Token de acceso de una sesión autorizada de RiskCare. No es la clave pública de autenticación ni una clave de administrador."
      }
    }
  },
  "externalDocs": {
    "description": "Guía de integración y activación",
    "url": "https://riskcare.ai/developers"
  },
  "x-riskcare-contract": {
    "sourceVersion": "0.1.0",
    "sourceOpenapi": "3.1.0",
    "sourceSha256": "69cf3f8502208adcc37c477b01c9e3c390fe69b825a816c098d5da1d8d55c74c",
    "excludedInternalOperations": 28
  }
}
