> ## Documentation Index
> Fetch the complete documentation index at: https://omniloy.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Inscribe (o crea) un paciente en un protocolo

> Crea o reutiliza el paciente por teléfono, lo inscribe en el protocolo y programa la primera llamada saliente. Requiere rol admin o coordinator.




## OpenAPI

````yaml /openapi/openapi-olivia.yaml post /v1/enrollments/enroll-patient
openapi: 3.1.0
info:
  title: OlivIA API
  version: 0.1.0
  description: >
    API externa de OlivIA, la plataforma de seguimiento clínico por voz de
    Omniloy. Permite a un sistema externo (EHR/HIS, CRM o backend propio):

    - Seguimiento (llamadas salientes): inscribir pacientes en un protocolo para
    que OlivIA los llame y complete un cuestionario.

    - Triaje (llamadas entrantes): los resultados de las llamadas de triaje se
    consultan por estos mismos endpoints de lectura.

    - Lectura de resultados: cuestionarios (protocol runs), respuestas, score,
    llamadas, transcripción y grabación.

    Autenticación por API key personal como bearer token (`Authorization: Bearer
    oc_sk_...`). Todas las rutas cuelgan del prefijo `/v1` y las respuestas
    envuelven el contenido en `data`.
servers:
  - url: https://{your-prod-endpoint}
    description: Producción
    variables:
      your-prod-endpoint:
        default: your-prod-endpoint
        description: Sustituye este valor por el host real antes de probar la petición.
  - url: https://{your-dev-endpoint}
    description: Staging
    variables:
      your-dev-endpoint:
        default: your-dev-endpoint
        description: Sustituye este valor por el host de staging.
security:
  - bearerAuth: []
tags:
  - name: Protocolos
    description: Consulta y archivado de protocolos.
  - name: Inscripciones
    description: Inscribir pacientes y consultar inscripciones (seguimiento saliente).
  - name: Cuestionarios
    description: Ejecuciones de protocolo (protocol runs) y sus resultados.
  - name: Llamadas
    description: Detalle de llamadas, transcripción y grabación.
paths:
  /v1/enrollments/enroll-patient:
    post:
      tags:
        - Inscripciones
      summary: Inscribe (o crea) un paciente en un protocolo
      description: >
        Crea o reutiliza el paciente por teléfono, lo inscribe en el protocolo y
        programa la primera llamada saliente. Requiere rol admin o coordinator.
      operationId: enroll-patient
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EnrollPatientRequest'
      responses:
        '201':
          description: Inscripción creada
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnrollmentResponse'
        '400':
          $ref: '#/components/responses/ValidationError'
        '403':
          $ref: '#/components/responses/Forbidden'
components:
  schemas:
    EnrollPatientRequest:
      type: object
      required:
        - phone
        - first_name
        - last_name
      properties:
        phone:
          type: string
          description: Teléfono en formato E.164.
        first_name:
          type: string
        last_name:
          type: string
        protocol_key:
          type: string
          description: Indica protocol_key o protocol_version_id (exactamente uno).
        protocol_version_id:
          type: string
          format: uuid
        version:
          type: integer
          description: Opcional, junto con protocol_key.
        language:
          type: string
          description: Etiqueta BCP-47 (p. ej. es, en).
        preferred_timezone:
          type: string
          description: Zona horaria IANA.
        started_at:
          type: string
          format: date-time
        freq_config:
          type: object
          additionalProperties: true
          description: Sobrescritura parcial de la programación.
        custom_variable_values:
          type: object
          additionalProperties: true
    EnrollmentResponse:
      type: object
      properties:
        data:
          allOf:
            - $ref: '#/components/schemas/Enrollment'
            - type: object
              properties:
                protocol_runs:
                  type: array
                  items:
                    $ref: '#/components/schemas/ProtocolRun'
    Enrollment:
      type: object
      properties:
        id:
          type: string
          format: uuid
        org_id:
          type: string
          format: uuid
        patient_id:
          type: string
          format: uuid
        protocol_version_id:
          type: string
          format: uuid
        status:
          type: string
          enum:
            - active
            - paused
            - completed
            - cancelled
        language:
          type: string
        started_at:
          type: string
          format: date-time
          nullable: true
        ended_at:
          type: string
          format: date-time
          nullable: true
        freq_config:
          type: object
          additionalProperties: true
        custom_variable_values:
          type: object
          additionalProperties: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    ProtocolRun:
      type: object
      properties:
        id:
          type: string
          format: uuid
        org_id:
          type: string
          format: uuid
        enrollment_id:
          type: string
          format: uuid
        protocol_version_id:
          type: string
          format: uuid
        sequence_number:
          type: integer
        scheduled_at:
          type: string
          format: date-time
          nullable: true
        started_at:
          type: string
          format: date-time
          nullable: true
        ended_at:
          type: string
          format: date-time
          nullable: true
        questionnaire_status:
          type: string
          enum:
            - pending
            - in_progress
            - completed
            - rejected
            - call_failed
            - wrong_number
            - no_answer
            - unresolved
            - cancelled
        language:
          type: string
        reviewed_at:
          type: string
          format: date-time
          nullable: true
        review_note:
          type: string
          nullable: true
        score:
          type: number
          nullable: true
        score_class:
          type: string
          nullable: true
        origin:
          type: string
          enum:
            - dispatcher_scheduled
            - manual
            - voice_initiated
            - external_api
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
            details: {}
  responses:
    ValidationError:
      description: Petición inválida
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: La key no tiene el rol necesario
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: oc_sk_ API key

````