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

# Create or match a patient

> Never creates a second copy of a person. Matching order: 1. a patient already linked to `external_id`; 2. the same phone and the same name (Arabic or English spelling); 3. the same phone with another name becomes a family member under that phone's holder; 4. otherwise a new patient. A matched patient is updated with the fields you send.



## OpenAPI

````yaml /openapi.json post /patients
openapi: 3.1.0
info:
  title: Docistra API
  version: 1.0.0
  description: >-
    Connect your software to Docistra in both directions. All times are ISO
    8601; Docistra's clinics run on Cairo time (Africa/Cairo). Every path {id}
    takes Docistra's id or `ext:<your id>`.
servers:
  - url: https://docistra.com/api/v1
security:
  - bearerAuth: []
tags:
  - name: Organization
  - name: Patients
  - name: Appointments
  - name: Availability
  - name: Doctors
  - name: Doctor schedule
  - name: Branches
  - name: Reference data
  - name: Webhooks
paths:
  /patients:
    post:
      tags:
        - Patients
      summary: Create or match a patient
      description: >-
        Never creates a second copy of a person. Matching order: 1. a patient
        already linked to `external_id`; 2. the same phone and the same name
        (Arabic or English spelling); 3. the same phone with another name
        becomes a family member under that phone's holder; 4. otherwise a new
        patient. A matched patient is updated with the fields you send.
      operationId: createPatient
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatientInput'
            example:
              external_id: P-10293
              name: Mona Samy
              phone: '01012345678'
              gender: female
              date_of_birth: '1990-04-12'
      responses:
        '200':
          description: Matched an existing patient (updated)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PatientWrite'
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PatientWrite'
        '400':
          $ref: '#/components/responses/BadRequest'
        '409':
          $ref: '#/components/responses/Conflict'
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      schema:
        type: string
        maxLength: 255
      description: >-
        A unique value (e.g. a UUID) per operation. A retry with the same key
        returns the first response for 24 hours.
  schemas:
    PatientInput:
      type: object
      properties:
        external_id:
          type:
            - string
            - 'null'
          maxLength: 200
        name:
          type: string
          maxLength: 200
          description: Required on create.
        phone:
          type:
            - string
            - 'null'
          description: >-
            Egyptian mobile in any spelling, or an international number starting
            with + or 00.
        contact_phone:
          type:
            - string
            - 'null'
        gender:
          type:
            - string
            - 'null'
          enum:
            - male
            - female
            - null
        date_of_birth:
          type:
            - string
            - 'null'
          format: date
        age:
          type:
            - integer
            - 'null'
          minimum: 0
          maximum: 130
        address:
          type:
            - string
            - 'null'
          maxLength: 500
        nationality:
          type:
            - string
            - 'null'
          description: Country code or name, e.g. EG / Egypt / مصر
        file_number:
          type:
            - string
            - 'null'
          maxLength: 30
        holder_id:
          type: string
          description: Create as a family member of this patient (create only).
        relationship:
          type:
            - string
            - 'null'
          enum:
            - son
            - daughter
            - wife
            - husband
            - father
            - mother
            - brother
            - sister
            - grandson
            - granddaughter
            - grandfather
            - grandmother
            - other
            - null
    PatientWrite:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/Patient'
        created:
          type: boolean
    Patient:
      type: object
      properties:
        object:
          const: patient
        id:
          type: string
          format: uuid
        external_id:
          type:
            - string
            - 'null'
        name:
          type:
            - string
            - 'null'
        phone:
          type:
            - string
            - 'null'
          example: '+201012345678'
        contact_phone:
          type:
            - string
            - 'null'
        gender:
          type:
            - string
            - 'null'
          enum:
            - male
            - female
            - other
            - null
        date_of_birth:
          type:
            - string
            - 'null'
          format: date
        age:
          type:
            - integer
            - 'null'
        address:
          type:
            - string
            - 'null'
        nationality:
          type:
            - string
            - 'null'
          description: ISO 3166-1 alpha-2
          example: EG
        file_number:
          type:
            - string
            - 'null'
        holder_id:
          type:
            - string
            - 'null'
          description: 'Set on a family member: the patient whose phone they use.'
        relationship:
          type:
            - string
            - 'null'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          example: slot_taken
      additionalProperties: true
  responses:
    BadRequest:
      description: Invalid input
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Conflict:
      description: >-
        The request clashes with the current state (slot taken, already linked,
        paid visit, ...)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your API key (dk_live_...), from Settings > Integrations > API in
        Docistra.

````

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