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

# Copy an appointment to a new time

> Opens a new `pending` appointment from an existing one; the source is left untouched. The copy
carries over the patient, doctor, room, description, notification channel, tags, assistants and
the whole treatment plan with its session products. Planned session dates keep their spacing by
moving as far as the appointment itself moved. Copying a session appointment keeps it a session
appointment and points the parent's plan at the copy. Like `POST /appointments`, closed days,
working hours and overlaps never refuse the copy.



## OpenAPI

````yaml /api-referansi/openapi.json post /v1/appointments/{id}/copy
openapi: 3.1.0
info:
  title: Flextell API
  version: 0.0.1
  description: >-
    Flextell REST API referansı. Kimlik doğrulama, scope ve istek kuralları için
    API sekmesindeki rehberlere bakın.
servers:
  - url: https://app.flextell.ai/api
    description: Üretim
security:
  - oauth2: []
  - bearer: []
paths:
  /v1/appointments/{id}/copy:
    post:
      tags:
        - Appointment
      summary: Copy an appointment to a new time
      description: >-
        Opens a new `pending` appointment from an existing one; the source is
        left untouched. The copy

        carries over the patient, doctor, room, description, notification
        channel, tags, assistants and

        the whole treatment plan with its session products. Planned session
        dates keep their spacing by

        moving as far as the appointment itself moved. Copying a session
        appointment keeps it a session

        appointment and points the parent's plan at the copy. Like `POST
        /appointments`, closed days,

        working hours and overlaps never refuse the copy.
      operationId: appointment.copy
      parameters:
        - name: id
          in: path
          required: true
          description: The appointment identifier
          schema:
            type: integer
        - name: X-Tenant
          in: header
          required: true
          description: >-
            Tenant identifier. Send the Tenant ID in the `X-Tenant` header to
            scope API requests to a specific tenant.
          schema:
            type: number
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AppointmentCopyRequest'
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: string
                  data:
                    $ref: '#/components/schemas/AppointmentResource'
                required:
                  - success
                  - data
        '401':
          $ref: '#/components/responses/AuthenticationException'
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '404':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  error_code:
                    type: string
                    const: RESOURCE_NOT_FOUND
                  message:
                    type: string
                  errors:
                    type: 'null'
                  data:
                    type: 'null'
                required:
                  - success
                  - error_code
                  - message
                  - errors
                  - data
        '409':
          $ref: '#/components/responses/CustomerErasedException'
        '422':
          $ref: '#/components/responses/ValidationException'
        '428':
          description: >-
            Mandatory setup is incomplete. Finish the setup wizard first;
            `data.next_step` names the step to continue with.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    examples:
                      - false
                  error_code:
                    type: string
                    enum:
                      - SETUP_REQUIRED
                    examples:
                      - SETUP_REQUIRED
                  message:
                    type: string
                    examples:
                      - Complete the required setup steps to continue.
                  data:
                    type: object
                    properties:
                      next_step:
                        type:
                          - string
                          - 'null'
                        examples:
                          - clinic_info
                    required:
                      - next_step
                required:
                  - success
                  - error_code
                  - message
                  - data
components:
  schemas:
    AppointmentCopyRequest:
      type: object
      properties:
        scheduled_at:
          type: string
          format: date-time
          description: >-
            The start of the copy. A value without an offset is read in the
            clinic's timezone.
        duration_minutes:
          type:
            - integer
            - 'null'
          description: >-
            The copy's duration in minutes. Defaults to the source appointment's
            duration.
          minimum: 5
          maximum: 1440
        is_manual_time:
          type:
            - boolean
            - 'null'
          description: >-
            Whether the start time was typed by hand instead of picked from the
            suggested slots. Defaults to the source appointment's value.
        send_message:
          type:
            - boolean
            - 'null'
          description: >-
            Whether to send the appointment-created notification to the
            customer. Defaults to the tenant setting when omitted.
      required:
        - scheduled_at
      title: AppointmentCopyRequest
    AppointmentResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        customer_id:
          type:
            - integer
            - 'null'
        room_id:
          type:
            - integer
            - 'null'
        channel_id:
          type:
            - integer
            - 'null'
        parent_appointment_id:
          type:
            - integer
            - 'null'
        code:
          type: string
        relation_type:
          type: string
        description:
          type:
            - string
            - 'null'
        scheduled_at:
          type: string
          format: date-time
        duration_minutes:
          type:
            - integer
            - 'null'
          description: >-
            The length set on the appointment, in minutes; `null` means the
            clinic's slot duration applies.
        effective_duration_minutes:
          type: integer
          description: >-
            The minutes the appointment actually occupies: `duration_minutes`,
            or the clinic's slot duration when that is `null`.
        duration_source:
          $ref: '#/components/schemas/AppointmentDurationSource'
          description: >-
            Where `effective_duration_minutes` comes from: the appointment's own
            duration or the clinic's slot duration.
        status:
          type: string
        cancellation_reason:
          type:
            - string
            - 'null'
        creation_type:
          type: string
        is_control_appointment:
          type: boolean
        is_ai_generated:
          type: boolean
          description: >-
            Whether the AI assistant booked the appointment; `creation_type`
            carries the same fact as a label.
        import_source_id:
          type:
            - integer
            - 'null'
          description: >-
            The external system the appointment was imported from, or `null`
            when it was created in Flextell.
        pending_scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            The time a bulk reschedule proposed to the patient, while it awaits
            their confirmation; otherwise `null`.
        pending_expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When the proposed time stops being held for the patient; `null`
            without a pending proposal.
        sale_id:
          type: integer
          description: The appointment's sale, or `null` when it has none.
        has_sale:
          type: boolean
          description: Whether the appointment has a sale; same as `sale_id !== null`.
        customer:
          $ref: '#/components/schemas/CustomerResource'
        doctor:
          $ref: '#/components/schemas/RelatedUserResource'
        room:
          $ref: '#/components/schemas/RoomResource'
        parent_appointment:
          $ref: '#/components/schemas/AppointmentResource'
        child_appointments:
          type: array
          items:
            $ref: '#/components/schemas/AppointmentResource'
        treatments:
          type: array
          items:
            $ref: '#/components/schemas/TreatmentResource'
        treatment_session_plans:
          type: array
          items:
            $ref: '#/components/schemas/AppointmentTreatmentPlanResource'
        linked_sessions:
          type: array
          description: >-
            The treatment sessions this appointment fulfils with the products
            used on each, in session order. Only present on detail responses.
          items:
            $ref: '#/components/schemas/AppointmentLinkedSessionResource'
        assistants:
          anyOf:
            - type: array
              items:
                $ref: '#/components/schemas/RelatedUserResource'
            - type: array
              items:
                type: string
              minItems: 0
              maxItems: 0
              additionalItems: false
        tags:
          type: array
          items:
            $ref: '#/components/schemas/TagResource'
        reminders:
          type: array
          items:
            $ref: '#/components/schemas/AppointmentReminderResource'
        customer_balance:
          anyOf:
            - $ref: '#/components/schemas/AppointmentCustomerBalanceResource'
              description: >-
                The patient's balance, or `null` when the viewer lacks
                View:CustomerBalances or the patient's details are masked for
                them. Only present on GET /appointments/{id}.
            - type: 'null'
        import_source:
          anyOf:
            - $ref: '#/components/schemas/RelatedImportSourceResource'
              description: >-
                The external system the record was imported from, or `null` when
                it was created in Flextell. Only present on detail responses.
            - type: 'null'
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        deleted_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - record_state
        - customer_id
        - room_id
        - channel_id
        - parent_appointment_id
        - code
        - relation_type
        - description
        - scheduled_at
        - duration_minutes
        - effective_duration_minutes
        - duration_source
        - status
        - cancellation_reason
        - creation_type
        - is_control_appointment
        - is_ai_generated
        - import_source_id
        - pending_scheduled_at
        - pending_expires_at
        - assistants
        - created_at
        - updated_at
        - deleted_at
      title: AppointmentResource
    RecordStateResource:
      type: object
      properties:
        is_read_only:
          type: boolean
          description: >-
            True when every write on this record is refused; false does not
            imply the caller may write.
        reason_code:
          type:
            - string
            - 'null'
          description: >-
            Why the record is read-only (`CUSTOMER_ERASED`, or
            `LEAD_NOT_ASSIGNED` for a salesperson on another rep's lead), or
            null when it is not.
      required:
        - is_read_only
        - reason_code
      title: RecordStateResource
    AppointmentDurationSource:
      type: string
      description: |
        Where the minutes an appointment occupies come from.
      enum:
        - appointment
        - clinic_default
      title: AppointmentDurationSource
    CustomerResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        first_name:
          anyOf:
            - type: string
            - type: 'null'
        last_name:
          anyOf:
            - type: string
            - type: 'null'
        phone_number:
          anyOf:
            - type: string
            - type: 'null'
        email:
          anyOf:
            - type: string
            - type: 'null'
        date_of_birth:
          type:
            - string
            - 'null'
        gender:
          anyOf:
            - $ref: '#/components/schemas/Gender'
            - type: 'null'
        country_id:
          type:
            - integer
            - 'null'
        country_name:
          type: string
        city_id:
          type:
            - integer
            - 'null'
        city_name:
          type: string
        district_id:
          type:
            - integer
            - 'null'
        district_name:
          type: string
        identity_number:
          anyOf:
            - type: string
            - type: 'null'
        passport_number:
          anyOf:
            - type: string
            - type: 'null'
        occupation_id:
          type:
            - integer
            - 'null'
        occupation_name:
          type: string
        address:
          anyOf:
            - type: string
            - type: 'null'
        default_channel_id:
          type:
            - integer
            - 'null'
        default_channel_name:
          type: string
        identities:
          type: array
          description: >-
            The customer's addresses on their channels, primary first. Present
            only for users who may view customer

            identities, and left out for masked records.
          items:
            $ref: '#/components/schemas/CustomerIdentitySummaryResource'
        channel_address:
          description: >-
            The address on the default channel, else the first address: the
            panel's "Kanal Adresi" column. Present together with `identities`.
          anyOf:
            - type: string
            - type: 'null'
        latest_conversation_id:
          type:
            - integer
            - 'null'
        avatar_url:
          type:
            - string
            - 'null'
        is_lead_stage:
          type: boolean
        is_intake_completed:
          type: boolean
          description: >-
            Whether the patient answered the intake form (set by the chatbot's
            intake flow). The value is kept

            whatever the intake setting; it is only meaningful while intake
            requirements are enabled.
        lead_id:
          type:
            - integer
            - 'null'
        is_masked:
          type: boolean
          description: >-
            Whether the identity fields are masked because the viewer may not
            see this lead's patient.
        can_start_conversation:
          type: boolean
          description: >-
            Whether the current user can open a conversation with this patient
            (or see the one they already have); `false` for a deleted or erased
            patient, a lead of a colleague and a patient they have no access to.
            The channel is not part of it.
        related_user:
          $ref: '#/components/schemas/RelatedUserResource'
        tags:
          type: array
          items:
            $ref: '#/components/schemas/TagResource'
        notification_channels:
          $ref: '#/components/schemas/CustomerNotificationChannelsResource'
        import_source:
          anyOf:
            - $ref: '#/components/schemas/RelatedImportSourceResource'
              description: >-
                The external system the record was imported from, or `null` when
                it was created in Flextell. Only present on detail responses.
            - type: 'null'
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        deleted_at:
          type:
            - string
            - 'null'
          format: date-time
        erased_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - record_state
        - first_name
        - last_name
        - phone_number
        - email
        - date_of_birth
        - gender
        - country_id
        - country_name
        - city_id
        - city_name
        - district_id
        - district_name
        - identity_number
        - passport_number
        - occupation_id
        - occupation_name
        - address
        - default_channel_id
        - default_channel_name
        - latest_conversation_id
        - avatar_url
        - is_lead_stage
        - is_intake_completed
        - lead_id
        - is_masked
        - can_start_conversation
        - related_user
        - created_at
        - updated_at
        - deleted_at
        - erased_at
      title: CustomerResource
    RelatedUserResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        avatar_url:
          type:
            - string
            - 'null'
          description: >-
            A signed profile photo URL valid for a few hours, or `null` without
            a photo. Only on responses that opt in.
      required:
        - id
        - name
      title: RelatedUserResource
    RoomResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        status:
          type: string
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        deleted_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - name
        - status
        - created_at
        - updated_at
        - deleted_at
      title: RoomResource
    TreatmentResource:
      type: object
      properties:
        id:
          type: integer
        group_id:
          type:
            - integer
            - 'null'
        name:
          type: string
        invoice_name:
          type:
            - string
            - 'null'
        keywords:
          type: array
          items: {}
        price:
          type: string
        currency_id:
          type:
            - integer
            - 'null'
        currency:
          anyOf:
            - $ref: '#/components/schemas/RelatedCurrencyResource'
            - type: 'null'
        tax_rate:
          type: integer
        converted_price:
          type:
            - number
            - 'null'
          description: >-
            `price` converted into the `target_currency_id` currency; null when
            a needed exchange rate is missing. Only present on the list with
            `target_currency_id`.
        converted_unit_price_excl_tax:
          type:
            - number
            - 'null'
          description: >-
            The net unit price a new sale or offer line gets in the
            `target_currency_id` currency, at the clinic's sale item tax rate;
            null when `converted_price` is. Only present on the list with
            `target_currency_id`.
        converted_currency_code:
          type: string
          description: >-
            The code of the `target_currency_id` currency. Only present on the
            list with `target_currency_id`.
        conversion_unavailable:
          type: boolean
          description: >-
            True when the price could not be converted because a needed exchange
            rate is missing. Only present on the list with `target_currency_id`.
        description:
          type:
            - string
            - 'null'
        session:
          type: integer
        duration_minutes:
          type:
            - integer
            - 'null'
          description: >-
            How long one session takes, in minutes; `null` means the clinic's
            slot duration applies.
        effective_duration_minutes:
          type: integer
          description: >-
            The minutes one session actually takes: `duration_minutes`, or the
            clinic's slot duration when that is `null`.
        duration_source:
          $ref: '#/components/schemas/TreatmentDurationSource'
          description: >-
            Where `effective_duration_minutes` comes from: the treatment's own
            duration or the clinic's slot duration.
        is_active:
          type: string
        extra_info:
          type: object
        group:
          type:
            - object
            - 'null'
          properties:
            id:
              type: integer
            name:
              type: string
            is_active:
              type: boolean
          required:
            - id
            - name
            - is_active
        users:
          type: array
          items:
            $ref: '#/components/schemas/RelatedDoctorResource'
        sessions:
          type: array
          items:
            $ref: '#/components/schemas/TreatmentSessionResource'
        import_source:
          anyOf:
            - $ref: '#/components/schemas/RelatedImportSourceResource'
              description: >-
                The external system the record was imported from, or `null` when
                it was created in Flextell. Only present on detail responses.
            - type: 'null'
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        deleted_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - group_id
        - name
        - invoice_name
        - keywords
        - price
        - currency_id
        - tax_rate
        - description
        - session
        - duration_minutes
        - effective_duration_minutes
        - duration_source
        - is_active
        - extra_info
        - created_at
        - updated_at
        - deleted_at
      title: TreatmentResource
    AppointmentTreatmentPlanResource:
      type: object
      properties:
        treatment_id:
          type: integer
        sessions:
          type: array
          items:
            $ref: '#/components/schemas/AppointmentTreatmentSessionResource'
      required:
        - treatment_id
      title: AppointmentTreatmentPlanResource
    AppointmentLinkedSessionResource:
      type: object
      properties:
        id:
          type: integer
        session_order:
          type: integer
        session_type:
          type:
            - string
            - 'null'
        treatment:
          type:
            - object
            - 'null'
          properties:
            id:
              type: integer
            name:
              type: string
            display_name:
              type: string
          required:
            - id
            - name
            - display_name
        products:
          type: array
          description: >-
            The products recorded as used on the session; the completion
            endpoint's prefill.
          items:
            $ref: '#/components/schemas/SessionProductResource'
      required:
        - id
        - session_order
        - session_type
        - treatment
      title: AppointmentLinkedSessionResource
    TagResource:
      type: object
      properties:
        id:
          type: integer
        tenant_id:
          type: integer
        name:
          type: string
        color:
          type: string
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        deleted_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - tenant_id
        - name
        - color
        - created_at
        - updated_at
        - deleted_at
      title: TagResource
    AppointmentReminderResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        appointment_id:
          type: integer
        tenant_id:
          type: integer
        type:
          type: string
        offset_days:
          type: integer
        scheduled_for:
          type: string
          format: date-time
        sent_at:
          type:
            - string
            - 'null'
          format: date-time
        channel:
          type: string
        message:
          type:
            - string
            - 'null'
          description: >-
            The sent message text; `null` when the patient's details are masked
            for the viewer, since it names the patient.
        status:
          type: string
        approval_status:
          type: string
        approved_at:
          type:
            - string
            - 'null'
          format: date-time
        approved_by:
          type:
            - integer
            - 'null'
        metadata:
          type:
            - array
            - 'null'
          items: {}
        preview_message:
          type:
            - string
            - 'null'
          description: >-
            The message the reminder will send, rendered as plain text from its
            template with today's data. `null` once it is sent (see `message`),
            when the template or appointment is missing, or when the patient's
            details are masked for the viewer. Only present on detail responses.
        appointment:
          $ref: '#/components/schemas/RelatedAppointmentResource'
        approver:
          anyOf:
            - $ref: '#/components/schemas/RelatedUserResource'
            - type: 'null'
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - record_state
        - appointment_id
        - tenant_id
        - type
        - offset_days
        - scheduled_for
        - sent_at
        - channel
        - message
        - status
        - approval_status
        - approved_at
        - approved_by
        - metadata
        - created_at
        - updated_at
      title: AppointmentReminderResource
    AppointmentCustomerBalanceResource:
      type: object
      properties:
        outstanding_balance:
          type: string
          description: >-
            Everything the patient owes in the clinic currency; negative is a
            credit in their favour.
        overdue_balance:
          type: string
          description: >-
            The part of the sale debt already due: cash sales and instalments
            past their due date, net of collections.
        currency_code:
          type: string
          description: The clinic currency both amounts are in.
      required:
        - outstanding_balance
        - overdue_balance
        - currency_code
      title: AppointmentCustomerBalanceResource
    RelatedImportSourceResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        company_logo:
          type: 'null'
      required:
        - id
        - name
        - company_logo
      title: RelatedImportSourceResource
    Gender:
      type: string
      enum:
        - male
        - female
        - other
      title: Gender
    CustomerIdentitySummaryResource:
      type: object
      properties:
        id:
          type: integer
        channel_id:
          type: integer
        channel_type:
          type: string
          description: The channel type, e.g. `whatsapp`, `telegram`, `instagram`.
        channel_name:
          type: string
        identifier:
          type: string
        is_primary:
          type: boolean
      required:
        - id
        - channel_id
        - channel_type
        - channel_name
        - identifier
        - is_primary
      title: CustomerIdentitySummaryResource
    CustomerNotificationChannelsResource:
      type: object
      properties:
        default_channel_id:
          type:
            - string
            - 'null'
        source:
          type:
            - string
            - 'null'
        channels:
          type: array
          items: {}
      required:
        - default_channel_id
        - source
        - channels
      title: CustomerNotificationChannelsResource
    RelatedCurrencyResource:
      type: object
      properties:
        id:
          type: integer
        code:
          type:
            - string
            - 'null'
        symbol:
          type:
            - string
            - 'null'
        name:
          type: string
      required:
        - id
        - code
        - symbol
        - name
      title: RelatedCurrencyResource
    TreatmentDurationSource:
      type: string
      description: |
        Where the minutes one session of a treatment takes come from.
      enum:
        - treatment
        - clinic_default
      title: TreatmentDurationSource
    RelatedDoctorResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        email:
          type: string
        phone:
          type:
            - string
            - 'null'
        is_active:
          type: boolean
      required:
        - id
        - name
        - email
        - phone
        - is_active
      title: RelatedDoctorResource
    TreatmentSessionResource:
      type: object
      properties:
        id:
          type: integer
        session_order:
          type: integer
        session_type:
          $ref: '#/components/schemas/AppointmentType'
        next_gap_days:
          type:
            - integer
            - 'null'
        offset_days:
          type: integer
        products:
          type: array
          items:
            $ref: '#/components/schemas/TreatmentSessionProductResource'
      required:
        - id
        - session_order
        - session_type
        - next_gap_days
        - offset_days
      title: TreatmentSessionResource
    AppointmentTreatmentSessionResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        appointment_id:
          type:
            - integer
            - 'null'
        session_order:
          type: integer
        is_custom:
          type: boolean
        session_type:
          type:
            - string
            - 'null'
        offset_days:
          type: integer
        next_gap_days:
          type:
            - integer
            - 'null'
        scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
        products:
          type: array
          items:
            $ref: '#/components/schemas/SessionProductResource'
      required:
        - id
        - record_state
        - appointment_id
        - session_order
        - is_custom
        - session_type
        - offset_days
        - next_gap_days
        - scheduled_at
      title: AppointmentTreatmentSessionResource
    SessionProductResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        full_name:
          type: string
          description: The brand-prefixed product name, e.g. `Allergan Harmonyca`.
        quantity:
          type: number
        unit_code:
          type:
            - object
            - 'null'
          properties:
            id:
              type: string
            name:
              type: string
            code:
              type: string
          required:
            - id
            - name
            - code
        warehouse:
          type:
            - object
            - 'null'
          description: >-
            The warehouse the product was deducted from; null when none was
            recorded.
          properties:
            id:
              type: integer
            name:
              type: string
          required:
            - id
            - name
      required:
        - id
        - quantity
      title: SessionProductResource
    RelatedAppointmentResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        code:
          type: string
        scheduled_at:
          type: string
          format: date-time
        status:
          type: string
        relation_type:
          type: string
        parent_appointment_id:
          type:
            - integer
            - 'null'
        customer:
          anyOf:
            - $ref: '#/components/schemas/RelatedCustomerResource'
            - type: 'null'
        doctor:
          anyOf:
            - $ref: '#/components/schemas/RelatedUserResource'
            - type: 'null'
        treatments:
          type: array
          items:
            $ref: '#/components/schemas/RelatedTreatmentResource'
        parent_appointment:
          anyOf:
            - $ref: '#/components/schemas/RelatedAppointmentResource'
            - type: 'null'
      required:
        - id
        - record_state
        - code
        - scheduled_at
        - status
        - relation_type
        - parent_appointment_id
      title: RelatedAppointmentResource
    AppointmentType:
      type: string
      enum:
        - control
        - operation
        - treatment
        - consultation
        - follow_up
        - emergency
        - surgery
      title: AppointmentType
    TreatmentSessionProductResource:
      type: object
      properties:
        id:
          type: integer
        product_id:
          type: integer
        min_quantity:
          type:
            - number
            - 'null'
        product:
          type: object
          properties:
            id:
              type: integer
            name:
              type: string
            full_name:
              type: string
            brand:
              type:
                - object
                - 'null'
              properties:
                id:
                  type: integer
                name:
                  type: string
              required:
                - id
                - name
            unit_code:
              type:
                - object
                - 'null'
              properties:
                id:
                  type: string
                name:
                  type: string
                code:
                  type: string
              required:
                - id
                - name
                - code
          required:
            - id
            - name
            - full_name
            - brand
            - unit_code
      required:
        - id
        - product_id
        - min_quantity
      title: TreatmentSessionProductResource
    RelatedCustomerResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        first_name:
          anyOf:
            - type: string
            - type: 'null'
        last_name:
          anyOf:
            - type: string
            - type: 'null'
        phone_number:
          anyOf:
            - type: string
            - type: 'null'
        email:
          anyOf:
            - type: string
            - type: 'null'
        is_masked:
          type: boolean
          description: >-
            Whether the identity fields are masked because the viewer may not
            see this lead's patient.
        is_lead_stage:
          type: boolean
          description: >-
            Whether the person is still a lead (link to `/leads/{lead_id}`)
            rather than a patient (link to `/customers/{id}`).
        lead_id:
          type:
            - integer
            - 'null'
          description: >-
            The lead the person came from; kept after conversion, so check
            `is_lead_stage` before linking to it.
        is_deleted:
          type: boolean
          description: >-
            Whether the person was deleted; records such as offers and sales
            outlive them, so there is no profile to open.
        can_start_conversation:
          type: boolean
          description: >-
            Whether the current user can open a conversation with this person
            (or see the one they already have); `false` for a deleted or erased
            person, a lead of a colleague and a person they have no access to.
            Use it to hide the link to their chat; the channel is not part of
            it.
      required:
        - id
        - record_state
        - first_name
        - last_name
        - phone_number
        - email
        - is_masked
        - is_lead_stage
        - lead_id
        - is_deleted
        - can_start_conversation
      title: RelatedCustomerResource
    RelatedTreatmentResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        group:
          type:
            - object
            - 'null'
          properties:
            id:
              type: integer
            name:
              type: string
          required:
            - id
            - name
      required:
        - id
        - name
        - group
      title: RelatedTreatmentResource
  responses:
    AuthenticationException:
      description: Unauthenticated
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    AuthorizationException:
      description: Authorization error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    CustomerErasedException:
      description: The patient record has been erased and is read-only
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                description: Always false for an error.
                examples:
                  - false
              error_code:
                type: string
                description: Machine-readable error code.
                examples:
                  - CUSTOMER_ERASED
              message:
                type: string
                description: Localized error message.
            required:
              - success
              - error_code
              - message
    ValidationException:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Errors overview.
              errors:
                type: object
                description: A detailed description of each field that failed validation.
                additionalProperties:
                  type: array
                  items:
                    type: string
            required:
              - message
              - errors
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://app.flextell.ai/oauth/authorize
          tokenUrl: https://app.flextell.ai/oauth/token
          scopes:
            '*': all
    bearer:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.