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

# Set a patient's referring provider

> Adds the provider with this NPI as the patient's referring provider in the EHR, keeping every other provider already on the chart. A provider the practice's directory does not have yet is added to it from the national provider registry first (`addedToDirectory: true`). EZDerm: the provider joins the patient's care team as the default referring physician; the other members stay on the team and lose the default flag. ModMed: the provider is added to the patient's referring providers. ModMed has no default flag and keeps reporting the longest-standing referring provider as THE referring provider, so `primaryReferringNpi` can name another provider when the chart already had one; remove the other provider in ModMed if this one must be the only one. Calling it again with the same NPI writes nothing and returns `changed: false`. 422 `npi_not_found` when the NPI is not in the national registry; 422 `chart_not_writable` when the chart could not be read in full (`data.reason: practice_data_unreadable`) or, on EZDerm, the practice address book has too many providers with this last name to rule out an existing entry (`directory_ambiguous`); nothing is written in either case. If the EHR does not confirm the change the request fails with 409 `ehr_write_uncertain`: the provider may already be on the chart or in the directory, so read the chart before retrying. Send an `Idempotency-Key` header: a retry with the same NPI replays the original result for 24 hours. Requires write:patients.



## OpenAPI

````yaml /openapi-v3.json put /patients/{id}/referring-provider
openapi: 3.0.0
info:
  title: Max AI Public API
  description: API for third-party marketplace apps
  version: '3.0'
  contact: {}
servers:
  - url: https://api.maxcare.ai/v3
security: []
tags: []
paths:
  /patients/{id}/referring-provider:
    put:
      tags:
        - Patients
      summary: Set a patient's referring provider
      description: >-
        Adds the provider with this NPI as the patient's referring provider in
        the EHR, keeping every other provider already on the chart. A provider
        the practice's directory does not have yet is added to it from the
        national provider registry first (`addedToDirectory: true`). EZDerm: the
        provider joins the patient's care team as the default referring
        physician; the other members stay on the team and lose the default flag.
        ModMed: the provider is added to the patient's referring providers.
        ModMed has no default flag and keeps reporting the longest-standing
        referring provider as THE referring provider, so `primaryReferringNpi`
        can name another provider when the chart already had one; remove the
        other provider in ModMed if this one must be the only one. Calling it
        again with the same NPI writes nothing and returns `changed: false`. 422
        `npi_not_found` when the NPI is not in the national registry; 422
        `chart_not_writable` when the chart could not be read in full
        (`data.reason: practice_data_unreadable`) or, on EZDerm, the practice
        address book has too many providers with this last name to rule out an
        existing entry (`directory_ambiguous`); nothing is written in either
        case. If the EHR does not confirm the change the request fails with 409
        `ehr_write_uncertain`: the provider may already be on the chart or in
        the directory, so read the chart before retrying. Send an
        `Idempotency-Key` header: a retry with the same NPI replays the original
        result for 24 hours. Requires write:patients.
      operationId: PatientsPublicController_setReferringProvider
      parameters:
        - name: id
          required: true
          in: path
          description: Patient ID
          schema:
            type: string
        - name: idempotency-key
          required: false
          in: header
          description: Client-generated key protecting retries for 24 hours
          schema:
            type: string
        - name: X-Organization-Id
          in: header
          required: true
          schema:
            type: string
          description: Target clinic organization ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SetReferringProviderBody'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SetReferringProviderSuccessResponse'
        '400':
          description: Missing or invalid request parameter
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiBadRequestResponse'
        '401':
          description: Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiUnauthorizedResponse'
        '403':
          description: Insufficient scope
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiForbiddenResponse'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiNotFoundResponse'
        '409':
          description: Resource conflict (e.g. editing a signed note)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiConflictResponse'
        '422':
          description: Request refused by the EHR's state (named `code`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiUnprocessableResponse'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiRateLimitResponse'
        '502':
          description: EHR sync failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiBadGatewayResponse'
        '503':
          description: EHR integration unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiServiceUnavailableResponse'
      security:
        - api-key: []
components:
  schemas:
    SetReferringProviderBody:
      type: object
      properties:
        npi:
          type: string
          description: The referring provider's 10-digit NPI
          example: '1255374757'
          pattern: ^\d{10}$
      required:
        - npi
    SetReferringProviderSuccessResponse:
      type: object
      properties:
        code:
          type: string
          description: Response code
          example: success
        data:
          $ref: '#/components/schemas/SetReferringProviderData'
      required:
        - code
        - data
    PublicApiBadRequestResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: bad_request
        message:
          type: string
          description: Human-readable error message
          example: '''id'' must be a valid UUID'
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    PublicApiUnauthorizedResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: unauthorized
        message:
          type: string
          description: Human-readable error message
          example: Invalid or missing API key
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    PublicApiForbiddenResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: forbidden
        message:
          type: string
          description: Human-readable error message
          example: Insufficient scope
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    PublicApiNotFoundResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: not_found
        message:
          type: string
          description: Human-readable error message
          example: Resource not found
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    PublicApiConflictResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: conflict
        message:
          type: string
          description: Human-readable error message
          example: Cannot edit a signed note
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    PublicApiUnprocessableResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: controlled_substance_unsupported
        message:
          type: string
          description: Human-readable error message
          example: Controlled substances cannot be prescribed through the API
        data:
          type: object
          description: Condition-specific detail, when the code defines any
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    PublicApiRateLimitResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: rate_limit_exceeded
        message:
          type: string
          description: Human-readable error message
          example: Rate limit exceeded. Maximum 1000 requests per 60 seconds.
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    PublicApiBadGatewayResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: unexpected_integration_error
        message:
          type: string
          description: Human-readable error message
          example: EHR sync failed
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    PublicApiServiceUnavailableResponse:
      type: object
      properties:
        code:
          type: string
          description: Error code
          example: server_unresponsive
        message:
          type: string
          description: Human-readable error message
          example: EHR integration is not available for this note
        trace_id:
          type: string
          description: Trace ID for debugging
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - code
        - message
        - trace_id
    SetReferringProviderData:
      type: object
      properties:
        patientId:
          type: string
          description: Patient the provider was set on
          example: pat_c56103bcd39c46d39f3138dd2b5e05f6
        npi:
          type: string
          description: The provider's NPI
          example: '1255374757'
        providerName:
          type: string
          nullable: true
          description: The provider's name as the EHR's directory records it
          example: Nazem Abdelfattah, MD
        ehrProviderId:
          type: string
          description: >-
            The EHR's directory id for the provider: the EZDerm address-book id,
            or the ModMed referral-contact id
          example: ef7da13e-fe38-4cde-8d39-8f573e4684ba
        addedToDirectory:
          type: boolean
          description: >-
            True when the provider was not in the practice's directory (EZDerm
            address book, ModMed referral contacts) and this request added it
            from the national registry
        changed:
          type: boolean
          description: False when the provider was already set and nothing was written
        primaryReferringNpi:
          type: string
          nullable: true
          description: >-
            The NPI the EHR reports as the patient's referring provider after
            this request. On EZDerm it is always `npi`. ModMed has no default:
            when the chart already had a referring provider, ModMed keeps
            reporting the longest-standing one, so this can be a different NPI.
          example: '1255374757'
      required:
        - patientId
        - npi
        - providerName
        - ehrProviderId
        - addedToDirectory
        - changed
        - primaryReferringNpi
  securitySchemes:
    api-key:
      scheme: bearer
      bearerFormat: JWT
      type: http
      description: Marketplace API key

````

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