> ## 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.

# Enroll (or create) a patient in a protocol

> Creates or reuses the patient by phone, enrolls them in the protocol, and schedules the first outbound call. Requires role admin or coordinator.




## OpenAPI

````yaml /openapi/openapi-olivia-en.yaml post /v1/enrollments/enroll-patient
openapi: 3.1.0
info:
  title: OlivIA API
  version: 0.1.0
  description: >
    OlivIA external API — Omniloy's clinical voice follow-up platform. It lets
    an external system (EHR/HIS, CRM, or your own backend):

    - Follow-up (outbound calls): enroll patients in a protocol so OlivIA calls
    them to complete a questionnaire.

    - Triage (inbound calls): results of triage calls are read through these
    same read endpoints.

    - Read results: questionnaires (protocol runs), answers, score, calls,
    transcript, and recording.

    Authentication uses a personal API key as a bearer token (`Authorization:
    Bearer oc_sk_...`). All routes are under the `/v1` prefix and responses wrap
    the payload in `data`.
servers:
  - url: https://{your-prod-endpoint}
    description: Production
    variables:
      your-prod-endpoint:
        default: your-prod-endpoint
        description: Replace this value with the real host before trying a request.
  - url: https://{your-dev-endpoint}
    description: Staging
    variables:
      your-dev-endpoint:
        default: your-dev-endpoint
        description: Replace this value with your staging host.
security:
  - bearerAuth: []
tags:
  - name: Protocols
    description: Read and archive protocols.
  - name: Enrollments
    description: Enroll patients and read enrollments (outbound follow-up).
  - name: Protocol Runs
    description: Protocol runs (questionnaire executions) and their results.
  - name: Calls
    description: Call detail, transcript, and recording.
paths:
  /v1/enrollments/enroll-patient:
    post:
      tags:
        - Enrollments
      summary: Enroll (or create) a patient in a protocol
      description: >
        Creates or reuses the patient by phone, enrolls them in the protocol,
        and schedules the first outbound call. Requires role admin or
        coordinator.
      operationId: enroll-patient
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EnrollPatientRequest'
      responses:
        '201':
          description: Enrollment created
          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: Phone in E.164 format.
        first_name:
          type: string
        last_name:
          type: string
        protocol_key:
          type: string
          description: Provide protocol_key or protocol_version_id (exactly one).
        protocol_version_id:
          type: string
          format: uuid
        version:
          type: integer
          description: Optional, together with protocol_key.
        language:
          type: string
          description: BCP-47 tag (e.g. es, en).
        preferred_timezone:
          type: string
          description: IANA time zone.
        started_at:
          type: string
          format: date-time
        freq_config:
          type: object
          additionalProperties: true
          description: Partial override of the scheduling.
        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: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: The key lacks the required role
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: oc_sk_ API key

````