{
  "openapi": "3.1.0",
  "info": {
    "title": "SunCharts EHR Clinical API",
    "version": "0.34.0",
    "license": {
      "name": "Apache-2.0",
      "identifier": "Apache-2.0"
    },
    "description": "API specification Apache-2.0; implementation AGPL-3.0-only. Synthetic development preview. This contract is served by each independent SunCharts EHR installation and covers its native REST, bounded FHIR R4, scheduling, billing, EDI, webhook and practice-owned integration surfaces. Tenant/user identity is derived from authenticated credentials. OAuth2 authorization code with S256 PKCE, scoped opaque tokens and explicit local consent permits independent clients; optional SunCharts Connect routes add onboarding and managed services but are not required for the instance-local clinical, scheduling, billing, clearinghouse or integration APIs. Provider callbacks retain their endpoint-specific verification and are not general unauthenticated writes. FHIR R4 projections and bounded Patient, clinical-list, local draft ServiceRequest and Immunization writes form an initial HL7-family boundary; no general HL7 v2 interface, US Core, SMART App Launch, Bulk Data or ONC claim. Legacy HS256 assertions require ENGINE_ALLOW_LEGACY_GATEWAY=true. Imports preserve source history and never authorize cutover. No automatic mutation retries."
  },
  "servers": [
    {
      "url": "/",
      "description": "The current SunCharts EHR installation"
    }
  ],
  "externalDocs": {
    "description": "API capability and optional-service boundary",
    "url": "https://github.com/PIndustries/suncharts-ehr/blob/main/docs/api.md"
  },
  "security": [
    {
      "oauth2": [
        "clinical.read"
      ]
    },
    {
      "browserSession": []
    }
  ],
  "paths": {
    "/api/v1/care-pathways/instances/{id}/steps/{step}/intake-packet": {
      "post": {
        "operationId": "issueWorkflowIntakePacket",
        "summary": "Issue the saved run revision patient form as a bound intake packet",
        "description": "Requires an active patient_form step with fields and a linked patient/appointment. If-Match is the step version. A retry returns the same packet ID; its secret URL appears only on first issuance. No message is sent and the step is not completed.",
        "security": [
          {
            "oauth2": [
              "clinical.write",
              "scheduling.write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "step",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Quoted current version."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created packet: packet_id, one-time intake_url, secret_shown_once, workflow_instance_id, workflow_step_key, workflow_definition_version."
          },
          "200": {
            "description": "Existing bound packet, with intake_url null and secret_shown_once false."
          },
          "403": {
            "description": "Native role, downstream scope or custom policy denied."
          },
          "409": {
            "description": "Inactive workflow, mismatched appointment, blocked step or stale version."
          }
        }
      }
    },
    "/api/v1/previsit/packets/{id}": {
      "get": {
        "operationId": "getIntakePacket",
        "summary": "Read a tenant-scoped intake packet and latest submitted answers",
        "description": "Returns packet_id, packet_version, status, created_at, nullable expires_at and expired, immutable template_snapshot, patient identity (patient_identity: given_name, family_name, birth_date for side-by-side comparison), nullable appointment_id/starts_at, attested_name, response and nullable workflow_instance_id/workflow_step_key/workflow_definition_version. Never returns the link secret or saved progress.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Packet detail; Cache-Control no-store."
          },
          "404": {
            "description": "Packet not found in the authenticated tenant."
          }
        }
      }
    },
    "/api/v1/previsit/packets/{id}/demographics": {
      "post": {
        "operationId": "promoteReviewedIntakeDemographics",
        "summary": "Apply explicitly selected mapped answers from a reviewed intake packet",
        "description": "Only immutable field chart_target values demographics.preferred_name, pronouns, language, administrative_gender, phone, email, address.line1, address.line2, address.city, address.region, address.postal_code, emergency_contact.name, emergency_contact.relationship and emergency_contact.phone are supported; name and date of birth are never changed here. Only the selected fields change; every other chart field is kept. Values come from the stored response, never caller-supplied values. Native validation, current demographics version, history and intake provenance apply atomically. No signed clinical content changes.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Quoted current version."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "fields",
                  "demographics_version",
                  "reason"
                ],
                "properties": {
                  "fields": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 14,
                    "uniqueItems": true,
                    "items": {
                      "type": "string"
                    }
                  },
                  "demographics_version": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 800
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "packet_id, patient_id, new demographics version and content; ETag is the new version."
          },
          "400": {
            "description": "Unsupported mapping, empty answer or invalid native contact field."
          },
          "403": {
            "description": "Native role, clinical edit policy or OAuth scope denied."
          },
          "409": {
            "description": "Packet is not reviewed, packet version changed, or demographics version changed."
          }
        }
      }
    },
    "/api/v1/patients": {
      "post": {
        "operationId": "createPatient",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Patient"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewPatient"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ]
      },
      "get": {
        "operationId": "listPatients",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Cursor returned by the previous page; 50 patients per page."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "archived",
                "all"
              ],
              "default": "active"
            },
            "description": "Directory status filter. Archived patients retain direct chart and record access."
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped patient page",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientPage"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{id}": {
      "get": {
        "operationId": "getPatient",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Patient"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/patients/{id}/record": {
      "get": {
        "operationId": "getSignedRecord",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Record"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/appointments": {
      "post": {
        "operationId": "bookAppointment",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Appointment"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewAppointment"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Book with an active native provider. Optional request_id gives safe retry matching, source_history_id links a staff-reviewed imported appointment. Enforces provider, patient, room and block conflicts atomically. Existing minimal booking fields remain supported."
      }
    },
    "/api/v1/appointments/{id}/check-in": {
      "post": {
        "operationId": "checkIn",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Appointment"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/visits": {
      "post": {
        "operationId": "startVisit",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Visit"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted current version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StartVisit"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/visits/{id}": {
      "get": {
        "operationId": "getVisit",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Visit"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted current version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/visits/{id}/note": {
      "put": {
        "operationId": "saveNote",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Visit"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted current version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Current quoted visit version, for example \"1\". Missing: 428. Stale: 409."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SoapNote"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "While the visit is in progress, the practice's clinical staff may save the note: the assigned clinician, any other clinician, the owner, and an enabled nurse or medical assistant. Front desk and read-only staff may not, and a custom access policy without clinical edit blocks it. A delegated support session may save a draft. The visit does not have to be assigned to the writer. Replaces the whole note; If-Match must carry the current visit version, so two writers cannot overwrite each other. The server records who saved in saved_by. procedure is optional. started_from may name an earlier signed visit of the same patient whose text the note was started from; it is verified, completed with that visit's date and audited once."
      }
    },
    "/api/v1/visits/{id}/previous-note": {
      "get": {
        "operationId": "getPreviousVisitNote",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreviousNote"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Text of the most recent earlier signed note",
        "description": "Anyone who may save this visit's note may read this (the same rule). Returns the note text of the patient's most recent signed visit dated on or before this one: the assigned clinician's own note when one exists, otherwise the most recent by any clinician in the practice. Unsigned notes, other patients and other practices are never returned. source is null when there is no earlier signed note. Read-only: the earlier visit is not changed; the read is audited."
      }
    },
    "/api/v1/visits/{id}/note-authorship": {
      "get": {
        "operationId": "getVisitNoteAuthorship",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NoteAuthorship"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Who wrote, signed and corrected a visit note",
        "description": "Staff-only, tenant-scoped. Names the assigned clinician, who last saved the note, who signed it and who wrote each amendment, and says whether the caller may draft, sign or amend, with the caller's custom access policy applied. Returns no note text. The read is audited."
      }
    },
    "/api/v1/visits/{id}/vitals": {
      "put": {
        "operationId": "saveVitals",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Visit"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted current version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Current quoted visit version, for example \"1\". Missing: 428. Stale: 409."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Vitals"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Enabled nurse/medical_assistant, the assigned clinician, or another clinician or the owner covering the visit, before signing. Shares Visit.version; each save is recorded with its author."
      }
    },
    "/api/v1/visits/{id}/sign": {
      "post": {
        "operationId": "signVisit",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Visit"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted current version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Current quoted visit version, for example \"1\". Missing: 428. Stale: 409."
          }
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "summary": "Sign the visit note",
        "description": "A clinician or the owner signs: the assigned clinician, or another clinician or the owner covering the visit. Nurses, medical assistants and delegated support sessions can never sign. signed_by records the person who actually signed. The visit's clinician_id is not changed: fee lookups and eligibility checks keep using the assigned clinician. The signed note and vitals are immutable afterwards."
      }
    },
    "/api/v1/visits/{id}/amendments": {
      "post": {
        "operationId": "amendVisit",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Visit"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted current version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Current quoted visit version, for example \"1\". Missing: 428. Stale: 409."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewAmendment"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "summary": "Append a signed correction to a signed note",
        "description": "Any clinician or the owner may append a correction to a signed note, whether or not they signed it or the visit is assigned to them. Nurses, medical assistants and delegated support sessions cannot. Each amendment records its author and the original note is never changed."
      }
    },
    "/api/v1/portal/record": {
      "get": {
        "operationId": "getPatientPortalRecord",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Record"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in trusted tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State/version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "428": {
            "description": "Version required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [],
        "security": [
          {
            "delegatedJwt": []
          }
        ]
      }
    },
    "/api/v1/patients/{id}/banner": {
      "get": {
        "operationId": "getStaffPatientBanner",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "description": "Staff only. Read-only facts for the patient banner: next appointment, last finished visit, status flags and a revision marker. The billing object (reviewed patient balance, card on file) is present only when the caller may view billing; eligibility (the latest check per coverage) only when the caller may also view claims.",
        "responses": {
          "200": {
            "description": "Patient banner facts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "patient_id",
                    "flags",
                    "revision"
                  ],
                  "properties": {
                    "patient_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "flags": {
                      "type": "object"
                    },
                    "next_appointment": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "last_visit": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "revision": {
                      "type": "string"
                    },
                    "billing": {
                      "type": "object"
                    },
                    "eligibility": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{id}/workspace": {
      "get": {
        "operationId": "getStaffPatientWorkspace",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "description": "Staff only. Includes draft visits. Latest 100 appointments and 100 visits. Full historical paging is pending.",
        "responses": {
          "200": {
            "description": "Clinical workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Workspace"
                }
              }
            }
          }
        }
      }
    },
    "/auth/login": {
      "post": {
        "operationId": "loginBrowser",
        "responses": {
          "200": {
            "description": "Session operation completed"
          }
        },
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string",
                    "format": "password"
                  }
                },
                "required": [
                  "email",
                  "password"
                ]
              }
            }
          }
        }
      }
    },
    "/auth/logout": {
      "post": {
        "operationId": "logoutBrowser",
        "responses": {
          "200": {
            "description": "Session operation completed"
          }
        }
      }
    },
    "/auth/me": {
      "get": {
        "operationId": "meBrowser",
        "responses": {
          "200": {
            "description": "Session operation completed"
          }
        }
      }
    },
    "/.well-known/oauth-authorization-server": {
      "get": {
        "operationId": "oauthMetadata",
        "description": "RFC8414 metadata for this installation.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": []
      }
    },
    "/oauth/authorize": {
      "get": {
        "operationId": "authorize",
        "description": "response_type=code, code_challenge_method=S256. Validates registered callback before redirecting to the local consent GUI. Returns 303.",
        "responses": {
          "303": {
            "description": "Local sign-in/consent redirect"
          },
          "400": {
            "description": "Invalid authorization request"
          }
        },
        "security": [],
        "parameters": [
          {
            "name": "response_type",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "client_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "redirect_uri",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "scope",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "state",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code_challenge_method",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/oauth/requests/{id}": {
      "get": {
        "operationId": "consentRequest",
        "description": "Local session only; tenant-bound pending request, expires in ten minutes.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/oauth/requests/{id}/decision": {
      "post": {
        "operationId": "consentDecision",
        "description": "One-time explicit consent; response redirect is validated at authorization start. migration.manage requires owner.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "approved": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "approved"
                ]
              }
            }
          }
        },
        "security": [
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/oauth/token": {
      "post": {
        "operationId": "oauthToken",
        "description": "Confidential client_secret_basic. No browser session substitution.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "clientBasic": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "grant_type": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string"
                  },
                  "redirect_uri": {
                    "type": "string"
                  },
                  "code_verifier": {
                    "type": "string"
                  },
                  "refresh_token": {
                    "type": "string"
                  },
                  "scope": {
                    "type": "string"
                  }
                },
                "required": [
                  "grant_type"
                ]
              }
            }
          }
        }
      }
    },
    "/oauth/revoke": {
      "post": {
        "operationId": "oauthRevoke",
        "description": "Confidential client_secret_basic. No browser session substitution.",
        "responses": {
          "200": {
            "description": "Revoked or unknown token; entire owned grant is revoked."
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "clientBasic": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string"
                  },
                  "token_type_hint": {
                    "type": "string"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/v1/oauth/clients": {
      "get": {
        "operationId": "listOAuthClients",
        "description": "Local owner only. Hashed client secrets are never returned.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "browserSession": []
          }
        ]
      },
      "post": {
        "operationId": "registerOAuthClient",
        "description": "Local owner only. Secret returned exactly once. Registration is not public dynamic client registration.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "redirect_uri": {
                    "type": "string"
                  },
                  "scope": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "redirect_uri",
                  "scope"
                ]
              }
            }
          }
        },
        "security": [
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/oauth/clients/{id}/disable": {
      "post": {
        "operationId": "disableOAuthClient",
        "description": "Local owner; disables app and revokes its grants atomically.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/oauth/grants": {
      "get": {
        "operationId": "listOAuthGrants",
        "description": "Local session; own grants or all tenant grants for owner.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/oauth/grants/{id}/revoke": {
      "post": {
        "operationId": "revokeOAuthGrant",
        "description": "Local session; own grant or tenant owner. Active streams terminate on the next authorization check.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/connection": {
      "get": {
        "operationId": "connectionIdentity",
        "description": "Authenticated installation tenant, user and role. Pin this identity when connecting.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        }
      }
    },
    "/api/v1/events": {
      "get": {
        "operationId": "listChanges",
        "description": "Durable tenant-scoped mutation notices; no clinical payload. Up to 100 notices per page; next_cursor for replay.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "oauth2": [
              "events.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ]
      }
    },
    "/api/v1/events/stream": {
      "get": {
        "operationId": "streamChanges",
        "description": "Durable tenant-scoped mutation notices; no clinical payload. Rechecks authorization each second. Event type clinical.change, id is cursor. Browser session or OAuth only.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "oauth2": [
              "events.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          },
          {
            "name": "Last-Event-ID",
            "in": "header",
            "schema": {
              "type": "string",
              "description": "Nonnegative cursor; max of header and query used."
            }
          }
        ]
      }
    },
    "/api/v1/migrations": {
      "get": {
        "operationId": "listMigrationJobs",
        "description": "Owner only; latest 100 jobs. Every job returns cutover.allowed=false.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "oauth2": [
              "migration.manage"
            ]
          },
          {
            "browserSession": []
          }
        ]
      },
      "post": {
        "operationId": "createMigrationJob",
        "description": "Owner only; manifest declares bounded source counts and source snapshot. Maximum 100000 total records. Does not independently verify source freeze.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "source_instance": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "source_revision": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "expected_counts": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "integer",
                      "minimum": 0
                    }
                  },
                  "consistency": {
                    "type": "string",
                    "enum": [
                      "read_only_export",
                      "transactional_export"
                    ]
                  },
                  "limitations": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "source_instance",
                  "source_revision",
                  "expected_counts",
                  "consistency"
                ]
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "migration.manage"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/migrations/{id}": {
      "get": {
        "operationId": "migrationStatus",
        "description": "Owner only; counts, digest, limitations and reconciliation issues.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "oauth2": [
              "migration.manage"
            ]
          },
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/migrations/{id}/items": {
      "post": {
        "operationId": "stageMigrationItems",
        "description": "Owner only; 1..50 records, 64KiB request limit. Exact retries safe; changed source record in one snapshot conflicts. Credentials rejected.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 50,
                    "items": {
                      "$ref": "#/components/schemas/MigrationItem"
                    }
                  }
                },
                "required": [
                  "items"
                ]
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "migration.manage"
            ]
          },
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/migrations/{id}/reconcile": {
      "post": {
        "operationId": "reconcileMigration",
        "description": "Checks declared counts, external identities, patient links and MRN conflicts; digest covers manifest and ordered items. The report lists every staged patient as new, linked by an earlier import, an exact single match to an existing chart (attach pre-selected) or a possible match needing an owner decision; ready_to_import is false while any decision is missing.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "oauth2": [
              "migration.manage"
            ]
          },
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/migrations/{id}/patient-decisions": {
      "post": {
        "operationId": "decideMigrationPatient",
        "description": "Owner only. For a staged patient that matches an existing chart (same normalized family name, first given name and birth date, or a weaker match), record attach with the chosen candidate chart, or create. Only listed candidates are accepted and one chart takes one imported patient. Not available after import. Audited.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in the authenticated clinic"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "source_id",
                  "action"
                ],
                "properties": {
                  "source_id": {
                    "type": "string"
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "attach",
                      "create"
                    ]
                  },
                  "patient_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Required for attach; omitted for create."
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "migration.manage"
            ]
          },
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/migrations/{id}/commit": {
      "post": {
        "operationId": "commitMigration",
        "description": "Owner only. Reconciled digest required and every matching patient needs a stored attach or create decision. Atomic import: attached patients are linked to the chosen chart without changing it, new charts get identity and contact details from the source, and all other records become immutable historical records with external identity mapping. Source signatures stay unverified; no native signing or cutover.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "digest": {
                    "type": "string"
                  }
                },
                "required": [
                  "digest"
                ]
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "migration.manage"
            ]
          },
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/migrations/{id}/patient-links": {
      "get": {
        "operationId": "migrationPatientLinks",
        "description": "Owner only; committed jobs only. Source patient id to chart id for every patient in the job, whether the chart was created by the import or attached by decision. Audited.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in the authenticated clinic"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": [
          {
            "oauth2": [
              "migration.manage"
            ]
          },
          {
            "browserSession": []
          }
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{id}/history": {
      "get": {
        "operationId": "sourceHistory",
        "description": "Staff-only imported history. external_unverified signature and staff_only_pending_review release policy. Immutable source records, distinct from native signed visits.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/fhir/metadata": {
      "get": {
        "operationId": "fhirCapabilities",
        "description": "Draft instance-level FHIR R4 4.0.1 CapabilityStatement for 17 bounded native projections. Read/search is implemented for the advertised resources (Binary is read-only); bounded create/update is implemented only for Patient, Condition, AllergyIntolerance, MedicationStatement, ServiceRequest and Immunization. No general HL7 v2, US Core, SMART App Launch, Bulk Data or certification assertion.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "security": []
      }
    },
    "/fhir/Patient/{id}": {
      "get": {
        "operationId": "fhirPatientRead",
        "description": "Read-only native patient demographics. FHIR OperationOutcome errors; tenant scoped.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current native resource version, suitable for supported If-Match writes",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "updateFhirPatient",
        "summary": "Update existing registration identity through FHIR",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "412": {
            "description": "FHIR identity version changed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "428": {
            "description": "Current version required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirPatient"
              }
            }
          }
        },
        "description": "Versioned native identity correction. Supply exactly one unchanged existing MRN identifier; registered names and birth date may change. MRN reassignment is rejected and prior identity revisions are retained.",
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "WeakFHIR W/\"n\" or quoted identity version; missing428/stale412."
          },
          {
            "in": "header",
            "name": "X-Change-Reason",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 1000,
              "minLength": 1
            }
          }
        ]
      }
    },
    "/fhir/Patient": {
      "get": {
        "operationId": "fhirPatientSearch",
        "description": "Searchset Bundle with next link. name is case-insensitive given/family prefix; identifier MRN with optional installation system; birthdate exact ISO date. _after is a custom UUID keyset cursor. Rejects unsupported/repeated parameters.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "parameters": [
          {
            "name": "_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "name",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "identifier",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "birthdate",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "_after",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "_count",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ]
      },
      "post": {
        "operationId": "createFhirPatient",
        "summary": "Create registration identity through FHIR",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "201": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewFhirPatient"
              }
            }
          }
        },
        "description": "Register a native patient from the supported FHIR Patient subset. Omit identifier; the server assigns and returns the MRN. Caller-supplied identifiers are rejected."
      }
    },
    "/api/v1/patients/{patient}/clinical": {
      "get": {
        "operationId": "clinicalLists",
        "description": "Single snapshot of native items, list review versions and attributed review history. Empty entries mean unknown, never automatically no-known. Staff only.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid content/status/date/classification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Patient or entry not in authenticated clinic"
          },
          "409": {
            "description": "Stale version, duplicate source mapping or conflicting review"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "post": {
        "operationId": "createClinicalEntry",
        "description": "Clinician/owner only; creates version 1 and immutable revision with atomic audit. Optional source_history_id must match this patient and kind, and can be reconciled only once. Invalidates prior list review.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid content/status/date/classification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Patient or entry not in authenticated clinic"
          },
          "409": {
            "description": "Stale version, duplicate source mapping or conflicting review"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClinicalChange"
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/clinical/{id}": {
      "put": {
        "operationId": "updateClinicalEntry",
        "description": "Clinician/owner only; full replacement of content with reason and optimistic version. Appends revision, invalidates list review. Kind and source_history_id cannot change; echo existing source_history_id. Use entered_in_error or inactive/stopped/resolved status instead of hard deletion. Medication statements do not create prescriptions.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid content/status/date/classification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Patient or entry not in authenticated clinic"
          },
          "409": {
            "description": "Stale version, duplicate source mapping or conflicting review"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClinicalChange"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current entry version, or list version for reviews. Initial unrecorded list version is 1."
          }
        ]
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/clinical/{id}/revisions": {
      "get": {
        "operationId": "clinicalEntryRevisions",
        "description": "Staff only; full immutable snapshots with author, time and change reason, newest first.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid content/status/date/classification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Patient or entry not in authenticated clinic"
          },
          "409": {
            "description": "Stale version, duplicate source mapping or conflicting review"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/clinical-review/{kind}": {
      "post": {
        "operationId": "reviewClinicalList",
        "description": "Clinician/owner only; version prevents reviewing a changed list. Unreconciled imported list records block reviewed/no_known. Current nonrefuted entries block no_known. Reviews append attributed history; later native mutations and new source imports invalidate review.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid content/status/date/classification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Patient or entry not in authenticated clinic"
          },
          "409": {
            "description": "Stale version, duplicate source mapping or conflicting review"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClinicalReview"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current entry version, or list version for reviews. Initial unrecorded list version is 1."
          }
        ]
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "kind",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "enum": [
              "problem",
              "allergy",
              "medication"
            ]
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/clinical-reconcile/{kind}": {
      "post": {
        "operationId": "reconcileImportedClinicalList",
        "description": "Clinician/owner only. Creates one native entry per listed imported problem or medication of this patient, each with its own source link, carried source codes (ICD-10-CM, SNOMED CT, RxNorm, NDC) and attributed revision. Already reconciled records are skipped; records whose suggested entry is not valid are returned in needs_review and left for individual reconciliation. No native signature is created.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in the authenticated clinic"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "history_ids"
                ],
                "properties": {
                  "history_ids": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "kind",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "enum": [
              "problem",
              "medication"
            ]
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/history/{id}/mapping": {
      "get": {
        "operationId": "previewClinicalSourceMapping",
        "description": "Clinician/owner only. Suggested source system list mapping, review issues, original source fields and existing native_entry_id if reconciled. Preview never mutates source or creates an entry; explicitly POST ClinicalChange to reconcile. Structured source codes (ICD-10-CM, SNOMED CT, RxNorm, NDC) are carried into the suggested entry as recorded. Mapping is not source identity authentication, terminology validation or eRx.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid content/status/date/classification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Patient or entry not in authenticated clinic"
          },
          "409": {
            "description": "Stale version, duplicate source mapping or conflicting review"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders": {
      "get": {
        "operationId": "patientOrdersAndResults",
        "description": "Single-snapshot native orders, immutable specimen intake, current report versions and all acknowledgments. Staff only; source signatures remain external_unverified. No patient-portal release.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "post": {
        "operationId": "createLocalOrder",
        "description": "Clinician/owner only. Draft order, optional patient-matching visit/source order. Required request_id provides exact retry safety; changed reuse conflicts. No external transmission.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewLabOrder"
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders/{order}": {
      "put": {
        "operationId": "editDraftOrder",
        "description": "Draft only. Complete replacement of content and nullable visit link. Placed order content stays unchanged; cancel and create a replacement. Appends attributed revision.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditLabOrder"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current order version."
          }
        ]
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "order",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders/{order}/actions": {
      "post": {
        "operationId": "transitionLocalOrder",
        "description": "Place draft locally; cancel/error before final results; complete only with final/corrected coverage for every requested test and acknowledgment of every current non-error report. Completion does not imply external delivery.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LabOrderAction"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current order version."
          }
        ]
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "order",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders/{order}/history": {
      "get": {
        "operationId": "orderRevisionHistory",
        "description": "Immutable attributed snapshots including state changes, newest first.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "order",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders/{order}/specimens": {
      "post": {
        "operationId": "recordSpecimenIntake",
        "description": "Immutable received/rejected laboratory specimen intake. Patient/order scoped. Collection <= receipt <= now+5min; rejected intake requires notes. Exact request_id retry returns original ID. Record replacements separately; post-intake amendment remains pending.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewLabSpecimen"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current order version."
          }
        ]
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "order",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders/{order}/reports": {
      "post": {
        "operationId": "recordPanelReport",
        "description": "Preliminary or final local entry. Exact request_id retries safe. Requested test keys and any specimen must belong to this order; rejected samples cannot support results. Final labs require received specimen; only linked imported reports may explicitly assert specimen_not_recorded. Source reports must match the reconciled source order. Every entry has an attributed immutable revision.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewLabReport"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current order version."
          }
        ]
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "order",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders/{order}/reports/{report}": {
      "put": {
        "operationId": "revisePanelReport",
        "description": "Current report version required. Preliminary -> preliminary/final/error. Final/corrected -> corrected/error with required reason. Original revisions remain unchanged. Any revision reopens completed order and requires its own acknowledgment. Source provenance is retained.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditLabReport"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current report version."
          }
        ]
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "order",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "report",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders/{order}/reports/{report}/history": {
      "get": {
        "operationId": "reportRevisionHistory",
        "description": "Immutable result snapshots, status, author, reason and source-signature origin, newest first.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "order",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "report",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/orders/{order}/reports/{report}/acknowledge": {
      "post": {
        "operationId": "acknowledgeReportRevision",
        "description": "Clinical acknowledgment of current preliminary/final/corrected version with review/follow-up note. Does not send a message or notify the patient. New versions need new acknowledgment. Exact repeat is safe; changing the existing acknowledgment note conflicts.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LabAcknowledgment"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current report version."
          }
        ]
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "order",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "report",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/labs/inbox": {
      "get": {
        "operationId": "resultReviewInbox",
        "description": "Up to 100 current preliminary/final/corrected report revisions without an acknowledgment; tenant scoped. Includes critical flag, patient/order/report identity and version. Not an external paging/escalation service.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "parameters": []
    },
    "/api/v1/patients/{patient}/history/{id}/lab-mapping": {
      "get": {
        "operationId": "previewSourceLabMapping",
        "description": "Clinician/owner only. legacy-ehi-labs-v1 suggested fields and original source data. Reconcile the source order before its report. No silent timezone, terminology or laboratory identity inference. No records change on preview; explicit creation requires clinician review. Source signatures remain unverified.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid data or clinical relationship"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Clinical role/scope denied"
          },
          "404": {
            "description": "Record not in authenticated clinic/patient"
          },
          "409": {
            "description": "Invalid transition, stale version, request ID collision or duplicate source mapping"
          },
          "413": {
            "description": "Request exceeds 64KiB"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "parameters": [
        {
          "name": "patient",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/schedule": {
      "get": {
        "operationId": "scheduleAgenda",
        "description": "Staff schedule; UTC half-open overlap range up to 31 days. At most 1000 appointments and 1000 blocks; narrow query if exceeded. Browser shows its local timezone.",
        "parameters": [
          {
            "name": "start",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "end",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "clinician_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Schedule"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        }
      }
    },
    "/api/v1/schedule/providers": {
      "get": {
        "operationId": "scheduleProviders",
        "description": "Active native owner/clinician accounts in the authenticated practice. No imported account impersonation.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScheduleProviders"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        }
      }
    },
    "/api/v1/schedule/markers": {
      "get": {
        "operationId": "scheduleMarkers",
        "description": "What each appointment overlapping a UTC half-open range of up to 31 days still needs: intake form state, insurance eligibility for the coverage that pays first, copay, patient balance, note and charge state, and whether it is the patient's first appointment. Read with a fixed number of queries. Requires the same access as the schedule. Insurance, copay, balance and charge facts are omitted when the staff member's access policy hides patient billing (insurance also needs claims access); note state is omitted without clinical access.",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "provider",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScheduleMarkers"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        }
      }
    },
    "/api/v1/appointments/{id}": {
      "get": {
        "operationId": "readAppointment",
        "description": "Read tenant appointment.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Appointment"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        }
      },
      "put": {
        "operationId": "editAppointment",
        "description": "Edit/reschedule booked appointments only. Serializes provider/patient/room/block conflicts.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current appointment/block version"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Appointment"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditAppointment"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/appointments/{id}/actions": {
      "post": {
        "operationId": "appointmentAction",
        "description": "Check in booked appointments; cancel booked/checked-in; mark no-show only after start. Terminal appointments are preserved; no DELETE.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current appointment/block version"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Appointment"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AppointmentAction"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/appointments/{id}/history": {
      "get": {
        "operationId": "appointmentHistory",
        "description": "Append-only versions including check-in, encounter start and signed completion.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppointmentHistory"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        }
      }
    },
    "/api/v1/schedule/blocks": {
      "post": {
        "operationId": "blockProviderTime",
        "description": "Scheduling role; request_id retries are idempotent. Rejects overlapping blocks or appointments. No recurrence.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScheduleBlock"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewScheduleBlock"
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/schedule/blocks/{id}/cancel": {
      "post": {
        "operationId": "cancelProviderBlock",
        "description": "Retains block and cancellation reason; version required.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current appointment/block version"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "cancelled": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "cancelled"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                },
                "required": [
                  "reason"
                ]
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/patients/{id}/history/{source}/appointment-mapping": {
      "get": {
        "operationId": "appointmentSourceMapping",
        "description": "Scheduling-role review of immutable source system appointment; native reconciliation uses POST appointments with source_history_id. Source import never creates bookings.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "source",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AppointmentMapping"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role/scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Conflict or stale version"
          },
          "428": {
            "description": "If-Match required"
          },
          "500": {
            "description": "Change rolled back or outcome requires verification"
          }
        }
      }
    },
    "/api/v1/billing/payers": {
      "get": {
        "operationId": "billingPayers",
        "description": "Staff payer directory; maximum 1000 records.",
        "parameters": [],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Payer"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        }
      },
      "post": {
        "operationId": "createPayer",
        "description": "Owner-managed payer identity. Stable request_id and optional reviewed insurance_company source; no credentials imported.",
        "parameters": [],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Payer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewPayer"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/payers/{id}": {
      "put": {
        "operationId": "editPayer",
        "description": "Owner only; deactivation preserves prior coverage/account snapshots.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current resource version"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Payer"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditPayer"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/payers/{id}/history": {
      "get": {
        "operationId": "payerHistory",
        "description": "Attributed append-only payer versions.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingHistory"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        }
      }
    },
    "/api/v1/billing/payer-sources": {
      "get": {
        "operationId": "sourcePayers",
        "description": "Owner review of imported payer directory; linked native_id prevents duplicate activation.",
        "parameters": [],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "properties": {
                          "source_history_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "source_instance": {
                            "type": "string",
                            "minLength": 0,
                            "maxLength": 200
                          },
                          "source_id": {
                            "type": "string",
                            "minLength": 0,
                            "maxLength": 200
                          },
                          "source_data": {
                            "type": "object"
                          },
                          "native_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "uuid"
                          }
                        },
                        "required": [
                          "source_history_id",
                          "source_instance",
                          "source_id",
                          "source_data",
                          "native_id"
                        ]
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        }
      }
    },
    "/api/v1/billing/worklist": {
      "get": {
        "operationId": "billingWorklist",
        "description": "Staff queue. 100 accounts per page ordered by UUID; balances include posted accounts only. No payer/patient responsibility split.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "posted",
                "void"
              ]
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingWorklist"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing": {
      "get": {
        "operationId": "patientBilling",
        "description": "Staff insurance, accounts and append-only ledger. Maximum 1000 policies/accounts and 10000 entries; explicit error rather than silent truncation. Financial values are integer USD cents. Includes appointment copay receipt evidence, which may predate an encounter or posted account.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientBilling"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        }
      }
    },
    "/api/v1/patients/{p}/coverages": {
      "post": {
        "operationId": "createCoverage",
        "description": "Owner/clinician/front-desk; inclusive effective dates and nonoverlapping active priority. Manual review is not electronic eligibility.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Coverage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewCoverage"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/coverages/{id}": {
      "put": {
        "operationId": "editCoverage",
        "description": "Versioned replacement; existing posted snapshots remain immutable.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current resource version"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Coverage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditCoverage"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/coverages/{id}/history": {
      "get": {
        "operationId": "coverageHistory",
        "description": "Attributed coverage snapshots.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingHistory"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/accounts": {
      "post": {
        "operationId": "createBillingAccount",
        "description": "Draft linked to native visit or reviewed billing history; one nonvoid account per native visit. Charge amounts are complete line totals.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingAccount"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewBillingAccount"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/accounts/{id}": {
      "put": {
        "operationId": "editBillingAccount",
        "description": "Edit current draft only. Server recomputes totals and validates patient/visit/coverage links.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current resource version"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingAccount"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditBillingAccount"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/accounts/{id}/actions": {
      "post": {
        "operationId": "billingAccountAction",
        "description": "Post or void draft. Posting native visit billing requires a signed visit, validates coverage dates and freezes charge/payer/policy versions. Posting is local accounting only.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current resource version"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingAccount"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BillingAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/accounts/{id}/history": {
      "get": {
        "operationId": "billingAccountHistory",
        "description": "Append-only account versions, including ledger changes.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingHistory"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/accounts/{id}/entries": {
      "post": {
        "operationId": "recordBillingEntry",
        "description": "Record manual payment/credit/debit/reversal against current posted account. No funds move. Exact request_id retries return the original entry despite the old version; conflicting reuse fails. Reversal amount is derived from one unreversed original. Reject overpayment/negative balance. Insurer payments require frozen coverage.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current resource version"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "account": {
                      "$ref": "#/components/schemas/BillingAccount"
                    }
                  },
                  "required": [
                    "id",
                    "account"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewBillingEntry"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/history/{id}/billing-mapping": {
      "get": {
        "operationId": "financialSourceMapping",
        "description": "Staff review insurance/billing/transaction originals. Insurance and charges require explicit native reconciliation; transactions remain archive until separately reconciled.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingMapping"
                }
              }
            }
          },
          "400": {
            "description": "Invalid mapping or values"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale version, duplicate source, conflicting coverage or balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; no partial mutation committed"
          }
        }
      }
    },
    "/api/v1/billing/claims": {
      "get": {
        "operationId": "claimsWorklist",
        "description": "List native claims, cursor paginated. Optional patient_id and account_id filters combine with AND inside the authenticated tenant scope; neither changes access authority.",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque UUID cursor from preceding page"
          },
          {
            "name": "patient_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Restrict results to this native patient."
          },
          {
            "name": "account_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Restrict results to this native account."
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClaimWorklist"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/accounts/{account}/claims": {
      "post": {
        "operationId": "createClaim",
        "description": "Create idempotent draft from a posted insured account. Optional source history must belong to this patient. Replacement/void request requires an eligible parent and reviewed payer control. A corrected original may link a rejected parent with no payer control number; no payer ID is fabricated.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "account",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current account version for claim creation; current claim or remittance version for subsequent mutations"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Claim"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewClaim"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/claims/{id}": {
      "get": {
        "operationId": "readClaim",
        "description": "Read tenant scoped record, validation issues and review evidence.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClaimDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      },
      "put": {
        "operationId": "editClaim",
        "description": "Edit current draft; released packet remains immutable.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current account version for claim creation; current claim or remittance version for subsequent mutations"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Claim"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditClaim"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/claims/{id}/actions": {
      "post": {
        "operationId": "actionClaim",
        "description": "Versioned local lifecycle event. Claim external events require reference and nonfuture date. ERA post atomically writes ledger, claim and audit history; reverse appends offsetting evidence. No payment or clearinghouse transport.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current account version for claim creation; current claim or remittance version for subsequent mutations"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Claim"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClaimRemittanceAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/claims/{id}/history": {
      "get": {
        "operationId": "historyClaim",
        "description": "Read append-only attributed revision history.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingHistory"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/remittances/{id}": {
      "get": {
        "operationId": "readRemittance",
        "description": "Read tenant scoped record, validation issues and review evidence.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RemittanceDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/remittances/{id}/actions": {
      "post": {
        "operationId": "actionRemittance",
        "description": "Versioned local lifecycle event. Claim external events require reference and nonfuture date. ERA post atomically writes ledger, claim and audit history; reverse appends offsetting evidence. No payment or clearinghouse transport.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current account version for claim creation; current claim or remittance version for subsequent mutations"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Remittance"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClaimRemittanceAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/remittances/{id}/history": {
      "get": {
        "operationId": "historyRemittance",
        "description": "Read append-only attributed revision history.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingHistory"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/claims/{id}/packet": {
      "get": {
        "operationId": "exportClaimPacket",
        "description": "Download JSON evidence packet; no X12 837 or submission state change.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClaimPacket"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/remittances": {
      "get": {
        "operationId": "remittanceWorklist",
        "description": "List remittance summaries, cursor paginated.",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque UUID cursor from preceding page"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RemittanceWorklist"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      },
      "post": {
        "operationId": "importRemittance",
        "description": "Stage idempotent normalized JSON or bounded single-transaction ASCII 835 (1 MiB, 1,000 claims, 1,000 PLB pairs). Original evidence is immutable. Duplicate payer/trace is blocked. Supported supplemental evidence is retained without adding ledger amounts; unknown/unbalanced data cannot post. Optional remote_report_id binds the exact retrieved 835. Matching and posting remain explicit whole-remittance operations.",
        "parameters": [],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Remittance"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImportRemittance"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/remittances/{id}/matches": {
      "put": {
        "operationId": "matchRemittance",
        "description": "Explicit exact-control claim matching with captured current claim/account versions. Only selected CO adjustments become credits. PR remains responsibility evidence. All rows and balances rechecked on posting.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current account version for claim creation; current claim or remittance version for subsequent mutations"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EraMatchResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EraMatches"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/history/{id}/claim-mapping": {
      "get": {
        "operationId": "claimSourceMapping",
        "description": "Read preserved source system claim fields and native reconciliation link. No automatic submission activation.",
        "parameters": [
          {
            "name": "p",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClaimSourceMapping"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/remittance-sources": {
      "get": {
        "operationId": "remittanceSources",
        "description": "List at most 100 preserved global remittance sources and native reconciliation links. Larger source sets require narrower import batches.",
        "parameters": [],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RemittanceSources"
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/clearinghouses": {
      "get": {
        "operationId": "ediPartnerDirectory",
        "description": "List up to 100 nonsecret partner profiles. No transport credentials or endpoint fields.",
        "parameters": [],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiPartners"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      },
      "post": {
        "operationId": "createEdiPartner",
        "description": "Create idempotent reviewed ISA/GS/submitter/receiver profile, optionally reconciled to source partner history. Usage never inferred from source. Owner role required.",
        "parameters": [],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiPartner"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewEdiPartner"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/clearinghouses/{id}": {
      "get": {
        "operationId": "readEdiPartner",
        "description": "Read profile and immutable configuration revisions.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiPartnerDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      },
      "put": {
        "operationId": "editEdiPartner",
        "description": "Versioned profile edit affects future artifacts; existing files keep frozen settings. Owner role required.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current claim version for generation, partner version for profile edit, submission version for submission writes"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiPartner"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditEdiPartner"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/claims/{id}/837p": {
      "post": {
        "operationId": "generate837P",
        "description": "Generate one immutable 005010X222A1 837P from the current ready claim and active partner version. Primary USD, routine POS 11, self/spouse/child, CPT/HCPCS profile. Exact integer cents, unique per-tenant ISA control, matched envelope counts and retained claim/profile/details snapshots. No transmission or claim submission occurs. Independent TR3, companion-guide and partner acceptance testing remain required. Bounded secondary commercial claims include frozen primary 2320/2330 and 2430 adjudication evidence. Original charges remain unchanged; no tertiary or Medicare-as-secondary/MSP profile.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current claim version for generation, partner version for profile edit, submission version for submission writes"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiSubmission"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Generate837P"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/submissions": {
      "get": {
        "operationId": "ediSubmissionQueue",
        "description": "Cursor paginated summaries with separate delivery, technical and payer outcomes.",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiSubmissionWorklist"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/submissions/{id}": {
      "get": {
        "operationId": "ediSubmissionDetail",
        "description": "Read immutable artifact, current claim, original acknowledgment files and attributed event history.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiSubmissionDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/submissions/{id}/file": {
      "get": {
        "operationId": "download837P",
        "description": "Audit and download exact generated bytes. Export does not change delivery or claim status. Cancelled artifacts and prepared files with a changed claim are blocked.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Exact immutable 837P bytes; attachment filename contains only generated interchange control",
            "content": {
              "application/EDI-X12": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/submissions/{id}/actions": {
      "post": {
        "operationId": "ediSubmissionAction",
        "description": "Cancel a prepared file, record completed external handoff against unchanged ready claim, or record separately reviewed payer evidence against the submitted claim. Delivery/reference/date and expected claim version required; payer acceptance requires control number. No outbound transport. Claim and outbox event commit atomically.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current claim version for generation, partner version for profile edit, submission version for submission writes"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiSubmission"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EdiSubmissionAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/submissions/{id}/acknowledgments": {
      "post": {
        "operationId": "importEdiAcknowledgment",
        "description": "Import bounded ASCII 999, TA1 or 277CA against an externally delivered artifact. Supported 999 group/transaction controls and counts must match. Technical rejection can reject the unchanged submitted claim; acceptance does not imply payer acceptance. Unsupported, partial or contradictory results remain reviewable; TA1/277CA are retained for manual review. Originals immutable and duplicate source/hash blocked. Optional remote_report_id enforces exact retrieved text, format and partner binding, then links original evidence atomically.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current claim version for generation, partner version for profile edit, submission version for submission writes"
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiAcknowledgmentResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImportEdiAcknowledgment"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/clearinghouse-sources": {
      "get": {
        "operationId": "ediSourceMappings",
        "description": "List up to 100 imported nonsecret partner/acknowledgment records and explicit native links. Staff review; owner needed to activate a partner.",
        "parameters": [],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiSources"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/delivery/routes": {
      "get": {
        "operationId": "ediDeliveryRoutes",
        "description": "Safe configured route metadata for authenticated tenant; excludes endpoints and credential names/values. Configuration is provisioned by operator on server.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiDeliveryRoutes"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/delivery/jobs": {
      "get": {
        "operationId": "ediDeliveryJobs",
        "description": "Last 100 tenant-scoped delivery jobs.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiDeliveryJobs"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/submissions/{id}/delivery": {
      "post": {
        "operationId": "queueEdiDelivery",
        "description": "Queue unchanged prepared artifact/ready claim against a route key. Idempotent request ID; one noncancelled job per artifact. No user-supplied destination or credential.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiDeliveryJob"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current submission/job version; initial immutable 277CA row review uses \"1\" plus captured submission/claim versions."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QueueEdiDelivery"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/delivery/jobs/{id}": {
      "get": {
        "operationId": "ediDeliveryDetail",
        "description": "Delivery state, attempt evidence and immutable history.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiDeliveryDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/delivery/jobs/{id}/actions": {
      "post": {
        "operationId": "ediDeliveryDecision",
        "description": "Cancel unsent/blocked jobs or explicitly reconcile uncertain receipt with reference/reason. Leased jobs cannot be cancelled. No automatic resend after ambiguous I/O.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EdiDeliveryJob"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current submission/job version; initial immutable 277CA row review uses \"1\" plus captured submission/claim versions."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EdiDeliveryDecision"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/277ca": {
      "get": {
        "operationId": "ca277List",
        "description": "Last 100 original acknowledgment document summaries for this tenant.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CA277List"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      },
      "post": {
        "operationId": "ca277Import",
        "description": "Stage bounded 005010X214 multi-claim/service evidence only. Declared issuer scope required. Source link must match original text and any declared origin exactly. No claim changes on import. Optional remote_report_id requires exact retrieved original, unlinked report and declared origin. Initial Stedi acknowledgments remain clearinghouse-origin.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CA277ImportResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Import277CA"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/277ca/{id}": {
      "get": {
        "operationId": "ca277Detail",
        "description": "Original hashed text, parsed hierarchy/claim/service evidence and immutable per-row review decisions.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CA277Detail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/277ca/{id}/rows/{row}/apply": {
      "post": {
        "operationId": "ca277Apply",
        "description": "Apply one reviewed row to exact current delivered submission/submitted claim. Verifies source, NPI, member, payer, receiver, control, supplied amount/date and service identities. Clearinghouse acceptance never infers payer acceptance. Unsupported/conflicting evidence, stale versions and repeated application conflict. Claim/submission/review/audit commit atomically.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CA277Applied"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "row",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current submission/job version; initial immutable 277CA row review uses \"1\" plus captured submission/claim versions."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Review277CA"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/connections": {
      "get": {
        "operationId": "providerConnections",
        "description": "Safe durable provider connection summaries. No credentials or cursor values returned.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProviderConnectionList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/connections/{key}": {
      "get": {
        "operationId": "providerConnectionDetail",
        "description": "Tenant-scoped durable state and immutable connection history.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProviderConnectionDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/billing/connections/{key}/actions": {
      "post": {
        "operationId": "providerConnectionAction",
        "description": "Owner-only attributed pause/resume/poll request. Does not change cursor. In-flight work may finish. Historical connections cannot activate transport.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current connection or report version."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProviderConnectionAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/retrieved-reports": {
      "get": {
        "operationId": "retrievedReports",
        "description": "Recent provider inbox summaries. Retrieval never changes claim acceptance or ledger balances.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RetrievedReportList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/retrieved-reports/{id}": {
      "get": {
        "operationId": "retrievedReportDetail",
        "description": "Retained original evidence, safe provider metadata, parser issues, native link and audit history.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RetrievedReportDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/retrieved-reports/{id}/actions": {
      "post": {
        "operationId": "retrievedReportAction",
        "description": "Retry only a quarantined download without original text; or explicitly link Claim.MD structured status to current delivered submission/claim versions after exact provider/payer/member/control/amount/date matching. Evidence linking never changes claim status.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current connection or report version."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RetrievedReportAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/retrieved-reports/from-source": {
      "post": {
        "operationId": "providerSourceMapping",
        "description": "Owner-only idempotent original source system/provider evidence mapping to independently reviewed native partner. Creates an inactive historical inbox connection; never activates transport or creates claims/delivery jobs.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProviderSourceMapping"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/era-automation": {
      "get": {
        "operationId": "eraAutomationWorklist",
        "description": "Tenant-scoped recent 100 ERA feeds, automation outcomes, and feed events. Independent Claim.MD ERA cursor is hidden. Download-only by default; opt-in staging prepares exact suggestions only. Live remittance status/version included; no ledger posting.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EraAutomationWorklist"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/era-automation/{key}/actions": {
      "post": {
        "operationId": "eraAutomationFeedAction",
        "description": "Owner-only enable_staging, disable_staging, or poll_now with current ERA feed If-Match and reason. Connection pause also stops ERA discovery/download/staging. Does not rewind cursor, retry held outcomes, select CO write-offs or post ledger entries. In-flight read may finish.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current connection or report version."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EraAutomationFeedAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/remittances/{id}/provider-adjustments": {
      "get": {
        "operationId": "providerSettlementDetail",
        "description": "Tenant-scoped PLB originals, classifications, immutable reviews and provider cash entries. No patient debt allocation.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProviderSettlementDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "put": {
        "operationId": "reviewProviderSettlement",
        "description": "Staff write-role review of every PLB pair with source code/sign classification and optional exact posted payer/provider reference. Current remittance If-Match and reason required. Leaves settlement staged until claim reconciliation. No posting.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current connection or report version."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProviderSettlementReview"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/recoupments": {
      "get": {
        "operationId": "recoupmentCases",
        "description": "Tenant-scoped provider recoupment follow-up cases with attributed event history; up to 100 items. Positive reviewed WO postings create cases; FB and negative offsets do not. Case actions never change patient balances or send messages.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecoupmentWorklist"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/recoupments/{id}/actions": {
      "post": {
        "operationId": "recoupmentCaseAction",
        "description": "Versioned attributed dispute/acknowledge/close/reopen evidence. Voided cases cannot change; remittance reversal appends cash offsets and void history atomically. If-Match is the case version.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current connection or report version."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecoupmentAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/era-batches": {
      "get": {
        "operationId": "eraBatchList",
        "description": "Most recent 100 tenant-owned ERA file imports; original text is only returned by detail.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      },
      "post": {
        "operationId": "importEraBatch",
        "description": "Atomic file import with immutable original/hash, exact transaction slices and envelope controls. Explicit payer per transaction; no ledger writes. Idempotent request ID, file-hash and payer/trace deduplication. Same trace may recur inside this file across distinct transactions.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EraBatchImport"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/era-batches/preview": {
      "post": {
        "operationId": "previewEraBatch",
        "description": "Validate envelopes, controls/counts, delimiters and transaction boundaries before selecting native payers. Returns parsed transactions, exact offsets and payer candidates. No source/native/ledger mutation.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "original_text"
                ],
                "properties": {
                  "original_text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1048576
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/era-batches/{id}": {
      "get": {
        "operationId": "eraBatchDetail",
        "description": "Exact original, ordered native transactions, envelope/byte-offset controls, current child versions and immutable action history.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/era-batches/{id}/actions": {
      "post": {
        "operationId": "eraBatchAction",
        "description": "Current batch If-Match plus ordered child versions. Reconcile simulates the file in a rolled-back savepoint; post executes all source-ordered transactions atomically; reverse unwinds rows/transactions newest first. Any stale version, dependency, failed match or audit failure leaves accounting unchanged. Native child posting/reversal is blocked.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current connection or report version."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EraBatchAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/claims/{id}/era-history": {
      "get": {
        "operationId": "claimEraHistory",
        "description": "Tenant-scoped active posting head plus up to 100 immutable posting rows for exact reversal/correction source selection.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported EDI profile/field/acknowledgment"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant scoped record not found"
          },
          "409": {
            "description": "Duplicate evidence, stale version, changed claim or incompatible state"
          },
          "428": {
            "description": "Quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/practice/worklist": {
      "get": {
        "operationId": "practiceUnfinishedEncounters",
        "summary": "Oldest unfinished native encounters across all dates",
        "description": "Staff-only, tenant-scoped saved encounter work. Returns up to 100 rows, exact total and has_more from one database snapshot. No note or vitals content. All staff can read the queue; clinical staff write an encounter's note and a clinician or the owner signs it. Signing removes it from this list; this is not a checkout task system.",
        "responses": {
          "200": {
            "description": "Unfinished encounters",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "items",
                    "total",
                    "has_more"
                  ],
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "type": "object",
                        "required": [
                          "visit_id",
                          "patient_id",
                          "mrn",
                          "patient_name",
                          "clinician_id",
                          "starts_at",
                          "created_at",
                          "version",
                          "note_saved",
                          "vitals_saved",
                          "title",
                          "appointment_id",
                          "provider_label",
                          "facility",
                          "room"
                        ],
                        "properties": {
                          "visit_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "patient_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "clinician_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "mrn": {
                            "type": "string"
                          },
                          "patient_name": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "starts_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "version": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "note_saved": {
                            "type": "boolean"
                          },
                          "vitals_saved": {
                            "type": "boolean"
                          },
                          "appointment_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "provider_label": {
                            "type": "string"
                          },
                          "facility": {
                            "type": "string"
                          },
                          "room": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff access required"
          }
        }
      }
    },
    "/api/v1/patients/{id}/demographics": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readPatientContactDetails",
        "summary": "Read native patient contact details",
        "description": "Staff-only tenant-scoped audited read; unknown fields are null. Core patient MRN, legal name and DOB remain separate.",
        "responses": {
          "200": {
            "description": "Current contact profile and last 50 immutable revisions",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "Quoted version, including \"0\" before first save"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "patient_id",
                    "version",
                    "content",
                    "history",
                    "history_truncated"
                  ],
                  "properties": {
                    "patient_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "version": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "content": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "preferred_name": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 100
                        },
                        "pronouns": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 100
                        },
                        "language": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 100
                        },
                        "phone": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 40
                        },
                        "email": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 254
                        },
                        "administrative_gender": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "female",
                            "male",
                            "other",
                            "unknown",
                            null
                          ]
                        },
                        "address": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "additionalProperties": false,
                          "properties": {
                            "line1": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 200
                            },
                            "line2": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 200
                            },
                            "city": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 100
                            },
                            "region": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 100
                            },
                            "postal_code": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 32
                            },
                            "country": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 2
                            }
                          }
                        },
                        "emergency_contact": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "additionalProperties": false,
                          "properties": {
                            "name": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 200
                            },
                            "relationship": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 100
                            },
                            "phone": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 40
                            }
                          }
                        }
                      }
                    },
                    "history": {
                      "type": "array",
                      "maxItems": 50,
                      "items": {
                        "type": "object",
                        "required": [
                          "version",
                          "content",
                          "author_id",
                          "reason",
                          "created_at"
                        ],
                        "properties": {
                          "version": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "content": {
                            "type": "object",
                            "additionalProperties": false,
                            "properties": {
                              "preferred_name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 100
                              },
                              "pronouns": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 100
                              },
                              "language": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 100
                              },
                              "phone": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 40
                              },
                              "email": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 254
                              },
                              "administrative_gender": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "enum": [
                                  "female",
                                  "male",
                                  "other",
                                  "unknown",
                                  null
                                ]
                              },
                              "address": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                  "line1": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 200
                                  },
                                  "line2": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 200
                                  },
                                  "city": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 100
                                  },
                                  "region": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 100
                                  },
                                  "postal_code": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 32
                                  },
                                  "country": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 2
                                  }
                                }
                              },
                              "emergency_contact": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                  "name": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 200
                                  },
                                  "relationship": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 100
                                  },
                                  "phone": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 40
                                  }
                                }
                              }
                            }
                          },
                          "author_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "reason": {
                            "type": "string",
                            "maxLength": 1000
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    },
                    "history_truncated": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff required"
          },
          "404": {
            "description": "Patient not found in this tenant"
          }
        }
      },
      "put": {
        "operationId": "replacePatientContactDetails",
        "summary": "Replace a reviewed patient contact profile",
        "description": "Owner, clinician or front-desk staff; quoted If-Match required. Full replacement normalizes blank optional fields to null. Profile, immutable history and audit commit together. This is not consent, message delivery permission, identity merge or complete registration.",
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version, \"0\" for first save"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "content",
                  "reason"
                ],
                "properties": {
                  "content": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "preferred_name": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "maxLength": 100
                      },
                      "pronouns": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "maxLength": 100
                      },
                      "language": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "maxLength": 100
                      },
                      "phone": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "maxLength": 40
                      },
                      "email": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "maxLength": 254
                      },
                      "administrative_gender": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "enum": [
                          "female",
                          "male",
                          "other",
                          "unknown",
                          null
                        ]
                      },
                      "address": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "additionalProperties": false,
                        "properties": {
                          "line1": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "line2": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "city": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 100
                          },
                          "region": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 100
                          },
                          "postal_code": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 32
                          },
                          "country": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 2
                          }
                        }
                      },
                      "emergency_contact": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "additionalProperties": false,
                        "properties": {
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 200
                          },
                          "relationship": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 100
                          },
                          "phone": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "maxLength": 40
                          }
                        }
                      }
                    }
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current contact profile and last 50 immutable revisions",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "Quoted version, including \"0\" before first save"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "patient_id",
                    "version",
                    "content",
                    "history",
                    "history_truncated"
                  ],
                  "properties": {
                    "patient_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "version": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "content": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "preferred_name": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 100
                        },
                        "pronouns": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 100
                        },
                        "language": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 100
                        },
                        "phone": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 40
                        },
                        "email": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "maxLength": 254
                        },
                        "administrative_gender": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "female",
                            "male",
                            "other",
                            "unknown",
                            null
                          ]
                        },
                        "address": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "additionalProperties": false,
                          "properties": {
                            "line1": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 200
                            },
                            "line2": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 200
                            },
                            "city": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 100
                            },
                            "region": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 100
                            },
                            "postal_code": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 32
                            },
                            "country": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 2
                            }
                          }
                        },
                        "emergency_contact": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "additionalProperties": false,
                          "properties": {
                            "name": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 200
                            },
                            "relationship": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 100
                            },
                            "phone": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "maxLength": 40
                            }
                          }
                        }
                      }
                    },
                    "history": {
                      "type": "array",
                      "maxItems": 50,
                      "items": {
                        "type": "object",
                        "required": [
                          "version",
                          "content",
                          "author_id",
                          "reason",
                          "created_at"
                        ],
                        "properties": {
                          "version": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "content": {
                            "type": "object",
                            "additionalProperties": false,
                            "properties": {
                              "preferred_name": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 100
                              },
                              "pronouns": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 100
                              },
                              "language": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 100
                              },
                              "phone": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 40
                              },
                              "email": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "maxLength": 254
                              },
                              "administrative_gender": {
                                "type": [
                                  "string",
                                  "null"
                                ],
                                "enum": [
                                  "female",
                                  "male",
                                  "other",
                                  "unknown",
                                  null
                                ]
                              },
                              "address": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                  "line1": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 200
                                  },
                                  "line2": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 200
                                  },
                                  "city": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 100
                                  },
                                  "region": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 100
                                  },
                                  "postal_code": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 32
                                  },
                                  "country": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 2
                                  }
                                }
                              },
                              "emergency_contact": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                  "name": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 200
                                  },
                                  "relationship": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 100
                                  },
                                  "phone": {
                                    "type": [
                                      "string",
                                      "null"
                                    ],
                                    "maxLength": 40
                                  }
                                }
                              }
                            }
                          },
                          "author_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "reason": {
                            "type": "string",
                            "maxLength": 1000
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    },
                    "history_truncated": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid contact values"
          },
          "403": {
            "description": "Owner, clinician or front desk required"
          },
          "404": {
            "description": "Patient not found in this tenant"
          },
          "409": {
            "description": "Stale version; reload and reconcile"
          },
          "422": {
            "description": "Unknown properties or invalid JSON shape"
          },
          "428": {
            "description": "Quoted If-Match required"
          }
        }
      }
    },
    "/api/v1/patients/{id}/history/{record}/use-contact": {
      "post": {
        "operationId": "useImportedContactValue",
        "summary": "Copy one imported contact value into an empty native field",
        "description": "Owner, clinician or front desk. Copies address, phone, email, administrative_gender or language from the imported record's contact block into the native contact profile only when that native field is empty; a filled field returns 409. Appends an attributed contact revision.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in the authenticated clinic"
          },
          "409": {
            "description": "Conflicting state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "field"
                ],
                "properties": {
                  "field": {
                    "type": "string",
                    "enum": [
                      "address",
                      "phone",
                      "email",
                      "administrative_gender",
                      "language"
                    ]
                  }
                }
              }
            }
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "record",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/billing/provider-settings": {
      "get": {
        "operationId": "listProviderSettings",
        "description": "Owner role required. List redacted settings and credential-storage health for the authenticated tenant.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no credential values returned",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProviderSettings"
                }
              }
            }
          },
          "400": {
            "description": "Invalid configuration, decryption unavailable, or activation requires authentication verification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role or billing scope required"
          },
          "404": {
            "description": "Tenant-scoped setting or partner not found"
          },
          "409": {
            "description": "Stale version, duplicate account credential, or incompatible connection"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database or audit failure; transaction rolled back"
          }
        }
      },
      "post": {
        "operationId": "createProviderSetting",
        "description": "Owner role required. Save a Claim.MD AccountKey encrypted at rest; creates a disabled, unverified connection. AccountKey is required. No network request is made.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no credential values returned",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProviderSetting"
                }
              }
            }
          },
          "400": {
            "description": "Invalid configuration, decryption unavailable, or activation requires authentication verification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role or billing scope required"
          },
          "404": {
            "description": "Tenant-scoped setting or partner not found"
          },
          "409": {
            "description": "Stale version, duplicate account credential, or incompatible connection"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database or audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SaveProviderSetting"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/provider-settings/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readProviderSetting",
        "description": "Owner role required. Read redacted current metadata and immutable attributed action history.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no credential values returned",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "setting": {
                      "$ref": "#/components/schemas/ProviderSetting"
                    },
                    "events": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid configuration, decryption unavailable, or activation requires authentication verification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role or billing scope required"
          },
          "404": {
            "description": "Tenant-scoped setting or partner not found"
          },
          "409": {
            "description": "Stale version, duplicate account credential, or incompatible connection"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database or audit failure; transaction rolled back"
          }
        }
      },
      "put": {
        "operationId": "updateProviderSetting",
        "description": "Owner role required. Save configuration changes and disable automation. Changing key or initial discovery position creates a new route and pauses the previous connection; partner/mode remain fixed.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current setting version."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; no credential values returned",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProviderSetting"
                }
              }
            }
          },
          "400": {
            "description": "Invalid configuration, decryption unavailable, or activation requires authentication verification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role or billing scope required"
          },
          "404": {
            "description": "Tenant-scoped setting or partner not found"
          },
          "409": {
            "description": "Stale version, duplicate account credential, or incompatible connection"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database or audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SaveProviderSetting"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/provider-settings/{id}/test": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "testProviderSetting",
        "description": "Owner role required. Query the documented Claim.MD payer-directory endpoint with the saved AccountKey. Never submits a claim or advances discovery cursors. Generic authentication result, serialized and limited to one per 30 seconds. Payer enrollment and account mode are not verified.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current setting version."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; no credential values returned",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "setting": {
                      "$ref": "#/components/schemas/ProviderSetting"
                    },
                    "authenticated": {
                      "type": "boolean"
                    },
                    "claim_submitted": {
                      "const": false
                    },
                    "discovery_cursor_changed": {
                      "const": false
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid configuration, decryption unavailable, or activation requires authentication verification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role or billing scope required"
          },
          "404": {
            "description": "Tenant-scoped setting or partner not found"
          },
          "409": {
            "description": "Stale version, duplicate account credential, or incompatible connection"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database or audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/billing/provider-settings/{id}/activation": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "activateProviderSetting",
        "description": "Owner role required. Explicitly enable a successfully tested saved connection, or disable/pause it. Merged configuration validation prevents duplicate account bindings and route-limit overflow. Workers reload without restart. Does not queue claims or enable remittance auto-posting.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current setting version."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; no credential values returned",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProviderSetting"
                }
              }
            }
          },
          "400": {
            "description": "Invalid configuration, decryption unavailable, or activation requires authentication verification"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role or billing scope required"
          },
          "404": {
            "description": "Tenant-scoped setting or partner not found"
          },
          "409": {
            "description": "Stale version, duplicate account credential, or incompatible connection"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database or audit failure; transaction rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "enabled"
                ],
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/visits/{visit}/checkout": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "visit",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readVisitCheckout",
        "summary": "Read checkout, prospective AVS and follow-up summaries",
        "description": "Staff-only audited read. Initial aggregate version 0. Safe preview digest is stable for unchanged native data; bounded release/event/task histories include truncation flags. Does not imply clinical readiness or payment.",
        "tags": [
          "Checkout and follow-up"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Role or patient identity not permitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State, review digest, idempotency or version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Atomic database/audit operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/visits/{visit}/checkout/actions": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "visit",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "recordVisitCheckoutAction",
        "summary": "Release patient instructions, record delivery or complete administrative checkout",
        "description": "Signed visit required. Whoever may sign the note may release: any clinician or the owner, never a delegated support session. reviewed_snapshot_digest must match recomputed native summary under medication/allergy/problem/order serialization. Writable front-desk staff may record current-version delivery and checkout. Delivery/decline is required before checkout. A new immutable AVS version clears current checkout and requires new evidence; no billing/result/task state is changed.",
        "tags": [
          "Checkout and follow-up"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Role or patient identity not permitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State, review digest, idempotency or version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Atomic database/audit operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Malformed typed JSON or unknown request fields",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "description": "Missing, malformed or negative quoted version",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutAction"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"(0|[1-9][0-9]*)\"$"
            },
            "example": "\"0\"",
            "description": "Current quoted checkout aggregate version; initial version is 0."
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/visits/{visit}/follow-ups": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "visit",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "createVisitFollowUp",
        "summary": "Create an assigned encounter follow-up task",
        "description": "Writable staff only; assignee must be an enabled owner/clinician/front-desk user in this tenant. Request UUID is idempotent for identical normalized content and visit; changed replay returns 409. No automatic notifications or task completion at checkout.",
        "tags": [
          "Checkout and follow-up"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FollowUpTaskDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Role or patient identity not permitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State, review digest, idempotency or version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Atomic database/audit operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Malformed typed JSON or unknown request fields",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateFollowUpTask"
              }
            }
          }
        }
      }
    },
    "/api/v1/follow-up/tasks": {
      "get": {
        "operationId": "listFollowUpTasks",
        "summary": "Read follow-up worklist",
        "description": "Staff-only audited worklist, up to 100 oldest-due matching tasks with total/has_more. Default status=open. can_update reflects current role and creator/assignee/owner authority.",
        "tags": [
          "Checkout and follow-up"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FollowUpWorklist"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Role or patient identity not permitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State, review digest, idempotency or version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Atomic database/audit operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "completed",
                "cancelled",
                "all"
              ],
              "default": "open"
            }
          },
          {
            "in": "query",
            "name": "assignee_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/follow-up/assignees": {
      "get": {
        "operationId": "listFollowUpAssignees",
        "summary": "Read enabled follow-up assignees",
        "description": "Staff-only tenant-scoped selector; up to 500 enabled writable users with has_more. A selection is revalidated under lock when assigning/reopening tasks.",
        "tags": [
          "Checkout and follow-up"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FollowUpAssignees"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Role or patient identity not permitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State, review digest, idempotency or version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Atomic database/audit operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/follow-up/tasks/{task}": {
      "parameters": [
        {
          "in": "path",
          "name": "task",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readFollowUpTask",
        "summary": "Read follow-up task and attributed history",
        "description": "Staff-only audited read. Returns latest 100 immutable history events and events_truncated.",
        "tags": [
          "Checkout and follow-up"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FollowUpTaskDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Role or patient identity not permitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State, review digest, idempotency or version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Atomic database/audit operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/follow-up/tasks/{task}/actions": {
      "parameters": [
        {
          "in": "path",
          "name": "task",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "recordFollowUpTaskAction",
        "summary": "Complete, cancel, reopen, reassign or reschedule follow-up",
        "description": "Current writable role plus task creator, assignee or clinic-owner authority required. Only open tasks may complete/cancel/reassign/reschedule; reopening rechecks assignee eligibility. Version/history/audit commit atomically.",
        "tags": [
          "Checkout and follow-up"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FollowUpTaskDetail"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Role or patient identity not permitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State, review digest, idempotency or version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Atomic database/audit operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Malformed typed JSON or unknown request fields",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "description": "Missing, malformed or negative quoted version",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FollowUpTaskAction"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "example": "\"1\"",
            "description": "Current quoted task version; tasks start at version 1."
          }
        ]
      }
    },
    "/api/v1/portal/visits/{visit}/avs": {
      "parameters": [
        {
          "in": "path",
          "name": "visit",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readPatientReleasedAvs",
        "summary": "Read latest released patient instructions",
        "description": "Patient role only with trusted matching tenant and patient_id; staff use checkout read instead. Returns latest immutable release without internal release reason. Does not provide patient onboarding, external identity matching or proxy authorization. Legacy development JWTs require explicit gateway opt-in; staff OAuth grants do not imply patient access.",
        "tags": [
          "Checkout and follow-up"
        ],
        "security": [
          {
            "delegatedJwt": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientAvsRelease"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Role or patient identity not permitted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found in authenticated tenant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "State, review digest, idempotency or version conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Atomic database/audit operation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/payments/settings": {
      "get": {
        "operationId": "readPaymentSettings",
        "description": "Owner-only redacted configuration and key-storage/Connect availability status. Never returns credentials. Returns environment availability separately from configured account readiness. Production disables test transactions; historical evidence remains readable.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "setting": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/PaymentSettings"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "test_mode_only": {
                      "const": true
                    },
                    "connect_available": {
                      "type": "boolean"
                    },
                    "credential_storage_ready": {
                      "type": "boolean"
                    },
                    "webhook_base": {
                      "type": "string",
                      "format": "uri"
                    },
                    "live_payments_available": {
                      "const": false,
                      "description": "Live card processing is not supported."
                    },
                    "test_payments_available": {
                      "type": "boolean",
                      "description": "False when ENGINE_ENVIRONMENT=production."
                    },
                    "collection_unavailable_reason": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Human-readable environment restriction, or null."
                    },
                    "native_setup_url": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uri",
                      "description": "Verified Connect clinic-scoped continuation URL derived from the paired connection, available independently of the last Stripe readiness refresh."
                    },
                    "connect_portal_url": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uri",
                      "description": "Verified Connect clinic-scoped continuation URL derived from the paired connection, available independently of the last Stripe readiness refresh."
                    },
                    "broker_available": {
                      "type": "boolean",
                      "description": "A valid payment broker origin is configured; this does not establish payment account readiness."
                    },
                    "hosted_copays_live_enabled": {
                      "type": "boolean",
                      "description": "EHR operator gate for the distinct appointment hosted-copay protocol. Account readiness and the Connect gate are also required; does not enable legacy posted-account live payments."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        }
      },
      "put": {
        "operationId": "savePaymentSettings",
        "description": "Owner-only encrypted credentials. Saved changes disable collection and invalidate verification. Immutable credential revisions remain pinned to existing attempts.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current settings/account version. Settings first save accepts \"0\"."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentSettings"
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentSettingsInput"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/payments/settings/test": {
      "post": {
        "operationId": "testPaymentSettings",
        "description": "Owner-only fixed Stripe /v1/account or authenticated broker status query. Broker status must match the installation and remote tenant. A correctly bound live account may supply readiness display evidence but never enables live collection. Test readiness requires test-mode charges and business details complete. Does not create a payment.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current settings/account version. Settings first save accepts \"0\"."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "setting": {
                      "$ref": "#/components/schemas/PaymentSettings"
                    },
                    "authenticated": {
                      "type": "boolean"
                    },
                    "ready": {
                      "type": "boolean"
                    },
                    "live_payment_enabled": {
                      "const": false
                    },
                    "processor_livemode": {
                      "type": [
                        "boolean",
                        "null"
                      ],
                      "description": "Broker processor account mode when present. True permits readiness display only; live_payment_enabled remains false and ready is false for live accounts."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        }
      }
    },
    "/api/v1/billing/payments/settings/activation": {
      "post": {
        "operationId": "activateTestPayments",
        "description": "Owner-only explicit test-collection enable/disable after verified account test. Existing attempt reconciliation remains available. Test-payment activation (enabled=true), creation, refresh, expiry and refund are blocked in production. Simulated funds cannot be reconciled into production balances.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current settings/account version. Settings first save accepts \"0\"."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentSettings"
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "enabled"
                ],
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/accounts/{id}/payments": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "accountHostedPayments",
        "description": "Staff tenant-scoped attempts and reserved/available balance for a posted account. Returns environment availability separately from configured account readiness. Production disables test transactions; historical evidence remains readable.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/HostedPayment"
                      }
                    },
                    "balance_cents": {
                      "type": "integer"
                    },
                    "reserved_cents": {
                      "type": "integer"
                    },
                    "available_cents": {
                      "type": "integer"
                    },
                    "payments_enabled": {
                      "type": "boolean"
                    },
                    "mode": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "test_mode": {
                      "const": true
                    },
                    "live_payments_available": {
                      "const": false,
                      "description": "Live card processing is not supported."
                    },
                    "test_payments_available": {
                      "type": "boolean",
                      "description": "False when ENGINE_ENVIRONMENT=production."
                    },
                    "collection_unavailable_reason": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Human-readable environment restriction, or null."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        }
      },
      "post": {
        "operationId": "createHostedPayment",
        "description": "Billing-write staff. Reserve a bounded posted-account amount before provider I/O. Opaque UUID/generic line only; no PHI. Stable native/provider idempotency; ambiguous requests remain reserved and are not retried after 23h. Test-payment activation (enabled=true), creation, refresh, expiry and refund are blocked in production. Simulated funds cannot be reconciled into production balances.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current settings/account version. Settings first save accepts \"0\"."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HostedPaymentResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HostedPaymentRequest"
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/payments/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readHostedPayment",
        "description": "Read tenant-scoped payment state, immutable history and redacted refund request states.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payment": {
                      "$ref": "#/components/schemas/HostedPayment"
                    },
                    "events": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "refund_requests": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        }
      }
    },
    "/api/v1/billing/payments/{id}/refresh": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "refreshHostedPayment",
        "description": "Retrieve exact test session, expanded payment intent and charge; post paid/refund deltas exactly once. Retry original uncertain creation only within safe idempotency window. Test-payment activation (enabled=true), creation, refresh, expiry and refund are blocked in production. Simulated funds cannot be reconciled into production balances.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HostedPaymentResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        }
      }
    },
    "/api/v1/billing/payments/{id}/expire": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "expireHostedPayment",
        "description": "Expire an own-account open Checkout Session. Broker contract does not support this operation. Test-payment activation (enabled=true), creation, refresh, expiry and refund are blocked in production. Simulated funds cannot be reconciled into production balances.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HostedPaymentResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        }
      }
    },
    "/api/v1/billing/payments/{id}/refunds": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "refundHostedPayment",
        "description": "Own-account only. Stable idempotent refund request; cumulative verified provider refund evidence controls ledger entries. Pending and confirmed-but-unreconciled requests hold additional refund capacity. Test-payment activation (enabled=true), creation, refresh, expiry and refund are blocked in production. Simulated funds cannot be reconciled into production balances.",
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/HostedPaymentResult"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "refund_confirmed": {
                          "type": "boolean"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentRefundRequest"
              }
            }
          }
        }
      }
    },
    "/api/v1/payments/webhooks/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "receiveSignedPaymentWebhook",
        "description": "Public signature-authenticated endpoint. Raw-body HMAC-SHA256, five-minute timestamp tolerance, test events only, 64KB bound. Receipts serialized by event ID/fingerprint; provider retrieval verifies ledger evidence. No browser-cookie authentication or patient content accepted.",
        "security": [],
        "parameters": [
          {
            "in": "header",
            "name": "Stripe-Signature",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success; no payment inferred from browser return",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid evidence, unavailable connection or unsupported live/payment operation"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner/staff role or billing scope denied"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, reused request, reserved balance, or conflicting provider evidence"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; database changes rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "description": "Raw request bytes must be preserved for signature verification."
            }
          }
        }
      }
    },
    "/api/v1/schedule/series": {
      "get": {
        "operationId": "listRecurringAppointmentSeries",
        "tags": [
          "Scheduling"
        ],
        "description": "Staff read; newest 100 tenant series, optionally patient-filtered.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/RecurringAppointmentSummary"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "has_more"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid cadence, timezone metadata or input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Actor role disallowed"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "409": {
            "description": "Booking conflict, stale version, changed idempotent request or invalid action state"
          }
        },
        "parameters": [
          {
            "name": "patient_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "post": {
        "operationId": "createRecurringAppointmentSeries",
        "tags": [
          "Scheduling"
        ],
        "description": "Owner, clinician or front desk. Atomic all-occurrence create with normal appointment history and audit; exact request retry returns persisted series.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecurringAppointmentSeries"
                }
              }
            }
          },
          "400": {
            "description": "Invalid cadence, timezone metadata or input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Actor role disallowed"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "409": {
            "description": "Booking conflict, stale version, changed idempotent request or invalid action state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecurringAppointmentPlan"
              }
            }
          }
        }
      }
    },
    "/api/v1/schedule/series/preview": {
      "post": {
        "operationId": "previewRecurringAppointmentSeries",
        "tags": [
          "Scheduling"
        ],
        "description": "Owner, clinician or front desk. Point-in-time availability, no reservations.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecurringAppointmentPreview"
                }
              }
            }
          },
          "400": {
            "description": "Invalid cadence, timezone metadata or input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Actor role disallowed"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "409": {
            "description": "Booking conflict, stale version, changed idempotent request or invalid action state"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecurringAppointmentPlan"
              }
            }
          }
        }
      }
    },
    "/api/v1/schedule/series/{id}": {
      "get": {
        "operationId": "getRecurringAppointmentSeries",
        "tags": [
          "Scheduling"
        ],
        "description": "Staff read of original plan, current instances and immutable series events.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecurringAppointmentSeries"
                }
              }
            }
          },
          "400": {
            "description": "Invalid cadence, timezone metadata or input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Actor role disallowed"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "409": {
            "description": "Booking conflict, stale version, changed idempotent request or invalid action state"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/appointments/{id}/series": {
      "get": {
        "operationId": "getAppointmentSeriesMembership",
        "tags": [
          "Scheduling"
        ],
        "description": "Staff read. Existing ordinary nonmember returns series:null; unknown tenant appointment returns404.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "series": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/RecurringAppointmentSeries"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "series"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid cadence, timezone metadata or input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Actor role disallowed"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "409": {
            "description": "Booking conflict, stale version, changed idempotent request or invalid action state"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/schedule/series/{id}/actions": {
      "post": {
        "operationId": "cancelUpcomingRecurringAppointments",
        "tags": [
          "Scheduling"
        ],
        "description": "Owner, clinician or front desk. Cancel only current future booked members; preserve past, arrived, started, completed and individually cancelled members. Current series and ALL ordered child versions required. No eligible member conflicts.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecurringAppointmentSeries"
                }
              }
            }
          },
          "400": {
            "description": "Invalid cadence, timezone metadata or input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Actor role disallowed"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "409": {
            "description": "Booking conflict, stale version, changed idempotent request or invalid action state"
          },
          "428": {
            "description": "Missing If-Match"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecurringAppointmentCancel"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "description": "Quoted positive current series version, e.g. \"1\".",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/patients/{patient_id}/reminder-preferences": {
      "get": {
        "summary": "Read current reminder permission and immutable history",
        "operationId": "reminders_get_patients_patient_id_reminder_preferences",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "patient_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "put": {
        "summary": "Record explicit patient permission and current destination verification",
        "operationId": "reminders_put_patients_patient_id_reminder_preferences",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "patient_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only for initial preferences/settings."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReminderPreferenceSave"
              }
            }
          }
        }
      }
    },
    "/api/v1/appointments/{appointment_id}/reminders": {
      "get": {
        "summary": "Read appointment reminder definitions and outcomes",
        "operationId": "reminders_get_appointments_appointment_id_reminders",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "appointment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "post": {
        "summary": "Create an idempotent custom appointment reminder",
        "operationId": "reminders_post_appointments_appointment_id_reminders",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "appointment_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only for initial preferences/settings."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AppointmentReminderCreate"
              }
            }
          }
        }
      }
    },
    "/api/v1/schedule/reminders": {
      "get": {
        "summary": "Read tenant reminder worklist; due excludes terminal or elapsed appointments",
        "operationId": "reminders_get_schedule_reminders",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "due"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/schedule/reminders/{reminder_id}": {
      "get": {
        "summary": "Read reminder and attributed event history",
        "operationId": "reminders_get_schedule_reminders_reminder_id",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "reminder_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/schedule/reminders/{reminder_id}/actions": {
      "post": {
        "summary": "Record allowed versioned staff outcome or request reconciliation",
        "operationId": "reminders_post_schedule_reminders_reminder_id_actions",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "reminder_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only for initial preferences/settings."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AppointmentReminderAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/schedule/reminder-settings": {
      "get": {
        "summary": "Owner: read redacted sender configuration",
        "operationId": "reminders_get_schedule_reminder_settings",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": []
      },
      "put": {
        "summary": "Owner: choose managed Connect email or save an encrypted own-account sender; sending paused",
        "operationId": "reminders_put_schedule_reminder_settings",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only for initial preferences/settings."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReminderSenderSave"
              }
            }
          }
        }
      }
    },
    "/api/v1/schedule/reminder-settings/test": {
      "post": {
        "summary": "Owner: authenticate and verify the saved sender domain without sending email",
        "operationId": "reminders_post_schedule_reminder_settings_test",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only for initial preferences/settings."
          }
        ]
      }
    },
    "/api/v1/schedule/reminder-settings/activation": {
      "post": {
        "summary": "Owner: explicitly enable or disable verified automatic email",
        "operationId": "reminders_post_schedule_reminder_settings_activation",
        "tags": [
          "Appointment reminders"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped result; provider acceptance is not delivery"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Tenant-scoped resource not found"
          },
          "409": {
            "description": "Stale version, changed idempotent request or unavailable action"
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only for initial preferences/settings."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReminderSenderActivation"
              }
            }
          }
        }
      }
    },
    "/api/v1/connect/services/settings": {
      "get": {
        "summary": "Staff: read redacted local Connect service status",
        "operationId": "connect_services_get_settings",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": []
      },
      "put": {
        "summary": "Owner: save encrypted installation token, disabled until tested",
        "operationId": "connect_services_put_settings",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only on initial save."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConnectServiceSave"
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Owner: disable and locally revoke service connection; remote revocation remains required",
        "operationId": "connect_services_delete_settings",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only on initial save."
          }
        ]
      }
    },
    "/api/v1/connect/services/settings/test": {
      "post": {
        "summary": "Owner: verify remote installation and service availability without sending email",
        "operationId": "connect_services_post_settings_test",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only on initial save."
          }
        ]
      }
    },
    "/api/v1/connect/services/settings/activation": {
      "post": {
        "summary": "Owner: enable or pause verified service connection",
        "operationId": "connect_services_post_settings_activation",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; 0 only on initial save."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReminderSenderActivation"
              }
            }
          }
        }
      }
    },
    "/api/v1/connect/services/tickets": {
      "get": {
        "summary": "Staff: list support requests for this installation",
        "operationId": "connect_services_get_tickets",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": []
      },
      "post": {
        "summary": "Staff: create an idempotent operational support request",
        "operationId": "connect_services_post_tickets",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SupportTicketCreate"
              }
            }
          }
        }
      }
    },
    "/api/v1/connect/services/tickets/{id}": {
      "get": {
        "summary": "Staff: read support conversation for this installation",
        "operationId": "connect_services_get_tickets_id",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/connect/services/tickets/{id}/replies": {
      "post": {
        "summary": "Staff: append an idempotent operational support reply",
        "operationId": "connect_services_post_tickets_id_replies",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped service result; no credentials returned"
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SupportReply"
              }
            }
          }
        }
      }
    },
    "/api/v1/connect/services/support-files": {
      "post": {
        "summary": "Staff: add a file to attach to a support message",
        "description": "Raw file bytes, 1 byte to 10 MB. Content-Type is one of image/png, image/jpeg, image/gif, image/webp, application/pdf, text/plain or text/csv. X-Filename is the percent-encoded UTF-8 file name, at most 200 characters decoded. Repeating a request_id with the same file returns the same result. 409 with error support_attachments_unavailable means the connected SunCharts service does not accept files yet.",
        "operationId": "connect_services_post_support_files",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "File stored for one support message",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SupportFile"
                }
              }
            }
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [
          {
            "name": "request_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-Filename",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/gif": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/webp": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "text/plain": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "text/csv": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        }
      }
    },
    "/api/v1/connect/services/support-files/{file}": {
      "get": {
        "summary": "Staff: read a file attached to a support message of this installation",
        "operationId": "connect_services_get_support_files_file",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "File bytes; never cached. Images are served inline, other files as downloads."
          },
          "403": {
            "description": "Role not permitted"
          },
          "404": {
            "description": "Scoped resource not found"
          },
          "409": {
            "description": "Stale version, unavailable service or changed idempotent content"
          }
        },
        "parameters": [
          {
            "name": "file",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/connect/status": {
      "get": {
        "summary": "Staff: read local SunCharts authorization and managed-service health snapshot",
        "operationId": "connect_status_read",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Sanitized authorization, service and transport health. New outbound connections require an active OAuth grant and a channel acknowledged within 45 seconds for Connected. Reconnecting/offline reflect transport health; managed-service entitlement is separate. Existing direct HTTPS connections retain their service-health status."
          },
          "403": {
            "description": "Patient role not permitted"
          }
        }
      }
    },
    "/api/v1/connect/status/refresh": {
      "post": {
        "summary": "Staff: verify live SunCharts service binding without changing activation or owner settings",
        "operationId": "connect_status_refresh",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "Sanitized authorization, service and transport health. New outbound connections require an active OAuth grant and a channel acknowledged within 45 seconds for Connected. Reconnecting/offline reflect transport health; managed-service entitlement is separate. Existing direct HTTPS connections retain their service-health status."
          },
          "403": {
            "description": "Patient role not permitted"
          }
        }
      }
    },
    "/api/v1/connect/onboarding": {
      "get": {
        "description": "Owner-only automatic connection availability, configured cloud origin, transport and pending intent. Does not require a public EHR URL for outbound mode. Returns no credentials.",
        "responses": {
          "200": {
            "description": "Safe onboarding status"
          },
          "403": {
            "description": "Owner or original session required"
          },
          "409": {
            "description": "Stale intent or changed configuration"
          }
        },
        "operationId": "readConnectOnboarding"
      },
      "post": {
        "description": "Start owner-session-bound OAuth2/S256 PKCE onboarding with an outbound authenticated WebSocket. The EHR origin may remain private; browser approval must still reach it. Returns an opaque authorization URL and configured cloud origin; all client and channel credentials travel server-to-server.",
        "responses": {
          "200": {
            "description": "Safe onboarding status"
          },
          "403": {
            "description": "Owner or original session required"
          },
          "409": {
            "description": "Stale intent or changed configuration"
          }
        },
        "operationId": "startConnectOnboarding"
      }
    },
    "/api/v1/connect/onboarding/{id}/complete": {
      "post": {
        "description": "Complete the pending intent in its original owner session with If-Match. Exchanges one-use code and stores encrypted service credentials. Configuration changes prevent replacement.",
        "responses": {
          "200": {
            "description": "Safe onboarding status"
          },
          "403": {
            "description": "Owner or original session required"
          },
          "409": {
            "description": "Stale intent or changed configuration"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "operationId": "completeConnectOnboarding"
      }
    },
    "/api/v1/connect/onboarding/{id}/cancel": {
      "post": {
        "description": "Cancel pending setup with If-Match and revoke only its dedicated generated client.",
        "responses": {
          "200": {
            "description": "Safe onboarding status"
          },
          "403": {
            "description": "Owner or original session required"
          },
          "409": {
            "description": "Stale intent or changed configuration"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "operationId": "cancelConnectOnboarding"
      }
    },
    "/api/v1/practice/staff": {
      "get": {
        "operationId": "listPracticeStaff",
        "summary": "List local staff",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "description": "Local owner browser session only; up to1000records with has_more. Not delegated by OAuth clinical scopes. sign_in is \"connect\" when SunCharts Connect handles staff sign-in for this installation (staff are invited by email and have no password here) and \"password\" otherwise."
      },
      "post": {
        "operationId": "createPracticeStaff",
        "summary": "Create local staff",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeStaffCreate"
              }
            }
          }
        },
        "description": "Owner-only same-origin write with attributed history. When sign_in is \"password\" a password is required. When sign_in is \"connect\" a password is refused: the account is saved first and Connect is then asked to email an invitation; the reply adds invitation {status, reason?, sent_at?, expires_at?} and the account is kept whatever the outcome (status not_sent carries the reason)."
      }
    },
    "/api/v1/practice/staff/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "updatePracticeStaff",
        "summary": "Update local staff",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeStaffChange"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "Quoted current resource version. Missing/malformed returns428; stale returns409.",
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Owner-only same-origin versioned write with attributed history; last active owner is protected. Sensitive staff changes revoke old sessions/grants. Provider activity affects scheduling eligibility; location identity changes cannot bypass existing future room bookings. A role change is enforced here and needs no new invitation: the role a person holds in Connect does not decide what they may do in this installation."
      }
    },
    "/api/v1/practice/staff/invitations": {
      "get": {
        "operationId": "listPracticeStaffInvitations",
        "summary": "Sign-in status of staff invited through SunCharts Connect",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "fresh",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Read Connect again now instead of using the copy kept for up to two minutes."
          }
        ],
        "responses": {
          "200": {
            "description": "sign_in (connect or password), available (false when Connect could not be read; statuses then come from what this installation knows) and items of PracticeStaffInvitation, one per staff member. With password sign-in items is empty.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sign_in": {
                      "type": "string",
                      "enum": [
                        "connect",
                        "password"
                      ]
                    },
                    "available": {
                      "type": "boolean"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PracticeStaffInvitation"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "description": "Owner browser session only. Status combines Connect's invitation records for this installation with Connect sign-ins this installation has seen. Each read is audited."
      }
    },
    "/api/v1/practice/staff/{id}/invitation": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "sendPracticeStaffInvitation",
        "summary": "Send or resend a staff member's sign-in invitation",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "The outcome as a PracticeStaffInvitation. A Connect outage or refusal is an outcome (status not_sent or access_off), not an error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PracticeStaffInvitation"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "Staff sign in with passwords here, or this account's access is turned off"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "description": "Owner-only same-origin write with no request body. Asks Connect, as this installation, to email the invitation again with a new request identifier; the attempt and its outcome are added to the staff member's history and audit trail."
      }
    },
    "/api/v1/practice/providers": {
      "get": {
        "operationId": "listPracticeProvider",
        "summary": "List local providers",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "description": "Local owner browser session only; up to1000records with has_more. Not delegated by OAuth clinical scopes."
      },
      "post": {
        "operationId": "createPracticeProvider",
        "summary": "Create local provider",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeProviderChange"
              }
            }
          }
        }
      }
    },
    "/api/v1/practice/providers/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "updatePracticeProvider",
        "summary": "Update local provider",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeProviderChange"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "Quoted current resource version. Missing/malformed returns428; stale returns409.",
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Owner-only same-origin versioned write with attributed history; last active owner is protected. Sensitive staff changes revoke old sessions/grants. Provider activity affects scheduling eligibility; location identity changes cannot bypass existing future room bookings."
      }
    },
    "/api/v1/practice/facilities": {
      "get": {
        "operationId": "listPracticeFacility",
        "summary": "List local facilities",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "description": "Local owner browser session only; up to1000records with has_more. Not delegated by OAuth clinical scopes."
      },
      "post": {
        "operationId": "createPracticeFacility",
        "summary": "Create local facility",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeFacilityChange"
              }
            }
          }
        }
      }
    },
    "/api/v1/practice/facilities/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "updatePracticeFacility",
        "summary": "Update local facility",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeFacilityChange"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "Quoted current resource version. Missing/malformed returns428; stale returns409.",
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Owner-only same-origin versioned write with attributed history; last active owner is protected. Sensitive staff changes revoke old sessions/grants. Provider activity affects scheduling eligibility; location identity changes cannot bypass existing future room bookings."
      }
    },
    "/api/v1/practice/rooms": {
      "get": {
        "operationId": "listPracticeRoom",
        "summary": "List local rooms",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "description": "Local owner browser session only; up to1000records with has_more. Not delegated by OAuth clinical scopes."
      },
      "post": {
        "operationId": "createPracticeRoom",
        "summary": "Create local room",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeRoomChange"
              }
            }
          }
        }
      }
    },
    "/api/v1/practice/rooms/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "updatePracticeRoom",
        "summary": "Update local room",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeRoomChange"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "Quoted current resource version. Missing/malformed returns428; stale returns409.",
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Owner-only same-origin versioned write with attributed history; last active owner is protected. Sensitive staff changes revoke old sessions/grants. Provider activity affects scheduling eligibility; location identity changes cannot bypass existing future room bookings."
      }
    },
    "/api/v1/practice/admin-history/{kind}/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "kind",
          "required": true,
          "schema": {
            "type": "string",
            "enum": [
              "staff",
              "provider",
              "facility",
              "room"
            ]
          }
        }
      ],
      "get": {
        "operationId": "readPracticeAdminHistory",
        "summary": "Read attributed directory history",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      }
    },
    "/api/v1/schedule/locations": {
      "get": {
        "operationId": "readScheduleLocations",
        "summary": "Read enabled facility and room choices",
        "tags": [
          "Scheduling"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "description": "Staff read; active facility/room names. Up to1000facilities and10000rooms; has_more reports truncation. Existing location text snapshots remain supported."
      }
    },
    "/api/v1/visits/{id}/rooming": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readVisitRooming",
        "summary": "Read intake, current visit version and attributed rooming/vitals history",
        "tags": [
          "Rooming"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "put": {
        "operationId": "saveVisitRooming",
        "summary": "Save delegated intake with shared encounter version",
        "tags": [
          "Rooming"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RoomingIntake"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "Quoted current resource version. Missing/malformed returns428; stale returns409.",
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Enabled tenant nurse/medical_assistant, the assigned clinician, or another clinician or the owner covering the visit, before signing. A delegated support session cannot. Ready requires nonblank chief complaint and both review attestations. Shares Visit.version with SOAP/vitals; returns visit and latest100history revisions. Does not update longitudinal clinical lists or grant signature authority."
      }
    },
    "/fhir/Encounter": {
      "get": {
        "operationId": "fhirEncounterSearch",
        "description": "Bounded read-only current native projection, not US Core/SMART/profile conformance. Staff clinical.read; patient roles denied. UUID keyset paging preserves patient filters. Unsupported/repeated parameters return OperationOutcome. MedicationStatement is recorded medication use, not a prescription.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native Encounter",
        "tags": [
          "FHIR"
        ]
      }
    },
    "/fhir/Encounter/{id}": {
      "get": {
        "operationId": "fhirEncounterRead",
        "description": "Tenant-scoped bounded current resource projection. No history or write operation. Missing/malformed IDs return FHIR404 OperationOutcome.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native Encounter",
        "tags": [
          "FHIR"
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/fhir/Condition": {
      "get": {
        "operationId": "fhirConditionSearch",
        "description": "Bounded current native projection, not US Core/SMART/profile conformance. Staff clinical.read; patient roles denied. UUID keyset paging preserves patient filters. Unsupported/repeated parameters return OperationOutcome. MedicationStatement is recorded medication use, not a prescription.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native Condition",
        "tags": [
          "FHIR"
        ]
      },
      "post": {
        "operationId": "postFhirCondition",
        "summary": "Create Condition",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician and clinical.write required. Ordinary POST creates a new entry and is not replay-safe; conditional and idempotency headers are rejected. PUT updates only an existing resource, requires matching id/version and nonblank X-Change-Reason, and uses the native revision/audit transaction. Unsupported fields fail. ",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirCondition"
              }
            }
          }
        }
      }
    },
    "/fhir/Condition/{id}": {
      "get": {
        "operationId": "fhirConditionRead",
        "description": "Tenant-scoped bounded current resource projection. No history or write operation. Missing/malformed IDs return FHIR404 OperationOutcome.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current native resource version, suitable for supported If-Match writes",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native Condition",
        "tags": [
          "FHIR"
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "putFhirCondition",
        "summary": "Correct Condition",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician and clinical.write required. Ordinary POST creates a new entry and is not replay-safe; conditional and idempotency headers are rejected. PUT updates only an existing resource, requires matching id/version and nonblank X-Change-Reason, and uses the native revision/audit transaction. Unsupported fields fail. ",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "428": {
            "description": "Current If-Match required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "412": {
            "description": "Stale resource version",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "X-Change-Reason",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirCondition"
              }
            }
          }
        }
      }
    },
    "/fhir/AllergyIntolerance": {
      "get": {
        "operationId": "fhirAllergyIntoleranceSearch",
        "description": "Bounded current native projection, not US Core/SMART/profile conformance. Staff clinical.read; patient roles denied. UUID keyset paging preserves patient filters. Unsupported/repeated parameters return OperationOutcome. MedicationStatement is recorded medication use, not a prescription.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native AllergyIntolerance",
        "tags": [
          "FHIR"
        ]
      },
      "post": {
        "operationId": "postFhirAllergyIntolerance",
        "summary": "Create AllergyIntolerance",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician and clinical.write required. Ordinary POST creates a new entry and is not replay-safe; conditional and idempotency headers are rejected. PUT updates only an existing resource, requires matching id/version and nonblank X-Change-Reason, and uses the native revision/audit transaction. Unsupported fields fail. ",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirAllergyIntolerance"
              }
            }
          }
        }
      }
    },
    "/fhir/AllergyIntolerance/{id}": {
      "get": {
        "operationId": "fhirAllergyIntoleranceRead",
        "description": "Tenant-scoped bounded current resource projection. No history or write operation. Missing/malformed IDs return FHIR404 OperationOutcome.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current native resource version, suitable for supported If-Match writes",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native AllergyIntolerance",
        "tags": [
          "FHIR"
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "putFhirAllergyIntolerance",
        "summary": "Correct AllergyIntolerance",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician and clinical.write required. Ordinary POST creates a new entry and is not replay-safe; conditional and idempotency headers are rejected. PUT updates only an existing resource, requires matching id/version and nonblank X-Change-Reason, and uses the native revision/audit transaction. Unsupported fields fail. ",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "428": {
            "description": "Current If-Match required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "412": {
            "description": "Stale resource version",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "X-Change-Reason",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirAllergyIntolerance"
              }
            }
          }
        }
      }
    },
    "/fhir/MedicationStatement": {
      "get": {
        "operationId": "fhirMedicationStatementSearch",
        "description": "Bounded current native projection, not US Core/SMART/profile conformance. Staff clinical.read; patient roles denied. UUID keyset paging preserves patient filters. Unsupported/repeated parameters return OperationOutcome. MedicationStatement is recorded medication use, not a prescription.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native MedicationStatement",
        "tags": [
          "FHIR"
        ]
      },
      "post": {
        "operationId": "postFhirMedicationStatement",
        "summary": "Create MedicationStatement",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician and clinical.write required. Ordinary POST creates a new entry and is not replay-safe; conditional and idempotency headers are rejected. PUT updates only an existing resource, requires matching id/version and nonblank X-Change-Reason, and uses the native revision/audit transaction. Unsupported fields fail. Recorded use only, never prescribing. Existing native verification and structured dose/route/frequency are preserved; editing structured dosage requires the native medication workflow.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirMedicationStatement"
              }
            }
          }
        }
      }
    },
    "/fhir/MedicationStatement/{id}": {
      "get": {
        "operationId": "fhirMedicationStatementRead",
        "description": "Tenant-scoped bounded current resource projection. No history or write operation. Missing/malformed IDs return FHIR404 OperationOutcome.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current native resource version, suitable for supported If-Match writes",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native MedicationStatement",
        "tags": [
          "FHIR"
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "putFhirMedicationStatement",
        "summary": "Correct MedicationStatement",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician and clinical.write required. Ordinary POST creates a new entry and is not replay-safe; conditional and idempotency headers are rejected. PUT updates only an existing resource, requires matching id/version and nonblank X-Change-Reason, and uses the native revision/audit transaction. Unsupported fields fail. Recorded use only, never prescribing. Existing native verification and structured dose/route/frequency are preserved; editing structured dosage requires the native medication workflow.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "428": {
            "description": "Current If-Match required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "412": {
            "description": "Stale resource version",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "X-Change-Reason",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirMedicationStatement"
              }
            }
          }
        }
      }
    },
    "/fhir/Observation": {
      "get": {
        "operationId": "fhirObservationSearch",
        "description": "Read/search native vitals plus individual laboratory observations. Search returns current report revisions only; version-qualified laboratory Observation IDs resolve immutable report snapshots. No measurement collection time is invented from report publication time.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "description": "Vitals UUID or canonical version-qualified lab report observation ID."
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "description": "Vitals UUID or canonical version-qualified lab report observation ID."
            }
          }
        ],
        "summary": "Search native Observation",
        "tags": [
          "FHIR"
        ]
      }
    },
    "/fhir/Observation/{id}": {
      "get": {
        "operationId": "fhirObservationRead",
        "description": "Read/search native vitals plus individual laboratory observations. Search returns current report revisions only; version-qualified laboratory Observation IDs resolve immutable report snapshots. No measurement collection time is invented from report publication time.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native Observation",
        "tags": [
          "FHIR"
        ]
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "maxLength": 64
          }
        }
      ]
    },
    "/api/v1/visits/{id}/diagnoses": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readVisitDiagnoses",
        "summary": "Read ordered encounter diagnoses and attributed revisions",
        "tags": [
          "Encounter diagnoses"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VisitDiagnoses"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "description": "Staff-only tenant-scoped read. Empty diagnoses is an unrecorded list, not a negative clinical assertion. Returns current shared visit version and at most100 newest immutable revisions; history_truncated signals older history. service_date is the date used for catalog selection; selected diagnoses include read-only catalog provenance."
      },
      "put": {
        "operationId": "saveVisitDiagnoses",
        "summary": "Replace ordered encounter diagnoses before signing",
        "tags": [
          "Encounter diagnoses"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VisitDiagnoses"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VisitDiagnosesInput"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "Quoted current resource version. Missing/malformed returns428; stale returns409.",
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Anyone who may save the visit's note may save its diagnoses while the visit is in progress: any clinician, the owner, an enabled nurse or medical assistant. Replaces the whole ordered list with at most20 unique ICD-10-CM codes; rank1 is primary. Codes are trimmed and uppercased, descriptions trimmed. Without catalog_release_id, format validation does not establish validity in an ICD-10-CM edition. With a tenant ICD-10-CM release, the server requires an active billable code for service_date, replaces code/display with catalog values, and preserves read-only edition and service-date provenance. Reason is required; an empty array explicitly removes all diagnoses. Shares Visit.version with intake, SOAP and vitals. Mutation, immutable snapshot revision and audit event commit atomically. Signed diagnoses are immutable. Does not update the longitudinal problem list, orders or billing automatically."
      }
    },
    "/api/v1/patients/{patient}/health-history": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listHealthHistory",
        "summary": "List patient surgical and dental history",
        "description": "Staff-only patient-scoped keyset page. Empty history does not assert no prior surgery or dental problems.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "tags": [
          "Health history"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthHistoryPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or idempotency conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "kind",
            "schema": {
              "type": "string",
              "enum": [
                "surgery",
                "dental"
              ]
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "resolved",
                "completed",
                "entered_in_error"
              ]
            }
          }
        ]
      },
      "post": {
        "operationId": "createHealthHistory",
        "summary": "Record surgical or dental history",
        "description": "Clinician/owner only. Request UUID is idempotent only for identical content and reason. Creates immutable attributed revision and atomic audit. Does not assert procedure performance or terminology validation.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "tags": [
          "Health history"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthHistoryEntry"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or idempotency conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HealthHistoryCreate"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/health-history/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readHealthHistory",
        "summary": "Read a surgical or dental history entry",
        "description": "",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "tags": [
          "Health history"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthHistoryEntry"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or idempotency conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "put": {
        "operationId": "updateHealthHistory",
        "summary": "Revise surgical or dental history",
        "description": "Clinician/owner only. Appends an attributed revision and audit atomically. No destructive deletion.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "tags": [
          "Health history"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthHistoryEntry"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or idempotency conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HealthHistoryEdit"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            },
            "description": "Quoted current entry/resource version."
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/health-history/{id}/revisions": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readHealthHistoryRevisions",
        "summary": "Read attributed surgical or dental history revisions",
        "description": "Bounded immutable revision history; response reports omitted older history. See current entry version before editing.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "tags": [
          "Health history"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "type": "object",
                        "properties": {
                          "version": {
                            "type": "integer"
                          },
                          "content": {
                            "$ref": "#/components/schemas/HealthHistoryContent"
                          },
                          "author_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "actor_label": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "reason": {
                            "type": "string"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "version",
                          "content",
                          "author_id",
                          "reason",
                          "created_at"
                        ]
                      }
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "truncated"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or idempotency conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      }
    },
    "/fhir/Appointment": {
      "get": {
        "operationId": "searchNativeAppointment",
        "description": "Bounded staff-only read/search projection. No US Core, SMART or full conformance claim. ",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native Appointment",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/fhir/Appointment/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readNativeAppointment",
        "description": "Bounded staff-only read/search projection. No US Core, SMART or full conformance claim. ",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native Appointment",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/fhir/Practitioner": {
      "get": {
        "operationId": "searchNativePractitioner",
        "description": "Bounded staff-only read/search projection. No US Core, SMART or full conformance claim. ",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "name",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "active",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ],
        "summary": "Search native Practitioner",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/fhir/Practitioner/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readNativePractitioner",
        "description": "Bounded staff-only read/search projection. No US Core, SMART or full conformance claim. ",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native Practitioner",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/fhir/Location": {
      "get": {
        "operationId": "searchNativeLocation",
        "description": "Bounded staff-only read/search projection. No US Core, SMART or full conformance claim. ",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "name",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "inactive"
              ]
            }
          }
        ],
        "summary": "Search native Location",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/fhir/Location/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readNativeLocation",
        "description": "Bounded staff-only read/search projection. No US Core, SMART or full conformance claim. ",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native Location",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/fhir/Coverage": {
      "get": {
        "operationId": "searchNativeCoverage",
        "description": "Bounded staff-only read/search projection. No US Core, SMART or full conformance claim. Billing read scope required.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native Coverage",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/fhir/Coverage/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readNativeCoverage",
        "description": "Bounded staff-only read/search projection. No US Core, SMART or full conformance claim. Billing read scope required.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native Coverage",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/orders/{order}/diagnoses": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "order",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "linkOrderDiagnoses",
        "summary": "Link selected encounter diagnoses to a draft order",
        "tags": [
          "Diagnosis links"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LabOrder"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderDiagnosisSelection"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "Quoted current resource version. Missing/malformed returns428; stale returns409.",
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Draft-only. If-Match checks target version and visit_version checks linked encounter version under a shared lock. Selected IDs must belong to the same tenant, patient and linked visit. Persists a code/display/ID snapshot with attributed history and atomic audit. Empty selection clears provenance. Charge linking appends selected codes while retaining manual and previously added codes; clearing does not remove codes. Finalized content is immutable."
      }
    },
    "/api/v1/patients/{p}/billing/accounts/{id}/diagnoses": {
      "parameters": [
        {
          "in": "path",
          "name": "p",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "linkAccountDiagnoses",
        "summary": "Link selected encounter diagnoses to a draft charge account",
        "tags": [
          "Diagnosis links"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingAccount"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountDiagnosisSelection"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "description": "Quoted current resource version. Missing/malformed returns428; stale returns409.",
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Draft-only. If-Match checks target version and visit_version checks linked encounter version under a shared lock. Selected IDs must belong to the same tenant, patient and linked visit. Persists a code/display/ID snapshot with attributed history and atomic audit. Empty selection clears provenance. Charge linking appends selected codes while retaining manual and previously added codes; clearing does not remove codes. Finalized content is immutable."
      }
    },
    "/api/v1/patients/{patient}/documents": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listPatientDocuments",
        "summary": "List patient document metadata",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientDocumentPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "category",
            "schema": {
              "type": "string",
              "enum": [
                "identity",
                "insurance",
                "legal",
                "consult",
                "laboratory",
                "imaging",
                "consent",
                "referral",
                "other"
              ]
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "archived",
                "entered_in_error"
              ]
            }
          }
        ]
      },
      "post": {
        "operationId": "uploadPatientDocument",
        "summary": "Upload an immutable patient document",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientDocument"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "413": {
            "description": "Upload exceeds body/decoded-byte limit"
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed. Retry shortly."
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentUpload"
              }
            }
          }
        },
        "description": "Owner/clinician may upload any supported category. Front desk may upload identity, insurance or legal only. Nonempty decoded files are limited to 10 MiB; UTF-8 text to 200,000 bytes. MIME and signatures are checked, not full file validation or malware scanning. Office packages remain opaque ZIP containers and cannot be rendered on the EHR origin. JSON body is limited to 15 MiB. Original bytes, filename, SHA-256 and uploader are immutable; metadata and working-file versions are separate. Exact retries are idempotent. Uploading alone does not release files to patients or send externally."
      }
    },
    "/api/v1/patients/{patient}/documents/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readPatientDocument",
        "summary": "Read patient document metadata",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientDocument"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "put": {
        "operationId": "updatePatientDocument",
        "summary": "Revise document metadata or lifecycle status",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientDocument"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentEdit"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Current If-Match and attributed reason required; original bytes remain immutable. Owner/clinician may edit supported metadata. Front desk may edit only when BOTH the stored category and requested category are identity, insurance or legal; relabeling a clinical document does not bypass authorization."
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/revisions": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readDocumentRevisions",
        "summary": "Read attributed document metadata revisions",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/DocumentRevision"
                      }
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "truncated"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/download": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "downloadPatientDocument",
        "summary": "Download the authenticated immutable original",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/mpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/wav": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/ogg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/webm": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/mp4": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed. Retry shortly."
          }
        },
        "description": "Staff-only. Download audit commits before bytes are returned. Attachment disposition, nosniff and no-store; uploaded HTML is not rendered inline. Filename in Content-Disposition uses document ID, not untrusted upload filename."
      }
    },
    "/api/v1/patients/{patient}/referrals": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listPatientReferrals",
        "summary": "List patient referrals",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "ready",
                "sent",
                "accepted",
                "scheduled",
                "completed",
                "cancelled",
                "entered_in_error"
              ]
            }
          }
        ]
      },
      "post": {
        "operationId": "createPatientReferral",
        "summary": "Create a draft referral",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Referral"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReferralCreate"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/referrals/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readPatientReferral",
        "summary": "Read patient referral",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Referral"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "put": {
        "operationId": "updatePatientReferral",
        "summary": "Revise referral content before handoff",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Referral"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReferralEdit"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Draft/ready only. Editing a ready referral returns it to draft and clears readiness snapshot. Attached documents must be active and belong to this patient; sent referral content is immutable."
      }
    },
    "/api/v1/patients/{patient}/referrals/{id}/actions": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "recordReferralAction",
        "summary": "Record reviewed referral lifecycle evidence",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Referral"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReferralAction"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Manual recording only; no network delivery occurs. Ready captures reviewed document metadata. Sent requires unchanged active attachments. Sent/accepted/scheduled/completed require nonblank evidence. Invalid transitions or stale versions fail409; sent content and prior revisions remain immutable."
      }
    },
    "/api/v1/patients/{patient}/referrals/{id}/revisions": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readReferralRevisions",
        "summary": "Read attributed referral revisions and recorded evidence",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/ReferralRevision"
                      }
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "truncated"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      }
    },
    "/api/v1/referrals/worklist": {
      "get": {
        "operationId": "referralWorklist",
        "summary": "Review practice referrals and overdue follow-up",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/ReferralWorklistEntry"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uuid"
                    },
                    "overdue_as_of": {
                      "type": "string",
                      "format": "date"
                    }
                  },
                  "required": [
                    "items",
                    "next_cursor",
                    "overdue_as_of"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "ready",
                "sent",
                "accepted",
                "scheduled",
                "completed",
                "cancelled",
                "entered_in_error"
              ]
            }
          },
          {
            "in": "query",
            "name": "overdue",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ]
      }
    },
    "/fhir/ServiceRequest": {
      "get": {
        "operationId": "searchNativeServiceRequest",
        "description": "Read-only tenant-scoped native orders/results projection. Strict bounded search; no external delivery or conformance claim.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native ServiceRequest",
        "tags": [
          "FHIR"
        ]
      },
      "post": {
        "operationId": "postFhirServiceRequest",
        "summary": "Create ServiceRequest",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician and clinical.write required. Ordinary POST creates a new entry and is not replay-safe; conditional and idempotency headers are rejected. PUT updates only an existing resource, requires matching id/version and nonblank X-Change-Reason, and uses the native revision/audit transaction. Unsupported fields fail. Only one-test draft with intent=order; placed orders are immutable. Multi-test editing, placement and external execution use native workflows.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirServiceRequest"
              }
            }
          }
        }
      }
    },
    "/fhir/ServiceRequest/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readNativeServiceRequest",
        "description": "Read-only tenant-scoped native orders/results projection. Strict bounded search; no external delivery or conformance claim.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current native resource version, suitable for supported If-Match writes",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native ServiceRequest",
        "tags": [
          "FHIR"
        ]
      },
      "put": {
        "operationId": "putFhirServiceRequest",
        "summary": "Correct ServiceRequest",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician and clinical.write required. Ordinary POST creates a new entry and is not replay-safe; conditional and idempotency headers are rejected. PUT updates only an existing resource, requires matching id/version and nonblank X-Change-Reason, and uses the native revision/audit transaction. Unsupported fields fail. Only one-test draft with intent=order; placed orders are immutable. Multi-test editing, placement and external execution use native workflows.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Weak current resource version",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Resource URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "428": {
            "description": "Current If-Match required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "412": {
            "description": "Stale resource version",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "X-Change-Reason",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirServiceRequest"
              }
            }
          }
        }
      }
    },
    "/fhir/Specimen": {
      "get": {
        "operationId": "searchNativeSpecimen",
        "description": "Read-only tenant-scoped native orders/results projection. Strict bounded search; no external delivery or conformance claim.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native Specimen",
        "tags": [
          "FHIR"
        ]
      }
    },
    "/fhir/Specimen/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readNativeSpecimen",
        "description": "Read-only tenant-scoped native orders/results projection. Strict bounded search; no external delivery or conformance claim.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native Specimen",
        "tags": [
          "FHIR"
        ]
      }
    },
    "/fhir/DiagnosticReport": {
      "get": {
        "operationId": "searchNativeDiagnosticReport",
        "description": "Read-only tenant-scoped native orders/results projection. Strict bounded search; no external delivery or conformance claim.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "patient",
            "schema": {
              "type": "string",
              "description": "Patient UUID or relative Patient/UUID reference"
            }
          },
          {
            "in": "query",
            "name": "_count",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "_after",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "summary": "Search native DiagnosticReport",
        "tags": [
          "FHIR"
        ]
      }
    },
    "/fhir/DiagnosticReport/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readNativeDiagnosticReport",
        "description": "Read-only tenant-scoped native orders/results projection. Strict bounded search; no external delivery or conformance claim.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "409": {
            "description": "Conflicting state"
          },
          "404": {
            "description": "Resource not found",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "summary": "Read native DiagnosticReport",
        "tags": [
          "FHIR"
        ]
      }
    },
    "/api/v1/patients/{id}/identity": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readPatientIdentity",
        "summary": "Read registration identity and correction history",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientIdentity"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "put": {
        "operationId": "updatePatientIdentity",
        "summary": "Correct registration identity with attributed history",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientIdentity"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatientIdentityChange"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Correct registered names and birth date with current If-Match and attributed history. Omit mrn; an unchanged legacy echo is accepted but changing an MRN is rejected."
      }
    },
    "/api/v1/patients/{id}/identity/revisions": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "patientIdentityRevisions",
        "summary": "Read immutable registration identity revisions",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "type": "object",
                        "properties": {
                          "version": {
                            "type": "integer"
                          },
                          "snapshot": {
                            "$ref": "#/components/schemas/PatientIdentitySnapshot"
                          },
                          "actor_id": {
                            "anyOf": [
                              {
                                "type": "string",
                                "format": "uuid"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "actor_label": {
                            "anyOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "reason": {
                            "type": "string"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "truncated"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      }
    },
    "/api/v1/referral-delivery/destinations": {
      "get": {
        "operationId": "listReferralDestinations",
        "summary": "Read configured referral receiving destinations",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/ReferralDestination"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "post": {
        "operationId": "createReferralDestination",
        "summary": "Configure a referral receiving gateway",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralDestination"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReferralDestinationInput"
              }
            }
          }
        },
        "description": "Local ownerbrowser only; no delegatedOAuthadministration. Requires request_id oncreation and a bearer credential. Productiondestinations require operator-approvedHTTPS host port443; no redirects/privateaddresses. Credentials are encrypted and neverreturned."
      }
    },
    "/api/v1/referral-delivery/destinations/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "put": {
        "operationId": "updateReferralDestination",
        "summary": "Update referral receiving configuration",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralDestination"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReferralDestinationInput"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/referrals/{id}/delivery/preview": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "previewReferralDelivery",
        "summary": "Review the exact referral package and destination",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "destination_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": [
                  "destination_id"
                ]
              }
            }
          }
        },
        "description": "Readyreferrals only. Validates documentversions, includes filemetadata/hash/bytescount inmanifest but no filebytes inpreview. Reviewexpiresafter10minutes; no networksend."
      }
    },
    "/api/v1/patients/{patient}/referrals/{id}/delivery": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "queueReferralDelivery",
        "summary": "Queue an explicitly reviewed referral delivery",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralDeliveryJob"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReferralDeliveryQueue"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "RequestUUID idempotent against identical review and reason. Locks exactreferral/destination versions and activeunchangeddocuments. Worker sends immutablepayload via receivinggateway with Idempotency-Key; acceptance requires verifiedreceiverreceipt. Clinicalacceptance is separate. Queued/sending/uncertain jobs reserve referral againstmanualedits."
      }
    },
    "/api/v1/patients/{patient}/referrals/{id}/deliveries": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listReferralDeliveries",
        "summary": "Read referral delivery status/history",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReferralDeliveryJob"
                      }
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "truncated"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      }
    },
    "/api/v1/referral-delivery/jobs/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readReferralDelivery",
        "summary": "Read delivery status and audit events",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      }
    },
    "/api/v1/referral-delivery/jobs/{id}/actions": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "reconcileReferralDelivery",
        "summary": "Cancel queued delivery or reconcile uncertain transport",
        "tags": [
          "Referral delivery"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralDeliveryJob"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReferralDeliveryAction"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Clinician/owner only. No blindretry. Reconciliation requires explicit boundedreceiverreceipt/evidence; sent retains clinicalacceptance unrecorded. If-Match checks job version."
      }
    },
    "/api/v1/connect/status/events": {
      "get": {
        "operationId": "connectStatusEvents",
        "summary": "Browser staff: live connection health",
        "description": "Session-cookie-only SSE connection events with sanitized status snapshots. Browser session and staff access are rechecked every two seconds; revocation closes the feed. No credentials or clinical records are emitted.",
        "tags": [
          "SunCharts Connect services"
        ],
        "responses": {
          "200": {
            "description": "SSE events named connection; payload has the same status shape as GET /api/v1/connect/status.",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Active browser session required"
          },
          "403": {
            "description": "Staff role required"
          }
        },
        "security": [
          {
            "browserSession": []
          }
        ]
      }
    },
    "/api/v1/connect/services/notifications": {
      "get": {
        "operationId": "listConnectReplyNotifications",
        "summary": "Read per-user unread support reply references",
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current user unread support replies for the active installation; no message text or credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectReplyNotifications"
                }
              }
            }
          },
          "401": {
            "description": "Active browser session required"
          },
          "403": {
            "description": "Owner, clinician or front-desk access required"
          }
        }
      }
    },
    "/api/v1/connect/services/notifications/read": {
      "post": {
        "operationId": "readConnectReplyNotifications",
        "summary": "Acknowledge selected support replies for the current staff account",
        "description": "Requires same-origin browser session. Identifiers are checked against the active tenant/installation; acknowledgments are durable, idempotent and audited. Acknowledging a reply does not change or close its support ticket.",
        "security": [
          {
            "browserSession": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReadConnectReplyNotifications"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current user unread support replies for the active installation; no message text or credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectReplyNotifications"
                }
              }
            }
          },
          "401": {
            "description": "Active browser session required"
          },
          "403": {
            "description": "Owner, clinician or front-desk access required"
          },
          "400": {
            "description": "One to one hundred positive event identifiers required"
          },
          "404": {
            "description": "An event does not belong to the active tenant and installation"
          }
        }
      }
    },
    "/api/v1/connect/services/events": {
      "get": {
        "operationId": "streamConnectServiceUpdates",
        "summary": "Live support and reminder change references",
        "description": "Session-cookie-only SSE. ready/reset establish cursor and unread notification snapshot; service.change identifies a committed support.reply, support.updated or reminder.updated by safe IDs; notifications updates per-user unread state. Support replies include message_id so only displayed replies are marked read. Last-Event-ID or after resumes the tenant cursor. Session/role, installation rotation and revocation are rechecked; no message bodies, patient content or credentials are broadcast.",
        "security": [
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "after",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 0
            }
          },
          {
            "in": "header",
            "name": "Last-Event-ID",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "SSE service update and notification snapshots",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Active browser session required"
          },
          "403": {
            "description": "Owner, clinician or front-desk access required"
          }
        }
      }
    },
    "/fhir/DocumentReference": {
      "get": {
        "operationId": "fhirDocumentReferenceSearch",
        "summary": "DocumentReference search",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff clinical.read only; patient-role tokens denied. Native immutable document originals and metadata.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "patient",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "_after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "_count",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ]
      }
    },
    "/fhir/DocumentReference/{id}": {
      "get": {
        "operationId": "fhirDocumentReferenceRead",
        "summary": "DocumentReference read",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff clinical.read only; patient-role tokens denied. Native immutable document originals and metadata.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/fhir/MedicationRequest": {
      "get": {
        "operationId": "fhirMedicationRequestSearch",
        "summary": "MedicationRequest search",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff clinical.read only; native_prescriptions projection only. Draft/active/cancelled/stopped/completed retain local status. No MedicationStatement inference, pharmacy transmission, acceptance or dispensing asserted.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "patient",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "_after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "_count",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ]
      }
    },
    "/fhir/MedicationRequest/{id}": {
      "get": {
        "operationId": "fhirMedicationRequestRead",
        "summary": "MedicationRequest read",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff clinical.read only; native_prescriptions projection only. Draft/active/cancelled/stopped/completed retain local status. No MedicationStatement inference, pharmacy transmission, acceptance or dispensing asserted.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/fhir/Binary/{id}": {
      "get": {
        "operationId": "fhirBinaryRead",
        "summary": "Read immutable patient document original",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff clinical.read only. JSON Binary with base64 data and DocumentReference securityContext by default; Accept matching original MIME returns exact original bytes. Binary search and writes are unsupported. no-store, nosniff and attachment disposition. No patient-role access.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "FHIR Binary JSON representation selected by application/json Accept."
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required or expired",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic operation or audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "406": {
            "description": "No acceptable supported representation",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed. Retry shortly."
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Accept",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "application/fhir+json or application/json for resource JSON; application/pdf, image/png or image/jpeg only when matching the stored original."
          }
        ]
      }
    },
    "/api/v1/prescribing/capabilities": {
      "get": {
        "operationId": "prescribingCapabilities",
        "summary": "prescribingCapabilities",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff-only truthful capability boundary: local medication orders; network eRx and controlled-substance authorization are unavailable.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        }
      }
    },
    "/api/v1/prescribing/pharmacies": {
      "get": {
        "operationId": "listPrescribingPharmacies",
        "summary": "listPrescribingPharmacies",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; at most 200 records with truncated flag.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrescribingPharmacyPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        }
      },
      "post": {
        "operationId": "createPrescribingPharmacy",
        "summary": "createPrescribingPharmacy",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician/nurse/medical assistant/front desk; request UUID replay is actor- and content-bound.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrescribingPharmacy"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted native version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PharmacyChange"
              }
            }
          }
        }
      }
    },
    "/api/v1/prescribing/pharmacies/{id}": {
      "get": {
        "operationId": "readPrescribingPharmacy",
        "summary": "readPrescribingPharmacy",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; tenant-scoped directory record.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrescribingPharmacy"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted native version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "put": {
        "operationId": "updatePrescribingPharmacy",
        "summary": "updatePrescribingPharmacy",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Directory roles; actor-bound request replay and version check.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrescribingPharmacy"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted native version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PharmacyChange"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/pharmacy": {
      "get": {
        "operationId": "readPreferredPharmacy",
        "summary": "readPreferredPharmacy",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; initial version 0 when unselected.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreferredPharmacy"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "put": {
        "operationId": "savePreferredPharmacy",
        "summary": "savePreferredPharmacy",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Directory roles. Version is in the body, not If-Match; null pharmacy clears preference.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreferredPharmacy"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted native version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PharmacyPreferenceChange"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/prescriptions": {
      "get": {
        "operationId": "listNativePrescriptions",
        "summary": "listNativePrescriptions",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; UUID _after keyset cursor, 100 records, next_cursor.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NativePrescriptionPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "_after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "post": {
        "operationId": "createNativePrescription",
        "summary": "createNativePrescription",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician/nurse/medical assistant may prepare drafts; this does not authorize medication or transmit it. Request UUID replay bound to actor/content.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NativePrescription"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted native version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PrescriptionDraft"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/prescribing-review": {
      "get": {
        "operationId": "nativePrescribingReview",
        "summary": "nativePrescribingReview",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; review_token binds current recorded allergy/medication review and active prescription state. No automated drug/dose/interaction/formulary safety checks.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrescribingReview"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/prescriptions/{id}": {
      "get": {
        "operationId": "readNativePrescription",
        "summary": "readNativePrescription",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; current local prescription and signed snapshot when authorized.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NativePrescription"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted native version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "put": {
        "operationId": "updateNativePrescription",
        "summary": "updateNativePrescription",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Draft preparation roles only; authorized content immutable. Provenance cannot change; request UUID replay bound to actor/content.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NativePrescription"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted native version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PrescriptionDraft"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/prescriptions/{id}/actions/{action}": {
      "post": {
        "operationId": "actOnNativePrescription",
        "summary": "actOnNativePrescription",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician authorize, cancel, stop or complete; authorization requires fresh review_token and attest=true. record_print/fulfill_local require rooming authority and record local evidence only. No electronic transmission or dispensing claim. Renewal/replacement creates a new draft through POST /prescriptions with prior_prescription_id and relationship; these are not action path values.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NativePrescription"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Quoted native version",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "authorize",
                "cancel",
                "stop",
                "complete",
                "record_print",
                "fulfill_local"
              ]
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PrescriptionAction"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/prescriptions/{id}/history": {
      "get": {
        "operationId": "nativePrescriptionHistory",
        "summary": "nativePrescriptionHistory",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; immutable attributed versions, limit 100 and truncated flag.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/prescriptions/{id}/print": {
      "get": {
        "operationId": "printNativePrescription",
        "summary": "printNativePrescription",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; authorized local record only. Draft returns 409. Rendering does not record printing or dispensing.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/patient-portal/activate": {
      "post": {
        "operationId": "activatePatientPortal",
        "summary": "activatePatientPortal",
        "tags": [
          "Patient portal"
        ],
        "security": [],
        "description": "Single-use unexpired invitation token; manual secure handoff, not automatic email delivery. Activation does not sign in.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {}
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalActivation"
              }
            }
          }
        }
      }
    },
    "/api/v1/patient-portal/login": {
      "post": {
        "operationId": "loginPatientPortal",
        "summary": "loginPatientPortal",
        "tags": [
          "Patient portal"
        ],
        "security": [],
        "description": "Practice-bound password login; sets sce_portal cookie. Rate limited; generic credential errors.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "no-store",
                "schema": {
                  "type": "string"
                }
              },
              "Set-Cookie": {
                "description": "HttpOnly sce_portal cookie (expired on logout); does not establish a staff session",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalLogin"
              }
            }
          }
        }
      }
    },
    "/api/v1/patient-portal/logout": {
      "post": {
        "operationId": "logoutPatientPortal",
        "summary": "logoutPatientPortal",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "patientPortalSession": []
          }
        ],
        "description": "Revoke current portal session and expire cookie.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "no-store",
                "schema": {
                  "type": "string"
                }
              },
              "Set-Cookie": {
                "description": "HttpOnly sce_portal cookie (expired on logout); does not establish a staff session",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          },
          {
            "name": "X-SunCharts-Portal-Account",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Account UUID returned by /session. Required even on GET/logout to fence another account replacing the browser cookie. Mismatch returns 409."
          }
        ]
      }
    },
    "/api/v1/patient-portal/dashboard": {
      "get": {
        "operationId": "patientPortalDashboard",
        "summary": "patientPortalDashboard",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "patientPortalSession": []
          }
        ],
        "description": "Cookie-bound patient only; up to 100 appointments and explicit signed-visit AVS releases, with has_more flags.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalDashboard"
                }
              }
            },
            "headers": {}
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "X-SunCharts-Portal-Account",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Account UUID returned by /session. Required even on GET/logout to fence another account replacing the browser cookie. Mismatch returns 409."
          }
        ]
      }
    },
    "/api/v1/patient-portal/avs/{visit}": {
      "get": {
        "operationId": "patientPortalAvs",
        "summary": "patientPortalAvs",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "patientPortalSession": []
          }
        ],
        "description": "Only explicitly published immutable AVS version belonging to current patient and signed visit; patient-facing whitelisted fields only.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {}
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "visit",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-SunCharts-Portal-Account",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Account UUID returned by /session. Required even on GET/logout to fence another account replacing the browser cookie. Mismatch returns 409."
          }
        ]
      }
    },
    "/api/v1/patient-portal/threads": {
      "get": {
        "operationId": "patientPortalThreads",
        "summary": "patientPortalThreads",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "patientPortalSession": []
          }
        ],
        "description": "Current patient conversations only; bounded list/truncated flag.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalThreadPage"
                }
              }
            },
            "headers": {}
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "X-SunCharts-Portal-Account",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Account UUID returned by /session. Required even on GET/logout to fence another account replacing the browser cookie. Mismatch returns 409."
          }
        ]
      },
      "post": {
        "operationId": "createPatientPortalThread",
        "summary": "createPatientPortalThread",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "patientPortalSession": []
          }
        ],
        "description": "Patient-bound idempotent request; no appointment is rescheduled by this operation.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalThread"
                }
              }
            },
            "headers": {}
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          },
          {
            "name": "X-SunCharts-Portal-Account",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Account UUID returned by /session. Required even on GET/logout to fence another account replacing the browser cookie. Mismatch returns 409."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalNewThread"
              }
            }
          }
        }
      }
    },
    "/api/v1/patient-portal/threads/{thread}": {
      "get": {
        "operationId": "patientPortalThread",
        "summary": "patientPortalThread",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "patientPortalSession": []
          }
        ],
        "description": "Current patient conversation and bounded message history.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalThreadMessages"
                }
              }
            },
            "headers": {}
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "thread",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-SunCharts-Portal-Account",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Account UUID returned by /session. Required even on GET/logout to fence another account replacing the browser cookie. Mismatch returns 409."
          }
        ]
      },
      "post": {
        "operationId": "replyPatientPortalThread",
        "summary": "replyPatientPortalThread",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "patientPortalSession": []
          }
        ],
        "description": "Current patient reply; quoted thread If-Match and request UUID required.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalThread"
                }
              }
            },
            "headers": {}
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "thread",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          },
          {
            "name": "X-SunCharts-Portal-Account",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Account UUID returned by /session. Required even on GET/logout to fence another account replacing the browser cookie. Mismatch returns 409."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalReply"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/portal": {
      "get": {
        "operationId": "readPatientPortalAccess",
        "summary": "readPatientPortalAccess",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician/front desk staff only; account status and current version. Initial version 0.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalAccess"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/portal/invite": {
      "post": {
        "operationId": "invitePatientPortal",
        "summary": "invitePatientPortal",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Scheduling roles; quoted current account version (0 initially). Returns a one-time invitation URL for manual secure handoff; email_sent=false.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalInvitation"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalInvite"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/portal/revoke": {
      "post": {
        "operationId": "revokePatientPortal",
        "summary": "revokePatientPortal",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Scheduling roles; revoke account/invitations/sessions atomically using current version.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalReason"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/portal/avs/{visit}": {
      "post": {
        "operationId": "publishPatientPortalAvs",
        "summary": "publishPatientPortalAvs",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Whoever may sign the note (any clinician or the owner, never a delegated support session) may publish/hide an existing released AVS version of a signed visit. If-Match is publication version, 0 initially; avs_version selects immutable release.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "visit",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalPublication"
              }
            }
          }
        }
      }
    },
    "/api/v1/portal-inbox": {
      "get": {
        "operationId": "staffPortalInbox",
        "summary": "staffPortalInbox",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Scheduling roles; tenant-scoped bounded inbox.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalThreadPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        }
      }
    },
    "/api/v1/portal-inbox/{thread}": {
      "get": {
        "operationId": "staffPortalThread",
        "summary": "staffPortalThread",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Scheduling roles; tenant-scoped conversation.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalThreadMessages"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          }
        },
        "parameters": [
          {
            "name": "thread",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "post": {
        "operationId": "staffReplyPortalThread",
        "summary": "staffReplyPortalThread",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Scheduling roles; current thread version and actor-bound request replay.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PortalThread"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "thread",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalReply"
              }
            }
          }
        }
      }
    },
    "/api/v1/portal-inbox/{thread}/status": {
      "post": {
        "operationId": "staffStatusPortalThread",
        "summary": "staffStatusPortalThread",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Scheduling roles; open/close conversation with current version and reason.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        },
        "parameters": [
          {
            "name": "thread",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current native version; portal initial account/publication uses \"0\". FHIR accepts W/\"n\" or \"n\"; native headers use \"n\"."
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Must exactly match the configured EHR origin."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PortalThreadStatus"
              }
            }
          }
        }
      }
    },
    "/api/v1/patient-portal/session": {
      "get": {
        "operationId": "patientPortalSession",
        "summary": "Check current patient portal session",
        "tags": [
          "Patient portal"
        ],
        "security": [
          {
            "patientPortalSession": []
          }
        ],
        "description": "Checks patient-cookie account/session expiry and revocation without extending the idle timeout. Returns account_id for browser account-switch fencing; no chart content and no staff session.",
        "responses": {
          "200": {
            "description": "Valid current patient session",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "account_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "account_id"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Patient cookie missing, expired or revoked"
          },
          "403": {
            "description": "Patient access denied"
          }
        }
      }
    },
    "/api/v1/prescribing/erx": {
      "get": {
        "operationId": "erxEnrollmentStatus",
        "summary": "erxEnrollmentStatus",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Local browser session with rooming authority. Candidate profiles are documentation references, never active providers. Owner sees organization and eligible local mappings; clinicians see their own. No vendor call or enrollment verification occurs.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErxSetupStatus"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "422": {
            "description": "Body fields missing, unknown or incorrectly typed"
          }
        },
        "parameters": []
      }
    },
    "/api/v1/prescribing/erx/connection": {
      "put": {
        "operationId": "saveErxEnrollmentPreparation",
        "summary": "saveErxEnrollmentPreparation",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Owner browser session and Origin required. Body version starts at 0. Request UUID binds exact actor/body including encrypted credential inputs. Candidate changes require explicit credential replacement/clearing and invalidate older prescriber mappings. This cannot activate a provider or send prescriptions.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErxConnectionState"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "422": {
            "description": "Body fields missing, unknown or incorrectly typed"
          }
        },
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ErxConnectionPreparation"
              }
            }
          }
        }
      }
    },
    "/api/v1/prescribing/erx/prescribers/{user}": {
      "put": {
        "operationId": "saveErxPrescriberPreparation",
        "summary": "saveErxPrescriberPreparation",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Owner or that clinician in a real local browser session, with Origin. Body version starts at 0. Metadata reports vendor references, not verified prescribing or EPCS authority. Cross-candidate credentials require explicit clearing/replacement.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErxPrescriberState"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "422": {
            "description": "Body fields missing, unknown or incorrectly typed"
          }
        },
        "parameters": [
          {
            "name": "user",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ErxPrescriberPreparation"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/prescribing/erx/attempts": {
      "get": {
        "operationId": "listErxReadinessAttempts",
        "summary": "listErxReadinessAttempts",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Rooming browser authority, tenant/patient scoped, latest 100 immutable checks and truncated flag.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/ErxReadinessAttempt"
                      }
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "truncated"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "422": {
            "description": "Body fields missing, unknown or incorrectly typed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "post": {
        "operationId": "recordErxReadinessCheck",
        "summary": "recordErxReadinessCheck",
        "tags": [
          "Prescribing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Clinician/owner browser session and Origin. Idempotently records a check blocked before vendor contact. Native prescription reference must belong to this patient, and its content/status is never modified. No vendor launch, queue, send or receipt is created.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErxReadinessAttempt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or unsupported input"
          },
          "401": {
            "description": "Authentication required or expired"
          },
          "403": {
            "description": "Scope, role, Origin or patient access denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, immutable-state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation or audit failed"
          },
          "422": {
            "description": "Body fields missing, unknown or incorrectly typed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ErxReadinessCheck"
              }
            }
          }
        }
      }
    },
    "/api/v1/immunizations/performers": {
      "get": {
        "operationId": "immunizationPerformers",
        "summary": "immunizationPerformers",
        "tags": [
          "Immunizations"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff only; active local owner/clinician/nurse names and IDs, at most 500 with truncated flag. Actual performer must be explicitly selected, not inferred from recorder.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 500,
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "display": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "display"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "truncated"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict"
          },
          "500": {
            "description": "Atomic write/audit failed"
          }
        }
      }
    },
    "/api/v1/patients/{patient}/immunizations": {
      "get": {
        "operationId": "listImmunizations",
        "summary": "listImmunizations",
        "tags": [
          "Immunizations"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff only. Patient-scoped UUID keyset pages with explicit next_cursor; an empty list does not establish vaccination status.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImmunizationPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict"
          },
          "500": {
            "description": "Atomic write/audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "_after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "_count",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": ""
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "completed",
                "not_done",
                "entered_in_error"
              ]
            },
            "description": ""
          }
        ]
      },
      "post": {
        "operationId": "createImmunization",
        "summary": "createImmunization",
        "tags": [
          "Immunizations"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner, clinician or nurse and clinical.write; medical assistants have read access only. Exactly matched request UUID replays are actor/content-bound. Every mutation/revision/audit commits atomically; no vaccine administration, registry exchange or clinical decision support is performed by saving.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImmunizationRecord"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Current native version; weak ETag on FHIR",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict"
          },
          "500": {
            "description": "Atomic write/audit failed"
          },
          "422": {
            "description": "JSON shape, typed date/timestamp or unsupported field deserialization rejected before the native write boundary"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateImmunization"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/immunizations/{id}": {
      "get": {
        "operationId": "readImmunization",
        "summary": "readImmunization",
        "tags": [
          "Immunizations"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff, tenant/patient scoped; includes historical performer snapshot.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImmunizationRecord"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Current native version; weak ETag on FHIR",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict"
          },
          "500": {
            "description": "Atomic write/audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          }
        ]
      },
      "put": {
        "operationId": "correctImmunization",
        "summary": "correctImmunization",
        "tags": [
          "Immunizations"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner, clinician or nurse and clinical.write; medical assistants have read access only. Exactly matched request UUID replays are actor/content-bound. Every mutation/revision/audit commits atomically; no vaccine administration, registry exchange or clinical decision support is performed by saving. Record type/status are unchanged; previous content remains in revisions. Previously recorded performer snapshots survive subsequent staff disablement.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImmunizationRecord"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Current native version; weak ETag on FHIR",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict"
          },
          "500": {
            "description": "Atomic write/audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          },
          "422": {
            "description": "JSON shape, typed date/timestamp or unsupported field deserialization rejected before the native write boundary"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; FHIR also accepts W/\"n\"."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CorrectImmunization"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/immunizations/{id}/entered-in-error": {
      "post": {
        "operationId": "immunizationEnteredInError",
        "summary": "immunizationEnteredInError",
        "tags": [
          "Immunizations"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner, clinician or nurse and clinical.write; medical assistants have read access only. Exactly matched request UUID replays are actor/content-bound. Every mutation/revision/audit commits atomically; no vaccine administration, registry exchange or clinical decision support is performed by saving. Terminal error marking; record cannot be reopened or deleted.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImmunizationRecord"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Current native version; weak ETag on FHIR",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict"
          },
          "500": {
            "description": "Atomic write/audit failed"
          },
          "428": {
            "description": "Current If-Match required"
          },
          "422": {
            "description": "JSON shape, typed date/timestamp or unsupported field deserialization rejected before the native write boundary"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; FHIR also accepts W/\"n\"."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImmunizationError"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/immunizations/{id}/revisions": {
      "get": {
        "operationId": "immunizationRevisions",
        "summary": "immunizationRevisions",
        "tags": [
          "Immunizations"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff; up to 100 immutable attributed revision snapshots with truncated flag.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/ImmunizationRevision"
                      }
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "items",
                    "truncated"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Scope or role denied"
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient"
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict"
          },
          "500": {
            "description": "Atomic write/audit failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          }
        ]
      }
    },
    "/fhir/Immunization": {
      "get": {
        "operationId": "fhirImmunizationSearch",
        "summary": "fhirImmunizationSearch",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff clinical.read only. Native event projection; exact date matches UTC day for timestamps and excludes historical occurrence strings. No patient-role access. Unsupported/repeated filters fail. Empty Bundle omits entry.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope or role denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic write/audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "patient",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": ""
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "completed",
                "not-done",
                "entered-in-error"
              ]
            },
            "description": ""
          },
          {
            "name": "date",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": ""
          },
          {
            "name": "_after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "_count",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": ""
          }
        ]
      },
      "post": {
        "operationId": "createFhirImmunization",
        "summary": "createFhirImmunization",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician/nurse clinical.write only. Bounded explicit native provenance and source; ordinary POST creates a new record and is not replay-safe. No forecasting, terminology validation or registry transmission.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Current native version; weak ETag on FHIR",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope or role denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic write/audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirImmunization"
              }
            }
          }
        }
      }
    },
    "/fhir/Immunization/{id}": {
      "get": {
        "operationId": "fhirImmunizationRead",
        "summary": "fhirImmunizationRead",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Staff clinical.read only; immutable revisions remain native, no FHIR vread endpoint.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Current native version; weak ETag on FHIR",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope or role denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic write/audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          }
        ]
      },
      "put": {
        "operationId": "correctFhirImmunization",
        "summary": "correctFhirImmunization",
        "tags": [
          "FHIR"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "description": "Owner/clinician/nurse clinical.write. Uses native correction boundary; record type/status cannot change. Entered-in-error uses native reviewed action. Unsupported fields fail rather than being discarded.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "ETag": {
                "description": "Current native version; weak ETag on FHIR",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid/unsupported content or context",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "403": {
            "description": "Scope or role denied",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "404": {
            "description": "Record not found in authenticated tenant/patient",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "409": {
            "description": "Version, request identity or immutable-state conflict",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "500": {
            "description": "Atomic write/audit failed",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          },
          "428": {
            "description": "Current If-Match required"
          },
          "412": {
            "description": "Stale Immunization version",
            "content": {
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/FhirOperationOutcome"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": ""
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version; FHIR also accepts W/\"n\"."
          },
          {
            "name": "X-Change-Reason",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            },
            "description": ""
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/fhir+json": {
              "schema": {
                "$ref": "#/components/schemas/WritableFhirImmunization"
              }
            }
          }
        }
      }
    },
    "/api/v1/care-pathways/definitions": {
      "get": {
        "operationId": "listCarePathwayDefinitions",
        "responses": {
          "200": {
            "description": "Tenant care-pathway definitions"
          }
        }
      },
      "post": {
        "operationId": "createCarePathwayDefinition",
        "summary": "Create a configurable visual care-pathway draft",
        "description": "Owner-only. Columns are ordered display lanes rather than fixed clinical phases; node dependencies and conditions remain the executable graph. request_id provides idempotency.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCarePathwayDefinition"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Created draft definition"
          },
          "400": {
            "description": "Invalid columns, nodes, dependency graph or trigger"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Slug or request identity conflict"
          }
        }
      }
    },
    "/api/v1/care-pathways/definitions/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readCarePathwayDefinition",
        "responses": {
          "200": {
            "description": "Definition"
          }
        }
      },
      "put": {
        "operationId": "updateCarePathwayDefinition",
        "summary": "Replace a care-pathway draft",
        "description": "Owner-only and versioned. Published revisions remain immutable. Empty columns may be removed after their nodes are reassigned; at least one visible column is required.",
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateCarePathwayDefinition"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated draft definition"
          },
          "400": {
            "description": "Invalid columns, nodes or dependency graph"
          },
          "403": {
            "description": "Owner role required"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/care-pathways/definitions/{id}/actions": {
      "post": {
        "operationId": "actOnCarePathwayDefinition",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Definition activated or archived"
          }
        }
      }
    },
    "/api/v1/care-pathways/definitions/{id}/revisions": {
      "get": {
        "operationId": "listCarePathwayDefinitionRevisions",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Immutable definition revisions"
          }
        }
      }
    },
    "/api/v1/care-pathways/trigger": {
      "post": {
        "operationId": "triggerCarePathways",
        "summary": "Idempotently instantiate active definitions for a tenant event",
        "description": "Staff-only. Starts matching published revisions and evaluates graph conditions; display-column placement does not alter dependency execution.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TriggerCarePathway"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Matching pathway instances"
          },
          "400": {
            "description": "Invalid trigger identity or context"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      }
    },
    "/api/v1/care-pathways/instances": {
      "get": {
        "operationId": "listCarePathwayInstances",
        "parameters": [
          {
            "name": "patient_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "completed",
                "cancelled"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant pathway worklist"
          }
        }
      }
    },
    "/api/v1/care-pathways/instances/{id}": {
      "get": {
        "operationId": "readCarePathwayInstance",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Pathway instance"
          }
        }
      }
    },
    "/api/v1/care-pathways/instances/{id}/actions": {
      "post": {
        "operationId": "actOnCarePathwayInstance",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Pathway cancelled or resumed"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/care-pathways/instances/{id}/steps/{step}/actions": {
      "post": {
        "operationId": "actOnCarePathwayStep",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "step",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated pathway instance"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/care-pathways/instances/{id}/events": {
      "get": {
        "operationId": "listCarePathwayEvents",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Immutable attributed pathway event history"
          }
        }
      }
    },
    "/api/public/v1/booking/{slug}": {
      "get": {
        "security": [],
        "summary": "Read an enabled practice public-booking profile",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-]{2,62}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public booking profile"
          },
          "404": {
            "description": "Profile unavailable"
          }
        }
      },
      "post": {
        "security": [],
        "summary": "Request an appointment and optionally receive a one-time intake URL",
        "description": "Always creates a provisional patient identity for staff review; it never merges against an existing chart. The requested time must match the practice timezone, weekdays, hours and slot cadence. Provider conflicts, booking horizon and per-contact request limits are enforced atomically.",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "request_id",
                  "given_name",
                  "family_name",
                  "birth_date",
                  "email",
                  "phone",
                  "starts_at"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "given_name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "family_name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "birth_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 40
                  },
                  "starts_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Appointment request recorded"
          },
          "200": {
            "description": "Idempotent replay"
          },
          "409": {
            "description": "Time unavailable, request reused with different content, or rate limited"
          }
        }
      }
    },
    "/api/public/v1/intake/read": {
      "post": {
        "security": [],
        "summary": "Read an open intake form using the link secret supplied in the request body",
        "description": "The browser receives the token in a URL fragment and removes it before making this request, so the credential is not present in normal HTTP access logs.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token"
                ],
                "properties": {
                  "token": {
                    "type": "string",
                    "maxLength": 100
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "packet_id, status, due_at, nullable expires_at, the issued form (template), saved progress (draft, draft_saved_at), practice_name, patient given and family name and nullable appointment context. Cache-Control no-store."
          },
          "404": {
            "description": "Unknown, expired, cancelled or already reviewed link. Always the same message, so a link cannot be probed."
          },
          "429": {
            "description": "Too many requests from this client or against this link in 15 minutes; Retry-After is set."
          }
        }
      }
    },
    "/api/public/v1/intake/save": {
      "post": {
        "security": [],
        "summary": "Save a patient's progress on an intake form that has not been sent in",
        "description": "Stores the answers so far so the patient can finish later with the same link. Answers must belong to the issued form and match each question's type and size; nothing is required yet. Sets the form to in_progress without advancing its version. The save is recorded in the form history at most once every five minutes.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token",
                  "answers"
                ],
                "properties": {
                  "token": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "answers": {
                    "type": "object"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "packet_id, status in_progress and saved_at."
          },
          "400": {
            "description": "An answer does not belong to the form or does not fit its question."
          },
          "404": {
            "description": "Unknown, expired, cancelled or already reviewed link. Always the same message, so a link cannot be probed."
          },
          "409": {
            "description": "The form was already sent to the practice."
          },
          "429": {
            "description": "Too many requests from this client or against this link in 15 minutes; Retry-After is set."
          }
        }
      }
    },
    "/api/public/v1/intake/lookup": {
      "post": {
        "security": [],
        "summary": "Names a patient can pick from while filling in an intake form",
        "description": "kind insurer returns the practice's active insurance companies and insurers the practice has already looked up in its clearinghouse directory (reference claimmd:<payer id>); then well-known US insurers from a built-in list, by name only with no id; kind pharmacy returns the practice's active pharmacies. Matches the typed text anywhere in the name; fewer than two characters returns nothing. No outside service is called, nothing is written, and only a name and a reference are returned.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token",
                  "kind",
                  "query"
                ],
                "properties": {
                  "token": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "kind": {
                    "enum": [
                      "insurer",
                      "pharmacy"
                    ]
                  },
                  "query": {
                    "type": "string",
                    "maxLength": 80
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "items: up to 10 of {id,name}; built-in insurer names carry no id. Cache-Control no-store."
          },
          "400": {
            "description": "Unsupported list or text too long."
          },
          "404": {
            "description": "Unknown, expired, cancelled or already reviewed link. Always the same message."
          },
          "429": {
            "description": "Too many requests from this client or against this link in 15 minutes; Retry-After is set."
          }
        }
      }
    },
    "/api/public/v1/intake/submit": {
      "post": {
        "security": [],
        "summary": "Send in or correct an open patient intake form",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token",
                  "response",
                  "attested_name",
                  "attested"
                ],
                "properties": {
                  "token": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "response": {
                    "type": "object"
                  },
                  "attested_name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "attested": {
                    "const": true
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Immutable response revision recorded"
          },
          "400": {
            "description": "A required answer is missing or an answer does not fit its question"
          },
          "404": {
            "description": "Unknown, expired, cancelled or already reviewed link. Always the same message, so a link cannot be probed."
          },
          "429": {
            "description": "Too many requests from this client or against this link in 15 minutes; Retry-After is set."
          }
        },
        "description": "A question is required only when it and its section are shown to the patient by the form's show_if rules; a skippable section left blank asks for nothing. Answers to questions the patient was not shown are dropped. Saved progress is cleared."
      }
    },
    "/api/v1/previsit/settings": {
      "get": {
        "summary": "Read tenant booking and active intake configuration",
        "responses": {
          "200": {
            "description": "profile, template (null until the practice saves or first sends a form), intake_mode (standard or own) and standard, the read-only standard intake form."
          }
        }
      },
      "put": {
        "summary": "Create or replace public-booking configuration",
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Versioned configuration saved"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Stale version or slug conflict"
          }
        }
      }
    },
    "/api/v1/previsit/templates": {
      "post": {
        "summary": "Create or revise a bounded intake template",
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Versioned template saved"
          },
          "400": {
            "description": "Invalid or unbounded schema"
          },
          "403": {
            "description": "Owner role required"
          }
        },
        "description": "schema.base \"standard\" asks the standard steps first and then the practice's own sections (which may be empty); without base the saved sections are the whole form. Optional per field: help, show_if {key, equals} or {key, any_of}, option_labels, autocomplete, inputmode, format, max_length. Optional per section: intro, show_if, skippable, skip_label. A show_if rule may name only an earlier question. Also optional per field: lookup (insurer or pharmacy) with id_key naming a hidden field that keeps the picked record's reference, hidden, and other_key naming the text field that holds what the patient wrote for \"Other\". required_with names an earlier question; the field is required only once that question has an answer."
      }
    },
    "/api/v1/previsit/readiness": {
      "get": {
        "summary": "List upcoming intake readiness for the authenticated tenant",
        "responses": {
          "200": {
            "description": "Up to 200 upcoming packets and latest patient-submitted response"
          }
        }
      }
    },
    "/api/v1/appointments/{id}/intake-packet": {
      "post": {
        "summary": "Issue the practice's default intake form for an appointment",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Form issued: packet_id, one-time intake_url, secret_shown_once and expires_at. A practice with no saved form gets the standard form."
          },
          "409": {
            "description": "The appointment already has a form that is not cancelled"
          }
        }
      }
    },
    "/api/v1/previsit/packets/{id}/review": {
      "post": {
        "summary": "Attest staff review of a submitted packet",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Review event committed"
          },
          "409": {
            "description": "Packet not submitted or stale"
          }
        }
      }
    },
    "/api/v1/previsit/packets/{id}/cancel": {
      "post": {
        "operationId": "cancelIntakeForm",
        "summary": "Cancel an intake form the patient has not sent in",
        "description": "Only a default form in status sent or in_progress can be cancelled. The link stops working at once, saved progress is removed and the form is kept as cancelled (void) with the reason in its history. Workflow forms are managed from their patient journey.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Quoted current version."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "packet_id, status void and the new version."
          },
          "404": {
            "description": "Form not found in the authenticated tenant."
          },
          "409": {
            "description": "Stale version, already filled in or cancelled, or a workflow form."
          }
        }
      }
    },
    "/api/v1/scheduling/locations": {
      "get": {
        "operationId": "listPartnerSchedulingLocations",
        "summary": "List active tenant locations and rooms",
        "security": [
          {
            "oauth2": [
              "scheduling.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "At most 1,001 active tenant-scoped locations with active rooms"
          }
        }
      }
    },
    "/api/v1/scheduling/providers": {
      "get": {
        "operationId": "listPartnerSchedulingProviders",
        "summary": "List active schedulable clinicians",
        "security": [
          {
            "oauth2": [
              "scheduling.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "At most 1,001 active owner or clinician provider records"
          }
        }
      }
    },
    "/api/v1/scheduling/services": {
      "get": {
        "operationId": "listPartnerSchedulingServices",
        "summary": "List enabled appointment services",
        "security": [
          {
            "oauth2": [
              "scheduling.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "At most 1,001 enabled services including provider, duration, category, facility, room and version"
          }
        }
      }
    },
    "/api/v1/scheduling/availability": {
      "get": {
        "operationId": "listPartnerSchedulingAvailability",
        "summary": "Read conflict-checked availability",
        "description": "The range must be positive and no longer than 31 days. Results respect the tenant booking profile, clinician appointments, schedule blocks and unexpired holds and are bounded to 500 slots.",
        "security": [
          {
            "oauth2": [
              "scheduling.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "service_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "start",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "end",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Service identifier and conflict-checked start/end slots"
          },
          "400": {
            "description": "Invalid or over-broad range"
          },
          "404": {
            "description": "Service not found in tenant"
          }
        }
      }
    },
    "/api/v1/scheduling/holds": {
      "post": {
        "operationId": "createPartnerSchedulingHold",
        "summary": "Place an idempotent short-lived slot hold",
        "description": "request_id is the durable idempotency key. Reuse with different content is rejected. hold_seconds defaults to 300 and must be 60 through 600.",
        "security": [
          {
            "oauth2": [
              "scheduling.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "service_id",
                  "starts_at"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "service_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "starts_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "hold_seconds": {
                    "type": "integer",
                    "minimum": 60,
                    "maximum": 600,
                    "default": 300
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Hold created"
          },
          "200": {
            "description": "Idempotent replay of the same request"
          },
          "409": {
            "description": "Slot unavailable or request_id reused with different content"
          }
        }
      }
    },
    "/api/v1/scheduling/holds/{id}": {
      "delete": {
        "operationId": "releasePartnerSchedulingHold",
        "summary": "Release an active slot hold",
        "security": [
          {
            "oauth2": [
              "scheduling.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Hold released"
          },
          "404": {
            "description": "Active hold not found in tenant"
          }
        }
      }
    },
    "/api/v1/scheduling/appointments": {
      "post": {
        "operationId": "createPartnerSchedulingAppointment",
        "summary": "Create an appointment from an active hold",
        "description": "request_id, and source_system plus external_reference, provide durable idempotency. Supply patient_id or all of given_name, family_name, birth_date, email and phone. A newly created identity receives an automatic MRN and remains marked for staff verification.",
        "security": [
          {
            "oauth2": [
              "scheduling.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "source_system",
                  "external_reference",
                  "hold_id"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "source_system": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 80,
                    "pattern": "^[a-z0-9_.-]+$"
                  },
                  "external_reference": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "hold_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "patient_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "given_name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "family_name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "birth_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 40
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Appointment and optional one-time intake URL created"
          },
          "200": {
            "description": "Idempotent replay of the same booking"
          },
          "409": {
            "description": "Hold missing or expired, conflict, or idempotency identifier mismatch"
          }
        }
      }
    },
    "/api/v1/scheduling/appointments/by-external-reference": {
      "get": {
        "operationId": "getPartnerAppointmentByExternalReference",
        "summary": "Read an appointment by partner reference",
        "security": [
          {
            "oauth2": [
              "scheduling.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "source_system",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 80
            }
          },
          {
            "name": "external_reference",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped appointment"
          },
          "404": {
            "description": "External appointment reference not found"
          }
        }
      }
    },
    "/api/v1/scheduling/appointments/{id}": {
      "get": {
        "operationId": "getPartnerSchedulingAppointment",
        "summary": "Read a partner-created appointment",
        "security": [
          {
            "oauth2": [
              "scheduling.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped appointment"
          },
          "404": {
            "description": "Partner-created appointment not found"
          }
        }
      }
    },
    "/api/v1/scheduling/appointments/{id}/reschedule": {
      "post": {
        "operationId": "reschedulePartnerAppointment",
        "summary": "Idempotently reschedule with conflict checks",
        "description": "Requires the current quoted appointment version in If-Match. request_id provides durable mutation idempotency.",
        "security": [
          {
            "oauth2": [
              "scheduling.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "starts_at",
                  "reason"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "starts_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated appointment or idempotent replay"
          },
          "409": {
            "description": "Conflict, stale version, or request_id mismatch"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/scheduling/appointments/{id}/cancel": {
      "post": {
        "operationId": "cancelPartnerAppointment",
        "summary": "Idempotently cancel a booked or checked-in appointment",
        "description": "Requires the current quoted appointment version in If-Match. request_id provides durable mutation idempotency.",
        "security": [
          {
            "oauth2": [
              "scheduling.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "reason"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled appointment or idempotent replay"
          },
          "409": {
            "description": "Invalid state, stale version, or request_id mismatch"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/scheduling/webhooks": {
      "get": {
        "operationId": "listPartnerSchedulingWebhooks",
        "summary": "List tenant scheduling webhook subscriptions",
        "security": [
          {
            "oauth2": [
              "scheduling.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Subscriptions without signing-secret disclosure"
          }
        }
      },
      "post": {
        "operationId": "createPartnerSchedulingWebhook",
        "summary": "Create a signed scheduling webhook subscription",
        "description": "Owner only. The endpoint must be public HTTPS without userinfo or fragments. The signing secret is returned once. Delivery pins public DNS, rejects private and local addresses, does not follow redirects, signs the exact body and timestamp with HMAC-SHA256, and retries at most eight times with bounded backoff. Receivers get SunCharts-Event-Id, SunCharts-Delivery-Id, SunCharts-Event-Type, SunCharts-Timestamp and SunCharts-Signature (v1=hex). Supported events are appointment.created, appointment.changed and appointment.cancelled.",
        "security": [
          {
            "oauth2": [
              "scheduling.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "label",
                  "endpoint",
                  "events"
                ],
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "endpoint": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://"
                  },
                  "events": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 3,
                    "uniqueItems": true,
                    "items": {
                      "enum": [
                        "appointment.created",
                        "appointment.changed",
                        "appointment.cancelled"
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Subscription created; signing_secret shown once"
          },
          "400": {
            "description": "Invalid endpoint or event selection"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      }
    },
    "/api/v1/scheduling/webhooks/{id}/disable": {
      "post": {
        "operationId": "disablePartnerSchedulingWebhook",
        "summary": "Disable a webhook and terminally stop its pending deliveries",
        "security": [
          {
            "oauth2": [
              "scheduling.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Subscription disabled"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Webhook changed, disabled or not found"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/oauth/start": {
      "post": {
        "operationId": "startRingCentralOAuth",
        "summary": "Start instance-local RingCentral OAuth with PKCE",
        "description": "Owner-only. Creates a ten-minute, one-use state and PKCE verifier and returns RingCentral's fixed production or sandbox authorization URL. Secrets and verifier material remain encrypted in this EHR instance.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "redirect_uri"
                ],
                "properties": {
                  "redirect_uri": {
                    "type": "string",
                    "format": "uri",
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bounded authorization URL and expiration"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Integration revoked"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/oauth/callback": {
      "get": {
        "operationId": "completeRingCentralOAuth",
        "summary": "Exchange a RingCentral OAuth code",
        "description": "Consumes one state exactly once, exchanges the code with PKCE and stores rotating access and refresh tokens encrypted in this EHR instance. Provider errors are reduced to a bounded allowlist before audit.",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 32,
              "maxLength": 512
            }
          },
          {
            "name": "code",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 8192
            }
          },
          {
            "name": "error",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 240
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Connected or bounded needs-attention result"
          },
          "409": {
            "description": "State expired or already used"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/test": {
      "post": {
        "operationId": "testRingCentralConnection",
        "summary": "Test the RingCentral account connection",
        "description": "Owner-only. Refreshes the token when required and verifies the authorized RingCentral extension without returning provider data.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Provider accepted the connection"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/subscription": {
      "post": {
        "operationId": "configureRingCentralEventTransport",
        "summary": "Enable RingCentral event delivery",
        "description": "Owner-only. Outbound WebSocket is the default and requires no public EHR URL. The optional webhook transport requires a clean public HTTPS origin. Events enter a reviewed queue and are never linked to a patient by phone number alone.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "transport": {
                    "enum": [
                      "websocket",
                      "webhook"
                    ],
                    "default": "websocket"
                  },
                  "public_base_url": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transport enabled; WebSocket returns public_url_required false"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/inbox": {
      "get": {
        "operationId": "listRingCentralReviewQueue",
        "summary": "List staged RingCentral events",
        "description": "Owner-only, tenant-scoped metadata for at most 100 encrypted inbound call, SMS, fax and voicemail events. Reading is audited.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Reviewed queue metadata without decrypted payloads"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/inbox/{event_id}": {
      "get": {
        "operationId": "getRingCentralReviewEvent",
        "summary": "Open one encrypted RingCentral event for review",
        "description": "Owner-only and audited. Does not infer or attach a patient.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "event_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Decrypted source event plus bounded metadata"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      },
      "post": {
        "operationId": "reviewRingCentralEvent",
        "summary": "Review, ignore or explicitly link one RingCentral event",
        "description": "Owner-only. A patient link is accepted only as an explicit tenant-scoped reviewer decision; phone numbers never auto-link records.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "event_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action",
                  "reason"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "review",
                      "ignore"
                    ]
                  },
                  "patient_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event reviewed exactly once"
          },
          "409": {
            "description": "Event was already reviewed"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/outbound": {
      "get": {
        "operationId": "listRingCentralOutboundDrafts",
        "summary": "List reviewed RingCentral outbound work",
        "description": "Tenant-scoped metadata for at most 100 SMS, fax and RingOut drafts. Encrypted message and document content is omitted from the list.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Outbound draft metadata and provider status"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      },
      "post": {
        "operationId": "createRingCentralOutboundDraft",
        "summary": "Create a RingCentral outbound draft",
        "description": "Creates encrypted SMS, PDF fax or RingOut content inside this EHR. request_id is the durable idempotency key and reuse with different content is rejected. Owner, clinician, front desk and delegated partner support may draft. No provider call occurs until a separate authorized person confirms the recipient, approves, and explicitly sends.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "kind",
                  "recipient"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "kind": {
                    "enum": [
                      "sms",
                      "fax",
                      "ringout"
                    ]
                  },
                  "recipient": {
                    "type": "string",
                    "pattern": "^\\+[0-9]{8,15}$",
                    "example": "+15550101010"
                  },
                  "sender": {
                    "type": "string",
                    "pattern": "^\\+[0-9]{8,15}$",
                    "example": "+15550101011",
                    "description": "Required for SMS; optional for RingOut; rejected for fax."
                  },
                  "text": {
                    "type": "string",
                    "maxLength": 1000,
                    "description": "Required for SMS; bounded to 1,000 UTF-16 code units."
                  },
                  "cover_page_text": {
                    "type": "string",
                    "maxLength": 1024,
                    "description": "Optional fax cover-page text."
                  },
                  "filename": {
                    "type": "string",
                    "maxLength": 200,
                    "pattern": "^[A-Za-z0-9._-]+\\.pdf$",
                    "example": "synthetic-referral.pdf"
                  },
                  "content_type": {
                    "type": "string",
                    "enum": [
                      "application/pdf"
                    ]
                  },
                  "document_base64": {
                    "type": "string",
                    "format": "byte",
                    "description": "Required nonempty PDF for fax; decoded content is limited to 10 MiB."
                  },
                  "play_prompt": {
                    "type": "boolean",
                    "description": "Optional RingOut prompt flag."
                  }
                }
              },
              "examples": {
                "sms": {
                  "summary": "Synthetic SMS draft",
                  "value": {
                    "request_id": "00000000-0000-4000-8000-000000000101",
                    "kind": "sms",
                    "recipient": "+15550101010",
                    "sender": "+15550101011",
                    "text": "Synthetic appointment message for review."
                  }
                },
                "ringout": {
                  "summary": "Synthetic RingOut draft",
                  "value": {
                    "request_id": "00000000-0000-4000-8000-000000000102",
                    "kind": "ringout",
                    "recipient": "+15550101010",
                    "sender": "+15550101011",
                    "play_prompt": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Draft created or identical idempotent replay"
          },
          "400": {
            "description": "Invalid kind-specific fields or bounds"
          },
          "403": {
            "description": "Drafting role required"
          },
          "409": {
            "description": "request_id reused with different content"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/outbound/{draft_id}": {
      "get": {
        "operationId": "getRingCentralOutboundDraft",
        "summary": "Open one RingCentral outbound draft for review",
        "description": "Returns decrypted draft content, metadata and immutable events to authenticated staff in the tenant. Reading is audited.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "draft_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Draft content, state and event history"
          },
          "404": {
            "description": "Draft not found in integration"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/outbound/{draft_id}/approve": {
      "post": {
        "operationId": "approveRingCentralOutboundDraft",
        "summary": "Confirm the recipient and approve a RingCentral draft",
        "description": "Separate human approval gate. Owner or clinician may approve all kinds; front desk may approve SMS and RingOut. Delegated partner support may draft but cannot approve or send. confirmed_recipient must exactly match the saved E.164 recipient. This action does not call RingCentral.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "draft_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "confirmed_recipient",
                  "reason"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "confirmed_recipient": {
                    "type": "string",
                    "pattern": "^\\+[0-9]{8,15}$",
                    "example": "+15550101010"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Approved or identical approval replay"
          },
          "403": {
            "description": "Approval role required"
          },
          "409": {
            "description": "Recipient mismatch, reused request or invalid state"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/outbound/{draft_id}/send": {
      "post": {
        "operationId": "sendRingCentralOutboundDraft",
        "summary": "Explicitly send an approved RingCentral draft",
        "description": "Separate send gate after recipient confirmation and approval. Owner or clinician may send all kinds; front desk may send SMS and RingOut. Provider acceptance is recorded but is not proof of SMS/fax delivery or call connection. Ambiguous provider outcomes require review and are never blindly retried.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "draft_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Provider accepted or identical send replay; delivery_confirmed remains false"
          },
          "400": {
            "description": "Bounded provider failure; inspect the terminal failed or needs_review state rather than blindly retrying"
          },
          "403": {
            "description": "Send role required"
          },
          "409": {
            "description": "Draft not approved or send request changed"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/outbound/{draft_id}/refresh": {
      "post": {
        "operationId": "refreshRingCentralOutboundStatus",
        "summary": "Refresh provider status for accepted outbound work",
        "description": "Reads RingCentral message/fax status for an accepted SMS or fax. RingOut has no supported refresh in this boundary. Provider state is evidence only; it does not silently retry or mutate clinical records.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "draft_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated provider status and immutable status event"
          },
          "400": {
            "description": "RingOut status refresh unsupported"
          },
          "409": {
            "description": "Draft has not been accepted by RingCentral"
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/{id}/outbound/{draft_id}/reconcile": {
      "post": {
        "operationId": "reconcileRingCentralOutboundDraft",
        "summary": "Reconcile an ambiguous RingCentral outbound result",
        "description": "Explicit evidence-backed recovery for a draft left in sending or needs_review. An authorized sender supplies the exact bounded RingCentral provider identifier; SunCharts reads that provider record and accepts the draft only when the returned identifier matches. This never retries the original SMS, fax or RingOut request. Owner or clinician may reconcile all kinds; front desk may reconcile SMS and RingOut.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "draft_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "provider_id",
                  "reason"
                ],
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 240,
                    "pattern": "^[A-Za-z0-9_-]+$",
                    "example": "synthetic_provider_001"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                }
              },
              "example": {
                "provider_id": "synthetic_provider_001",
                "reason": "Matched the provider record to the reviewed synthetic draft."
              }
            }
          },
          "responses": {
            "200": {
              "description": "Provider-verified accepted state and current delivery evidence"
            },
            "400": {
              "description": "Invalid provider evidence or bounded provider response"
            },
            "403": {
              "description": "Authorized send role required"
            },
            "404": {
              "description": "Draft or provider record not found"
            },
            "409": {
              "description": "Draft is not ambiguous, provider identifier mismatched or state changed during review"
            }
          }
        }
      }
    },
    "/api/v1/integrations/ringcentral/webhooks/{hook_key}": {
      "post": {
        "operationId": "receiveRingCentralWebhook",
        "summary": "Receive an optional RingCentral webhook",
        "description": "Provider callback. Echoes documented validation tokens, verifies the configured verification token in constant time, encrypts bounded payloads and durably deduplicates by provider UUID.",
        "security": [],
        "parameters": [
          {
            "name": "hook_key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 32,
              "maxLength": 512
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Validation echoed or event staged"
          },
          "401": {
            "description": "Verification token rejected"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/oauth/start": {
      "post": {
        "operationId": "startGmailReferralOAuth",
        "summary": "Start instance-local Gmail OAuth with PKCE",
        "description": "Owner-only. Uses the clinic's Google OAuth client ID and encrypted client secret, requests gmail.readonly plus gmail.send, and returns Google's authorization URL. Gmail read access is restricted and send access is sensitive; production use may require Google verification and a security assessment. Existing connections must reconnect before outbound sending when gmail.send was not granted.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "redirect_uri"
                ],
                "properties": {
                  "redirect_uri": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ten-minute authorization URL, requested scopes and enrollment notice"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Integration revoked"
          }
        }
      }
    },
    "/api/v1/integrations/gmail/oauth/callback": {
      "get": {
        "operationId": "completeGmailReferralOAuth",
        "summary": "Exchange a Gmail OAuth code",
        "description": "Consumes one state exactly once, exchanges the code with S256 PKCE, and stores access and refresh tokens encrypted in this EHR instance. Tokens and client secrets are never returned.",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 32,
              "maxLength": 512
            }
          },
          {
            "name": "code",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 8192
            }
          },
          {
            "name": "error",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 240
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Connected or bounded needs-attention result"
          },
          "400": {
            "description": "Invalid callback or rejected token exchange"
          },
          "409": {
            "description": "State expired or already used"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/watch": {
      "get": {
        "operationId": "getGmailReferralTransport",
        "summary": "Read Gmail referral transport status",
        "description": "Staff-visible tenant status without OAuth credentials or push verification secrets.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Polling or Pub/Sub watch state"
          }
        }
      },
      "post": {
        "operationId": "configureGmailReferralTransport",
        "summary": "Configure outbound polling or optional Pub/Sub",
        "description": "Owner-only. Outbound polling is the default, runs inside the EHR, and needs no public URL or inbound firewall rule. poll_seconds must be 60 through 3600 and defaults to 300. Pub/Sub is optional and requires a Google topic, clean public HTTPS base URL, exact HTTPS OIDC audience, verified Google service-account identity and users.watch enrollment. Google OAuth verification and security-assessment requirements remain external enrollment blockers.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "delivery_mode": {
                    "enum": [
                      "poll",
                      "pubsub"
                    ],
                    "default": "poll"
                  },
                  "topic_name": {
                    "type": "string",
                    "maxLength": 500,
                    "pattern": "^projects/.+/topics/.+$"
                  },
                  "label_ids": {
                    "type": "array",
                    "maxItems": 20,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    }
                  },
                  "public_base_url": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://"
                  },
                  "oidc_audience": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://"
                  },
                  "oidc_service_account": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 320
                  },
                  "poll_seconds": {
                    "type": "integer",
                    "minimum": 60,
                    "maximum": 3600,
                    "default": 300
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Mailbox transport configured; optional one-time push endpoint and setup requirements"
          },
          "400": {
            "description": "Invalid delivery, Pub/Sub, Google profile or watch configuration"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/pubsub": {
      "post": {
        "operationId": "receiveGmailReferralPubSub",
        "summary": "Receive an optional authenticated Gmail Pub/Sub notice",
        "description": "Provider callback. Requires the one-time verification token plus a Google-signed OIDC bearer JWT with the exact configured audience and service-account email. The bounded notice is durably deduplicated and triggers Gmail history synchronization; it never links mail to a chart automatically.",
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 32,
              "maxLength": 256
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message",
                  "subscription"
                ],
                "properties": {
                  "message": {
                    "type": "object",
                    "required": [
                      "data",
                      "messageId"
                    ],
                    "properties": {
                      "data": {
                        "type": "string",
                        "maxLength": 8192
                      },
                      "messageId": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      },
                      "publishTime": {
                        "type": "string"
                      }
                    }
                  },
                  "subscription": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Notice accepted or idempotently ignored"
          },
          "401": {
            "description": "Verification token or Google OIDC identity rejected"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/sync": {
      "post": {
        "operationId": "syncGmailReferralInbox",
        "summary": "Request an immediate bounded Gmail synchronization",
        "description": "Owner-only. Processes one queued Pub/Sub notification or one outbound polling cycle. A cycle reads no more than 500 messages. Each attachment is limited to 10 MiB, total attachments per message to 20 MiB, message responses to 2 MiB, and attachment responses to 14 MiB.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Whether a notification was processed or polling occurred"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/referrals": {
      "get": {
        "operationId": "listGmailReferralReviewQueue",
        "summary": "List staged Gmail referral candidates",
        "description": "Staff-only tenant queue, at most 100 entries. Gmail content remains unlinked until explicit human review; sender, recipients, or subject never select a patient automatically.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Bounded referral-review metadata and attachment counts"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/referrals/{entry}": {
      "get": {
        "operationId": "getGmailReferralReviewEntry",
        "summary": "Open one staged Gmail referral for review",
        "description": "Staff-only. Returns bounded message details and attachment metadata but not OAuth credentials.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "entry",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped staged referral with attachment metadata"
          },
          "404": {
            "description": "Entry not found in integration"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/referrals/{entry}/actions": {
      "post": {
        "operationId": "reviewGmailReferralEntry",
        "summary": "Explicitly link or dismiss a staged Gmail referral",
        "description": "Staff review is mandatory. Linking requires clinical permission and an explicit tenant-scoped patient choice. This action does not create a patient, infer identity, or send an email.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "entry",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action",
                  "reason"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "link",
                      "dismiss"
                    ]
                  },
                  "patient_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Required only for link."
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reviewed status, explicit patient link and new version"
          },
          "400": {
            "description": "Unsupported action or missing patient"
          },
          "403": {
            "description": "Clinical permission required to link"
          },
          "404": {
            "description": "Entry or patient not found in tenant"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/outbound-drafts": {
      "get": {
        "operationId": "listGmailOutboundDrafts",
        "summary": "List reviewed Gmail outbound work",
        "description": "Tenant-scoped metadata for at most 100 drafts. Message bodies, attachment content, credential material and idempotency keys are omitted.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Draft metadata, review state and attachment count"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      },
      "post": {
        "operationId": "createGmailOutboundDraft",
        "summary": "Create a reviewed Gmail message or reply draft",
        "description": "Creates immutable message content inside this EHR. idempotency_key must be at least 16 characters and reuse with changed content is rejected. inbox_id optionally preserves the reviewed Gmail thread, In-Reply-To and References headers. A workflow may create this draft, but only a browser-authenticated owner or clinician can separately approve and send it.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "idempotency_key",
                  "to",
                  "subject",
                  "body_text"
                ],
                "properties": {
                  "idempotency_key": {
                    "type": "string",
                    "minLength": 16,
                    "maxLength": 200,
                    "example": "synthetic-message-0001"
                  },
                  "inbox_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid",
                    "description": "Optional reviewed Gmail referral entry used for reply threading."
                  },
                  "to": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 20,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "format": "email",
                      "maxLength": 320
                    },
                    "example": [
                      "referrals@example.test"
                    ]
                  },
                  "cc": {
                    "type": "array",
                    "maxItems": 20,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "format": "email",
                      "maxLength": 320
                    }
                  },
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500,
                    "example": "Synthetic referral follow-up"
                  },
                  "body_text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 262144,
                    "example": "This is synthetic content prepared for review."
                  },
                  "attachments": {
                    "type": "array",
                    "maxItems": 10,
                    "description": "Each decoded attachment is limited to 5 MiB and the decoded aggregate to 6 MiB.",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "filename",
                        "mime_type",
                        "data_base64"
                      ],
                      "properties": {
                        "filename": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "mime_type": {
                          "type": "string",
                          "minLength": 3,
                          "maxLength": 100
                        },
                        "data_base64": {
                          "type": "string",
                          "format": "byte"
                        }
                      }
                    }
                  }
                }
              }
            },
            "examples": {
              "newMessage": {
                "summary": "Synthetic reviewed message",
                "value": {
                  "idempotency_key": "synthetic-message-0001",
                  "inbox_id": null,
                  "to": [
                    "referrals@example.test"
                  ],
                  "cc": [],
                  "subject": "Synthetic referral follow-up",
                  "body_text": "This is synthetic content prepared for review.",
                  "attachments": []
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "New immutable-content draft awaiting approval or identical idempotent replay; created indicates which"
          },
          "400": {
            "description": "Invalid recipient, MIME or size bounds"
          },
          "409": {
            "description": "Idempotency key reused with different content or invalid reply entry"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/outbound-drafts/{draft}": {
      "get": {
        "operationId": "getGmailOutboundDraft",
        "summary": "Open one Gmail outbound draft for review",
        "description": "Returns tenant-scoped message content, attachment metadata and immutable provider receipt metadata. Attachment bytes and secrets are not returned.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "draft",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Draft content, version, attachment metadata and optional receipt"
          },
          "404": {
            "description": "Draft not found in integration"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/gmail/outbound-drafts/{draft}/actions": {
      "post": {
        "operationId": "actOnGmailOutboundDraft",
        "summary": "Approve, explicitly send, reconcile, or cancel a Gmail draft",
        "description": "Browser-authenticated owner or clinician only. approve records human review without transmitting. send is a separate action valid only at the approved expected_version and requires the gmail.send grant. An uncertain send remains needs_review and is never blindly retried. reconcile is valid only for sending or needs_review: SunCharts searches the authenticated account's Sent mail by the draft's stored RFC Message-ID and marks it sent only when exactly one matching provider message is returned. cancel is available only before sending.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "draft",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action",
                  "reason",
                  "expected_version"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "approve",
                      "send",
                      "reconcile",
                      "cancel"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "expected_version": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              },
              "examples": {
                "approve": {
                  "value": {
                    "action": "approve",
                    "reason": "Recipient and content reviewed against the synthetic referral.",
                    "expected_version": 1
                  }
                },
                "send": {
                  "value": {
                    "action": "send",
                    "reason": "Approved draft is ready for transmission.",
                    "expected_version": 2
                  }
                },
                "reconcile": {
                  "value": {
                    "action": "reconcile",
                    "reason": "Verify the ambiguous result against Sent mail without resending.",
                    "expected_version": 3
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated draft state and version; sent or reconciled responses include immutable Gmail receipt evidence"
          },
          "400": {
            "description": "Bounded provider response or reconciliation search failure; no resend occurs"
          },
          "403": {
            "description": "Owner or clinician browser session required"
          },
          "409": {
            "description": "Stale version, invalid transition, missing gmail.send grant, no matching Sent message or an ambiguous match set"
          }
        }
      }
    },
    "/api/v1/care-pathways/instances/{instance}/steps/{step}/dispatch": {
      "post": {
        "operationId": "createWorkflowDispatch",
        "summary": "Submit a workflow node for explicit native-operation review",
        "description": "Creates a tenant-scoped, idempotent work item only when the active pathway step is ready, integration-aware, and configured for manual approval. The step moves to awaiting_approval. No native scheduling mutation, provider transmission or model call occurs until a separate authorized reviewer approves this dispatch. Communication nodes and Claude/Erebine nodes create downstream drafts only; those drafts retain their own approval/send gates. Empty input on a configured AI node resolves only its explicit source_field from this run\u2019s immutable definition and context. Original AI input stays local and is omitted from dispatch responses; an authorized reviewer must prepare and approve a privacy preview before execution. Eligibility and payment nodes use the configured native provider paths. A payment request creates test-mode checkout and waits for processor-confirmed payment plus ledger evidence; eligibility completion does not approve benefits. Patient-form issuance also has a direct versioned intake-packet endpoint.",
        "parameters": [
          {
            "name": "instance",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "step",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 63
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "input",
                  "reason"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "input": {
                    "type": "object",
                    "maxProperties": 100,
                    "description": "Kind-specific native-operation input, limited to 262,144 serialized bytes. intake_request accepts optional appointment_id and form_step_key (an exact patient_form in this run). payment_request requires account_id, expected_version and amount_cents. eligibility_query requires coverage_id and the structured native eligibility request object; the dispatch supplies its request_id."
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              },
              "examples": {
                "availabilityReview": {
                  "summary": "Synthetic availability review",
                  "value": {
                    "request_id": "00000000-0000-4000-8000-000000000201",
                    "input": {
                      "clinician_id": "00000000-0000-4000-8000-000000000202",
                      "starts_at": "2026-11-09T15:00:00Z",
                      "ends_at": "2026-11-09T15:30:00Z",
                      "facility": "Synthetic clinic",
                      "room": "Room 1"
                    },
                    "reason": "Review the requested synthetic appointment window."
                  }
                },
                "gmailDraftReview": {
                  "summary": "Synthetic downstream email draft",
                  "value": {
                    "request_id": "00000000-0000-4000-8000-000000000203",
                    "input": {
                      "provider": "gmail",
                      "integration_id": "00000000-0000-4000-8000-000000000204",
                      "inbox_id": null,
                      "to": [
                        "referrals@example.test"
                      ],
                      "cc": [],
                      "subject": "Synthetic referral follow-up",
                      "body_text": "Synthetic content for review.",
                      "attachments": []
                    },
                    "reason": "Prepare a draft only; do not send automatically."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "New pending-review dispatch or identical idempotent replay"
          },
          "400": {
            "description": "Invalid or over-broad kind-specific input"
          },
          "403": {
            "description": "Read-only or assigned-role restriction"
          },
          "409": {
            "description": "Step not ready/manual-review enabled or request_id reused with different input"
          }
        }
      }
    },
    "/api/v1/workflow-dispatches": {
      "get": {
        "operationId": "listWorkflowDispatches",
        "summary": "List native workflow work items",
        "description": "Staff-only, tenant-scoped worklist of at most 100 dispatches. List responses omit kind-specific input and input digests. AI dispatch metadata exposes privacy_review_required=true.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending_review",
                "executing",
                "downstream_review",
                "completed",
                "rejected",
                "failed"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Workflow dispatch metadata ordered newest first"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      }
    },
    "/api/v1/workflow-dispatches/{id}": {
      "get": {
        "operationId": "getWorkflowDispatch",
        "summary": "Open one native workflow work item",
        "description": "Returns the tenant-scoped dispatch input, result and immutable event history for review. Reading is audited. AI dispatches omit original input and expose privacy_review_required=true; use the reviewer-only privacy-preview endpoint to inspect the exact outbound request.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dispatch detail and immutable events"
          },
          "404": {
            "description": "Dispatch not found in tenant"
          }
        }
      }
    },
    "/api/v1/workflow-dispatches/{id}/actions": {
      "post": {
        "operationId": "actOnWorkflowDispatch",
        "summary": "Approve, reject or confirm a reviewed native workflow operation",
        "description": "Requires the current quoted dispatch version in If-Match. approve executes the bounded native scheduling/intake operation or creates a Gmail, RingCentral or Claude or Erebine downstream draft. It never auto-sends communication or auto-accepts AI output. reject returns the linked step to in-progress. confirm is valid only after the downstream Claude or Erebine draft is approved, Gmail draft is sent, or RingCentral draft is provider-accepted; it then completes the pathway step. Owner, clinician and delegated partner support may review. AI approval additionally requires privacy_preview_id and privacy_approved=true from the workflow privacy-preview endpoint. Invalid or expired previews fail before the execution transition. Active run, immutable definition revision and exact current step linkage are rechecked before provider execution. Provider output is restored locally and still requires downstream human review. Eligibility approval executes a configured native inquiry and leaves benefits review explicit. Payment approval requires the current posted account version and matching workflow patient/linked encounter; confirm requires processor-confirmed paid status, a ledger entry and no refund. All approve and confirm actions recheck the current run/step and downstream custom-policy/OAuth authority.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current workflow-dispatch version."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action",
                  "reason"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "approve",
                      "reject",
                      "confirm"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  },
                  "privacy_preview_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Required for approve on AI dispatches; must be this reviewer\u2019s current bound preview."
                  },
                  "privacy_approved": {
                    "type": "boolean",
                    "default": false,
                    "description": "Must be true for AI approval after reviewing exact sanitized instruction/source; omitted for other native operations."
                  }
                }
              },
              "examples": {
                "approve": {
                  "value": {
                    "action": "approve",
                    "reason": "Reviewed the synthetic workflow input and authorized the bounded operation."
                  }
                },
                "confirm": {
                  "value": {
                    "action": "confirm",
                    "reason": "Confirmed the downstream reviewed draft completed its separate gate."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated dispatch; one-time intake URL is returned only when an approved intake-request operation issues one"
          },
          "403": {
            "description": "Reviewer role required"
          },
          "409": {
            "description": "Stale version, invalid transition or downstream gate incomplete"
          },
          "428": {
            "description": "Current If-Match required"
          },
          "400": {
            "description": "Missing explicit AI privacy-preview approval or invalid action input"
          }
        }
      }
    },
    "/api/v1/ai/drafts": {
      "get": {
        "operationId": "listClaudeDrafts",
        "summary": "List clinic-owned Claude and Erebine draft metadata",
        "description": "Staff-only, tenant-scoped, at most 100 records. List responses omit draft content and never disclose the clinic API key. Optional status is draft, failed, approved or rejected.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "draft",
                "failed",
                "approved",
                "rejected"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AiDraftMetadata"
                      },
                      "maxItems": 100
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "generateClaudeDraft",
        "summary": "Generate a review-required draft with a clinic-owned AI connection",
        "description": "Uses the selected Claude or Erebine connection directly from the EHR with its encrypted clinic-owned credential. If integration_id is omitted, exactly one enabled eligible connection must exist. Source text is bounded to 65536 UTF-8 bytes, instruction to 4000 UTF-8 bytes, accepted response data to 524288 bytes and accepted generated text to 131072 bytes. Structured purposes require valid JSON; Erebine and workflow_design require an object. workflow_design is Owner-only (including authorized delegated management actors mapped to Owner), requires an explicitly enabled workflow_design connection capability, cannot link a patient or running pathway, and produces only a proposed definition for separate native validation and human-reviewed application to an unsaved Studio draft. request_id is durable idempotency: replay returns the stored draft and changed input conflicts. pathway_instance_id and step_key must be supplied together. Generated content always requires review and never mutates the chart or transmits a response automatically. Mandatory privacy_preview_id and privacy_approved=true bind execution to the exact sanitized request. The server checks preview ownership, expiry, one-use status, input and context revisions before provider execution. Provider output is restored with the local mapping before storage as a review-required draft; mappings and original identifiers are never added to the provider request.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "purpose",
                  "instruction",
                  "source_text",
                  "privacy_preview_id",
                  "privacy_approved"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "integration_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Explicit clinic-owned Claude or Erebine connection; omission is allowed only when exactly one eligible connection exists."
                  },
                  "purpose": {
                    "enum": [
                      "document_classification",
                      "structured_extraction",
                      "draft_summary",
                      "draft_response",
                      "workflow_design"
                    ]
                  },
                  "instruction": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000
                  },
                  "source_text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536
                  },
                  "pathway_instance_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "step_key": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 63
                  },
                  "patient_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid",
                    "description": "Optional tenant patient used only for local identifier detection and revision binding. A linked pathway supplies its trusted patient; any explicit patient must match."
                  },
                  "privacy_preview_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Unexpired, unused preview prepared by this actor for these exact inputs and current context."
                  },
                  "privacy_approved": {
                    "type": "boolean",
                    "const": true,
                    "description": "Explicit approval after inspecting the exact sanitized instruction and source."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent existing draft or newly generated draft awaiting human review",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AiDraft"
                }
              }
            }
          },
          "400": {
            "description": "Invalid purpose, model, bounds or pathway linkage, or missing explicit privacy-preview approval"
          },
          "403": {
            "description": "Read-only or role-assignment restriction"
          },
          "409": {
            "description": "Missing enabled connection, reused request ID, invalid pathway state or provider failure, or expired/used/mismatched privacy preview"
          }
        }
      }
    },
    "/api/v1/ai/drafts/{id}": {
      "get": {
        "operationId": "getClaudeDraft",
        "summary": "Open one AI draft and immutable event history",
        "description": "Staff-only and audited. Returns draft content for review plus at most 100 events; never returns the clinic API key or request digest. local_input contains the original local instruction/source for authorized tenant staff review; privacy replacement mappings are never returned.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "draft": {
                      "$ref": "#/components/schemas/AiDraft"
                    },
                    "events": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AiDraftEvent"
                      },
                      "maxItems": 100
                    },
                    "local_input": {
                      "oneOf": [
                        {
                          "type": "object",
                          "additionalProperties": false,
                          "required": [
                            "instruction",
                            "source_text"
                          ],
                          "properties": {
                            "instruction": {
                              "type": "string"
                            },
                            "source_text": {
                              "type": "string"
                            }
                          }
                        },
                        {
                          "type": "null"
                        }
                      ],
                      "readOnly": true,
                      "description": "Original local input for authorized staff review; null on legacy drafts. Never included in the provider request or replacement-map output."
                    }
                  },
                  "required": [
                    "draft",
                    "events",
                    "local_input"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Draft not found"
          }
        }
      }
    },
    "/api/v1/ai/drafts/{id}/actions": {
      "post": {
        "operationId": "reviewClaudeDraft",
        "summary": "Approve or reject a Claude or Erebine draft",
        "description": "Owner or clinician only. Approval records an attributed review and may complete a linked manual-approval pathway step; it does not automatically change clinical documentation, dial, text, fax, email or otherwise transmit the draft.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action",
                  "reason"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "approve",
                      "reject"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Attributed approved or rejected draft",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AiDraft"
                }
              }
            }
          },
          "403": {
            "description": "Owner or clinician role required"
          },
          "409": {
            "description": "Stale or already reviewed draft"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/integrations/providers": {
      "get": {
        "operationId": "listInstanceIntegrationProviders",
        "summary": "List bounded instance-local integration provider contracts",
        "description": "Owner-only catalog for RingCentral, Gmail, clinic-owned Claude and Erebine and HealthClinics as an EHR OAuth client. Catalog entries describe configuration boundaries; they do not claim vendor authentication or enrollment.",
        "responses": {
          "200": {
            "description": "Provider auth type, allowed capabilities and boundary"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      }
    },
    "/api/v1/integrations": {
      "get": {
        "operationId": "listInstanceIntegrations",
        "summary": "List tenant instance integrations",
        "description": "Never returns credential or OAuth callback material.",
        "responses": {
          "200": {
            "description": "At most 100 tenant integrations plus credential-storage readiness"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      },
      "post": {
        "operationId": "createInstanceIntegration",
        "summary": "Create an instance-local integration setting",
        "description": "At most 50 integrations per tenant. Protected credential is encrypted and never echoed. HealthClinics accepts oauth_client_id in config and rejects a vendor credential.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "provider",
                  "label"
                ],
                "properties": {
                  "provider": {
                    "enum": [
                      "ringcentral",
                      "gmail",
                      "claude",
                      "erebine",
                      "healthclinics"
                    ]
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "capabilities": {
                    "type": "array",
                    "uniqueItems": true,
                    "items": {
                      "type": "string"
                    }
                  },
                  "config": {
                    "type": "object",
                    "maxProperties": 40,
                    "description": "Non-secret provider configuration, at most 32 KiB; credential-like keys are rejected recursively. Erebine requires ErebineConfig: project_id and model, with optional workspace_id and endpoint_slug."
                  },
                  "credential": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 16384,
                    "description": "Protected secret input; never returned. Not accepted for HealthClinics."
                  }
                },
                "allOf": [
                  {
                    "if": {
                      "properties": {
                        "provider": {
                          "const": "erebine"
                        }
                      },
                      "required": [
                        "provider"
                      ]
                    },
                    "then": {
                      "properties": {
                        "config": {
                          "$ref": "#/components/schemas/ErebineConfig"
                        }
                      },
                      "required": [
                        "config"
                      ]
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Public integration state without secret material"
          },
          "400": {
            "description": "Unsupported provider, capability or secret-bearing config"
          },
          "403": {
            "description": "Owner role required"
          }
        }
      }
    },
    "/api/v1/integrations/{id}": {
      "get": {
        "operationId": "getInstanceIntegration",
        "summary": "Read integration state and immutable event history",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public integration state and up to 100 events; no secret material"
          },
          "403": {
            "description": "Owner role required"
          },
          "404": {
            "description": "Integration not found in tenant"
          }
        }
      },
      "put": {
        "operationId": "updateInstanceIntegration",
        "summary": "Versioned settings update or credential rotation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "label"
                ],
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "capabilities": {
                    "type": "array",
                    "uniqueItems": true,
                    "items": {
                      "type": "string"
                    }
                  },
                  "config": {
                    "type": "object",
                    "maxProperties": 40,
                    "description": "Non-secret provider configuration, at most 32 KiB; credential-like keys are rejected recursively. Erebine requires ErebineConfig: project_id and model, with optional workspace_id and endpoint_slug."
                  },
                  "credential": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 16384,
                    "description": "Optional protected replacement; never returned."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated public integration state"
          },
          "409": {
            "description": "Stale or revoked integration"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/actions": {
      "post": {
        "operationId": "actOnInstanceIntegration",
        "summary": "Test local readiness, enable, disable or revoke",
        "description": "The test action only verifies local encrypted credential readability or a tenant HealthClinics OAuth client. It does not call a vendor or prove vendor acceptance. Enabling a non-HealthClinics adapter leaves it pending until a real adapter completes its official contract.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "test",
                      "enable",
                      "disable",
                      "revoke"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated public integration state"
          },
          "400": {
            "description": "Missing credential or OAuth client, or unsupported action"
          },
          "409": {
            "description": "Stale or revoked integration"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/oauth/intents": {
      "post": {
        "operationId": "createInstanceIntegrationOAuthIntent",
        "summary": "Create an expiring provider authorization intent",
        "description": "RingCentral and Gmail only. The response intentionally has authorization_url=null until a real provider adapter constructs the official authorization URL. HealthClinics uses the EHR OAuth client and grant APIs instead.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "redirect_uri"
                ],
                "properties": {
                  "redirect_uri": {
                    "type": "string",
                    "format": "uri",
                    "maxLength": 2000
                  },
                  "scopes": {
                    "type": "array",
                    "maxItems": 50,
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ten-minute intent, one-time state and callback path; no invented provider authorization URL"
          },
          "400": {
            "description": "Invalid redirect, scope or provider boundary"
          },
          "409": {
            "description": "Revoked integration"
          }
        }
      }
    },
    "/api/v1/integrations/oauth/callback": {
      "get": {
        "operationId": "captureInstanceIntegrationOAuthCallback",
        "summary": "Capture a one-time provider authorization response",
        "description": "Accepts exactly one of code or error. Callback material is encrypted. A successful capture remains pending_exchange because no vendor token exchange is claimed by this boundary.",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 32,
              "maxLength": 512
            }
          },
          {
            "name": "code",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 8192
            }
          },
          {
            "name": "error",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 240
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Response securely captured; pending_exchange or needs_attention"
          },
          "400": {
            "description": "Invalid callback shape"
          },
          "404": {
            "description": "State not found"
          },
          "409": {
            "description": "Intent expired or already used"
          }
        }
      }
    },
    "/api/v1/connector-catalog/installations": {
      "get": {
        "operationId": "listConnectorInstallations",
        "summary": "List installed open connector manifests",
        "description": "Staff-only, tenant-scoped catalog. Returns at most 200 installations and public source provenance; it never returns credentials.",
        "responses": {
          "200": {
            "description": "Installed connector metadata"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      },
      "post": {
        "operationId": "installConnectorManifest",
        "summary": "Install a declarative open connector manifest",
        "description": "Owner-only and idempotent by request_id. The manifest is data, not executable code: arbitrary scripts, HTTP targets, headers and templates are not accepted. Source repository, revision and digest are retained as public provenance.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "manifest",
                  "provenance",
                  "reason"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "manifest": {
                    "$ref": "#/components/schemas/ConnectorManifest"
                  },
                  "provenance": {
                    "$ref": "#/components/schemas/ConnectorProvenance"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Installed connector or the same idempotent result"
          },
          "400": {
            "description": "Manifest, provenance or reason is invalid"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Request ID reused or connector already installed"
          }
        }
      }
    },
    "/api/v1/connector-catalog/builtins": {
      "get": {
        "operationId": "listBuiltinConnectorManifests",
        "summary": "List reviewed connectors bundled with this EHR build",
        "description": "Staff-only and tenant-scoped. Each result includes the declarative manifest, whether that connector is already installed for the tenant, and builtin provenance. This endpoint exposes no secrets and loads no remote code.",
        "responses": {
          "200": {
            "description": "Bundled manifests and tenant installation state"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      }
    },
    "/api/v1/connector-catalog/builtins/{connector_id}/install": {
      "post": {
        "operationId": "installBuiltinConnectorManifest",
        "summary": "Install one reviewed bundled connector",
        "description": "Owner-only and idempotent by request_id. The selected manifest and its compiled action identifiers ship with the EHR; callers cannot provide executable code, arbitrary URLs or provider credentials.",
        "parameters": [
          {
            "name": "connector_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 3,
              "maxLength": 120
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "reason"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Installed connector or the same idempotent result"
          },
          "403": {
            "description": "Owner role required"
          },
          "404": {
            "description": "Bundled connector not found"
          },
          "409": {
            "description": "Request identity conflict or connector already installed"
          }
        }
      }
    },
    "/api/v1/connector-catalog/installations/{id}": {
      "get": {
        "operationId": "getConnectorInstallation",
        "summary": "Read one connector installation and its immutable history",
        "description": "Staff-only and tenant-scoped. Reading is audited. No connector credential material is stored in this catalog.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationId"
          }
        ],
        "responses": {
          "200": {
            "description": "Installation, current manifest, revisions and events"
          },
          "403": {
            "description": "Staff role required"
          },
          "404": {
            "description": "Installation not found in tenant"
          }
        }
      },
      "put": {
        "operationId": "reviseConnectorInstallation",
        "summary": "Install a new immutable manifest revision",
        "description": "Owner-only. Requires the current quoted installation version. Connector identity cannot change, and deactivated connectors cannot be revised.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationId"
          },
          {
            "$ref": "#/components/parameters/AutomationIfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "manifest",
                  "provenance",
                  "reason"
                ],
                "properties": {
                  "manifest": {
                    "$ref": "#/components/schemas/ConnectorManifest"
                  },
                  "provenance": {
                    "$ref": "#/components/schemas/ConnectorProvenance"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated installation with new current revision"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Stale version, deactivated installation, unchanged version or identity mismatch"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/connector-catalog/installations/{id}/actions": {
      "post": {
        "operationId": "changeConnectorInstallationState",
        "summary": "Enable, disable or permanently deactivate a connector",
        "description": "Owner-only and versioned. Disabling or deactivating a connector stops its trigger subscriptions; deactivated connectors cannot be enabled again.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationId"
          },
          {
            "$ref": "#/components/parameters/AutomationIfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action",
                  "reason"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "enable",
                      "disable",
                      "deactivate"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated installation state"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Stale version or invalid transition"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/automation/subscriptions": {
      "get": {
        "operationId": "listAutomationTriggerSubscriptions",
        "summary": "List exact automation trigger subscriptions",
        "description": "Staff-only, tenant-scoped list of at most 100 subscriptions. Configuration and secrets are never returned.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "configured",
                "active",
                "inactive",
                "error"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription metadata"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      },
      "post": {
        "operationId": "createAutomationTriggerSubscription",
        "summary": "Subscribe to an enabled connector trigger",
        "description": "Owner-only. event_type and transport are derived from the enabled current connector manifest; callers cannot supply arbitrary transport, configuration or credentials.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAutomationSubscription"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Configured subscription"
          },
          "400": {
            "description": "Invalid exact connector or trigger identity"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Enabled connector trigger not found or invalid"
          }
        }
      }
    },
    "/api/v1/automation/subscriptions/{id}/actions": {
      "post": {
        "operationId": "changeAutomationTriggerSubscriptionState",
        "summary": "Activate or deactivate an exact trigger subscription",
        "description": "Owner-only and versioned. Activation requires the referenced connector installation to remain enabled.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationId"
          },
          {
            "$ref": "#/components/parameters/AutomationIfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AutomationLifecycleAction"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated subscription"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Stale version, disabled connector or invalid transition"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/automation/events": {
      "get": {
        "operationId": "listAutomationEvents",
        "summary": "List durable automation event metadata",
        "description": "Staff-only, tenant-scoped list of at most 100 events. List responses omit event payload, tenant ID and deduplication key. PHI payloads are erased after their bounded retention period while digest and audit metadata remain.",
        "responses": {
          "200": {
            "description": "Event metadata ordered newest first"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      }
    },
    "/api/v1/automation/events/{id}": {
      "get": {
        "operationId": "getAutomationEvent",
        "summary": "Open one automation event and its deliveries",
        "description": "Staff-only, tenant-scoped and audited. Returns retained payload plus delivery metadata; erased PHI payloads are represented without recoverable content.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationId"
          }
        ],
        "responses": {
          "200": {
            "description": "Event detail and related deliveries"
          },
          "403": {
            "description": "Staff role required"
          },
          "404": {
            "description": "Event not found in tenant"
          }
        }
      }
    },
    "/api/v1/automation/deliveries": {
      "get": {
        "operationId": "listAutomationDeliveries",
        "summary": "List durable automation deliveries",
        "description": "Staff-only tenant worklist of at most 100 deliveries. Delivery is at-least-once with a stable event-and-subscription idempotency key; effectful work must enter the governed action boundary.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending",
                "leased",
                "delivered",
                "dead_letter",
                "cancelled"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Delivery metadata without lease tokens or worker identities"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      }
    },
    "/api/v1/automation/deliveries/{id}/actions": {
      "post": {
        "operationId": "actOnAutomationDelivery",
        "summary": "Cancel or safely replay an automation delivery",
        "description": "Owner-only. Cancel applies to pending or dead-letter deliveries. Replay applies only to cancelled or dead-letter deliveries while evidence is retained and the subscription is active. Replay preserves the original event-and-subscription idempotency identity; repeating an intended effect requires a new source event.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action",
                  "reason"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "cancel",
                      "replay"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled delivery or new pending replay record"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Invalid state, expired evidence or inactive subscription"
          }
        }
      }
    },
    "/api/v1/automation/action-invocations": {
      "get": {
        "operationId": "listConnectorActionInvocations",
        "summary": "List governed connector action invocations",
        "description": "Staff-only tenant worklist of at most 100 invocations. List responses omit action input and its digest. Sensitive clinical writes, communications and charges never auto-retry.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "pending_review",
                "ready",
                "executing",
                "retry_wait",
                "succeeded",
                "failed",
                "needs_reconciliation",
                "rejected",
                "cancelled",
                "sandboxed"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Governed invocation metadata"
          },
          "403": {
            "description": "Staff role required"
          }
        }
      }
    },
    "/api/v1/automation/action-invocations/{id}": {
      "get": {
        "operationId": "getConnectorActionInvocation",
        "summary": "Open one governed connector action invocation",
        "description": "Staff-only, tenant-scoped and audited. Returns invocation metadata, result evidence and immutable execution/review history; action input and its digest are not returned by this boundary.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationId"
          }
        ],
        "responses": {
          "200": {
            "description": "Invocation detail and immutable events"
          },
          "403": {
            "description": "Staff role required"
          },
          "404": {
            "description": "Invocation not found in tenant"
          }
        }
      }
    },
    "/api/v1/automation/action-invocations/{id}/actions": {
      "post": {
        "operationId": "reviewConnectorActionInvocation",
        "summary": "Approve, reject or cancel a governed connector action",
        "description": "Versioned human-review gate. Approval follows the action policy and optional separation of duties. Owner authorization is required to cancel. Expired leases for clinical writes, communications and charges stop for reconciliation instead of retrying.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AutomationId"
          },
          {
            "$ref": "#/components/parameters/AutomationIfMatch"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "action",
                  "reason"
                ],
                "properties": {
                  "action": {
                    "enum": [
                      "approve",
                      "reject",
                      "cancel"
                    ]
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated invocation and review state"
          },
          "403": {
            "description": "Approval policy, separation-of-duties or owner gate denied"
          },
          "409": {
            "description": "Stale version or invalid transition"
          },
          "428": {
            "description": "Current If-Match required"
          }
        }
      }
    },
    "/api/v1/terminology/releases": {
      "get": {
        "operationId": "listTerminologyReleases",
        "summary": "List authorized tenant terminology releases",
        "tags": [
          "Terminology"
        ],
        "description": "Staff-only, audited and tenant-scoped. Excludes expired licenses. Ordered by release UUID; unknown query fields are rejected.",
        "parameters": [
          {
            "name": "system",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "description": "Canonical system: ICD-10-CM, ICD-10-PCS, HCPCS or CPT. Matching is case-insensitive; documented system URI and compact ICD aliases are also accepted."
            }
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Previous next_cursor."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TerminologyRelease"
                      },
                      "maxItems": 100
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "items",
                    "next_cursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, bounds, code syntax or cursor context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in this tenant or catalog license expired"
          }
        }
      },
      "post": {
        "operationId": "importTerminologyRelease",
        "summary": "Import an immutable tenant terminology release",
        "tags": [
          "Terminology"
        ],
        "description": "Owner-only. Imports supplied records atomically with an audit event; does not fetch the source URL. Enforces syntax, unique canonical codes, dates and rights attestation. Identical normalized content under the same request ID or system/edition is an idempotent replay; changed content conflicts. Source SHA-256 records owner-supplied provenance and is not an independently verified publisher signature.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TerminologyImport"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "release": {
                      "$ref": "#/components/schemas/TerminologyRelease"
                    },
                    "created": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "release",
                    "created"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, bounds, code syntax or cursor context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in this tenant or catalog license expired"
          },
          "409": {
            "description": "Request ID or system/edition already exists with different content"
          },
          "413": {
            "description": "Request exceeds 64 MiB"
          }
        }
      }
    },
    "/api/v1/terminology/codes": {
      "get": {
        "operationId": "searchTerminologyCodes",
        "summary": "Search codes for a service date",
        "tags": [
          "Terminology"
        ],
        "description": "Staff-only, audited and tenant-scoped. Searches code prefixes or publisher description word prefixes. Selects the latest effective release unless release_id is supplied. Applies release/code dates and active status; active=false selects inactive entries. Empty results with release=null mean no effective authorized release. Cursor fixes the release and binds the canonical system, normalized query, service date, billable filter and active filter; reuse those filters on the next page. Unknown query fields are rejected.",
        "parameters": [
          {
            "name": "system",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Canonical system: ICD-10-CM, ICD-10-PCS, HCPCS or CPT. Matching is case-insensitive; documented system URI and compact ICD aliases are also accepted."
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "description": "At most 200 UTF-8 bytes; no control characters."
            }
          },
          {
            "name": "service_date",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Defaults to current UTC date; use the returned value for subsequent pages."
          },
          {
            "name": "billable",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Omit to include both billable entries and category headings."
          },
          {
            "name": "active",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "release_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 256
            },
            "description": "Opaque next_cursor from the same search."
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TerminologyCode"
                      },
                      "maxItems": 100
                    },
                    "release": {
                      "oneOf": [
                        {
                          "$ref": "#/components/schemas/TerminologyRelease"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "service_date": {
                      "type": "string",
                      "format": "date"
                    }
                  },
                  "required": [
                    "items",
                    "release",
                    "next_cursor",
                    "service_date"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, bounds, code syntax or cursor context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in this tenant or catalog license expired"
          }
        }
      }
    },
    "/api/v1/terminology/releases/{release}/codes/{code}": {
      "get": {
        "operationId": "getTerminologyCode",
        "summary": "Read one code from an authorized tenant release",
        "tags": [
          "Terminology"
        ],
        "description": "Staff-only and audited. Case-insensitive exact code lookup ignores decimal punctuation. May return inactive or historical entries; clinical selection separately enforces active, billable and service-date requirements. Expired licenses are unavailable.",
        "parameters": [
          {
            "name": "release",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TerminologyCode"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, bounds, code syntax or cursor context"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in this tenant or catalog license expired"
          }
        }
      }
    },
    "/api/v1/sun/workflow-proposals/validate": {
      "post": {
        "operationId": "validateSunWorkflowProposal",
        "summary": "Validate a reviewed Sun workflow design draft without applying it",
        "description": "Owner-only, including delegated management actors mapped to Owner. Loads the tenant-scoped stored output of a completed workflow_design AI draft with persisted privacy approval; caller-supplied proposal text is not accepted. Reuses native name, trigger, column, step, form and acyclic-dependency validation, rejects unknown fields and arbitrary integration mappings, requires manual approval on all nodes except staff_task and patient_form, and verifies configured AI nodes reference enabled purpose-capable tenant connections. Missing AI configuration is returned as a warning. Validation does not verify live source-field availability or create integration mappings. A valid proposal may be applied only to an unsaved Studio draft after a separate human diff review; normal versioned save and publish permissions remain in force. No definition, live workflow or clinical record is mutated. Audit must commit before the proposal is returned.",
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "draft_id"
                ],
                "properties": {
                  "draft_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validated local proposal; Cache-Control: no-store",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "valid",
                    "draft_id",
                    "proposal",
                    "warnings",
                    "application"
                  ],
                  "properties": {
                    "valid": {
                      "const": true
                    },
                    "draft_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "proposal": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "name",
                        "description",
                        "trigger_type",
                        "definition"
                      ],
                      "properties": {
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 200
                        },
                        "description": {
                          "type": "string",
                          "maxLength": 2000
                        },
                        "trigger_type": {
                          "$ref": "#/components/schemas/CarePathwayTriggerType"
                        },
                        "definition": {
                          "$ref": "#/components/schemas/CarePathwayDefinition"
                        }
                      }
                    },
                    "warnings": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "application": {
                      "const": "unsaved_studio_draft_only"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid proposal, native schema, dependency graph, form or required approval"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role or clinical.write scope required; read-only partner support is not an author"
          },
          "404": {
            "description": "Draft not found in the trusted tenant"
          },
          "409": {
            "description": "Draft is not a completed privacy-approved workflow proposal, or a referenced AI connection is unavailable or unauthorized"
          },
          "422": {
            "description": "Invalid request body or unsupported request fields"
          },
          "500": {
            "description": "Database or audit failure; no proposal is returned"
          }
        }
      }
    },
    "/api/v1/sun/context": {
      "get": {
        "operationId": "getSunLocalContext",
        "summary": "Read permitted local practice counts for Sun",
        "description": "Authenticated staff only, including read-only staff; patients are denied. Trusted tenant scope comes from authentication. No query parameters, caller-supplied tenant, patient selection, filters or model-selected SQL are accepted. Fixed native tools read aggregate counts in one REPEATABLE READ transaction and return only after the read audit commits. No names, record identifiers, chart text, prompts, credentials or external provider calls are included. OAuth requires clinical.read; appointment counts additionally require scheduling.read. Without scheduling.read, appointments and its capability are omitted and unavailable explains why; expired or revoked authentication fails the entire request. This whole-practice observation is not authority to perform an action, and any later AI use still requires the separate privacy preview and approval flow.",
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Audited local database snapshot; appointment facts may be omitted by scope",
            "headers": {
              "Cache-Control": {
                "description": "Authenticated aggregate data must not be stored by caches",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "observed_at",
                    "practice_timezone",
                    "timezone_source",
                    "source",
                    "facts",
                    "capabilities",
                    "unavailable"
                  ],
                  "properties": {
                    "observed_at": {
                      "type": "string",
                      "format": "date-time",
                      "description": "UTC database transaction timestamp for this repeatable-read observation; not a continuously live count"
                    },
                    "practice_timezone": {
                      "type": "string",
                      "description": "Saved practice booking timezone, or UTC when no booking profile exists"
                    },
                    "timezone_source": {
                      "type": "string",
                      "enum": [
                        "practice_booking_settings",
                        "UTC_default"
                      ]
                    },
                    "source": {
                      "type": "string",
                      "const": "native_local_database"
                    },
                    "facts": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "patients",
                        "workflows"
                      ],
                      "properties": {
                        "patients": {
                          "type": "object",
                          "additionalProperties": false,
                          "required": [
                            "total",
                            "scope",
                            "definition"
                          ],
                          "properties": {
                            "total": {
                              "type": "integer",
                              "format": "int64",
                              "minimum": 0,
                              "description": "All patient rows stored in this tenant, including registered and imported records regardless of legacy source status flags. Not an active-patient or deduplicated-person count; independent of browser pagination."
                            },
                            "scope": {
                              "type": "string",
                              "const": "all_local_patient_records"
                            },
                            "definition": {
                              "type": "string",
                              "description": "Human-readable explanation of the count boundary"
                            }
                          }
                        },
                        "appointments": {
                          "type": "object",
                          "additionalProperties": false,
                          "description": "Native appointments starting on the practice-local date, including completed, cancelled, no-show and imported appointments converted to native records. Historical-only records and schedule blocks are excluded. A prior-day appointment overlapping this date is excluded. Omitted when scheduling.read is unavailable.",
                          "required": [
                            "date",
                            "total",
                            "by_status",
                            "scope",
                            "definition"
                          ],
                          "properties": {
                            "date": {
                              "type": "string",
                              "format": "date",
                              "description": "Local date at observed_at in practice_timezone"
                            },
                            "total": {
                              "type": "integer",
                              "format": "int64",
                              "minimum": 0
                            },
                            "by_status": {
                              "type": "object",
                              "additionalProperties": false,
                              "required": [
                                "booked",
                                "checked_in",
                                "in_progress",
                                "completed",
                                "cancelled",
                                "no_show",
                                "other"
                              ],
                              "properties": {
                                "booked": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "checked_in": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "in_progress": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "completed": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "cancelled": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "no_show": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "other": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                }
                              }
                            },
                            "scope": {
                              "type": "string",
                              "const": "appointments_starting_on_local_date"
                            },
                            "definition": {
                              "type": "string"
                            }
                          }
                        },
                        "workflows": {
                          "type": "object",
                          "additionalProperties": false,
                          "description": "All saved workflow runs, including completed and cancelled runs. Step counts include active runs only and are not unique-patient or unique-run counts.",
                          "required": [
                            "total",
                            "by_status",
                            "ready_steps",
                            "awaiting_approval_steps",
                            "scope",
                            "definition"
                          ],
                          "properties": {
                            "total": {
                              "type": "integer",
                              "format": "int64",
                              "minimum": 0
                            },
                            "by_status": {
                              "type": "object",
                              "additionalProperties": false,
                              "required": [
                                "active",
                                "completed",
                                "cancelled",
                                "other"
                              ],
                              "properties": {
                                "active": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "completed": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "cancelled": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                },
                                "other": {
                                  "type": "integer",
                                  "format": "int64",
                                  "minimum": 0
                                }
                              }
                            },
                            "ready_steps": {
                              "type": "integer",
                              "format": "int64",
                              "minimum": 0
                            },
                            "awaiting_approval_steps": {
                              "type": "integer",
                              "format": "int64",
                              "minimum": 0
                            },
                            "scope": {
                              "type": "string",
                              "const": "all_local_workflow_instances"
                            },
                            "definition": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    },
                    "capabilities": {
                      "type": "array",
                      "uniqueItems": true,
                      "maxItems": 3,
                      "description": "Stable IDs of the native tools whose facts are included",
                      "items": {
                        "type": "string",
                        "enum": [
                          "patients.count",
                          "appointments.today.count",
                          "workflows.count"
                        ]
                      }
                    },
                    "unavailable": {
                      "type": "array",
                      "maxItems": 3,
                      "description": "Tools omitted for this request; missing facts must not be interpreted as zero",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": [
                          "tool",
                          "reason"
                        ],
                        "properties": {
                          "tool": {
                            "type": "string",
                            "enum": [
                              "patients.count",
                              "appointments.today.count",
                              "workflows.count"
                            ]
                          },
                          "reason": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Query parameters are not accepted"
          },
          "401": {
            "description": "Authentication required, expired or revoked"
          },
          "403": {
            "description": "Patient role or clinical.read scope denied"
          },
          "404": {
            "description": "Native local database is unavailable"
          },
          "500": {
            "description": "Database or audit failure; no facts are returned"
          }
        }
      }
    },
    "/api/v1/ai/connections": {
      "get": {
        "operationId": "listAiConnections",
        "summary": "List safe staff-visible Claude and Erebine connections",
        "description": "Staff-only, audited, tenant-scoped. At most 100 enabled, nonrevoked connections with a stored credential. No config, credential or provider model listing is exposed by this projection.",
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AiConnection"
                      },
                      "maxItems": 100
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          }
        }
      }
    },
    "/api/v1/integrations/erebine/models": {
      "post": {
        "operationId": "previewErebineModels",
        "summary": "Discover Erebine models before saving a connection",
        "description": "Owner-only and audited. Uses the native SDK and supplied protected credential without persisting it. Returns bounded model IDs only; no credential or provider response body is returned.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "config": {
                    "$ref": "#/components/schemas/ErebineRoutingConfig"
                  },
                  "credential": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 16384,
                    "writeOnly": true
                  }
                },
                "required": [
                  "config",
                  "credential"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErebineModels"
                }
              }
            }
          },
          "400": {
            "description": "Invalid routing configuration or credential input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Provider rejected the request or returned unavailable/invalid data; errors disclose only stable categories"
          }
        }
      }
    },
    "/api/v1/integrations/{id}/erebine/models": {
      "get": {
        "operationId": "listErebineModels",
        "summary": "Discover models for a saved Erebine connection",
        "description": "Owner-only and audited. Uses the current encrypted credential on a tenant-owned, nonrevoked Erebine connection; enabled status is not required. Returns bounded model IDs only.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped data with Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErebineModels"
                }
              }
            }
          },
          "400": {
            "description": "Invalid routing configuration or credential input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner role required"
          },
          "409": {
            "description": "Provider rejected the request or returned unavailable/invalid data; errors disclose only stable categories"
          },
          "404": {
            "description": "Erebine connection or stored credential not found in tenant"
          }
        }
      }
    },
    "/api/v1/ai/privacy/preview": {
      "post": {
        "operationId": "previewAiPrivacy",
        "summary": "Prepare the exact sanitized AI request for human review",
        "description": "Local-only preparation; makes no provider request. Identifies supported direct identifiers, preserves supported clinical code syntax and stores a bounded encrypted local restoration map. Approval is required in a subsequent draft request by the same actor; changing input, connection, credential or bound context requires another preview. pathway_instance_id and step_key must be supplied together.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AiPrivacyPreviewInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Actor-bound sanitized request for explicit review; Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AiPrivacyPreview"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, unavailable local privacy context or unsupported bounds"
          },
          "403": {
            "description": "Staff role or linked workflow assignment denied"
          },
          "404": {
            "description": "Tenant context or connection not found"
          },
          "409": {
            "description": "Connection, patient context or workflow state is not eligible"
          }
        }
      }
    },
    "/api/v1/workflow-dispatches/{id}/privacy-preview": {
      "post": {
        "operationId": "previewWorkflowAiPrivacy",
        "summary": "Prepare a reviewer-bound privacy preview for a Sun workflow dispatch",
        "description": "Owner, clinician or delegated partner support only. Requires a pending-review AI dispatch linked to an active run and its exact awaiting-approval step. Reads the immutable local input prepared from the run definition revision and trusted patient. Returns the sanitized request only; no original source or local mappings. The approving reviewer must create this preview; another reviewer must prepare a new one. No provider request occurs.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            },
            "description": "Quoted current dispatch version; preview does not increment it."
          }
        ],
        "responses": {
          "200": {
            "description": "Actor-bound sanitized request for explicit review; Cache-Control: no-store",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AiPrivacyPreview"
                }
              }
            }
          },
          "400": {
            "description": "Not an AI node or invalid local AI configuration"
          },
          "403": {
            "description": "Reviewer role required"
          },
          "404": {
            "description": "Dispatch or run not found in tenant"
          },
          "409": {
            "description": "Stale version, nonpending dispatch, cancelled/completed run or changed step linkage"
          },
          "428": {
            "description": "Current quoted dispatch If-Match required"
          }
        }
      }
    },
    "/api/v1/practice/access-policy/current": {
      "get": {
        "summary": "Read current staff access policy and module permissions",
        "description": "Authenticated bootstrap metadata. No assignment means native role authorization; flags never grant authority beyond native checks.",
        "responses": {
          "200": {
            "description": "Tenant-scoped policy result. Cache-Control: no-store."
          }
        }
      }
    },
    "/api/v1/practice/access-policies": {
      "get": {
        "summary": "List owner-managed policies, staff assignments and configuration catalog",
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped policy result. Cache-Control: no-store."
          },
          "400": {
            "description": "Invalid policy or role assignment."
          },
          "401": {
            "description": "Authentication required."
          },
          "403": {
            "description": "Native role or custom policy denies access."
          },
          "409": {
            "description": "Version changed; reload before saving."
          }
        }
      },
      "post": {
        "summary": "Create a restrictive named staff policy",
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped policy result. Cache-Control: no-store."
          },
          "400": {
            "description": "Invalid policy or role assignment."
          },
          "401": {
            "description": "Authentication required."
          },
          "403": {
            "description": "Native role or custom policy denies access."
          },
          "409": {
            "description": "Version changed; reload before saving."
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccessPolicyChange"
              }
            }
          }
        }
      }
    },
    "/api/v1/practice/access-policies/{id}": {
      "put": {
        "summary": "Revise a named policy and revoke affected staff sessions",
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped policy result. Cache-Control: no-store."
          },
          "400": {
            "description": "Invalid policy or role assignment."
          },
          "401": {
            "description": "Authentication required."
          },
          "403": {
            "description": "Native role or custom policy denies access."
          },
          "409": {
            "description": "Version changed; reload before saving."
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version. Use \"0\" for first assignment."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccessPolicyChange"
              }
            }
          }
        }
      }
    },
    "/api/v1/practice/staff/{id}/access-policy": {
      "put": {
        "summary": "Assign or clear a matching native-role policy and revoke staff sessions",
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped policy result. Cache-Control: no-store."
          },
          "400": {
            "description": "Invalid policy or role assignment."
          },
          "401": {
            "description": "Authentication required."
          },
          "403": {
            "description": "Native role or custom policy denies access."
          },
          "409": {
            "description": "Version changed; reload before saving."
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current version. Use \"0\" for first assignment."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "policy_id",
                  "reason"
                ],
                "properties": {
                  "policy_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/practice/workspace-settings": {
      "get": {
        "summary": "Read versioned practice navigation and chart configuration",
        "description": "Authenticated staff bootstrap metadata. Hidden presentation never substitutes for native role or custom-policy authorization.",
        "responses": {
          "200": {
            "description": "Version, content, updated_by and updated_at."
          }
        }
      },
      "put": {
        "summary": "Save a versioned workspace configuration with an audit reason",
        "description": "Owner only. Does not modify role policy, patient records or workflow definitions.",
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted version; \"0\" for first configuration."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "content",
                  "reason"
                ],
                "properties": {
                  "content": {
                    "$ref": "#/components/schemas/PracticeWorkspaceConfiguration"
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved version and configuration."
          },
          "400": {
            "description": "Invalid configuration."
          },
          "403": {
            "description": "Owner authority required."
          },
          "409": {
            "description": "Configuration version changed."
          }
        }
      }
    },
    "/api/v1/practice/document-storage": {
      "get": {
        "operationId": "readDocumentStorage",
        "summary": "Read where patient files are kept",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Owner browser session only. Reports whether new files are kept in the database or in encrypted file storage, and how many files of this practice are in each. Counts include original uploads and later file versions.",
        "responses": {
          "200": {
            "description": "Storage mode and file counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "mode",
                    "storage_available",
                    "files"
                  ],
                  "properties": {
                    "mode": {
                      "type": "string",
                      "enum": [
                        "database",
                        "s3"
                      ],
                      "description": "Where new files are written."
                    },
                    "storage_available": {
                      "type": [
                        "boolean",
                        "null"
                      ],
                      "description": "Whether file storage answered its last check (cached up to 30 seconds); null in database mode."
                    },
                    "files": {
                      "type": "object",
                      "required": [
                        "database",
                        "s3"
                      ],
                      "properties": {
                        "database": {
                          "type": "object",
                          "required": [
                            "count",
                            "bytes"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer",
                              "minimum": 0
                            },
                            "bytes": {
                              "type": "integer",
                              "minimum": 0
                            }
                          }
                        },
                        "s3": {
                          "type": "object",
                          "required": [
                            "count",
                            "bytes"
                          ],
                          "properties": {
                            "count": {
                              "type": "integer",
                              "minimum": 0
                            },
                            "bytes": {
                              "type": "integer",
                              "minimum": 0
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner authority required."
          }
        }
      }
    },
    "/api/v1/practice/document-storage/move": {
      "post": {
        "operationId": "moveDocumentsToStorage",
        "summary": "Move one batch of patient files from the database into file storage",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "description": "Owner browser session only; never runs on its own. Takes no request body. Each call handles a bounded batch (up to 25 files or 200 MiB) of this practice's files that are still in the database. Every file is encrypted, stored, read back, decrypted and compared with the SHA-256 and size recorded at upload; only then is its row switched, in one transaction with its audit event. A file that cannot be verified stays in the database and is listed in failed. Safe to repeat and to call concurrently; call again until remaining is 0.",
        "responses": {
          "200": {
            "description": "Batch result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "moved",
                    "moved_bytes",
                    "remaining",
                    "failed",
                    "storage_available"
                  ],
                  "properties": {
                    "moved": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Files moved by this call."
                    },
                    "moved_bytes": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "remaining": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Files of this practice still in the database after this call."
                    },
                    "failed": {
                      "type": "array",
                      "description": "Files examined by this call that were left in the database.",
                      "items": {
                        "type": "object",
                        "required": [
                          "document_id",
                          "file_version",
                          "reason"
                        ],
                        "properties": {
                          "document_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "file_version": {
                            "type": "integer",
                            "minimum": 1,
                            "description": "1 is the original upload."
                          },
                          "reason": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "storage_available": {
                      "type": "boolean",
                      "description": "False when file storage stopped answering part way through; files already moved stay moved."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Owner authority required."
          },
          "409": {
            "description": "File storage is not set up on this server."
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed."
          }
        }
      }
    },
    "/api/v1/care-pathways/instances/{id}/readiness": {
      "get": {
        "operationId": "readCarePathwayNativeReadiness",
        "description": "Authenticated staff readiness from the immutable workflow definition and tenant-bound native records. Per-resource native/custom/OAuth read permissions are enforced; denied sections contain no record identifiers. Readiness is not completion and is rechecked atomically on complete/approve. Multiple matching records require selection from returned candidates. Payment evidence is currently test mode; eligibility response completion does not establish active benefits or credentialing.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "No-store response with instance_id, definition_version, observed_at, steps and progress. Each step includes resource, ready, status (manual, missing, pending, ambiguous, unconfigured, forbidden, verified), reason, and permitted native action hints. Candidate/resource IDs are scoped to the run; no patient names or clinical text are returned."
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Workflow access denied"
          },
          "404": {
            "description": "Tenant-scoped run not found"
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/accounts/{id}/invoices": {
      "get": {
        "summary": "List immutable patient invoice snapshots for a tenant-scoped account",
        "responses": {
          "200": {
            "description": "Up to 100 immutable snapshots; old snapshots retain their original shape",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/PatientInvoice"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "operationId": "listPatientInvoiceSnapshots"
      },
      "post": {
        "summary": "Save reviewed patient responsibility less net patient ledger credits without collecting payment",
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "responsibility_cents",
                  "reason"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "responsibility_cents": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1000000000
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Immutable itemized snapshot; exact retries return the original",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientInvoice"
                }
              }
            }
          },
          "409": {
            "description": "Account changed, unposted account, or reused request with different content"
          }
        },
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "operationId": "createPatientInvoiceSnapshot",
        "description": "Billing-write staff. Requires a posted account and its current quoted If-Match. Reviewed responsibility must be between zero and gross charges, excluding insurer responsibility. Net patient ledger payments, credits, reversals and confirmed refunds determine amount due and credit balance. Freeze service lines and patient payment activity at issuance; do not recompute older snapshots. Never moves funds, emails an invoice, or submits insurance."
      },
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient}/documents/{id}/preview": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "previewPatientDocument",
        "summary": "Preview the authenticated immutable original",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Original bytes for in-chart preview; no-store and inline disposition",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/mpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/wav": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/ogg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/webm": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/mp4": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "no-store"
              },
              "Content-Disposition": {
                "schema": {
                  "type": "string"
                },
                "description": "inline; generated document-ID filename"
              },
              "X-Content-Type-Options": {
                "schema": {
                  "type": "string"
                },
                "description": "nosniff"
              },
              "X-Frame-Options": {
                "schema": {
                  "type": "string"
                },
                "description": "SAMEORIGIN"
              },
              "Content-Security-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "default-src 'none'; frame-ancestors 'self'; base-uri 'none'; form-action 'none'"
              },
              "Referrer-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "no-referrer"
              },
              "Cross-Origin-Resource-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "same-origin"
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed. Retry shortly."
          }
        },
        "description": "Staff-only, tenant/patient/document scoped original PDF, PNG, JPEG, plain-text or audio bytes. Office files require a separately configured editor or authenticated download; HTML/SVG and remote URLs are never previewed. Audit commits before response. Inline generated filename, no-store, nosniff, same-origin resource/framing policy and restrictive CSP. This endpoint returns the original binary without later annotation overlays."
      }
    },
    "/api/v1/patients/{p}/billing/copays": {
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "recordAppointmentCopay",
        "summary": "Record an already received appointment copay",
        "description": "Owner, clinician or front desk with billing write authority. Requires a same-patient appointment, excluding cancelled/canceled/no_show. Coverage is optional and tenant/patient scoped. Works before an encounter or posted account exists. Matching posted encounter charges receive available credit atomically; otherwise credit remains unapplied. A tenant-scoped request UUID with identical input returns the same receipt; differing input conflicts. Audited receipt and allocation commit together.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          },
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CopayReceipt"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CopayReceiptInput"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/copays/{id}/void": {
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "voidUnallocatedCopayReceipt",
        "summary": "Void an unallocated receipt record",
        "description": "Billing-write staff. Append a void record only if the receipt has never been allocated. Repeated voids retain the original void record. Allocated receipts require ledger correction instead. This does not refund funds and never deletes the original receipt.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          },
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "voided": {
                      "const": true
                    }
                  },
                  "required": [
                    "voided"
                  ]
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CopayVoidInput"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/billing/accounts/{id}/copays/apply": {
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "applyRecordedAppointmentCopays",
        "summary": "Apply available appointment copay credit",
        "description": "Billing-write staff and current posted account version required. Only unvoided, unreversed receipts for the account encounter appointment apply. Allocation is bounded by the remaining account balance after pending processor reservations. Already allocated cents are never applied twice; any ledger reversal excludes the receipt from automatic reuse. Positive allocation advances the account version. No external funds move.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          },
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "applied_cents": {
                      "type": "integer",
                      "minimum": 0
                    }
                  },
                  "required": [
                    "applied_cents"
                  ]
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current posted account version."
          }
        ]
      }
    },
    "/api/v1/patients/{p}/appointments/{a}/copay-checkouts": {
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "a",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listHostedAppointmentCopays",
        "summary": "List appointment card attempts and collection availability",
        "description": "Billing-read staff. Returns at most 100 attempts; excessive history requires review rather than silent truncation. Availability is verified against configured account readiness and environment gates.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current durable operation state; financial effects require verified provider evidence",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/HostedCopayOperation"
                      }
                    },
                    "availability": {
                      "type": "object",
                      "properties": {
                        "available": {
                          "type": "boolean"
                        },
                        "livemode": {
                          "type": [
                            "boolean",
                            "null"
                          ]
                        },
                        "reason": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "available",
                        "livemode",
                        "reason"
                      ]
                    }
                  },
                  "required": [
                    "items",
                    "availability"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unavailable/mismatched payment mode"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Billing permission denied"
          },
          "404": {
            "description": "Tenant/patient/appointment-scoped record not found"
          },
          "409": {
            "description": "Conflicting retry, pending collection, unsafe balance or over-limit history"
          },
          "500": {
            "description": "Database/audit failure; mutation rolled back"
          }
        }
      },
      "post": {
        "operationId": "createHostedAppointmentCopay",
        "summary": "Collect an appointment copay with Stripe-hosted Checkout",
        "description": "Billing-write staff. Reserve a same-patient appointment attempt before provider I/O. Binds installation, credential revision, Stripe account, mode, amount and optional coverage snapshot immutably. Exact request retry returns the original attempt; conflicting reuse fails. Test mode is blocked in production. Live mode requires both the EHR and Connect operator gates. Pending/uncertain attempts retain their identity; recovery retries only within the verified 23-hour window. This can precede encounter charges. With `reader_id` the copay is taken on that card reader instead: the same reservation, binding and paid rule apply, the attempt has `channel` `reader`, and it closes by itself if the card is declined, the payment is cancelled, or no card is presented within five minutes.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current durable operation state; financial effects require verified provider evidence",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "operation": {
                      "$ref": "#/components/schemas/HostedCopayOperation"
                    }
                  },
                  "required": [
                    "operation"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unavailable/mismatched payment mode"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Billing permission denied"
          },
          "404": {
            "description": "Tenant/patient/appointment-scoped record not found"
          },
          "409": {
            "description": "Conflicting retry, pending collection, unsafe balance or over-limit history"
          },
          "500": {
            "description": "Database/audit failure; mutation rolled back"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HostedCopayInput"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{p}/appointments/{a}/copay-checkouts/{id}": {
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "a",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getHostedAppointmentCopay",
        "summary": "Read an appointment card attempt",
        "description": "Tenant, patient and appointment scoped. Does not reconcile or infer payment from a browser return.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current durable operation state; financial effects require verified provider evidence",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "operation": {
                      "$ref": "#/components/schemas/HostedCopayOperation"
                    }
                  },
                  "required": [
                    "operation"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unavailable/mismatched payment mode"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Billing permission denied"
          },
          "404": {
            "description": "Tenant/patient/appointment-scoped record not found"
          },
          "409": {
            "description": "Conflicting retry, pending collection, unsafe balance or over-limit history"
          },
          "500": {
            "description": "Database/audit failure; mutation rolled back"
          }
        }
      }
    },
    "/api/v1/patients/{p}/appointments/{a}/copay-checkouts/{id}/refresh": {
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "a",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "refreshHostedAppointmentCopay",
        "summary": "Retrieve and reconcile the original card attempt",
        "description": "Billing-write staff. Uses the original immutable broker/account/mode binding. Confirmed captured funds create one receipt; allocations and cumulative refund deltas commit with audit atomically. Disputed, inconsistent, ambiguous or unsupported evidence enters review. The background worker also reconciles due attempts without an open browser. No refund is initiated here.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current durable operation state; financial effects require verified provider evidence",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "operation": {
                      "$ref": "#/components/schemas/HostedCopayOperation"
                    }
                  },
                  "required": [
                    "operation"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unavailable/mismatched payment mode"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Billing permission denied"
          },
          "404": {
            "description": "Tenant/patient/appointment-scoped record not found"
          },
          "409": {
            "description": "Conflicting retry, pending collection, unsafe balance or over-limit history"
          },
          "500": {
            "description": "Database/audit failure; mutation rolled back"
          }
        }
      }
    },
    "/api/v1/documents/office-availability": {
      "get": {
        "summary": "Office editor availability",
        "operationId": "office_get_office_editor_availability",
        "tags": [
          "Documents"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Confirmed server state",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "available": {
                      "type": "boolean"
                    },
                    "editor_origin": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "reason": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "available",
                    "editor_origin",
                    "reason"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Expired or invalid session or signature"
          },
          "403": {
            "description": "Current actor or resource access denied"
          },
          "409": {
            "description": "Version or request binding conflict"
          }
        }
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/office-sessions": {
      "post": {
        "summary": "Open scoped Office editor",
        "operationId": "office_post_open_scoped_office_editor",
        "tags": [
          "Documents"
        ],
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmed server state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OfficeEditorSession"
                }
              }
            }
          },
          "401": {
            "description": "Expired or invalid session or signature"
          },
          "403": {
            "description": "Current actor or resource access denied"
          },
          "409": {
            "description": "Version or request binding conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OfficeEditorSessionCreate"
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/office-sessions/{session}": {
      "get": {
        "summary": "Read confirmed Office save status",
        "operationId": "office_get_read_confirmed_office_save_status",
        "tags": [
          "Documents"
        ],
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmed server state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OfficeEditorSession"
                }
              }
            }
          },
          "401": {
            "description": "Expired or invalid session or signature"
          },
          "403": {
            "description": "Current actor or resource access denied"
          },
          "409": {
            "description": "Version or request binding conflict"
          }
        }
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/office-sessions/{session}/save": {
      "post": {
        "summary": "Request operation bound Office save",
        "operationId": "office_post_request_operation_bound_office_save",
        "tags": [
          "Documents"
        ],
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmed server state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OfficeEditorSession"
                }
              }
            }
          },
          "401": {
            "description": "Expired or invalid session or signature"
          },
          "403": {
            "description": "Current actor or resource access denied"
          },
          "409": {
            "description": "Version or request binding conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OfficeEditorSave"
              }
            }
          }
        }
      }
    },
    "/api/v1/office/source/{session}": {
      "get": {
        "summary": "Read scoped immutable Office source",
        "operationId": "office_get_read_scoped_immutable_office_source",
        "tags": [
          "Documents"
        ],
        "parameters": [
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Short-lived signed capability bound to this exact Office session and route purpose."
          }
        ],
        "responses": {
          "200": {
            "description": "Authenticated immutable DOCX or XLSX bytes",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Expired or invalid session or signature"
          },
          "403": {
            "description": "Current actor or resource access denied"
          },
          "409": {
            "description": "Version or request binding conflict"
          }
        }
      }
    },
    "/api/v1/office/callback/{session}": {
      "post": {
        "summary": "Confirm signed Office save callback",
        "operationId": "office_post_confirm_signed_office_save_callback",
        "tags": [
          "Documents"
        ],
        "parameters": [
          {
            "name": "session",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Short-lived signed capability bound to this exact Office session and route purpose."
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmed server state",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "error": {
                      "type": "integer",
                      "enum": [
                        0,
                        1
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Expired or invalid session or signature"
          },
          "403": {
            "description": "Current actor or resource access denied"
          },
          "409": {
            "description": "Version or request binding conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/files": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listDocumentFileVersions",
        "summary": "List immutable file version history",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Audited result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentFileVersionPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid format, annotation, reason or decoded size"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or clinical scope denied"
          },
          "404": {
            "description": "File version not found within tenant/patient/document"
          },
          "409": {
            "description": "Stale file version, lifecycle state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "post": {
        "operationId": "appendDocumentFileVersion",
        "summary": "Append a text, binary or annotation working copy",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Audited result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentFileVersion"
                }
              }
            }
          },
          "400": {
            "description": "Invalid format, annotation, reason or decoded size"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or clinical scope denied"
          },
          "404": {
            "description": "File version not found within tenant/patient/document"
          },
          "409": {
            "description": "Stale file version, lifecycle state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted file version required"
          },
          "413": {
            "description": "JSON body exceeds 15 MiB"
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed. Retry shortly."
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            },
            "description": "Quoted current file_version. Independent of document metadata version."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentFileSave"
              }
            }
          }
        },
        "description": "Owner/clinician may append active documents; front desk is limited to the existing identity/insurance/legal category. Parent row locking serializes file saves with metadata changes. Successful copies and audits commit together. No signature or encounter-note amendment is implied."
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/files/{version}": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "version",
          "required": true,
          "schema": {
            "type": "integer",
            "minimum": 1
          }
        }
      ],
      "get": {
        "operationId": "readDocumentFileVersion",
        "summary": "Read an immutable file version and annotations",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Audited result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentFileVersion"
                }
              }
            }
          },
          "400": {
            "description": "Invalid format, annotation, reason or decoded size"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or clinical scope denied"
          },
          "404": {
            "description": "File version not found within tenant/patient/document"
          },
          "409": {
            "description": "Stale file version, lifecycle state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed. Retry shortly."
          }
        }
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/files/{version}/preview": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "version",
          "required": true,
          "schema": {
            "type": "integer",
            "minimum": 1
          }
        }
      ],
      "get": {
        "operationId": "previewDocumentFileVersion",
        "summary": "Preview authenticated immutable file version",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Original bytes for in-chart preview; no-store and inline disposition",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/mpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/wav": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/ogg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/webm": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/mp4": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "no-store"
              },
              "Content-Disposition": {
                "schema": {
                  "type": "string"
                },
                "description": "inline; generated document-ID filename"
              },
              "X-Content-Type-Options": {
                "schema": {
                  "type": "string"
                },
                "description": "nosniff"
              },
              "X-Frame-Options": {
                "schema": {
                  "type": "string"
                },
                "description": "SAMEORIGIN"
              },
              "Content-Security-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "default-src 'none'; frame-ancestors 'self'; base-uri 'none'; form-action 'none'"
              },
              "Referrer-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "no-referrer"
              },
              "Cross-Origin-Resource-Policy": {
                "schema": {
                  "type": "string"
                },
                "description": "same-origin"
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed. Retry shortly."
          }
        },
        "description": "Staff-only read scoped by tenant, patient, document and exact file version. Version 1 is the original. The audit commits before bytes return. Generated safe filename, no-store and nosniff; same-origin framing and restrictive CSP. Annotation overlays are returned separately in version metadata and are not flattened into these bytes. Office packages cannot be previewed here; use a configured Office session."
      }
    },
    "/api/v1/patients/{patient}/documents/{id}/files/{version}/download": {
      "parameters": [
        {
          "in": "path",
          "name": "patient",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "in": "path",
          "name": "version",
          "required": true,
          "schema": {
            "type": "integer",
            "minimum": 1
          }
        }
      ],
      "get": {
        "operationId": "downloadDocumentFileVersion",
        "summary": "Download authenticated immutable file version",
        "tags": [
          "Documents"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/mpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/wav": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/ogg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/webm": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "audio/mp4": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant/patient"
          },
          "409": {
            "description": "Version, state or request identity conflict"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "503": {
            "description": "File storage is temporarily unavailable; nothing was changed. Retry shortly."
          }
        },
        "description": "Staff-only read scoped by tenant, patient, document and exact file version. Version 1 is the original. The audit commits before bytes return. Generated safe filename, no-store and nosniff; same-origin framing and restrictive CSP. Annotation overlays are returned separately in version metadata and are not flattened into these bytes."
      }
    },
    "/api/v1/billing/claims/{id}/secondary-review": {
      "get": {
        "operationId": "reviewSecondaryClaim",
        "description": "Read current primary adjudication, effective secondary policies, existing secondary claims and blockers before explicit same-account preparation. Authorized billing staff only; tenant-scoped audited read. No claim creation, provider call or ledger change. Posted primaryCLP19 returns bounded verified received-secondary835 candidates when available; never infers destination from forwarding status alone.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current evidence and blockers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "primary_claim": {
                      "$ref": "#/components/schemas/Claim"
                    },
                    "account": {
                      "type": "object"
                    },
                    "coverages": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "existing_secondary_claims": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "primary_adjudication": {
                      "type": "object",
                      "description": "Exact remittance id/version/row, payment date, trace, normalized claim row and already-posted primary CO credits; absent when unavailable."
                    },
                    "blockers": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "crossover_candidates": {
                      "type": "array",
                      "description": "Present for primaryCLP19; unused received835 rows with exact trusted payer/provider/control/date/service evidence. Each includes coverage id/version, remittance id/version/row, payer name, trace/date/payee NPI and normalized claim row. Empty means no verified unused source is available. No source mutation.",
                      "items": {
                        "type": "object"
                      }
                    }
                  },
                  "required": [
                    "primary_claim",
                    "account",
                    "coverages",
                    "existing_secondary_claims",
                    "blockers"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid values or unsupported shape"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Role or billing scope denied"
          },
          "404": {
            "description": "Tenant/patient scoped record not found"
          },
          "409": {
            "description": "Stale review, duplicate evidence, incompatible lifecycle or unsafe balance"
          },
          "428": {
            "description": "Current quoted If-Match required"
          },
          "500": {
            "description": "Database/audit failure; transaction rolled back"
          }
        }
      }
    },
    "/api/v1/patients/{id}/lifecycle": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readPatientLifecycle",
        "summary": "Read patient archive status and attributed history",
        "tags": [
          "Patients"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientLifecycle"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "Current quoted lifecycle version."
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "put": {
        "operationId": "updatePatientLifecycle",
        "summary": "Archive or restore a patient chart with an audited reason",
        "tags": [
          "Patients"
        ],
        "security": [
          {
            "oauth2": [
              "clinical.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientLifecycle"
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "Current quoted lifecycle version."
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Record not found in tenant"
          },
          "409": {
            "description": "Stale version or invalid state"
          },
          "500": {
            "description": "Atomic operation failed"
          },
          "428": {
            "description": "Current quoted version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatientLifecycleChange"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[0-9]+\"$"
            }
          }
        ],
        "description": "Owner, clinician or front desk with clinical edit permission may archive or restore using the current quoted If-Match. Status, reason and audit commit atomically. Existing records are never deleted or rewritten. Archived charts cannot start new appointments or encounters until restored; direct records remain accessible. Stale versions return 409."
      }
    },
    "/api/v1/practice/fee-schedules": {
      "get": {
        "operationId": "listPracticeFeeSchedules",
        "summary": "List newest 100 owner-visible fee schedules",
        "tags": [
          "Practice fees"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid scope, source, amount or missing approval acknowledgement"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff role, owner privilege or billing scope denied"
          },
          "404": {
            "description": "Resource not found in tenant/patient scope"
          },
          "409": {
            "description": "Version, immutable scope or approved-schedule conflict"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "description": "Owner browser sessions only, including valid delegated owners. No OAuth administration. Entries omitted; response {items,limit:100}."
      },
      "post": {
        "operationId": "createPracticeFeeProposal",
        "summary": "Save an immutable inactive fee proposal",
        "tags": [
          "Practice fees"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid scope, source, amount or missing approval acknowledgement"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff role, owner privilege or billing scope denied"
          },
          "404": {
            "description": "Resource not found in tenant/patient scope"
          },
          "409": {
            "description": "Version, immutable scope or approved-schedule conflict"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewPracticeFeeProposal"
              }
            }
          }
        },
        "description": "16 MiB request limit. Tenant-scoped request_id replay binding; validates active provider/facility and captures their versions. Draft proposals never price charges. Fees create no ledger entries."
      }
    },
    "/api/v1/practice/fee-schedules/{id}": {
      "get": {
        "operationId": "getPracticeFeeSchedule",
        "summary": "Read complete immutable fee proposal and status",
        "tags": [
          "Practice fees"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid scope, source, amount or missing approval acknowledgement"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff role, owner privilege or billing scope denied"
          },
          "404": {
            "description": "Resource not found in tenant/patient scope"
          },
          "409": {
            "description": "Version, immutable scope or approved-schedule conflict"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/practice/fee-schedules/{id}/actions": {
      "post": {
        "operationId": "actOnPracticeFeeSchedule",
        "summary": "Approve or retire the current immutable proposal",
        "tags": [
          "Practice fees"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid scope, source, amount or missing approval acknowledgement"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff role, owner privilege or billing scope denied"
          },
          "404": {
            "description": "Resource not found in tenant/patient scope"
          },
          "409": {
            "description": "Version, immutable scope or approved-schedule conflict"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PracticeFeeAction"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "\"1\""
            }
          }
        ],
        "description": "Approval rechecks unchanged provider/facility evidence and rejects overlapping approved provider/facility/setting/service-date ranges. State change, attributed history and audit commit atomically. No automatic approval or repricing."
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/practice/fee-schedules/{id}/history": {
      "get": {
        "operationId": "listPracticeFeeHistory",
        "summary": "Read attributed immutable proposal state history",
        "tags": [
          "Practice fees"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid scope, source, amount or missing approval acknowledgement"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff role, owner privilege or billing scope denied"
          },
          "404": {
            "description": "Resource not found in tenant/patient scope"
          },
          "409": {
            "description": "Version, immutable scope or approved-schedule conflict"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        }
      },
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "/api/v1/patients/{patient_id}/fee-context": {
      "get": {
        "operationId": "getPatientFeeContext",
        "summary": "Derive safe charge context",
        "tags": [
          "Practice fees"
        ],
        "security": [
          {
            "browserSession": []
          },
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "delegatedJwt": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid scope, source, amount or missing approval acknowledgement"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff role, owner privilege or billing scope denied"
          },
          "404": {
            "description": "Resource not found in tenant/patient scope"
          },
          "409": {
            "description": "Version, immutable scope or approved-schedule conflict"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "parameters": [
          {
            "name": "patient_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "visit_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "service_date",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "description": "Staff only with native billing view permission and billing.read OAuth scope when applicable. Tenant and patient-bound encounter lookup. Returns provider_id, active facilities, exact unique appointment-facility match and explicitly approved setting default, otherwise null choices."
      }
    },
    "/api/v1/patients/{patient_id}/fee-quote": {
      "get": {
        "operationId": "quotePatientPracticeFee",
        "summary": "Read an exact approved fee quote",
        "tags": [
          "Practice fees"
        ],
        "security": [
          {
            "browserSession": []
          },
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "delegatedJwt": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid scope, source, amount or missing approval acknowledgement"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Staff role, owner privilege or billing scope denied"
          },
          "404": {
            "description": "Resource not found in tenant/patient scope"
          },
          "409": {
            "description": "Version, immutable scope or approved-schedule conflict"
          },
          "428": {
            "description": "Current quoted If-Match version required"
          }
        },
        "parameters": [
          {
            "name": "patient_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "visit_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "service_date",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "facility_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "setting",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "facility",
                "nonfacility"
              ]
            }
          },
          {
            "name": "code_system",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "CPT",
                "HCPCS"
              ]
            }
          },
          {
            "name": "code",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 5
            }
          },
          {
            "name": "modifiers",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "units",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          }
        ],
        "description": "Staff only with native billing view permission and billing.read OAuth scope when applicable. Tenant and patient-bound encounter lookup. Returns {quote,reason}. quote is null without an approved exact code/modifier/date/context match or after provider/facility version change. Amounts are one unit fee and complete unit-times-units line total. No price is fabricated and no financial state changes."
      }
    },
    "/api/v1/practice/billing-organizations": {
      "get": {
        "operationId": "listBillingOrganizations",
        "summary": "List billing organizations",
        "description": "Owner browser session only. At most100 tenant-scoped masked records; full tax IDs and ciphertext are never returned.",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      },
      "post": {
        "operationId": "createBillingOrganization",
        "summary": "Create reviewed billing tax identity",
        "description": "Owner browser session only. Explicit actual nine-digit tax identity is encrypted under the instance credential master key; append-only masked history and audit commit atomically. Stable request_id replays matching unchanged creation; conflicting reuse fails.",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BillingOrganizationCreate"
              }
            }
          }
        }
      }
    },
    "/api/v1/practice/billing-organizations/{id}": {
      "put": {
        "operationId": "updateBillingOrganization",
        "summary": "Update billing tax identity",
        "description": "Owner browser session and current quoted version required. Omitted tax_id preserves the saved encrypted value; changing tax_id_type requires the actual replacement value. No historical request changes. request_id is not accepted for updates.",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BillingOrganizationChange"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\"[1-9][0-9]*\"$"
            }
          }
        ]
      }
    },
    "/api/v1/practice/billing-organizations/{id}/history": {
      "get": {
        "operationId": "billingOrganizationHistory",
        "summary": "Review billing identity history",
        "description": "Owner browser session only. Returns latest100 immutable attributed revisions with masked tax identity; no ciphertext or full tax IDs.",
        "tags": [
          "Practice administration"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/claimmd/provider-defaults": {
      "get": {
        "operationId": "claimmdProviderDefaults",
        "summary": "Read current provider and billing identity choices",
        "description": "Staff only, trusted tenant. Active providers must have a checksum-valid NPI and enabled owner/clinician staff identity. Includes provider version, active masked billing_organizations with versions, facilities and unambiguous single-provider/facility default IDs. Directory membership does not prove payer enrollment; no tax ID is returned.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        }
      }
    },
    "/api/v1/patients/{patient}/coverages/{coverage}/claimmd-eligibility": {
      "get": {
        "operationId": "listClaimmdEligibility",
        "summary": "Review saved eligibility evidence",
        "description": "Staff only. Latest100 scoped checks with immutable requested identity/version and service-date snapshot. Newly recorded tax IDs are masked. Failed checks may carry response_snapshot.failure with kind,http_status,provider_codes; numeric codes alone are preserved, never raw system-error text. Historical failures without evidence remain unknown. Each check also carries actor_name, the display name (or sign-in email) of the staff member who ran it, and request_snapshot.automatic when the page ran it without a click.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "coverage",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "post": {
        "operationId": "requestClaimmdEligibility",
        "summary": "Request real-time eligibility",
        "description": "Scheduling-authorized staff only. Choose current provider and billing organization IDs+versions; server resolves and locks trusted active directory identity before reserving the request. Legacy explicit NPI/TIN remains supported. Service codes and procedure_code are mutually exclusive. Stable request_id prevents repeat provider submission; failed or pending replay requires review. Top-level Claim.MD rejection differs from payer messages in elig.error; no failed response implies uninsured status.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClaimmdEligibilityRequest"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "coverage",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/coverages/{coverage}/claimmd-eligibility/check": {
      "post": {
        "operationId": "checkClaimmdEligibility",
        "summary": "Check eligibility with what the chart already knows",
        "description": "Scheduling-authorized staff only. The server builds the Claim.MD request itself: subscriber from the patient (relationship self) or from the coverage's subscriber name and birth date with the patient as dependent; member ID and payer ID from the coverage and its payer; provider from the appointment or visit clinician when they have an NPI, else the practice's booking clinician, else the provider last used, else the only provider with an NPI; billing organization last used, else the only one; service date from service_date, else the appointment date in the practice time zone, else today; benefit type 30. Returns outcome `checked` with the saved check (completed or failed; a failed check keeps only kind, HTTP status, numeric codes and hint words, never Claim.MD's text), outcome `needs` with exactly what is missing (payer_id, member_id, subscriber_name, subscriber_birth_date, provider or billing_organization with choices, provider_npi, billing_organization_missing, claim_connection) and nothing sent, or, when automatic is true, outcome `skipped` with a reason (coverage_not_active, no_payer_id, recent_check within 30 days, recent_failure within 12 hours, in_progress, rate_limited). The same request_id returns the saved check and never asks the insurer twice.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "appointment_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "visit_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "service_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "automatic": {
                    "type": "boolean",
                    "default": false
                  },
                  "provider_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "billing_organization_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "coverage",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/patients/{patient}/coverages/{coverage}/claimmd-eligibility/enrollment": {
      "post": {
        "operationId": "startClaimmdEligibilityEnrollment",
        "summary": "Start Claim.MD eligibility setup from a check",
        "description": "Owner only. Starts Claim.MD enrollment of type elig for the insurer, provider NPI and billing organization that the named eligibility check used. The tax ID is resolved on the server and stored masked. Returns status `started` with a Claim.MD external_url to continue in a new tab, `no_link` when Claim.MD answered without a form, or `refused` with the bounded failure evidence (kind, codes, hint words).",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success; tenant-scoped attributed data, no credentials"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Role or scope denied"
          },
          "404": {
            "description": "Resource not found in tenant"
          },
          "409": {
            "description": "State or version conflict"
          },
          "428": {
            "description": "Current quoted resource version required"
          },
          "500": {
            "description": "Atomic operation failed"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "check_id"
                ],
                "properties": {
                  "check_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "coverage",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/copay-checkouts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getHostedCopayReturn",
        "summary": "Resolve an authorized card-checkout return",
        "description": "Authenticated staff billing-read lookup by opaque operation UUID. Tenant-scoped and audited; returns only the authorized saved operation, including its patient and appointment IDs. The return URL is not payment evidence.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current durable operation state; financial effects require verified provider evidence",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "operation": {
                      "$ref": "#/components/schemas/HostedCopayOperation"
                    }
                  },
                  "required": [
                    "operation"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unavailable/mismatched payment mode"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Billing permission denied"
          },
          "404": {
            "description": "Tenant/patient/appointment-scoped record not found"
          },
          "409": {
            "description": "Conflicting retry, pending collection, unsafe balance or over-limit history"
          },
          "500": {
            "description": "Database/audit failure; mutation rolled back"
          }
        }
      }
    },
    "/api/v1/billing/copay-checkouts/{id}/refresh": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "refreshHostedCopayReturn",
        "summary": "Reconcile an existing checkout after browser return",
        "description": "Billing-edit and native scheduling authorization are required. Retrieves only a previously bound provider session using the stored tenant/account/mode binding; never creates or retries creating a checkout. Missing session binding remains pending. Payment and refund ledger changes require independently verified provider evidence, never query parameters. Existing worker/manual retry behavior is unchanged.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current durable operation state; financial effects require verified provider evidence",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "operation": {
                      "$ref": "#/components/schemas/HostedCopayOperation"
                    }
                  },
                  "required": [
                    "operation"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unavailable/mismatched payment mode"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Billing permission denied"
          },
          "404": {
            "description": "Tenant/patient/appointment-scoped record not found"
          },
          "409": {
            "description": "Conflicting retry, pending collection, unsafe balance or over-limit history"
          },
          "500": {
            "description": "Database/audit failure; mutation rolled back"
          }
        }
      }
    },
    "/api/v1/billing/overview": {
      "get": {
        "operationId": "nativeBillingOverview",
        "description": "Native account and receipt overview. Totals cover the whole selected mode, not just a page. Only the latest invoice per account is counted; any subsequent account/ledger changes require review, so its historical amount is excluded from current open totals. Receipts may exist before charge accounts. Voided records add no collected amount; usable credit excludes reversed or held allocations and verified refunds. No claims are returned: claim policy authorization remains separate.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "mode",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "recorded",
                "test"
              ],
              "default": "recorded"
            }
          },
          {
            "name": "accounts_after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "copays_after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "patient_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Scope all aggregate totals and pages to this tenant patient, including archived charts."
          }
        ],
        "responses": {
          "200": {
            "description": "Audited native billing read; no payment, invoice, allocation or provider mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingOverview"
                }
              }
            }
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Native billing view or billing.read denied"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "500": {
            "description": "Read or audit failure"
          }
        }
      }
    },
    "/api/v1/billing/invoices/{id}": {
      "get": {
        "operationId": "readNativePatientInvoice",
        "description": "Read an immutable invoice without loading a clinical chart; billing view still required.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Audited native billing read; no payment, invoice, allocation or provider mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientInvoice"
                }
              }
            }
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Native billing view or billing.read denied"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "500": {
            "description": "Read or audit failure"
          }
        }
      }
    },
    "/api/v1/billing/copay-receipts/{id}": {
      "get": {
        "operationId": "readNativeCopayReceiptCopy",
        "description": "Read receipt evidence and minimal current patient/appointment identity for a print copy without clinical chart access. Original receipt is immutable; verified refunds and allocation status remain explicit.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Audited native billing read; no payment, invoice, allocation or provider mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingCopayReceiptCopy"
                }
              }
            }
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Native billing view or billing.read denied"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "500": {
            "description": "Read or audit failure"
          }
        }
      }
    },
    "/api/v1/billing/payments/operations": {
      "get": {
        "summary": "Read the connected Stripe account summary",
        "description": "Owner-only, including existing authorized delegated-owner sessions. Read-only Connect broker calls bound to the current installation, tenant, Stripe account/mode and credential revision. Returns available/pending balances, capability readiness and latest ten payment/payout records with timestamps. Unavailable sections have status unavailable and data null; an empty successful list is distinct. No customer or card/bank data, Stripe invoice totals or provider URLs. This does not enable collection or reconcile patient balances. Response is no-store; stale/revoked identity or connection fails closed.",
        "responses": {
          "200": {
            "description": "Versioned sanitized account activity",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "contract_version",
                    "installation_id",
                    "remote_tenant_id",
                    "account_id",
                    "livemode",
                    "checked_at",
                    "limit",
                    "setting_version",
                    "account",
                    "balance",
                    "payments",
                    "payouts"
                  ],
                  "properties": {
                    "contract_version": {
                      "type": "integer",
                      "const": 1
                    },
                    "installation_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "remote_tenant_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "account_id": {
                      "type": "string",
                      "pattern": "^acct_[A-Za-z0-9_]+$"
                    },
                    "livemode": {
                      "type": "boolean"
                    },
                    "checked_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "limit": {
                      "type": "integer",
                      "const": 10
                    },
                    "setting_version": {
                      "type": "integer"
                    },
                    "account": {
                      "type": "object",
                      "properties": {
                        "charges_enabled": {
                          "type": "boolean"
                        },
                        "card_payments_active": {
                          "type": "boolean"
                        },
                        "payouts_enabled": {
                          "type": "boolean"
                        },
                        "details_submitted": {
                          "type": "boolean"
                        }
                      }
                    },
                    "balance": {
                      "type": "object",
                      "required": [
                        "status",
                        "data"
                      ],
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "available",
                            "unavailable"
                          ]
                        },
                        "data": {
                          "type": [
                            "object",
                            "null"
                          ]
                        }
                      }
                    },
                    "payments": {
                      "type": "object",
                      "required": [
                        "status",
                        "data"
                      ],
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "available",
                            "unavailable"
                          ]
                        },
                        "data": {
                          "type": [
                            "object",
                            "null"
                          ]
                        }
                      }
                    },
                    "payouts": {
                      "type": "object",
                      "required": [
                        "status",
                        "data"
                      ],
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "available",
                            "unavailable"
                          ]
                        },
                        "data": {
                          "type": [
                            "object",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Owner permission required"
          },
          "409": {
            "description": "Account setup or binding changed; refresh required"
          },
          "400": {
            "description": "Provider unavailable or response could not be verified"
          }
        }
      }
    },
    "/api/v1/billing/payments/readers/hardware-session": {
      "post": {
        "summary": "Open card reader ordering for the practice owner",
        "description": "Owner-only, including existing authorized delegated-owner sessions; staff with a custom access policy also need billing edit. Asks SunCharts Connect for a short-lived Stripe session limited to the Terminal hardware shop and the practice's hardware orders, bound to the current installation, tenant, Stripe account/mode and credential revision. Readers are ordered from, shipped by and billed by Stripe. Takes no payment and changes no patient balance. `status` is `ready` (with the values the browser passes to Stripe Connect.js), `not_connected` when the practice has not finished payment account setup, or `unavailable` when reader ordering is not set up on SunCharts Connect. The session secret is never stored, logged or audited. Response is no-store; stale/revoked identity or connection fails closed.",
        "responses": {
          "200": {
            "description": "Reader ordering state for this practice",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ready",
                        "not_connected",
                        "unavailable"
                      ]
                    },
                    "client_secret": {
                      "type": "string",
                      "description": "Present only when status is ready. Short-lived; pass to Stripe Connect.js and do not store."
                    },
                    "publishable_key": {
                      "type": "string",
                      "pattern": "^pk_(test|live)_[A-Za-z0-9_]+$",
                      "description": "Present only when status is ready."
                    },
                    "livemode": {
                      "type": "boolean",
                      "description": "Present only when status is ready."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "SunCharts Connect or Stripe did not confirm the request; nothing was ordered"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Practice owner access required"
          },
          "409": {
            "description": "Payment account changed while the request was in progress"
          },
          "500": {
            "description": "Read or audit failure"
          }
        }
      }
    },
    "/api/v1/billing/patients": {
      "get": {
        "operationId": "searchBillingPatients",
        "description": "Minimal tenant-scoped patient directory for billing-authorized staff. Includes archived patients; no clinical record access or birth dates. Search is literal and paginated.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 120
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Audited native billing read; no payment, invoice, allocation or provider mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingPatientPage"
                }
              }
            }
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Native billing view or billing.read denied"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "500": {
            "description": "Read or audit failure"
          }
        }
      }
    },
    "/api/v1/billing/patients/{id}/invoices": {
      "get": {
        "operationId": "listPatientInvoiceHistory",
        "description": "All immutable native invoices for the selected tenant patient, with current review and latest-copy markers. No amounts are recomputed or changed.",
        "security": [
          {
            "oauth2": [
              "billing.read"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "mode",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "recorded",
                "test"
              ],
              "default": "recorded"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Audited native billing read; no payment, invoice, allocation or provider mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingPatientInvoicePage"
                }
              }
            }
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Native billing view or billing.read denied"
          },
          "404": {
            "description": "Tenant-scoped record not found"
          },
          "500": {
            "description": "Read or audit failure"
          }
        }
      }
    },
    "/api/v1/billing/patients/{id}/payment-profile": {
      "get": {
        "summary": "Read this patient\u2019s verified Stripe profile",
        "description": "Billing view permission required. Server binds tenant, patient, installation, Stripe account/mode and credential revision. GET never creates a customer. Returns masked card summaries, separately recorded Stripe invoices/subscriptions and an unresolved local setup reference. Independent pages contain at most twenty entries. Unavailable sections have null data. No provider credentials or clinical details. No-store.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "methods_after",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "invoices_after",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "subscriptions_after",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Verified profile",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "contract_version": {
                      "type": "integer",
                      "const": 1
                    },
                    "installation_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "remote_tenant_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "patient_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "account_id": {
                      "type": "string"
                    },
                    "livemode": {
                      "type": "boolean"
                    },
                    "checked_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "customer": {
                      "type": "object"
                    },
                    "payment_methods": {
                      "type": "object",
                      "description": "status not_created, unavailable or available; available data has items, has_more and next_cursor"
                    },
                    "invoices": {
                      "type": "object",
                      "description": "status not_created, unavailable or available; available data has items, has_more and next_cursor"
                    },
                    "subscriptions": {
                      "type": "object",
                      "description": "status not_created, unavailable or available; available data has items, has_more and next_cursor"
                    },
                    "setup_available": {
                      "type": "boolean"
                    },
                    "active_setup": {
                      "type": [
                        "object",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "contract_version",
                    "installation_id",
                    "remote_tenant_id",
                    "patient_id",
                    "account_id",
                    "livemode",
                    "checked_at",
                    "customer",
                    "payment_methods",
                    "invoices",
                    "subscriptions",
                    "setup_available",
                    "active_setup"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/patients/{id}/payment-setups": {
      "post": {
        "summary": "Reserve explicitly consented hosted card setup",
        "description": "Billing create plus scheduling role required. Reserves exact patient/account/mode/installation/credentials and consent actor before broker I/O. The Stripe page shows the practice wording for later charges; the setup is stored with `consent_scope` `later_charges`, its `consent_version` and, once the processor confirms the card, `consent_recorded_at`. Cards saved earlier keep `patient_present` and cannot be charged later. Saving a card does not authorize recurring charges. Retry only the same request UUID within the bounded 23-hour window; unknown outcomes remain reserved. No card fields or financial ledger mutation. Return URL is generated server-side.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "consent"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "consent": {
                    "type": "boolean",
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Fresh minimized provider evidence; never a payment or ledger entry",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientPaymentSetup"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/payment-setups/{id}": {
      "get": {
        "summary": "Verify an existing hosted card setup",
        "description": "Billing view required. Resolves only the reserved patient/account/credentials, retrieves existing provider evidence and updates the audited local projection. Never creates a customer, setup or payment. A browser return is not proof of completion.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh minimized provider evidence; never a payment or ledger entry",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientPaymentSetup"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/patients/{id}/payment-history": {
      "get": {
        "summary": "Read patient payment sources once across encounters",
        "description": "Billing view permission. Allocations and managed-payment ledger links are excluded from standalone entries so each collection appears once. Copay receipts, legacy test account-checkout attempts and directly recorded patient payments retain their evidence and status. Null received amounts mean unverified, not zero. Reversed, void and needs-review states remain visible. Read-only history does not move money or recompute liability.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "mode",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "recorded",
                "test"
              ],
              "default": "recorded"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque kind:uuid cursor from the previous response"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Patient-scoped payment history",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "patient_id",
                    "mode",
                    "currency",
                    "items",
                    "next_cursor"
                  ],
                  "properties": {
                    "patient_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "mode": {
                      "type": "string"
                    },
                    "currency": {
                      "const": "USD"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "enum": [
                              "copay",
                              "account_payment",
                              "recorded_payment",
                              "invoice_checkout"
                            ]
                          },
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "received_cents": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "refunded_cents": {
                            "type": "integer"
                          },
                          "unapplied_cents": {
                            "type": "integer"
                          },
                          "ledger_recorded": {
                            "type": "boolean"
                          },
                          "test_activity": {
                            "type": "boolean"
                          },
                          "status": {
                            "type": "string"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "account_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "uuid"
                          },
                          "visit_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "uuid"
                          },
                          "appointment_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "uuid"
                          },
                          "receipt_id": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "format": "uuid"
                          },
                          "reference": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        }
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/patients/{patient}/installment-plans": {
      "get": {
        "summary": "List finite invoice-bound plans and reviewed invoice eligibility",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientInstallmentPlanList"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      },
      "post": {
        "summary": "Create an immutable finite patient-present installment agreement",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientInstallmentPlan"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatientInstallmentCreateRequest"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current account version for plan creation, or plan version for checkout."
          },
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/patients/{patient}/installment-plans/preview": {
      "post": {
        "summary": "Validate exact finite schedule against current reviewed patient responsibility",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientInstallmentPreview"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatientInstallmentPreviewRequest"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/patients/{patient}/installment-plans/{plan}": {
      "get": {
        "summary": "Read invoice-bound plan, current eligibility and collection evidence",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientInstallmentPlan"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          }
        },
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "plan",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/patients/{patient}/installment-plans/{plan}/installments/{number}/checkout": {
      "post": {
        "summary": "Explicit patient-present checkout for the exact displayed collectible amount",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientInstallmentCheckoutResult"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          },
          "503": {
            "description": "collection_unavailable: explicit live activation is off or test collection is forbidden in production"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatientInstallmentCheckoutRequest"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Quoted current account version for plan creation, or plan version for checkout."
          },
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "plan",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "number",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 60
            }
          }
        ],
        "description": "With `reader_id` the amount is taken on that card reader instead of a hosted Checkout link; the same reservation, binding, guards and paid rule apply."
      }
    },
    "/api/v1/billing/invoice-checkouts/{id}": {
      "get": {
        "summary": "Resolve authorized invoice collection without creating a checkout",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceCheckoutResult"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/invoice-checkouts/{id}/refresh": {
      "post": {
        "summary": "Retrieve and reconcile an already-bound session; never creates a checkout",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceCheckoutResult"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          },
          "503": {
            "description": "collection_unavailable: explicit live activation is off or test collection is forbidden in production"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ]
      }
    },
    "/api/v1/billing/membership-prices": {
      "get": {
        "summary": "List approved membership prices",
        "description": "Billing view; bounded catalog page plus durable pending price recovery. Only the initiating authorized Owner receives its original approval input.",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh minimized account-bound evidence; no encounter ledger mutation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "contract_version": {
                      "const": 1
                    },
                    "installation_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "remote_tenant_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "account_id": {
                      "type": "string"
                    },
                    "livemode": {
                      "type": "boolean"
                    },
                    "checked_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "items": {
                      "type": "array",
                      "maxItems": 20,
                      "items": {
                        "$ref": "#/components/schemas/PatientMembershipPrice"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string",
                          "format": "uuid"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "pending_operations": {
                      "type": "array",
                      "maxItems": 20,
                      "items": {
                        "$ref": "#/components/schemas/PatientMembershipPending"
                      }
                    },
                    "creation_available": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "contract_version",
                    "installation_id",
                    "remote_tenant_id",
                    "account_id",
                    "livemode",
                    "checked_at",
                    "items",
                    "has_more",
                    "next_cursor",
                    "pending_operations",
                    "creation_available"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Approve a fixed recurring membership price",
        "description": "Owner and billing create. Immutable fixed USD price/cadence and explicit approval reason. Default-off live membership gate. Same request ID recovers uncertain creation.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Fresh minimized account-bound evidence; no encounter ledger mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientMembershipPriceResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "amount_cents": {
                    "type": "integer",
                    "minimum": 50,
                    "maximum": 100000000
                  },
                  "currency": {
                    "const": "usd"
                  },
                  "interval": {
                    "enum": [
                      "day",
                      "week",
                      "month",
                      "year"
                    ]
                  },
                  "interval_count": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365
                  },
                  "approved": {
                    "const": true
                  },
                  "approval_reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  }
                },
                "required": [
                  "request_id",
                  "name",
                  "amount_cents",
                  "currency",
                  "interval",
                  "interval_count",
                  "approved",
                  "approval_reason"
                ]
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/membership-prices/{id}": {
      "get": {
        "summary": "Refresh a reserved membership price",
        "description": "Read-only broker retrieval for an existing tenant-scoped local request. Never creates or retries a provider price.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh minimized account-bound evidence; no encounter ledger mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientMembershipPriceResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/patients/{id}/memberships": {
      "get": {
        "summary": "Read native memberships and pending operations",
        "description": "Billing view; exact patient/tenant/installation/account/mode and current credentials. Pages are bounded to twenty entries. Pending request inputs only belong to the authorized initiator.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh minimized account-bound evidence; no encounter ledger mutation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "contract_version": {
                      "const": 1
                    },
                    "installation_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "remote_tenant_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "account_id": {
                      "type": "string"
                    },
                    "livemode": {
                      "type": "boolean"
                    },
                    "checked_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "patient_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "items": {
                      "type": "array",
                      "maxItems": 20,
                      "items": {
                        "$ref": "#/components/schemas/PatientMembership"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "anyOf": [
                        {
                          "type": "string",
                          "format": "uuid"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "pending_operations": {
                      "type": "array",
                      "maxItems": 20,
                      "items": {
                        "$ref": "#/components/schemas/PatientMembershipPending"
                      }
                    },
                    "creation_available": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "contract_version",
                    "installation_id",
                    "remote_tenant_id",
                    "account_id",
                    "livemode",
                    "checked_at",
                    "patient_id",
                    "items",
                    "has_more",
                    "next_cursor",
                    "pending_operations",
                    "creation_available"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Start hosted membership enrollment",
        "description": "Scheduling role and billing create, active patient, explicit consent. Hosted Checkout separately records patient recurring authorization against immutable approved price and terms. Does not change encounter invoices or ledger.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh minimized account-bound evidence; no encounter ledger mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientMembershipResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "price_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "consent": {
                    "const": true
                  }
                },
                "required": [
                  "request_id",
                  "price_id",
                  "consent"
                ]
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/memberships/{id}": {
      "get": {
        "summary": "Refresh a native membership operation",
        "description": "Retrieves an existing enrollment or cancellation by immutable local request ID. GET never retries provider writes. Retry permission is bounded to the original actor, input and nonextended deadline.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh minimized account-bound evidence; no encounter ledger mutation",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/PatientMembershipResponse"
                    },
                    {
                      "$ref": "#/components/schemas/PatientMembershipCancellation"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/patients/{id}/memberships/{subscription}/cancel-at-period-end": {
      "post": {
        "summary": "Schedule native membership cancellation",
        "description": "Scheduling role and billing edit; verified native subscription mapping required. Stable request ID; cancels only at period end with no proration or refund. No new collection flag is enabled.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "subscription",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^sub_[A-Za-z0-9]+$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh minimized account-bound evidence; no encounter ledger mutation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientMembershipCancellation"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "expected_cancel_at_period_end": {
                    "const": false
                  }
                },
                "required": [
                  "request_id",
                  "expected_cancel_at_period_end"
                ]
              }
            }
          }
        }
      }
    },
    "/api/v1/patients/{patient}/intake-packets": {
      "get": {
        "operationId": "listPatientIntakePackets",
        "summary": "List retained patient intake forms across all appointment dates and statuses",
        "description": "Requires staff clinical-view access. Audited patient- and tenant-scoped metadata only: packet identity/version/status, immutable template revision name, nullable appointment context, submitted/reviewed times, expires_at, expired, started_at, default_form, response-presence flag, and all-history counts. No answers, attestation, access token or token hash. Existing packet detail reads authorize answer access separately. Does not change review status or chart data.",
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Packet cursor belonging to this patient; newest-issued ordering is stable."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{patient_id,items,next_cursor,summary:{total,submitted,reviewed,cancelled}}; Cache-Control: no-store."
          },
          "400": {
            "description": "Invalid page limit or cursor outside this patient."
          },
          "403": {
            "description": "Clinical-view access is not granted."
          },
          "404": {
            "description": "Patient is not in the authorized tenant."
          }
        }
      }
    },
    "/api/v1/patients/{patient}/intake-forms": {
      "post": {
        "operationId": "sendPatientIntakeForm",
        "summary": "Send the practice's intake form to a patient, with or without an appointment",
        "description": "Owner, clinician or front desk with clinical access. Issues the practice's default form (the standard form when nothing is saved) and returns its link once. The link works for 30 days, or through the day of the appointment when that is later. A default form the patient has not sent in yet is cancelled in the same transaction when it is for the same appointment or for none; forms for other appointments keep their links. No message is sent by the server.",
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "appointment_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "packet_id, patient_id, one-time intake_url, secret_shown_once, expires_at and replaced (forms cancelled). Cache-Control no-store."
          },
          "400": {
            "description": "The appointment does not belong to this patient."
          },
          "404": {
            "description": "Patient is not in the authorized tenant."
          },
          "409": {
            "description": "The appointment already has a filled-in form."
          }
        }
      }
    },
    "/api/v1/billing/payments/readers": {
      "get": {
        "summary": "List the practice's card readers",
        "description": "Owner, clinician and front desk staff. Asks SunCharts Connect for the Stripe readers registered for the practice's connected payment account, bound to the current installation, tenant and Stripe account/mode. `status` is `ready`, `not_connected` when payment account setup is not finished, or `unavailable` when a production practice is bound to a test account. `can_manage` says whether this staff member may add, rename or remove readers. `payments_available` says whether a card payment can be taken on a reader in this environment and payment mode. `practice_code` is present only for a test account outside production and is the Stripe code for a practice reader. Takes no payment. Response is no-store.",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "The practice's card readers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "readers",
                    "can_manage"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ready",
                        "not_connected",
                        "unavailable"
                      ]
                    },
                    "readers": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CardReader"
                      }
                    },
                    "can_manage": {
                      "type": "boolean"
                    },
                    "payments_available": {
                      "type": "boolean"
                    },
                    "practice_code": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, or the reader code was not accepted"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Not permitted for this staff member"
          },
          "404": {
            "description": "Reader not found for this practice"
          },
          "409": {
            "description": "Payment setup is not finished, the practice address is missing, or the reader is taking a payment"
          },
          "500": {
            "description": "Database/audit failure"
          }
        }
      },
      "post": {
        "summary": "Add a card reader",
        "description": "Owner-only; staff with a custom access policy also need billing edit. Registers the reader that is showing `code` with the practice's connected payment account and gives it `name`. SunCharts Connect creates the practice's reader location on first use from the business address Stripe already holds. The same `request_id` never registers twice. A practice reader code is accepted only for a test account outside production. Takes no payment.",
        "tags": [
          "Billing"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "code",
                  "name"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "code": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "description": "The code shown on the reader's screen."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 60
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The reader that was added",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "reader"
                  ],
                  "properties": {
                    "reader": {
                      "$ref": "#/components/schemas/CardReader"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, or the reader code was not accepted"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Not permitted for this staff member"
          },
          "404": {
            "description": "Reader not found for this practice"
          },
          "409": {
            "description": "Payment setup is not finished, the practice address is missing, or the reader is taking a payment"
          },
          "500": {
            "description": "Database/audit failure"
          }
        }
      }
    },
    "/api/v1/billing/payments/readers/{reader}": {
      "parameters": [
        {
          "name": "reader",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^tmr_[A-Za-z0-9]+$"
          }
        }
      ],
      "put": {
        "summary": "Rename a card reader",
        "description": "Owner-only; staff with a custom access policy also need billing edit. Only a reader registered for this practice can be renamed.",
        "tags": [
          "Billing"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 60
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The renamed reader",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "reader"
                  ],
                  "properties": {
                    "reader": {
                      "$ref": "#/components/schemas/CardReader"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, or the reader code was not accepted"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Not permitted for this staff member"
          },
          "404": {
            "description": "Reader not found for this practice"
          },
          "409": {
            "description": "Payment setup is not finished, the practice address is missing, or the reader is taking a payment"
          },
          "500": {
            "description": "Database/audit failure"
          }
        }
      },
      "delete": {
        "summary": "Remove a card reader",
        "description": "Owner-only; staff with a custom access policy also need billing delete. Only a reader registered for this practice can be removed, and not while it is taking a payment.",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "The reader was removed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "removed"
                  ],
                  "properties": {
                    "removed": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input, or the reader code was not accepted"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Not permitted for this staff member"
          },
          "404": {
            "description": "Reader not found for this practice"
          },
          "409": {
            "description": "Payment setup is not finished, the practice address is missing, or the reader is taking a payment"
          },
          "500": {
            "description": "Database/audit failure"
          }
        }
      }
    },
    "/api/v1/patients/{p}/appointments/{a}/copay-checkouts/{id}/reader-cancel": {
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "a",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "cancelReaderAppointmentCopay",
        "summary": "Cancel a copay that is waiting on a card reader",
        "description": "Billing-write staff. Records the cancel request, resets the reader and cancels the payment at the processor if no card was taken. If a card is being approved at that moment the payment is left alone and its real outcome is recorded: `open` with `last_result` `reader_finishing`, then `paid` or `expired`. A reader payment also closes by itself when the card is declined, the patient cancels on the reader, or no card is presented within five minutes. No refund is initiated here.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current durable operation state; financial effects require verified provider evidence",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "operation": {
                      "$ref": "#/components/schemas/HostedCopayOperation"
                    }
                  },
                  "required": [
                    "operation"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unavailable/mismatched payment mode"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Billing permission denied"
          },
          "404": {
            "description": "Tenant/patient/appointment-scoped record not found"
          },
          "409": {
            "description": "Conflicting retry, pending collection, unsafe balance or over-limit history"
          },
          "500": {
            "description": "Database/audit failure; mutation rolled back"
          }
        }
      }
    },
    "/api/v1/billing/invoice-checkouts/{id}/reader-cancel": {
      "post": {
        "summary": "Cancel an invoice payment that is waiting on a card reader",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceCheckoutResult"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "description": "Billing edit. Records the cancel request, resets the reader and cancels the payment at the processor if no card was taken. If a card is being approved at that moment the payment is left alone and its real outcome is recorded. No refund is initiated here."
      }
    },
    "/api/v1/patients/{p}/appointments/{a}/copay-checkouts/{id}/cancel": {
      "parameters": [
        {
          "name": "p",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "a",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "cancelAppointmentCopayCardLink",
        "summary": "Cancel an unfinished copay card link",
        "description": "Billing-write staff. Records the cancel request, then expires the Stripe Checkout Session through SunCharts Connect and records what really happened: `expired` with `last_result` `link_cancelled`, or `paid` when the patient completed the link in the same moment. `cancel_requested` is true while the payment service has not confirmed yet; the worker finishes the cancellation. Only a hosted card link can be cancelled here. No refund is initiated here.",
        "tags": [
          "Billing"
        ],
        "security": [
          {
            "oauth2": [
              "billing.write"
            ]
          },
          {
            "browserSession": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current durable operation state; financial effects require verified provider evidence",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "operation": {
                      "$ref": "#/components/schemas/HostedCopayOperation"
                    }
                  },
                  "required": [
                    "operation"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or unavailable/mismatched payment mode"
          },
          "401": {
            "description": "Sign in required"
          },
          "403": {
            "description": "Billing permission denied"
          },
          "404": {
            "description": "Tenant/patient/appointment-scoped record not found"
          },
          "409": {
            "description": "Conflicting retry, pending collection, unsafe balance or over-limit history"
          },
          "500": {
            "description": "Database/audit failure; mutation rolled back"
          }
        }
      }
    },
    "/api/v1/billing/invoice-checkouts/{id}/cancel": {
      "post": {
        "summary": "Cancel an unfinished invoice or installment card link",
        "tags": [
          "Billing"
        ],
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceCheckoutResult"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "description": "Billing edit. Records the cancel request, then expires the Stripe Checkout Session through SunCharts Connect and records what really happened: `expired` with `last_result` `link_cancelled`, or `paid` when the patient completed the link in the same moment. Only a hosted card link can be cancelled here. No refund is initiated here."
      }
    },
    "/api/v1/billing/payment-setups/{id}/cancel": {
      "post": {
        "summary": "Cancel an unfinished hosted card setup link",
        "description": "Billing edit plus scheduling role required. Records who cancelled and when, expires the Stripe Checkout Session through SunCharts Connect and stores what really happened: `expired` with `cancelled` true, or `succeeded` when the patient saved the card in the same moment. Another card setup can be started as soon as this one is `expired`. Never creates a customer, setup or payment.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh minimized provider evidence; never a payment or ledger entry",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientPaymentSetup"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/billing/patients/{patient}/invoices/{invoice}/saved-card-charge": {
      "post": {
        "summary": "Charge a reviewed invoice balance to a card on file",
        "tags": [
          "Billing"
        ],
        "description": "Billing create. Charges the whole remaining reviewed balance of an invoice without a payment plan to a card the patient saved with consent to later charges. The balance becomes a one-payment plan and the charge is an invoice card attempt with `channel` `saved_card`, posted by the same code as hosted checkout and reader payments. A card saved for in-person use is refused with 409 before anything is saved. The result is `paid`, or `expired` with `last_result` `saved_card_declined`, `saved_card_needs_patient`, `saved_card_not_eligible` or `saved_card_unavailable`. Retrying the same `request_id` never charges twice.",
        "parameters": [
          {
            "name": "patient",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "invoice",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "request_id",
                  "amount_cents",
                  "saved_card_setup_id"
                ],
                "properties": {
                  "request_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "amount_cents": {
                    "type": "integer",
                    "minimum": 50,
                    "maximum": 100000000
                  },
                  "saved_card_setup_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authenticated tenant-scoped result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvoiceCheckoutResult"
                }
              }
            }
          },
          "403": {
            "description": "Billing permission required"
          },
          "409": {
            "description": "Responsibility, version, reservation or idempotency conflict"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "delegatedJwt": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      },
      "browserSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "sce_session",
        "description": "Standalone GUI cookie, HttpOnly, SameSite=Strict, Secure over HTTPS. Mutations also require the configured Origin header."
      },
      "oauth2": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "/oauth/authorize",
            "tokenUrl": "/oauth/token",
            "refreshUrl": "/oauth/token",
            "scopes": {
              "clinical.read": "Read staff clinical records",
              "clinical.write": "Write within the delegated staff role",
              "events.read": "Read tenant change notices",
              "migration.manage": "Owner-only staging, reconciliation and import",
              "offline_access": "Receive rotating refresh tokens",
              "billing.read": "Read insurance and local billing records",
              "billing.write": "Update insurance and record local accounting activity",
              "scheduling.read": "Read tenant scheduling locations, providers, services, availability, partner-created appointments and webhook subscriptions",
              "scheduling.write": "Create holds and appointments, reschedule or cancel partner-created appointments, and manage scheduling webhooks within the delegated role"
            }
          }
        },
        "description": "Pre-register confidential clients locally. Exact callback, state, issuer response validation and S256 PKCE required. Access tokens last 300 seconds; refresh tokens rotate and replay revokes the grant. Not SMART or OIDC."
      },
      "clientBasic": {
        "type": "http",
        "scheme": "basic",
        "description": "Registered client ID and secret; token and revocation endpoints only."
      },
      "patientPortalSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "sce_portal",
        "description": "Separate patient portal session; HttpOnly, SameSite=Strict, Secure over HTTPS; Path=/api/v1/patient-portal. Not a staff browser session or OAuth credential. All mutations require configured Origin. 20-minute inactivity timeout and bounded absolute expiry; account/version revocation enforced."
      }
    },
    "parameters": {
      "AutomationId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "AutomationIfMatch": {
        "name": "If-Match",
        "in": "header",
        "required": true,
        "description": "Quoted current resource version.",
        "schema": {
          "type": "string",
          "pattern": "^\"[1-9][0-9]*\"$"
        }
      }
    },
    "schemas": {
      "ConnectorProvenance": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "repository_url",
          "source_revision",
          "source_digest"
        ],
        "properties": {
          "repository_url": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "source_revision": {
            "type": "string",
            "minLength": 7,
            "maxLength": 200
          },
          "source_digest": {
            "type": "string",
            "pattern": "^[A-Fa-f0-9]{64}$"
          }
        }
      },
      "ConnectorLifecycle": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "setup",
          "deactivate",
          "sample_events"
        ],
        "properties": {
          "setup": {
            "type": "boolean"
          },
          "deactivate": {
            "type": "boolean"
          },
          "sample_events": {
            "type": "boolean"
          }
        }
      },
      "ConnectorObjectSchema": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "fields"
        ],
        "properties": {
          "fields": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/ConnectorFieldSchema"
            }
          }
        }
      },
      "ConnectorFieldSchema": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "title",
          "field_type",
          "required",
          "phi",
          "enum_values",
          "fields",
          "items"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "field_type": {
            "enum": [
              "string",
              "integer",
              "number",
              "boolean",
              "uuid",
              "date_time",
              "object",
              "array"
            ]
          },
          "required": {
            "type": "boolean"
          },
          "phi": {
            "$ref": "#/components/schemas/ConnectorPhiClass"
          },
          "enum_values": {
            "type": "array",
            "maxItems": 100,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 240
            }
          },
          "fields": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/ConnectorFieldSchema"
            }
          },
          "items": {
            "type": "array",
            "maxItems": 1,
            "items": {
              "$ref": "#/components/schemas/ConnectorFieldSchema"
            }
          }
        }
      },
      "ConnectorPhiClass": {
        "enum": [
          "none",
          "identifiers",
          "limited",
          "clinical",
          "billing"
        ]
      },
      "ConnectorAuthScheme": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "kind",
          "scopes",
          "credential_fields"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "enum": [
              "none",
              "api_key",
              "oauth2",
              "oauth2_client"
            ]
          },
          "scopes": {
            "type": "array",
            "maxItems": 64,
            "uniqueItems": true,
            "items": {
              "type": "string"
            }
          },
          "credential_fields": {
            "type": "array",
            "maxItems": 16,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "id",
                "title",
                "secret"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                },
                "secret": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "CarePathwayColumnDefinition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "title"
        ],
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$",
            "description": "Stable lane identity retained when its title or order changes."
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "description": {
            "type": "string",
            "maxLength": 500,
            "default": ""
          },
          "hidden": {
            "type": "boolean",
            "default": false,
            "description": "Hides the visual lane without changing node or dependency execution."
          }
        }
      },
      "CarePathwayCondition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "field",
          "operator"
        ],
        "properties": {
          "field": {
            "type": "string",
            "pattern": "^/",
            "maxLength": 200,
            "description": "JSON Pointer into the immutable trigger context."
          },
          "operator": {
            "enum": [
              "equals",
              "not_equals",
              "present",
              "absent"
            ]
          },
          "value": {
            "description": "Comparison value for equals or not_equals; ignored by presence operators."
          }
        }
      },
      "CarePathwayFormField": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "label",
          "field_type"
        ],
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "field_type": {
            "enum": [
              "short_text",
              "long_text",
              "date",
              "choice",
              "checkbox",
              "number"
            ]
          },
          "required": {
            "type": "boolean",
            "default": false
          },
          "options": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            },
            "description": "Allowed only for choice fields."
          },
          "chart_target": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "demographics.preferred_name",
              "demographics.pronouns",
              "demographics.language",
              "demographics.administrative_gender",
              "demographics.phone",
              "demographics.email",
              null
            ],
            "description": "Optional mapping for short_text, long_text or choice fields; each target must be unique within the form. Patient-form packets pin this mapping to the run revision. Explicit staff review and selected-answer promotion are required; no automatic chart write."
          }
        }
      },
      "CarePathwayStepDefinition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "title",
          "kind"
        ],
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$",
            "description": "Stable node identity used by dependency edges."
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "kind": {
            "enum": [
              "patient_form",
              "staff_task",
              "eligibility_query",
              "payment_request",
              "document_signature",
              "notification",
              "clinical_template",
              "order",
              "referral",
              "human_approval",
              "availability_query",
              "slot_hold",
              "appointment_booking",
              "appointment_reschedule",
              "appointment_cancel",
              "intake_request",
              "communication_send",
              "ai_extract_draft",
              "ai_response_draft"
            ]
          },
          "phase": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$",
            "description": "Column key used for visual placement; legacy definitions may omit it."
          },
          "required": {
            "type": "boolean",
            "default": false
          },
          "manual_approval": {
            "type": "boolean",
            "default": false,
            "description": "AI nodes require true. The human_approval kind is always an approval gate, including legacy saved definitions."
          },
          "assigned_role": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "owner",
              "clinician",
              "nurse",
              "medical_assistant",
              "front_desk",
              null
            ]
          },
          "escalation_role": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "owner",
              "clinician",
              "nurse",
              "medical_assistant",
              "front_desk",
              null
            ]
          },
          "due_after_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 525600
          },
          "depends_on": {
            "type": "array",
            "maxItems": 20,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$"
            },
            "description": "Directed incoming edges. The complete definition must remain acyclic."
          },
          "condition": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/CarePathwayCondition"
              },
              {
                "type": "null"
              }
            ]
          },
          "form_fields": {
            "type": "array",
            "maxItems": 30,
            "items": {
              "$ref": "#/components/schemas/CarePathwayFormField"
            },
            "description": "Allowed for patient_form and clinical_template nodes. Patient-form fields issue a real immutable intake packet; clinical-template completion uses its separate native resource binding."
          },
          "ai": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/CarePathwayAiConfiguration"
              },
              {
                "type": "null"
              }
            ]
          },
          "editor_position": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "x",
                  "y"
                ],
                "properties": {
                  "x": {
                    "type": "number",
                    "minimum": -100000,
                    "maximum": 100000
                  },
                  "y": {
                    "type": "number",
                    "minimum": -100000,
                    "maximum": 100000
                  }
                }
              },
              {
                "type": "null"
              }
            ],
            "description": "Optional finite canvas coordinates stored in the immutable definition revision. Presentation only; phase, dependencies and approvals retain their runtime meaning."
          },
          "native": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "resource"
                ],
                "properties": {
                  "resource": {
                    "enum": [
                      "appointment_booked",
                      "check_in",
                      "signed_visit",
                      "functional_status",
                      "neurotoxin",
                      "baclofen_pump_refill",
                      "stretching_program",
                      "care_coordination",
                      "eligibility",
                      "payment",
                      "order",
                      "referral",
                      "intake_reviewed",
                      "follow_up",
                      "claim_review",
                      "claim_submitted",
                      "claim_accepted"
                    ]
                  }
                }
              },
              {
                "type": "null"
              }
            ],
            "description": "Optional native evidence binding; allowed resources depend on node kind. Completion and approval require current tenant-, patient- and encounter-bound evidence. Clinical-template nodes require a supported binding to complete."
          }
        }
      },
      "CarePathwayDefinition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "steps"
        ],
        "properties": {
          "columns": {
            "type": "array",
            "minItems": 1,
            "maxItems": 12,
            "items": {
              "$ref": "#/components/schemas/CarePathwayColumnDefinition"
            },
            "description": "Ordered, clinic-configurable visual lanes. Omission on a legacy definition applies the four standard journey columns."
          },
          "steps": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/CarePathwayStepDefinition"
            }
          }
        },
        "description": "A versioned directed acyclic workflow graph. Column order changes presentation; depends_on, condition and manual_approval control execution. Column keys and step keys must be unique, and at least one column must remain visible."
      },
      "CreateCarePathwayDefinition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "slug",
          "name",
          "trigger_type",
          "definition",
          "reason"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "slug": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_-]{0,62}$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "description": {
            "type": "string",
            "maxLength": 2000,
            "default": ""
          },
          "trigger_type": {
            "$ref": "#/components/schemas/CarePathwayTriggerType"
          },
          "definition": {
            "$ref": "#/components/schemas/CarePathwayDefinition"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "UpdateCarePathwayDefinition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "trigger_type",
          "definition",
          "reason"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "description": {
            "type": "string",
            "maxLength": 2000,
            "default": ""
          },
          "trigger_type": {
            "$ref": "#/components/schemas/CarePathwayTriggerType"
          },
          "definition": {
            "$ref": "#/components/schemas/CarePathwayDefinition"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "CarePathwayTriggerType": {
        "enum": [
          "inquiry_received",
          "referral_received",
          "referral_status_changed",
          "call_received",
          "sms_received",
          "fax_received",
          "email_received",
          "external_booking_received",
          "appointment_created",
          "appointment_rescheduled",
          "appointment_cancelled",
          "eligibility_returned",
          "patient_checked_in",
          "visit_signed",
          "order_placed"
        ]
      },
      "TriggerCarePathway": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "trigger_type",
          "trigger_key",
          "reason"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "trigger_type": {
            "$ref": "#/components/schemas/CarePathwayTriggerType"
          },
          "trigger_key": {
            "type": "string",
            "minLength": 1,
            "maxLength": 300
          },
          "definition_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "patient_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "appointment_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "visit_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "context": {
            "type": "object",
            "default": {},
            "description": "Bounded event context evaluated by node conditions and retained with the pathway instance."
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "expected_definition_version": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "description": "Optional published-version constraint. A mismatched or no-longer-published definition does not start a run."
          }
        }
      },
      "ConnectorTriggerDefinition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "title",
          "description",
          "event_type",
          "transport",
          "auth_scheme",
          "required_roles",
          "required_scopes",
          "phi",
          "output"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "event_type": {
            "type": "string"
          },
          "transport": {
            "enum": [
              "internal_event",
              "webhook",
              "websocket",
              "polling"
            ]
          },
          "auth_scheme": {
            "type": [
              "string",
              "null"
            ]
          },
          "required_roles": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string"
            }
          },
          "required_scopes": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string"
            }
          },
          "phi": {
            "$ref": "#/components/schemas/ConnectorPhiClass"
          },
          "output": {
            "$ref": "#/components/schemas/ConnectorObjectSchema"
          },
          "dispatch_action": {
            "type": [
              "string",
              "null"
            ],
            "description": "Optional action ID in the same manifest staged by the durable runtime when this exact trigger is delivered. Trigger output and action input schemas must match exactly."
          }
        }
      },
      "ConnectorActionDefinition": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "title",
          "description",
          "implementation",
          "transport",
          "auth_scheme",
          "required_roles",
          "required_scopes",
          "phi",
          "effect",
          "approval",
          "idempotency",
          "retry",
          "input",
          "output"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "implementation": {
            "type": "string",
            "description": "Identifier of an adapter compiled into the EHR; never a URL or script."
          },
          "transport": {
            "enum": [
              "native",
              "provider_api"
            ]
          },
          "auth_scheme": {
            "type": [
              "string",
              "null"
            ]
          },
          "required_roles": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string"
            }
          },
          "required_scopes": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string"
            }
          },
          "phi": {
            "$ref": "#/components/schemas/ConnectorPhiClass"
          },
          "effect": {
            "enum": [
              "read",
              "write",
              "external_send",
              "clinical_write",
              "billing_write"
            ]
          },
          "approval": {
            "enum": [
              "none",
              "staff",
              "clinical",
              "owner"
            ]
          },
          "idempotency": {
            "enum": [
              "none",
              "request_key",
              "natural_key"
            ]
          },
          "retry": {
            "enum": [
              "never",
              "read_only",
              "safe_idempotent"
            ]
          },
          "input": {
            "$ref": "#/components/schemas/ConnectorObjectSchema"
          },
          "output": {
            "$ref": "#/components/schemas/ConnectorObjectSchema"
          }
        }
      },
      "ConnectorManifest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "api_version",
          "id",
          "name",
          "version",
          "license",
          "homepage",
          "repository",
          "description",
          "auth_schemes",
          "triggers",
          "actions",
          "lifecycle"
        ],
        "properties": {
          "api_version": {
            "const": "suncharts.dev/connector/v1"
          },
          "id": {
            "type": "string",
            "minLength": 3,
            "maxLength": 120
          },
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 120
          },
          "version": {
            "type": "string",
            "description": "Semantic version."
          },
          "license": {
            "enum": [
              "AGPL-3.0-only",
              "Apache-2.0",
              "MIT",
              "BSD-2-Clause",
              "BSD-3-Clause",
              "MPL-2.0"
            ]
          },
          "homepage": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "repository": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "description": {
            "type": "string",
            "maxLength": 1000
          },
          "auth_schemes": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "$ref": "#/components/schemas/ConnectorAuthScheme"
            }
          },
          "triggers": {
            "type": "array",
            "maxItems": 64,
            "items": {
              "$ref": "#/components/schemas/ConnectorTriggerDefinition"
            }
          },
          "actions": {
            "type": "array",
            "maxItems": 128,
            "items": {
              "$ref": "#/components/schemas/ConnectorActionDefinition"
            }
          },
          "lifecycle": {
            "$ref": "#/components/schemas/ConnectorLifecycle"
          }
        },
        "description": "Declarative open-source connector contract. At least one trigger or action is required. Executable code, arbitrary HTTP targets, headers and templates are not part of this manifest."
      },
      "CreateAutomationSubscription": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "connector_key",
          "trigger_key",
          "reason"
        ],
        "properties": {
          "connector_key": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160
          },
          "trigger_key": {
            "type": "string",
            "minLength": 2,
            "maxLength": 160
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "AutomationLifecycleAction": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "action",
          "reason"
        ],
        "properties": {
          "action": {
            "enum": [
              "activate",
              "deactivate"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "Patient": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "mrn": {
            "type": "string"
          },
          "given_name": {
            "type": "string"
          },
          "family_name": {
            "type": "string"
          },
          "birth_date": {
            "type": "string",
            "format": "date"
          },
          "archived": {
            "type": "boolean",
            "description": "Current append-only chart archive status on native patient directory and workspace responses. Historical identity snapshots may omit it."
          }
        },
        "required": [
          "id",
          "mrn",
          "given_name",
          "family_name",
          "birth_date"
        ]
      },
      "NewPatient": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "given_name": {
            "type": "string"
          },
          "family_name": {
            "type": "string"
          },
          "birth_date": {
            "type": "string",
            "format": "date"
          }
        },
        "required": [
          "given_name",
          "family_name",
          "birth_date"
        ],
        "description": "Register with name and date of birth. The server assigns the MRN; a caller-supplied MRN is rejected. Reviewed historical imports preserve established identifiers through their separate import contract."
      },
      "Appointment": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "booked",
              "checked_in",
              "in_progress",
              "completed",
              "cancelled",
              "no_show"
            ]
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "category": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "facility": {
            "type": "string",
            "minLength": 0,
            "maxLength": 200
          },
          "room": {
            "type": "string",
            "minLength": 0,
            "maxLength": 100
          },
          "notes": {
            "type": "string",
            "minLength": 0,
            "maxLength": 2000
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "id",
          "patient_id",
          "clinician_id",
          "starts_at",
          "ends_at",
          "status",
          "title",
          "category",
          "facility",
          "room",
          "notes",
          "version",
          "source_history_id"
        ]
      },
      "NewAppointment": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "category": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "facility": {
            "type": "string",
            "minLength": 0,
            "maxLength": 200
          },
          "room": {
            "type": "string",
            "minLength": 0,
            "maxLength": 100
          },
          "notes": {
            "type": "string",
            "minLength": 0,
            "maxLength": 2000
          },
          "request_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "patient_id",
          "clinician_id",
          "starts_at",
          "ends_at"
        ]
      },
      "StartVisit": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "appointment_id"
        ]
      },
      "SoapNote": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "subjective": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          },
          "objective": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          },
          "assessment": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          },
          "plan": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          },
          "procedure": {
            "type": "string",
            "maxLength": 10000,
            "description": "Optional fifth section shown after Plan. Empty or blank text is not stored, so the field is absent on notes that do not use it and on every note written before it existed."
          },
          "started_from": {
            "$ref": "#/components/schemas/NoteSource"
          },
          "saved_by": {
            "$ref": "#/components/schemas/NoteSaved"
          }
        },
        "required": [
          "subjective",
          "objective",
          "assessment",
          "plan"
        ],
        "description": "Visit note text. subjective, objective, assessment and plan are required; procedure and started_from are optional and omitted when unused. saved_by is set by the server. Signed notes are stored once and returned exactly as signed."
      },
      "NoteSource": {
        "type": "object",
        "additionalProperties": false,
        "description": "Recorded on an in-progress note whose text was started from an earlier signed note of the same patient. The earlier note is only read. Kept with the note when it is signed.",
        "properties": {
          "visit_id": {
            "type": "string",
            "format": "uuid",
            "description": "Earlier signed visit of the same patient in this practice; anything else is rejected with 400."
          },
          "version": {
            "type": "integer",
            "minimum": 1,
            "description": "Version of the earlier visit when its text was brought in; not above its current version."
          },
          "sections": {
            "type": "array",
            "minItems": 1,
            "maxItems": 5,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "enum": [
                "subjective",
                "objective",
                "assessment",
                "plan",
                "procedure"
              ]
            },
            "description": "Sections whose text was brought in. Stored in note order."
          },
          "visit_date": {
            "type": "string",
            "format": "date-time",
            "description": "Service date of the earlier visit. Set by the server; a submitted value is ignored."
          }
        },
        "required": [
          "visit_id",
          "version",
          "sections"
        ]
      },
      "PreviousNote": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "source": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/PreviousNoteSource"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "source"
        ]
      },
      "PreviousNoteSource": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "visit_date": {
            "type": "string",
            "format": "date-time"
          },
          "signed_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_name": {
            "type": "string",
            "description": "Provider or staff display name; empty when none is recorded."
          },
          "same_clinician": {
            "type": "boolean",
            "description": "The earlier visit was assigned to the same clinician as this visit."
          },
          "note": {
            "type": "object",
            "additionalProperties": false,
            "description": "Note text only. Vitals, diagnoses, orders and charges are never included.",
            "properties": {
              "subjective": {
                "type": "string"
              },
              "objective": {
                "type": "string"
              },
              "assessment": {
                "type": "string"
              },
              "plan": {
                "type": "string"
              },
              "procedure": {
                "type": "string"
              }
            },
            "required": [
              "subjective",
              "objective",
              "assessment",
              "plan",
              "procedure"
            ]
          },
          "own": {
            "type": "boolean",
            "description": "The earlier visit was assigned to the person asking."
          }
        },
        "required": [
          "visit_id",
          "version",
          "visit_date",
          "signed_at",
          "clinician_id",
          "clinician_name",
          "same_clinician",
          "own",
          "note"
        ]
      },
      "Vitals": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "systolic_mm_hg": {
            "type": "integer",
            "minimum": 30,
            "maximum": 350
          },
          "diastolic_mm_hg": {
            "type": "integer",
            "minimum": 10,
            "maximum": 250
          },
          "heart_rate_bpm": {
            "type": "integer",
            "minimum": 10,
            "maximum": 350
          },
          "temperature_c": {
            "type": "number",
            "minimum": 20,
            "maximum": 50
          },
          "weight_kg": {
            "type": "number",
            "minimum": 0.1,
            "maximum": 700
          },
          "height_cm": {
            "type": "number",
            "minimum": 10,
            "maximum": 300
          },
          "oxygen_saturation_pct": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          }
        },
        "required": [
          "systolic_mm_hg",
          "diastolic_mm_hg",
          "heart_rate_bpm",
          "temperature_c",
          "weight_kg",
          "height_cm",
          "oxygen_saturation_pct"
        ]
      },
      "Visit": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "in_progress",
              "signed"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "note": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/SoapNote"
              },
              {
                "type": "null"
              }
            ]
          },
          "vitals": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Vitals"
              },
              {
                "type": "null"
              }
            ]
          },
          "signed_by": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "signed_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "patient_id",
          "appointment_id",
          "clinician_id",
          "status",
          "version",
          "note",
          "vitals",
          "signed_by",
          "signed_at"
        ]
      },
      "NewAmendment": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          }
        },
        "required": [
          "reason",
          "text"
        ]
      },
      "Amendment": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "author_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "visit_id",
          "author_id",
          "reason",
          "text",
          "created_at"
        ]
      },
      "Record": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient": {
            "$ref": "#/components/schemas/Patient"
          },
          "visits": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Visit"
            }
          },
          "amendments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Amendment"
            }
          }
        },
        "required": [
          "patient",
          "visits",
          "amendments"
        ]
      },
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "message"
        ]
      },
      "PatientPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Patient"
            }
          },
          "next_cursor": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "items",
          "next_cursor"
        ]
      },
      "Workspace": {
        "type": "object",
        "properties": {
          "patient": {
            "$ref": "#/components/schemas/Patient"
          },
          "appointments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Appointment"
            }
          },
          "visits": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Visit"
            }
          },
          "amendments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Amendment"
            }
          }
        },
        "required": [
          "patient",
          "appointments",
          "visits",
          "amendments"
        ]
      },
      "MigrationManifest": {
        "type": "object",
        "properties": {
          "source_instance": {
            "type": "string",
            "maxLength": 200
          },
          "source_revision": {
            "type": "string",
            "maxLength": 200
          },
          "expected_counts": {
            "type": "object",
            "additionalProperties": {
              "type": "integer",
              "minimum": 0
            }
          },
          "consistency": {
            "type": "string",
            "enum": [
              "read_only_export",
              "transactional_export"
            ]
          },
          "limitations": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "source_instance",
          "source_revision",
          "expected_counts",
          "consistency"
        ]
      },
      "MigrationItem": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string"
          },
          "source_id": {
            "type": "string"
          },
          "patient_source_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "data": {
            "type": "object"
          },
          "source_data": {
            "type": "object"
          }
        },
        "required": [
          "kind",
          "source_id",
          "data",
          "source_data"
        ]
      },
      "ClinicalCoding": {
        "type": "object",
        "properties": {
          "system": {
            "type": "string",
            "maxLength": 200
          },
          "code": {
            "type": "string",
            "maxLength": 120
          },
          "display": {
            "type": "string",
            "maxLength": 200
          }
        },
        "required": [
          "system",
          "code"
        ],
        "additionalProperties": false
      },
      "ClinicalContent": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "inactive",
              "resolved",
              "recurrence",
              "remission",
              "on_hold",
              "stopped",
              "completed",
              "not_taken",
              "intended",
              "entered_in_error"
            ]
          },
          "verification": {
            "type": "string",
            "enum": [
              "unconfirmed",
              "confirmed",
              "refuted",
              "entered_in_error"
            ]
          },
          "onset_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "notes": {
            "type": "string",
            "maxLength": 10000
          },
          "codes": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/ClinicalCoding"
            }
          },
          "detail": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "const": "problem"
                  },
                  "problem_type": {
                    "type": "string",
                    "enum": [
                      "problem",
                      "diagnosis",
                      "health_concern"
                    ]
                  }
                },
                "required": [
                  "kind",
                  "problem_type"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "const": "allergy"
                  },
                  "category": {
                    "type": "string",
                    "enum": [
                      "medication",
                      "food",
                      "environment",
                      "biologic",
                      "other"
                    ]
                  },
                  "reaction": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "severity": {
                    "type": "string",
                    "enum": [
                      "unknown",
                      "mild",
                      "moderate",
                      "severe"
                    ]
                  },
                  "criticality": {
                    "type": "string",
                    "enum": [
                      "unknown",
                      "low",
                      "high"
                    ]
                  }
                },
                "required": [
                  "kind",
                  "category",
                  "reaction",
                  "severity",
                  "criticality"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "const": "medication"
                  },
                  "dose": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "route": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "frequency": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "indication": {
                    "type": "string",
                    "maxLength": 500
                  }
                },
                "required": [
                  "kind",
                  "dose",
                  "route",
                  "frequency",
                  "indication"
                ],
                "additionalProperties": false
              }
            ]
          }
        },
        "required": [
          "title",
          "status",
          "verification",
          "detail"
        ],
        "additionalProperties": false
      },
      "ClinicalChange": {
        "type": "object",
        "properties": {
          "content": {
            "$ref": "#/components/schemas/ClinicalContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "content",
          "reason"
        ],
        "additionalProperties": false
      },
      "ClinicalReview": {
        "type": "object",
        "properties": {
          "review_state": {
            "type": "string",
            "enum": [
              "unknown",
              "reviewed",
              "no_known"
            ]
          },
          "note": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000
          }
        },
        "required": [
          "review_state",
          "note"
        ],
        "additionalProperties": false
      },
      "RequestedLabTest": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "maxLength": 80
          },
          "label": {
            "type": "string",
            "maxLength": 200
          },
          "code": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClinicalCoding"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "key",
          "label"
        ],
        "additionalProperties": false
      },
      "OrderContent": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 200
          },
          "category": {
            "type": "string",
            "enum": [
              "laboratory",
              "imaging",
              "procedure"
            ]
          },
          "priority": {
            "type": "string",
            "enum": [
              "routine",
              "urgent",
              "stat"
            ]
          },
          "clinical_reason": {
            "type": "string",
            "maxLength": 2000
          },
          "destination": {
            "type": "string",
            "maxLength": 200
          },
          "instructions": {
            "type": "string",
            "maxLength": 4000
          },
          "tests": {
            "type": "array",
            "minItems": 1,
            "maxItems": 30,
            "items": {
              "$ref": "#/components/schemas/RequestedLabTest"
            }
          }
        },
        "required": [
          "title",
          "category",
          "priority",
          "clinical_reason",
          "destination",
          "tests"
        ],
        "additionalProperties": false
      },
      "NewLabOrder": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/OrderContent"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ],
        "additionalProperties": false
      },
      "EditLabOrder": {
        "type": "object",
        "properties": {
          "visit_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/OrderContent"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "required": [
          "content",
          "reason"
        ],
        "additionalProperties": false
      },
      "LabOrderAction": {
        "type": "object",
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "place",
              "cancel",
              "entered_in_error",
              "complete"
            ]
          },
          "reason": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "required": [
          "action",
          "reason"
        ],
        "additionalProperties": false
      },
      "SpecimenContent": {
        "type": "object",
        "properties": {
          "accession": {
            "type": "string",
            "maxLength": 120
          },
          "specimen_type": {
            "type": "string",
            "maxLength": 200
          },
          "body_site": {
            "type": "string",
            "maxLength": 200
          },
          "collected_at": {
            "type": "string",
            "format": "date-time"
          },
          "received_at": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "received",
              "rejected"
            ]
          },
          "notes": {
            "type": "string",
            "maxLength": 4000
          }
        },
        "required": [
          "accession",
          "specimen_type",
          "body_site",
          "collected_at",
          "received_at",
          "status",
          "notes"
        ],
        "additionalProperties": false
      },
      "NewLabSpecimen": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/SpecimenContent"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ],
        "additionalProperties": false
      },
      "LabObservation": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "maxLength": 200
          },
          "code": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClinicalCoding"
              },
              {
                "type": "null"
              }
            ]
          },
          "value_type": {
            "type": "string",
            "enum": [
              "numeric",
              "text",
              "coded",
              "absent"
            ]
          },
          "number": {
            "type": [
              "number",
              "null"
            ]
          },
          "comparator": {
            "type": "string",
            "enum": [
              "",
              "<",
              "<=",
              ">",
              ">="
            ]
          },
          "text": {
            "type": "string",
            "maxLength": 4000
          },
          "coded": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClinicalCoding"
              },
              {
                "type": "null"
              }
            ]
          },
          "units": {
            "type": "string",
            "maxLength": 100
          },
          "reference_range": {
            "type": "string",
            "maxLength": 500
          },
          "flag": {
            "type": "string",
            "enum": [
              "unknown",
              "normal",
              "abnormal",
              "high",
              "low",
              "critical_high",
              "critical_low",
              "critical"
            ]
          },
          "absent_reason": {
            "type": "string",
            "maxLength": 200
          },
          "notes": {
            "type": "string",
            "maxLength": 4000
          }
        },
        "required": [
          "label",
          "value_type",
          "flag"
        ],
        "additionalProperties": false,
        "description": "Exactly one typed value: finite number plus nonempty units for numeric; nonempty text; Coding for coded; or nonempty absent_reason. Other typed value fields must be empty/null. Absent observations require unknown flag. Units/codes are recorded as supplied, not terminology-validated. Flags are not calculated from numeric ranges."
      },
      "LabReportContent": {
        "type": "object",
        "properties": {
          "test_keys": {
            "type": "array",
            "minItems": 1,
            "maxItems": 30,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "maxLength": 80
            }
          },
          "specimen_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "specimen_not_recorded": {
            "type": "boolean",
            "default": false
          },
          "accession": {
            "type": "string",
            "maxLength": 120
          },
          "performing_lab": {
            "type": "string",
            "maxLength": 200
          },
          "reported_at": {
            "type": "string",
            "format": "date-time"
          },
          "observations": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/LabObservation"
            }
          },
          "notes": {
            "type": "string",
            "maxLength": 10000
          }
        },
        "required": [
          "test_keys",
          "accession",
          "performing_lab",
          "reported_at",
          "observations"
        ],
        "additionalProperties": false
      },
      "NewLabReport": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/LabReportContent"
          },
          "status": {
            "type": "string",
            "enum": [
              "preliminary",
              "final"
            ]
          },
          "reason": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "status",
          "reason"
        ],
        "additionalProperties": false
      },
      "EditLabReport": {
        "type": "object",
        "properties": {
          "content": {
            "$ref": "#/components/schemas/LabReportContent"
          },
          "status": {
            "type": "string",
            "enum": [
              "preliminary",
              "final",
              "corrected",
              "entered_in_error"
            ]
          },
          "reason": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "required": [
          "content",
          "status",
          "reason"
        ],
        "additionalProperties": false
      },
      "LabAcknowledgment": {
        "type": "object",
        "properties": {
          "note": {
            "type": "string",
            "maxLength": 2000
          }
        },
        "required": [
          "note"
        ],
        "additionalProperties": false
      },
      "EditAppointment": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "category": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "facility": {
            "type": "string",
            "minLength": 0,
            "maxLength": 200
          },
          "room": {
            "type": "string",
            "minLength": 0,
            "maxLength": 100
          },
          "notes": {
            "type": "string",
            "minLength": 0,
            "maxLength": 2000
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "clinician_id",
          "starts_at",
          "ends_at",
          "title",
          "category",
          "facility",
          "room",
          "notes",
          "reason"
        ]
      },
      "AppointmentAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "check_in",
              "cancel",
              "no_show"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "NewScheduleBlock": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          }
        },
        "required": [
          "request_id",
          "clinician_id",
          "starts_at",
          "ends_at",
          "label"
        ]
      },
      "ScheduleBlock": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "active": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "clinician_id",
          "starts_at",
          "ends_at",
          "label",
          "version",
          "active"
        ]
      },
      "ScheduleAppointment": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "booked",
              "checked_in",
              "in_progress",
              "completed",
              "cancelled",
              "no_show"
            ]
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "category": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "facility": {
            "type": "string",
            "minLength": 0,
            "maxLength": 200
          },
          "room": {
            "type": "string",
            "minLength": 0,
            "maxLength": 100
          },
          "notes": {
            "type": "string",
            "minLength": 0,
            "maxLength": 2000
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "patient_name": {
            "type": "string",
            "minLength": 0,
            "maxLength": 201
          },
          "mrn": {
            "type": "string",
            "minLength": 0,
            "maxLength": 64
          },
          "provider_label": {
            "type": "string",
            "minLength": 0,
            "maxLength": 320
          }
        },
        "required": [
          "id",
          "patient_id",
          "clinician_id",
          "starts_at",
          "ends_at",
          "status",
          "title",
          "category",
          "facility",
          "room",
          "notes",
          "version",
          "source_history_id",
          "patient_name",
          "mrn",
          "provider_label"
        ]
      },
      "Schedule": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "appointments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ScheduleAppointment"
            }
          },
          "blocks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ScheduleBlock"
            }
          }
        },
        "required": [
          "appointments",
          "blocks"
        ]
      },
      "AppointmentHistory": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "version": {
                  "type": "integer"
                },
                "snapshot": {
                  "$ref": "#/components/schemas/Appointment"
                },
                "actor_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "reason": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 1000
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "required": [
                "version",
                "snapshot",
                "actor_id",
                "reason",
                "created_at"
              ]
            }
          }
        },
        "required": [
          "items"
        ]
      },
      "ScheduleProviders": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "label": {
                  "type": "string",
                  "minLength": 0,
                  "maxLength": 320
                }
              },
              "required": [
                "id",
                "label"
              ]
            }
          },
          "hours": {
            "type": [
              "object",
              "null"
            ],
            "description": "The practice's opening hours for online booking, when set. Times are local to the time zone given.",
            "additionalProperties": false,
            "properties": {
              "start": {
                "type": "string",
                "pattern": "^[0-2][0-9]:[0-5][0-9]$"
              },
              "end": {
                "type": "string",
                "pattern": "^[0-2][0-9]:[0-5][0-9]$"
              },
              "timezone": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              }
            },
            "required": [
              "start",
              "end",
              "timezone"
            ]
          }
        },
        "required": [
          "items"
        ]
      },
      "ScheduleMarkers": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 1000,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "appointment_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "patient_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "new_patient": {
                  "type": "boolean"
                },
                "visit_id": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "forms": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "sent",
                        "in_progress",
                        "submitted",
                        "reviewed"
                      ]
                    },
                    "packet_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "status",
                    "packet_id"
                  ]
                },
                "insurance": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "active",
                        "not_active",
                        "not_checked",
                        "check_failed",
                        "self_pay"
                      ]
                    },
                    "coverage_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "checked_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "status"
                  ]
                },
                "copay": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "due_cents": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "paid_cents": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "test_paid_cents": {
                      "type": "integer",
                      "minimum": 0
                    }
                  },
                  "required": [
                    "due_cents",
                    "paid_cents",
                    "test_paid_cents"
                  ]
                },
                "balance_cents": {
                  "type": "integer",
                  "minimum": 0
                },
                "note": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "not_started",
                    "in_progress",
                    "signed",
                    null
                  ]
                },
                "charges": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "none",
                    "draft",
                    "posted",
                    null
                  ]
                }
              },
              "required": [
                "appointment_id",
                "patient_id",
                "new_patient",
                "visit_id",
                "forms"
              ]
            }
          },
          "billing": {
            "type": "boolean"
          },
          "insurance": {
            "type": "boolean"
          },
          "clinical": {
            "type": "boolean"
          }
        },
        "required": [
          "items",
          "billing",
          "insurance",
          "clinical"
        ]
      },
      "AppointmentMapping": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "source": {
            "type": "object",
            "description": "Immutable history ID, source identifiers, original source_data and normalized data; no inferred timezone/status/provider"
          },
          "native_appointment_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "policy": {
            "type": "string"
          }
        },
        "required": [
          "source",
          "native_appointment_id",
          "policy"
        ]
      },
      "PayerContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "payer_code": {
            "type": "string",
            "minLength": 0,
            "maxLength": 100
          },
          "phone": {
            "type": "string",
            "minLength": 0,
            "maxLength": 50
          },
          "address": {
            "type": "string",
            "minLength": 0,
            "maxLength": 1000
          },
          "active": {
            "type": "boolean"
          }
        },
        "required": [
          "name",
          "payer_code",
          "phone",
          "address",
          "active"
        ]
      },
      "CoverageContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "payer_id": {
            "type": "string",
            "format": "uuid"
          },
          "priority": {
            "type": "string",
            "enum": [
              "primary",
              "secondary",
              "tertiary"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "inactive",
              "entered_in_error"
            ]
          },
          "member_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 150
          },
          "group_number": {
            "type": "string",
            "minLength": 0,
            "maxLength": 150
          },
          "plan_name": {
            "type": "string",
            "minLength": 0,
            "maxLength": 200
          },
          "subscriber_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "subscriber_birth_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "relationship": {
            "type": "string",
            "enum": [
              "self",
              "spouse",
              "child",
              "other"
            ]
          },
          "effective_date": {
            "type": "string",
            "format": "date"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "copay_cents": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 100000000
          },
          "verification": {
            "type": "string",
            "enum": [
              "unverified",
              "manually_verified"
            ]
          },
          "notes": {
            "type": "string",
            "minLength": 0,
            "maxLength": 2000
          }
        },
        "required": [
          "payer_id",
          "priority",
          "status",
          "member_id",
          "group_number",
          "plan_name",
          "subscriber_name",
          "subscriber_birth_date",
          "relationship",
          "effective_date",
          "end_date",
          "copay_cents",
          "verification",
          "notes"
        ]
      },
      "ChargeLine": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code_system": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "description": "Local code unless catalog_release_id is supplied. Canonical CPT syntax: ^[0-9]{4}[0-9FTUM]$; HCPCS: ^[A-Z][0-9]{4}$. Syntax alone does not establish catalog assignment or coverage."
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000,
            "description": "Nonblank, at most 10000 UTF-8 bytes. A selected catalog supplies the publisher description."
          },
          "modifiers": {
            "type": "string",
            "minLength": 0,
            "maxLength": 100
          },
          "units": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000,
            "description": "Complete USD line total for the stated units; never multiplied by units again"
          },
          "diagnosis_codes": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "maxItems": 12
          },
          "catalog_release_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Optional tenant-owned catalog release. The server resolves the code and requires it to be active and billable for the service date. Only CPT or HCPCS; code_system must exactly match the selected catalog. Uses the billing account service_date."
          },
          "catalog_snapshot": {
            "$ref": "#/components/schemas/TerminologySelectionSnapshot",
            "readOnly": true,
            "description": "Server-resolved code and service-date provenance. Any supplied value is discarded and regenerated from catalog_release_id; omitted without a catalog selection."
          },
          "fee_schedule_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "fee_entry_key": {
            "type": [
              "string",
              "null"
            ],
            "description": "Canonical system:code:exact-modifiers key returned by the quote."
          },
          "fee_snapshot": {
            "$ref": "#/components/schemas/PracticeFeeSnapshot"
          },
          "fee_override_reason": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 1000,
            "description": "Required when an approved fee line amount differs from unit fee times units."
          }
        },
        "required": [
          "code_system",
          "code",
          "description",
          "modifiers",
          "units",
          "amount_cents",
          "diagnosis_codes"
        ]
      },
      "BillingAccountContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "coverage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "service_date": {
            "type": "string",
            "format": "date"
          },
          "currency": {
            "type": "string",
            "enum": [
              "USD"
            ]
          },
          "lines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChargeLine"
            },
            "minItems": 1,
            "maxItems": 100
          },
          "notes": {
            "type": "string",
            "minLength": 0,
            "maxLength": 2000
          },
          "fee_context": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/PracticeFeeContext"
              },
              {
                "type": "null"
              }
            ],
            "description": "Optional once-per-account fee context; provider is derived from the linked visit. Required for newly selected approved fee lines."
          }
        },
        "required": [
          "visit_id",
          "coverage_id",
          "service_date",
          "currency",
          "lines",
          "notes"
        ]
      },
      "NewPayer": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/PayerContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ]
      },
      "EditPayer": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "content": {
            "$ref": "#/components/schemas/PayerContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "content",
          "reason"
        ]
      },
      "Payer": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/PayerContent"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "id",
          "content",
          "version",
          "source_history_id"
        ]
      },
      "NewCoverage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/CoverageContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ]
      },
      "EditCoverage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "content": {
            "$ref": "#/components/schemas/CoverageContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "content",
          "reason"
        ]
      },
      "Coverage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/CoverageContent"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "id",
          "content",
          "version",
          "source_history_id"
        ]
      },
      "NewBillingAccount": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/BillingAccountContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ]
      },
      "EditBillingAccount": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "content": {
            "$ref": "#/components/schemas/BillingAccountContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "content",
          "reason"
        ]
      },
      "BillingAccount": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/BillingAccountContent"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "posted",
              "void"
            ]
          },
          "total_cents": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000000000
          },
          "coverage_snapshot": {
            "type": [
              "object",
              "null"
            ],
            "description": "Frozen payer and policy versions captured at local posting; no eligibility assertion"
          },
          "diagnosis_snapshot": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/AccountDiagnosisSnapshot"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "content",
          "version",
          "source_history_id",
          "patient_id",
          "status",
          "total_cents",
          "coverage_snapshot"
        ]
      },
      "BillingAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "post",
              "void"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "NewBillingEntry": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "payment",
              "adjustment_credit",
              "adjustment_debit",
              "reversal"
            ]
          },
          "amount_cents": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 1000000000
          },
          "reverses_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "party": {
            "type": "string",
            "enum": [
              "patient",
              "insurer",
              "other"
            ]
          },
          "method": {
            "type": "string",
            "enum": [
              "cash",
              "check",
              "external",
              "other",
              "none"
            ]
          },
          "reference": {
            "type": "string",
            "minLength": 0,
            "maxLength": 200
          },
          "occurred_on": {
            "type": "string",
            "format": "date"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "kind",
          "amount_cents",
          "reverses_id",
          "party",
          "method",
          "reference",
          "occurred_on",
          "reason"
        ]
      },
      "BillingEntry": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "payment",
              "adjustment_credit",
              "adjustment_debit",
              "reversal"
            ]
          },
          "effect_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "content": {
            "$ref": "#/components/schemas/BillingEntryContent"
          },
          "reverses_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "account_id",
          "kind",
          "effect_cents",
          "content",
          "reverses_id",
          "actor_id",
          "created_at"
        ]
      },
      "PatientBilling": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "coverages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Coverage"
            }
          },
          "accounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BillingAccount"
            }
          },
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BillingEntry"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "USD"
            ]
          },
          "payment_policy": {
            "type": "string",
            "minLength": 0,
            "maxLength": 500
          },
          "claims_policy": {
            "type": "string",
            "minLength": 0,
            "maxLength": 500
          },
          "copays": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CopayReceipt"
            },
            "description": "Bounded appointment receipt history with allocation and void state."
          }
        },
        "required": [
          "coverages",
          "accounts",
          "entries",
          "currency",
          "payment_policy",
          "claims_policy",
          "copays"
        ]
      },
      "BillingWorkItem": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_name": {
            "type": "string",
            "minLength": 0,
            "maxLength": 201
          },
          "mrn": {
            "type": "string",
            "minLength": 0,
            "maxLength": 64
          },
          "service_date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "posted",
              "void"
            ]
          },
          "version": {
            "type": "integer"
          },
          "total_cents": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000000000
          },
          "balance_cents": {
            "type": [
              "integer",
              "null"
            ]
          },
          "payer_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "id",
          "patient_id",
          "patient_name",
          "mrn",
          "service_date",
          "status",
          "version",
          "total_cents",
          "balance_cents",
          "payer_name",
          "source_history_id"
        ]
      },
      "BillingWorklist": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BillingWorkItem"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "currency": {
            "type": "string",
            "enum": [
              "USD"
            ]
          },
          "claims_policy": {
            "type": "string",
            "minLength": 0,
            "maxLength": 500
          }
        },
        "required": [
          "items",
          "next_cursor",
          "currency",
          "claims_policy"
        ]
      },
      "BillingHistory": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "version": {
                  "type": "integer"
                },
                "snapshot": {
                  "type": "object"
                },
                "actor_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "reason": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 1000
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "required": [
                "version",
                "snapshot",
                "actor_id",
                "reason",
                "created_at"
              ]
            }
          }
        },
        "required": [
          "items"
        ]
      },
      "BillingMapping": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "source_history_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "insurance",
              "billing",
              "transaction"
            ]
          },
          "data": {
            "type": "object"
          },
          "source_data": {
            "type": "object"
          },
          "native_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "policy": {
            "type": "string",
            "minLength": 0,
            "maxLength": 1000
          }
        },
        "required": [
          "source_history_id",
          "kind",
          "data",
          "source_data",
          "native_id",
          "policy"
        ]
      },
      "ClaimContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "billing_provider_name": {
            "type": "string",
            "maxLength": 200
          },
          "billing_npi": {
            "type": "string",
            "maxLength": 10
          },
          "tax_id": {
            "type": "string",
            "maxLength": 9
          },
          "billing_address": {
            "type": "string",
            "maxLength": 1000
          },
          "rendering_npi": {
            "type": "string",
            "maxLength": 10
          },
          "patient_address": {
            "type": "string",
            "maxLength": 1000
          },
          "subscriber_address": {
            "type": "string",
            "maxLength": 1000
          },
          "place_of_service": {
            "type": "string",
            "maxLength": 2
          },
          "external_control_number": {
            "type": "string",
            "maxLength": 100
          },
          "notes": {
            "type": "string",
            "maxLength": 2000
          },
          "subscriber_birth_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "diagnosis_codes": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 20
            },
            "maxItems": 12
          },
          "line_diagnosis_pointers": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "integer",
                "minimum": 1,
                "maximum": 12
              },
              "maxItems": 4
            },
            "maxItems": 100
          }
        },
        "required": [
          "billing_provider_name",
          "billing_npi",
          "tax_id",
          "billing_address",
          "rendering_npi",
          "patient_address",
          "subscriber_address",
          "place_of_service",
          "external_control_number",
          "notes",
          "subscriber_birth_date",
          "diagnosis_codes",
          "line_diagnosis_pointers"
        ]
      },
      "NewClaim": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "parent_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "frequency": {
            "enum": [
              "original",
              "replacement",
              "void_request"
            ]
          },
          "content": {
            "$ref": "#/components/schemas/ClaimContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "coordination": {
            "$ref": "#/components/schemas/SecondaryCoordinationRequest"
          },
          "crossover": {
            "$ref": "#/components/schemas/CrossoverTrackingRequest"
          }
        },
        "required": [
          "request_id",
          "frequency",
          "content",
          "reason"
        ]
      },
      "EditClaim": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "content": {
            "$ref": "#/components/schemas/ClaimContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "content",
          "reason"
        ]
      },
      "Claim": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "payer_id": {
            "type": "string",
            "format": "uuid"
          },
          "control_number": {
            "type": "string",
            "maxLength": 100
          },
          "frequency": {
            "enum": [
              "original",
              "replacement",
              "void_request"
            ]
          },
          "parent_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/ClaimContent"
          },
          "snapshot": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "account": {
                "$ref": "#/components/schemas/BillingAccount"
              },
              "patient": {
                "type": "object",
                "description": "Frozen patient demographic evidence"
              },
              "financial_summary": {
                "type": "object",
                "description": "Ledger totals frozen at claim creation, including combined account balance; not an automatic patient responsibility determination."
              },
              "coordination_of_benefits": {
                "type": "object",
                "description": "Frozen primary coverage/details/adjudication/source, reviewed paid units and previously posted primary credits. Optional crossover object binds received secondary remittance id/version/row/hash, payee NPI, trace/date and row evidence. Presence of crossover makes the claim tracking-only with no packet, CMS1500, 837 or delivery."
              }
            },
            "required": [
              "account",
              "patient"
            ]
          },
          "status": {
            "enum": [
              "draft",
              "ready",
              "submitted",
              "accepted",
              "rejected",
              "adjudicated",
              "void"
            ],
            "description": "For received crossover tracking, submitted means received secondary response linked for review; no outbound delivery is implied. Adjudicated follows reviewed ERA posting; void may follow reviewed withdrawal."
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "payer_control_number": {
            "type": "string",
            "maxLength": 150
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "id",
          "patient_id",
          "account_id",
          "payer_id",
          "control_number",
          "frequency",
          "parent_id",
          "content",
          "snapshot",
          "status",
          "version",
          "payer_control_number",
          "source_history_id"
        ]
      },
      "ClaimDetail": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "claim": {
            "$ref": "#/components/schemas/Claim"
          },
          "preflight_issues": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 300
            },
            "maxItems": 100
          },
          "transport": {
            "type": "object",
            "additionalProperties": true,
            "description": "Configured clearinghouse routes, artifact availability and retrieval health; unrelated to Connect WSS."
          },
          "tracking": {
            "$ref": "#/components/schemas/ClaimTracking"
          },
          "submission_defaults": {
            "type": "object",
            "additionalProperties": true,
            "description": "Structured review defaults from claim and chart; does not submit a claim."
          }
        },
        "required": [
          "claim",
          "preflight_issues",
          "transport"
        ]
      },
      "ClaimRemittanceAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "enum": [
              "ready",
              "void_draft",
              "record_submission",
              "record_acceptance",
              "record_rejection",
              "post",
              "reject",
              "reverse",
              "withdraw_crossover"
            ],
            "description": "withdraw_crossover only withdraws submitted/accepted/rejected crossover tracking without an active ERA head or non-void descendant; history remains. Normal outbound/manual submission events are refused for tracking records."
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "reference": {
            "type": "string",
            "maxLength": 200
          },
          "event_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "payer_control_number": {
            "type": "string",
            "maxLength": 150
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "EraAdjustment": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "group": {
            "type": "string",
            "maxLength": 5,
            "enum": [
              "CO",
              "PR",
              "OA",
              "PI",
              "CR"
            ]
          },
          "reason_code": {
            "type": "string",
            "maxLength": 20
          },
          "amount_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "service_index": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          }
        },
        "required": [
          "group",
          "reason_code",
          "amount_cents",
          "service_index"
        ]
      },
      "EraService": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string",
            "maxLength": 200
          },
          "charged_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "paid_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "line_control": {
            "type": "string",
            "maxLength": 100
          }
        },
        "required": [
          "code",
          "charged_cents",
          "paid_cents",
          "line_control"
        ]
      },
      "EraClaim": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "control_number": {
            "type": "string",
            "maxLength": 100
          },
          "payer_control_number": {
            "type": "string",
            "maxLength": 150
          },
          "status": {
            "type": "string",
            "maxLength": 10,
            "description": "Supported ordinary statuses 1,2,3,4,19,20,21; 22 is an exact-original signed reversal requiring a reviewed source posting."
          },
          "patient_name": {
            "type": "string",
            "maxLength": 300
          },
          "charged_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "paid_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "patient_responsibility_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "adjustments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EraAdjustment"
            },
            "maxItems": 100
          },
          "services": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EraService"
            },
            "maxItems": 100
          }
        },
        "required": [
          "control_number",
          "payer_control_number",
          "status",
          "patient_name",
          "charged_cents",
          "paid_cents",
          "patient_responsibility_cents",
          "adjustments",
          "services"
        ]
      },
      "EraDocument": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "payer_code": {
            "type": "string",
            "maxLength": 100
          },
          "trace": {
            "type": "string",
            "maxLength": 150
          },
          "payment_date": {
            "type": "string",
            "format": "date"
          },
          "total_paid_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000
          },
          "currency": {
            "type": "string",
            "maxLength": 10
          },
          "claims": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EraClaim"
            },
            "maxItems": 1000,
            "minItems": 0
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 300
            },
            "maxItems": 100000
          },
          "provider_adjustments": {
            "type": "array",
            "maxItems": 1000,
            "default": [],
            "items": {
              "$ref": "#/components/schemas/ProviderAdjustment"
            }
          },
          "payer_identity": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/EraPayerIdentity"
              },
              {
                "type": "null"
              }
            ],
            "description": "Omitted for historical normalized documents; existing evidence and hashes are not rewritten."
          },
          "supplemental": {
            "type": "array",
            "maxItems": 100000,
            "default": [],
            "items": {
              "$ref": "#/components/schemas/EraSupplementalEvidence"
            }
          }
        },
        "required": [
          "payer_code",
          "trace",
          "payment_date",
          "total_paid_cents",
          "currency",
          "claims"
        ],
        "description": "At least one claim or provider adjustment. USD BPR equals summed CLP paid cents minus signed PLB cents. Provider-only settlements and exact-original negative CLP22 supported; unsupported profiles remain held."
      },
      "ImportRemittance": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "payer_id": {
            "type": "string",
            "format": "uuid"
          },
          "format": {
            "enum": [
              "normalized",
              "x12_835"
            ]
          },
          "document": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/EraDocument"
              },
              {
                "type": "null"
              }
            ]
          },
          "original_text": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 1048576
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "remote_report_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "request_id",
          "payer_id",
          "format",
          "reason"
        ]
      },
      "EraMatch": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "row_index": {
            "type": "integer",
            "minimum": 0,
            "maximum": 999
          },
          "claim_id": {
            "type": "string",
            "format": "uuid"
          },
          "claim_version": {
            "type": "integer",
            "minimum": 1
          },
          "account_version": {
            "type": "integer",
            "minimum": 1
          },
          "writeoff_adjustments": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 99
            },
            "maxItems": 100
          },
          "reverses_remittance_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Required for CLP22; exact posted original remittance"
          },
          "reverses_row_index": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 999,
            "description": "Zero-based original posted claim row required for CLP22"
          },
          "correction_of_remittance_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Explicit positive-correction source: the active exact reversal remittance, including an earlier transaction in the same batch."
          },
          "correction_of_row_index": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 999,
            "description": "Zero-based reversal row; pair with correction_of_remittance_id."
          }
        },
        "required": [
          "row_index",
          "claim_id",
          "claim_version",
          "account_version",
          "writeoff_adjustments"
        ]
      },
      "EraMatches": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "matches": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EraMatch"
            },
            "maxItems": 1000
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "matches",
          "reason"
        ]
      },
      "Remittance": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "payer_id": {
            "type": "string",
            "format": "uuid"
          },
          "trace": {
            "type": "string",
            "maxLength": 150
          },
          "document": {
            "$ref": "#/components/schemas/EraDocument"
          },
          "original_text": {
            "type": [
              "string",
              "null"
            ]
          },
          "document_hash": {
            "type": "string",
            "maxLength": 64
          },
          "status": {
            "enum": [
              "staged",
              "reconciled",
              "posted",
              "reversed",
              "rejected"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "matches": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EraMatch"
            },
            "maxItems": 1000
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "id",
          "payer_id",
          "trace",
          "document",
          "original_text",
          "document_hash",
          "status",
          "version",
          "matches",
          "source_history_id"
        ]
      },
      "RemittanceDetail": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "remittance": {
            "$ref": "#/components/schemas/Remittance"
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 300
            }
          },
          "postings": {
            "type": "array",
            "items": {
              "type": "object",
              "description": "Immutable account/claim/PR/selected CO posting evidence plus an explicitly current account balance projection; negative means patient credit.",
              "properties": {
                "current_account_balance_cents": {
                  "type": "integer",
                  "format": "int64",
                  "description": "Current charges plus net ledger, computed when read. A negative value is a patient credit. This projection does not modify original posting evidence or saved invoice snapshots."
                }
              }
            },
            "maxItems": 1000
          },
          "ready_to_post": {
            "type": "boolean"
          },
          "automation": {
            "type": [
              "object",
              "null"
            ],
            "description": "Provider staging provenance and immutable findings; suggested matches still require staff review",
            "properties": {
              "report_id": {
                "type": "string",
                "format": "uuid"
              },
              "issues": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "batch_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "remittance",
          "issues",
          "postings",
          "ready_to_post",
          "automation",
          "batch_id"
        ]
      },
      "ClaimPacket": {
        "type": "object",
        "description": "SunCharts JSON packet with frozen patient, payer, account and reviewed provider/diagnosis content. not_x12_837=true. No transmission or automatic claim state change."
      },
      "ClaimWorklist": {
        "type": "object",
        "description": "Tenant-scoped claim summary page with patient_name, payer_name, coverage_priority, total_cents, lifecycle and boolean crossover_tracking_only; at most100 items. Tracking-only submitted rows represent a received secondary response, not an EHR transmission.",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "maxItems": 100
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "RemittanceWorklist": {
        "type": "object",
        "description": "Tenant-scoped remittance summary page; at most 100 items",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "maxItems": 100
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "EraMatchResult": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "remittance": {
            "$ref": "#/components/schemas/Remittance"
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 300
            }
          }
        },
        "required": [
          "remittance",
          "issues"
        ]
      },
      "ClaimSourceMapping": {
        "type": "object",
        "properties": {
          "source_history_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_data": {
            "type": "object"
          },
          "native_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "policy": {
            "type": "string"
          }
        }
      },
      "RemittanceSources": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "properties": {
                "source_history_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "source_instance": {
                  "type": "string"
                },
                "source_id": {
                  "type": "string"
                },
                "source_data": {
                  "type": "object"
                },
                "native_id": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                }
              }
            }
          }
        }
      },
      "EdiPartnerContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "sender_id": {
            "type": "string",
            "maxLength": 15
          },
          "receiver_id": {
            "type": "string",
            "maxLength": 15
          },
          "application_sender": {
            "type": "string",
            "maxLength": 15
          },
          "application_receiver": {
            "type": "string",
            "maxLength": 15
          },
          "submitter_name": {
            "type": "string",
            "maxLength": 60
          },
          "submitter_id": {
            "type": "string",
            "maxLength": 80
          },
          "receiver_name": {
            "type": "string",
            "maxLength": 60
          },
          "receiver_identifier": {
            "type": "string",
            "maxLength": 80
          },
          "contact_name": {
            "type": "string",
            "maxLength": 60
          },
          "contact_phone": {
            "type": "string",
            "maxLength": 10
          },
          "guide_reference": {
            "type": "string",
            "maxLength": 200
          },
          "active": {
            "type": "boolean"
          },
          "sender_qualifier": {
            "enum": [
              "ZZ",
              "01",
              "14",
              "30"
            ]
          },
          "receiver_qualifier": {
            "enum": [
              "ZZ",
              "01",
              "14",
              "30"
            ]
          },
          "usage": {
            "enum": [
              "T",
              "P"
            ]
          }
        },
        "required": [
          "name",
          "sender_id",
          "receiver_id",
          "application_sender",
          "application_receiver",
          "submitter_name",
          "submitter_id",
          "receiver_name",
          "receiver_identifier",
          "contact_name",
          "contact_phone",
          "guide_reference",
          "active",
          "sender_qualifier",
          "receiver_qualifier",
          "usage"
        ]
      },
      "EdiPartner": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/EdiPartnerContent"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "id",
          "content",
          "version",
          "source_history_id"
        ]
      },
      "NewEdiPartner": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/EdiPartnerContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ]
      },
      "EditEdiPartner": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "content": {
            "$ref": "#/components/schemas/EdiPartnerContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "content",
          "reason"
        ]
      },
      "EdiAddress": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "line1": {
            "type": "string",
            "maxLength": 55
          },
          "line2": {
            "type": "string",
            "maxLength": 55
          },
          "city": {
            "type": "string",
            "maxLength": 30
          },
          "state": {
            "type": "string",
            "maxLength": 2
          },
          "postal_code": {
            "type": "string",
            "maxLength": 9
          }
        },
        "required": [
          "line1",
          "line2",
          "city",
          "state",
          "postal_code"
        ]
      },
      "EdiClaimDetails": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "billing_address": {
            "$ref": "#/components/schemas/EdiAddress"
          },
          "subscriber_address": {
            "$ref": "#/components/schemas/EdiAddress"
          },
          "patient_address": {
            "$ref": "#/components/schemas/EdiAddress"
          },
          "payer_address": {
            "$ref": "#/components/schemas/EdiAddress"
          },
          "subscriber_given_name": {
            "type": "string",
            "maxLength": 35
          },
          "subscriber_family_name": {
            "type": "string",
            "maxLength": 35
          },
          "rendering_given_name": {
            "type": "string",
            "maxLength": 35
          },
          "rendering_family_name": {
            "type": "string",
            "maxLength": 35
          },
          "patient_sex": {
            "enum": [
              "U",
              "F",
              "M"
            ]
          },
          "subscriber_sex": {
            "enum": [
              "U",
              "F",
              "M"
            ]
          },
          "billing_taxonomy": {
            "type": "string",
            "maxLength": 10
          },
          "filing_indicator": {
            "enum": [
              "CI",
              "MB",
              "MC",
              "MA",
              "CH",
              "VA",
              "TV",
              "WC",
              "ZZ"
            ]
          },
          "signature_on_file": {
            "type": "boolean"
          },
          "benefits_assigned": {
            "type": "boolean"
          },
          "release_authorized": {
            "type": "boolean"
          },
          "routine_professional_reviewed": {
            "type": "boolean"
          }
        },
        "required": [
          "billing_address",
          "subscriber_address",
          "patient_address",
          "payer_address",
          "subscriber_given_name",
          "subscriber_family_name",
          "rendering_given_name",
          "rendering_family_name",
          "patient_sex",
          "subscriber_sex",
          "billing_taxonomy",
          "filing_indicator",
          "signature_on_file",
          "benefits_assigned",
          "release_authorized",
          "routine_professional_reviewed"
        ]
      },
      "Generate837P": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "partner_id": {
            "type": "string",
            "format": "uuid"
          },
          "partner_version": {
            "type": "integer",
            "minimum": 1
          },
          "details": {
            "$ref": "#/components/schemas/EdiClaimDetails"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "partner_id",
          "partner_version",
          "details",
          "reason"
        ]
      },
      "EdiSubmission": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "claim_id": {
            "type": "string",
            "format": "uuid"
          },
          "partner_id": {
            "type": "string",
            "format": "uuid"
          },
          "claim_version": {
            "type": "integer",
            "minimum": 1
          },
          "partner_version": {
            "type": "integer",
            "minimum": 1
          },
          "claim_snapshot": {
            "$ref": "#/components/schemas/Claim"
          },
          "partner_snapshot": {
            "$ref": "#/components/schemas/EdiPartner"
          },
          "details": {
            "$ref": "#/components/schemas/EdiClaimDetails"
          },
          "payload": {
            "type": "string",
            "maxLength": 48000
          },
          "payload_hash": {
            "type": "string",
            "maxLength": 64
          },
          "interchange_control": {
            "type": "string",
            "maxLength": 9
          },
          "group_control": {
            "type": "string",
            "maxLength": 9
          },
          "transaction_control": {
            "type": "string",
            "maxLength": 9
          },
          "status": {
            "enum": [
              "prepared",
              "delivered",
              "cancelled"
            ]
          },
          "technical_status": {
            "enum": [
              "pending",
              "accepted",
              "rejected",
              "needs_review"
            ]
          },
          "payer_outcome": {
            "enum": [
              "pending",
              "accepted",
              "rejected"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "delivered_claim_version": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          }
        },
        "required": [
          "id",
          "claim_id",
          "partner_id",
          "claim_version",
          "partner_version",
          "claim_snapshot",
          "partner_snapshot",
          "details",
          "payload",
          "payload_hash",
          "interchange_control",
          "group_control",
          "transaction_control",
          "status",
          "technical_status",
          "payer_outcome",
          "version",
          "delivered_claim_version"
        ]
      },
      "EdiSubmissionAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "enum": [
              "cancel",
              "record_delivery",
              "record_payer_acceptance",
              "record_payer_rejection"
            ]
          },
          "reference": {
            "type": "string",
            "maxLength": 200
          },
          "event_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "claim_version": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "payer_control_number": {
            "type": "string",
            "maxLength": 150
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "ImportEdiAcknowledgment": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "format": {
            "enum": [
              "x12_999",
              "x12_ta1",
              "x12_277ca"
            ]
          },
          "original_text": {
            "type": "string",
            "maxLength": 48000
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "remote_report_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "format",
          "original_text",
          "reason"
        ]
      },
      "EdiAcknowledgmentResult": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "submission": {
            "$ref": "#/components/schemas/EdiSubmission"
          },
          "parsed": {
            "type": "object",
            "properties": {
              "outcome": {
                "enum": [
                  "accepted",
                  "rejected",
                  "needs_review"
                ]
              },
              "issues": {
                "type": "array",
                "maxItems": 100,
                "items": {
                  "type": "string",
                  "maxLength": 300
                }
              },
              "format": {
                "type": "string",
                "maxLength": 20
              },
              "claim_acceptance": {
                "const": false
              }
            }
          },
          "acknowledgment_id": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "submission",
          "parsed",
          "acknowledgment_id"
        ]
      },
      "EdiSubmissionDetail": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "submission": {
            "$ref": "#/components/schemas/EdiSubmission"
          },
          "claim": {
            "$ref": "#/components/schemas/Claim"
          },
          "events": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object"
            }
          },
          "acknowledgments": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "description": "Immutable original text/hash, parsed results, source link and attributed reason"
            }
          },
          "transport": {
            "enum": [
              "manual_file",
              "https_gateway_and_manual_file",
              "provider_adapters_and_manual_file"
            ]
          },
          "network_sender_configured": {
            "type": "boolean"
          }
        },
        "required": [
          "submission",
          "claim",
          "events",
          "acknowledgments",
          "transport",
          "network_sender_configured"
        ]
      },
      "EdiPartners": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/EdiPartner"
            }
          },
          "transport": {
            "enum": [
              "manual_file",
              "https_gateway_and_manual_file",
              "provider_adapters_and_manual_file"
            ]
          },
          "network_sender_configured": {
            "type": "boolean"
          }
        },
        "required": [
          "items",
          "transport",
          "network_sender_configured"
        ]
      },
      "EdiPartnerDetail": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "partner": {
            "$ref": "#/components/schemas/EdiPartner"
          },
          "history": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object"
            }
          }
        },
        "required": [
          "partner",
          "history"
        ]
      },
      "EdiSubmissionWorklist": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "description": "Patient/claim/partner, frozen usage, control identifiers and independent delivery/technical/payer states"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "transport": {
            "enum": [
              "manual_file",
              "https_gateway_and_manual_file",
              "provider_adapters_and_manual_file"
            ]
          }
        },
        "required": [
          "items",
          "next_cursor",
          "transport"
        ]
      },
      "EdiSources": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "description": "Tenant scoped x12_partner/edi_acknowledgment source evidence and native reconciliation ID"
            }
          }
        },
        "required": [
          "items"
        ]
      },
      "QueueEdiDelivery": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "route_key": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "route_key",
          "reason"
        ]
      },
      "EdiDeliveryDecision": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "enum": [
              "cancel",
              "confirmed_received",
              "confirmed_not_received"
            ]
          },
          "reference": {
            "type": "string",
            "maxLength": 200
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "EdiDeliveryJob": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "tenant_id": {
            "type": "string",
            "format": "uuid"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "submission_id": {
            "type": "string",
            "format": "uuid"
          },
          "route_key": {
            "type": "string"
          },
          "requested_by": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "enum": [
              "queued",
              "leased",
              "retry",
              "unknown",
              "blocked",
              "delivered",
              "cancelled"
            ]
          },
          "version": {
            "type": "integer"
          },
          "attempts": {
            "type": "integer"
          },
          "lease_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "receipt_reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "receipt": {
            "type": "object"
          },
          "last_result": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "submission_id",
          "route_key",
          "requested_by",
          "status",
          "version",
          "attempts",
          "lease_id",
          "receipt_reference",
          "receipt",
          "last_result"
        ]
      },
      "EdiDeliveryRoute": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "key": {
            "type": "string"
          },
          "partner_id": {
            "type": "string",
            "format": "uuid"
          },
          "usage": {
            "enum": [
              "T",
              "P"
            ]
          },
          "loopback_test": {
            "type": "boolean"
          },
          "credential_configured": {
            "type": "boolean"
          },
          "adapter": {
            "enum": [
              "gateway",
              "stedi",
              "claim_md",
              "office_ally_sftp",
              "availity_sftp"
            ]
          },
          "retrieval_enabled": {
            "type": "boolean"
          }
        },
        "required": [
          "key",
          "partner_id",
          "usage",
          "loopback_test",
          "credential_configured"
        ]
      },
      "EdiDeliveryRoutes": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EdiDeliveryRoute"
            }
          },
          "worker": {
            "type": "string"
          }
        },
        "required": [
          "items",
          "worker"
        ]
      },
      "EdiDeliveryJobs": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EdiDeliveryJob"
            }
          },
          "limit": {
            "type": "integer",
            "const": 100
          }
        },
        "required": [
          "items",
          "limit"
        ]
      },
      "EdiDeliveryDetail": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "job": {
            "$ref": "#/components/schemas/EdiDeliveryJob"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "required": [
          "job",
          "events"
        ]
      },
      "Import277CA": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "original_text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 48000
          },
          "origin": {
            "enum": [
              "clearinghouse",
              "payer"
            ]
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "remote_report_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "request_id",
          "original_text",
          "origin",
          "reason"
        ]
      },
      "Review277CA": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "submission_id": {
            "type": "string",
            "format": "uuid"
          },
          "submission_version": {
            "type": "integer",
            "minimum": 1
          },
          "claim_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "submission_id",
          "submission_version",
          "claim_version",
          "reason"
        ]
      },
      "CA277Status": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "category": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "entity": {
            "type": "string"
          },
          "date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "action": {
            "type": "string"
          },
          "amount_cents": {
            "type": [
              "integer",
              "null"
            ]
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "category",
          "code",
          "entity",
          "date",
          "action",
          "amount_cents",
          "message"
        ]
      },
      "CA277Service": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string"
          },
          "amount_cents": {
            "type": [
              "integer",
              "null"
            ]
          },
          "line_control": {
            "type": "string"
          },
          "statuses": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CA277Status"
            }
          },
          "dates": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "required": [
          "code",
          "amount_cents",
          "line_control",
          "statuses",
          "dates"
        ]
      },
      "CA277Row": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "transaction": {
            "type": "string"
          },
          "control": {
            "type": "string"
          },
          "payer_id": {
            "type": "string"
          },
          "receiver_id": {
            "type": "string"
          },
          "provider_npi": {
            "type": "string"
          },
          "patient_name": {
            "type": "string"
          },
          "member_id": {
            "type": "string"
          },
          "payer_control": {
            "type": "string"
          },
          "intermediary_control": {
            "type": "string"
          },
          "outcome": {
            "type": "string"
          },
          "statuses": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CA277Status"
            }
          },
          "ancestor_statuses": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CA277Status"
            }
          },
          "services": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CA277Service"
            }
          },
          "references": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "dates": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "transaction",
          "control",
          "payer_id",
          "receiver_id",
          "provider_npi",
          "patient_name",
          "member_id",
          "payer_control",
          "intermediary_control",
          "outcome",
          "statuses",
          "ancestor_statuses",
          "services",
          "references",
          "dates",
          "issues"
        ]
      },
      "CA277Parsed": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "transactions": {
            "type": "integer"
          },
          "claims": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CA277Row"
            }
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "transactions",
          "claims",
          "issues"
        ]
      },
      "CA277ImportResult": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "parsed": {
            "$ref": "#/components/schemas/CA277Parsed"
          },
          "origin": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "parsed",
          "origin"
        ]
      },
      "CA277Document": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "original_text": {
            "type": "string"
          },
          "original_hash": {
            "type": "string"
          },
          "parsed": {
            "$ref": "#/components/schemas/CA277Parsed"
          },
          "origin": {
            "type": "string"
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "id",
          "original_text",
          "original_hash",
          "parsed",
          "origin"
        ]
      },
      "CA277Detail": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "document": {
            "$ref": "#/components/schemas/CA277Document"
          },
          "reviews": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "required": [
          "document",
          "reviews"
        ]
      },
      "CA277List": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "limit": {
            "type": "integer",
            "const": 100
          }
        },
        "required": [
          "items",
          "limit"
        ]
      },
      "CA277Applied": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "document_id": {
            "type": "string",
            "format": "uuid"
          },
          "row": {
            "type": "integer"
          },
          "outcome": {
            "type": "string"
          },
          "origin": {
            "type": "string"
          },
          "claim_changed": {
            "type": "boolean"
          }
        },
        "required": [
          "document_id",
          "row",
          "outcome",
          "origin",
          "claim_changed"
        ]
      },
      "ProviderConnection": {
        "type": "object",
        "properties": {
          "route_key": {
            "type": "string"
          },
          "partner_id": {
            "type": "string",
            "format": "uuid"
          },
          "adapter": {
            "type": "string"
          },
          "usage": {
            "enum": [
              "T",
              "P"
            ]
          },
          "paused": {
            "type": "boolean"
          },
          "version": {
            "type": "integer"
          },
          "pages": {
            "type": "integer"
          },
          "cursor_saved": {
            "type": "boolean"
          },
          "last_result": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_poll_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_success_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "next_poll_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "description": "Safe tenant-scoped durable state; endpoints, secrets, binding hash and opaque page token are excluded."
      },
      "ProviderConnectionList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ProviderConnection"
            }
          }
        },
        "required": [
          "items"
        ]
      },
      "ProviderConnectionDetail": {
        "type": "object",
        "properties": {
          "connection": {
            "$ref": "#/components/schemas/ProviderConnection"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "required": [
          "connection",
          "events"
        ]
      },
      "ProviderConnectionAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "enum": [
              "pause",
              "resume",
              "poll_now"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "RetrievedReport": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "route_key": {
            "type": "string"
          },
          "remote_id": {
            "type": "string"
          },
          "format": {
            "type": "string"
          },
          "status": {
            "enum": [
              "pending",
              "leased",
              "retrieved",
              "quarantined",
              "ignored"
            ]
          },
          "version": {
            "type": "integer"
          },
          "attempts": {
            "type": "integer"
          },
          "original_text": {
            "type": [
              "string",
              "null"
            ]
          },
          "original_hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "metadata": {
            "type": "object"
          },
          "parse_summary": {
            "type": "object"
          },
          "native_kind": {
            "type": [
              "string",
              "null"
            ]
          },
          "native_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "description": "Original text and metadata appear in detail only. Immutable provider/account/report identity, content/hash and native links; bounded append-only events."
      },
      "RetrievedReportList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RetrievedReport"
            }
          },
          "limit": {
            "const": 100
          }
        },
        "required": [
          "items",
          "limit"
        ]
      },
      "RetrievedReportDetail": {
        "type": "object",
        "properties": {
          "report": {
            "$ref": "#/components/schemas/RetrievedReport"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "required": [
          "report",
          "events"
        ]
      },
      "RetrievedReportAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "enum": [
              "retry_download",
              "link_status_evidence"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "submission_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "submission_version": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "claim_version": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "ProviderSourceMapping": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_history_id": {
            "type": "string",
            "format": "uuid"
          },
          "partner_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "source_history_id",
          "partner_id",
          "reason"
        ]
      },
      "EraAutomationFeedAction": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "action",
          "reason"
        ],
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "enable_staging",
              "disable_staging",
              "poll_now"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "EraAutomationFeed": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "route_key": {
            "type": "string"
          },
          "auto_stage": {
            "type": "boolean"
          },
          "paused": {
            "type": "boolean"
          },
          "cursor_saved": {
            "type": "boolean"
          },
          "version": {
            "type": "integer",
            "format": "int64"
          },
          "pages": {
            "type": "integer",
            "format": "int64"
          },
          "next_poll_at": {
            "type": "string",
            "format": "date-time"
          },
          "lease_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_success_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_result": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "route_key",
          "auto_stage",
          "paused",
          "cursor_saved",
          "version",
          "pages",
          "next_poll_at"
        ]
      },
      "EraAutomationOutcome": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "report_id": {
            "type": "string",
            "format": "uuid"
          },
          "route_key": {
            "type": "string"
          },
          "remote_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "held",
              "staged"
            ]
          },
          "remittance_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "remittance_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "remittance_version": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Immutable findings at staging, not a current posting authorization"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "report_id",
          "route_key",
          "remote_id",
          "status",
          "remittance_id",
          "issues",
          "created_at"
        ]
      },
      "EraAutomationWorklist": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "feeds": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/EraAutomationFeed"
            }
          },
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/EraAutomationOutcome"
            }
          },
          "events": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "properties": {
                "route_key": {
                  "type": "string"
                },
                "version": {
                  "type": "integer",
                  "format": "int64"
                },
                "actor_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "reason": {
                  "type": "string"
                },
                "evidence": {
                  "type": "object"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "ledger_posting": {
            "type": "string",
            "enum": [
              "staff_review_required"
            ]
          }
        },
        "required": [
          "feeds",
          "items",
          "events",
          "ledger_posting"
        ]
      },
      "ProviderAdjustment": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "provider_id",
          "fiscal_date",
          "reason_code",
          "reference",
          "amount_cents"
        ],
        "properties": {
          "provider_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "fiscal_date": {
            "type": "string",
            "format": "date"
          },
          "reason_code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 5
          },
          "reference": {
            "type": "string",
            "maxLength": 150
          },
          "amount_cents": {
            "type": "integer",
            "minimum": -1000000000,
            "maximum": 1000000000,
            "description": "Signed PLB source amount. Positive decreases provider settlement cash; negative increases it."
          }
        }
      },
      "ProviderSettlementDecision": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "index",
          "category"
        ],
        "properties": {
          "index": {
            "type": "integer",
            "minimum": 0,
            "maximum": 999
          },
          "category": {
            "type": "string",
            "enum": [
              "forward_balance",
              "recoupment",
              "overpayment_offset",
              "refund",
              "interest",
              "other"
            ]
          },
          "original_remittance_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "ProviderSettlementReview": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "decisions",
          "reason"
        ],
        "properties": {
          "decisions": {
            "type": "array",
            "maxItems": 1000,
            "items": {
              "$ref": "#/components/schemas/ProviderSettlementDecision"
            }
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "RecoupmentAction": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "action",
          "reason"
        ],
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "dispute",
              "acknowledge",
              "close",
              "reopen"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "ProviderSettlementDetail": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version",
          "status",
          "adjustments",
          "reviews",
          "entries",
          "suggested_classifications"
        ],
        "properties": {
          "version": {
            "type": "integer",
            "format": "int64"
          },
          "status": {
            "type": "string"
          },
          "adjustments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ProviderAdjustment"
            }
          },
          "reviews": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "remittance_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "version": {
                  "type": "integer",
                  "format": "int64"
                },
                "decisions": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ProviderSettlementDecision"
                  }
                },
                "actor_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "reason": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "entries": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "remittance_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "row_index": {
                  "type": "integer"
                },
                "provider_id": {
                  "type": "string"
                },
                "payer_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "effect_cents": {
                  "type": "integer",
                  "format": "int64"
                },
                "category": {
                  "type": "string"
                },
                "evidence": {
                  "type": "object"
                },
                "reverses_id": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uuid"
                },
                "actor_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "reason": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "suggested_classifications": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ProviderSettlementDecision"
            }
          }
        }
      },
      "RecoupmentWorklist": {
        "type": "object",
        "required": [
          "items"
        ],
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "required": [
                "id",
                "remittance_id",
                "row_index",
                "version",
                "status",
                "trace",
                "payer_id",
                "adjustment",
                "events"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "remittance_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "row_index": {
                  "type": "integer"
                },
                "version": {
                  "type": "integer",
                  "format": "int64"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "open",
                    "disputed",
                    "acknowledged",
                    "closed",
                    "void"
                  ]
                },
                "trace": {
                  "type": "string"
                },
                "payer_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "adjustment": {
                  "$ref": "#/components/schemas/ProviderAdjustment"
                },
                "events": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "case_id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "version": {
                        "type": "integer",
                        "format": "int64"
                      },
                      "actor_id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "reason": {
                        "type": "string"
                      },
                      "evidence": {
                        "type": "object"
                      },
                      "created_at": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "EraBatchImport": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "original_text",
          "payer_ids",
          "reason"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "original_text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1048576,
            "description": "Exact original ASCII 835 file, up to 1 MiB, 100 transaction sets and 100,000 segments; multiple groups/interchanges or unwrapped transactions."
          },
          "payer_ids": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Native payer IDs in source transaction order; exact payer-code match required."
          },
          "source_history_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "remote_report_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "EraBatchVersion": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "version"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "EraBatchAction": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "action",
          "versions",
          "reason"
        ],
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "reconcile",
              "post",
              "reverse"
            ]
          },
          "versions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/EraBatchVersion"
            },
            "description": "Exact ordered child versions from batch detail. Posting also requires the previously reconciled vector."
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "ProviderSetting": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "partner_id",
          "provider",
          "usage",
          "label",
          "route_key",
          "start_at",
          "response_id",
          "interval_seconds",
          "enabled",
          "verified",
          "last_test_at",
          "last_test_result",
          "version",
          "credential_configured"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "partner_id": {
            "type": "string",
            "format": "uuid"
          },
          "provider": {
            "const": "claim_md"
          },
          "usage": {
            "type": "string",
            "enum": [
              "T",
              "P"
            ]
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "route_key": {
            "type": "string"
          },
          "start_at": {
            "type": "string",
            "format": "date-time"
          },
          "response_id": {
            "type": "string",
            "pattern": "^[0-9]{1,20}$"
          },
          "interval_seconds": {
            "type": "integer",
            "minimum": 30,
            "maximum": 86400
          },
          "enabled": {
            "type": "boolean"
          },
          "verified": {
            "type": "boolean"
          },
          "last_test_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_test_result": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "credential_configured": {
            "const": true
          }
        },
        "description": "Owner-only redacted Claim.MD configuration. Credentials, ciphertext, fingerprints and private key paths are never returned."
      },
      "SaveProviderSetting": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "label",
          "partner_id",
          "usage",
          "start_at"
        ],
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "partner_id": {
            "type": "string",
            "format": "uuid"
          },
          "usage": {
            "type": "string",
            "enum": [
              "T",
              "P"
            ]
          },
          "start_at": {
            "type": "string",
            "format": "date-time"
          },
          "response_id": {
            "type": "string",
            "pattern": "^[0-9]{1,20}$"
          },
          "interval_seconds": {
            "type": "integer",
            "minimum": 30,
            "maximum": 86400
          },
          "account_key": {
            "type": "string",
            "minLength": 8,
            "maxLength": 512,
            "writeOnly": true,
            "description": "Required on creation; omit on update to keep saved key. No whitespace. A replacement key invalidates verification and creates a fresh route revision."
          }
        }
      },
      "ProviderSettings": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ProviderSetting"
            }
          },
          "credential_storage_ready": {
            "type": "boolean"
          },
          "key_configured": {
            "type": "boolean"
          },
          "key_storage": {
            "const": "server_private_file"
          },
          "provider": {
            "const": "claim_md"
          }
        }
      },
      "CheckoutVisitMetadata": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "in_progress",
              "signed"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "signed_by": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "signed_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "appointment_id",
          "clinician_id",
          "status",
          "version",
          "signed_by",
          "signed_at",
          "created_at"
        ]
      },
      "AvsContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "instructions": {
            "type": "string",
            "maxLength": 10000,
            "minLength": 1
          },
          "follow_up_instructions": {
            "type": "string",
            "maxLength": 5000,
            "minLength": 0
          }
        },
        "required": [
          "instructions",
          "follow_up_instructions"
        ]
      },
      "AvsMedication": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "verification": {
            "type": "string"
          },
          "codes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ClinicalCoding"
            }
          },
          "dose": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "route": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "frequency": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "version",
          "title",
          "status",
          "verification",
          "codes",
          "dose",
          "route",
          "frequency"
        ]
      },
      "AvsAllergy": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "verification": {
            "type": "string"
          },
          "codes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ClinicalCoding"
            }
          },
          "reaction": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "severity": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "criticality": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "version",
          "title",
          "status",
          "verification",
          "codes",
          "reaction",
          "severity",
          "criticality"
        ]
      },
      "AvsProblem": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "verification": {
            "type": "string"
          },
          "codes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ClinicalCoding"
            }
          },
          "onset_date": {
            "anyOf": [
              {
                "type": "string",
                "format": "date"
              },
              {
                "type": "null"
              }
            ]
          },
          "problem_type": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "version",
          "title",
          "status",
          "verification",
          "codes",
          "onset_date",
          "problem_type"
        ]
      },
      "AvsListReview": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "allergy",
              "medication",
              "problem"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "review_state": {
            "type": "string",
            "enum": [
              "unknown",
              "needs_review",
              "reviewed",
              "no_known"
            ]
          },
          "reviewed_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "kind",
          "version",
          "review_state",
          "reviewed_at"
        ]
      },
      "AvsOrder": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "status": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "priority": {
            "type": "string"
          },
          "destination": {
            "type": "string"
          },
          "tests": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RequestedLabTest"
            }
          }
        },
        "required": [
          "id",
          "version",
          "status",
          "title",
          "category",
          "priority",
          "destination",
          "tests"
        ]
      },
      "AvsSnapshot": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "mrn": {
                "type": "string"
              },
              "given_name": {
                "type": "string"
              },
              "family_name": {
                "type": "string"
              },
              "birth_date": {
                "type": "string",
                "format": "date"
              }
            },
            "required": [
              "id",
              "mrn",
              "given_name",
              "family_name",
              "birth_date"
            ]
          },
          "visit": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "appointment_id": {
                "type": "string",
                "format": "uuid"
              },
              "visit_version": {
                "type": "integer",
                "minimum": 1
              },
              "signed_by": {
                "anyOf": [
                  {
                    "type": "string",
                    "format": "uuid"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "signed_at": {
                "anyOf": [
                  {
                    "type": "string",
                    "format": "date-time"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "title": {
                "type": "string"
              },
              "category": {
                "type": "string"
              },
              "starts_at": {
                "type": "string",
                "format": "date-time"
              },
              "clinician_id": {
                "type": "string",
                "format": "uuid"
              },
              "clinician_label": {
                "type": "string"
              },
              "facility": {
                "type": "string"
              },
              "room": {
                "type": "string"
              },
              "signed_by_label": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Name of the person who signed the note, when that is not the assigned clinician; otherwise null or absent."
              }
            },
            "required": [
              "id",
              "appointment_id",
              "visit_version",
              "signed_by",
              "signed_at",
              "title",
              "category",
              "starts_at",
              "clinician_id",
              "facility",
              "room"
            ]
          },
          "medications": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AvsMedication"
            },
            "maxItems": 100
          },
          "orders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AvsOrder"
            },
            "maxItems": 100
          },
          "allergies": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AvsAllergy"
            },
            "maxItems": 100
          },
          "problems": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AvsProblem"
            },
            "maxItems": 100
          },
          "list_reviews": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AvsListReview"
            },
            "maxItems": 3
          },
          "vitals": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Vitals"
              },
              {
                "type": "null"
              }
            ]
          },
          "snapshot_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "patient",
          "visit",
          "medications",
          "orders"
        ],
        "description": "Server-selected native clinical summary. No SOAP or private medication/order notes are copied. Optional allergy/problem/review/vitals fields may be absent in earlier releases; unknown and no-known remain distinct. Draft/cancelled order status is retained."
      },
      "AvsRelease": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "content": {
            "$ref": "#/components/schemas/AvsContent"
          },
          "snapshot": {
            "$ref": "#/components/schemas/AvsSnapshot"
          },
          "released_by": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          },
          "released_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "visit_id",
          "version",
          "content",
          "snapshot",
          "released_by",
          "reason",
          "released_at"
        ]
      },
      "PatientAvsRelease": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "content": {
            "$ref": "#/components/schemas/AvsContent"
          },
          "snapshot": {
            "$ref": "#/components/schemas/AvsSnapshot"
          },
          "released_by": {
            "type": "string",
            "format": "uuid"
          },
          "released_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "visit_id",
          "version",
          "content",
          "snapshot",
          "released_by",
          "released_at"
        ]
      },
      "CheckoutEvent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "checkout_version": {
            "type": "integer",
            "minimum": 1
          },
          "action": {
            "type": "string",
            "enum": [
              "release_avs",
              "delivery",
              "checkout"
            ]
          },
          "avs_version": {
            "type": "integer",
            "minimum": 1
          },
          "method": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "print",
                  "declined",
                  "other"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "visit_id",
          "checkout_version",
          "action",
          "avs_version",
          "method",
          "reason",
          "actor_id",
          "created_at"
        ]
      },
      "CheckoutState": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "completed": {
            "type": "boolean"
          },
          "checked_out_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "checked_out_by": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "completed",
          "checked_out_at",
          "checked_out_by"
        ]
      },
      "FollowUpTask": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "title": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1
          },
          "instructions": {
            "type": "string",
            "maxLength": 4000,
            "minLength": 1
          },
          "assignee_id": {
            "type": "string",
            "format": "uuid"
          },
          "assignee_label": {
            "type": "string"
          },
          "assignee_enabled": {
            "type": "boolean"
          },
          "due_date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "completed",
              "cancelled"
            ]
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "patient_name": {
            "type": "string"
          },
          "mrn": {
            "type": "string"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "can_update": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "patient_id",
          "visit_id",
          "version",
          "title",
          "instructions",
          "assignee_id",
          "assignee_label",
          "assignee_enabled",
          "due_date",
          "status",
          "created_by",
          "created_at",
          "updated_at",
          "patient_name",
          "mrn",
          "starts_at",
          "can_update"
        ]
      },
      "FollowUpEvent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "snapshot": {
            "type": "object",
            "description": "Immutable task snapshot including identity, assignee, due date and lifecycle state; excludes tenant, creation hash and request UUID."
          },
          "action": {
            "type": "string",
            "enum": [
              "create",
              "complete",
              "cancel",
              "reopen",
              "reassign",
              "reschedule"
            ]
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "version",
          "snapshot",
          "action",
          "reason",
          "actor_id",
          "created_at"
        ]
      },
      "FollowUpTaskDetail": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "title": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1
          },
          "instructions": {
            "type": "string",
            "maxLength": 4000,
            "minLength": 1
          },
          "assignee_id": {
            "type": "string",
            "format": "uuid"
          },
          "assignee_label": {
            "type": "string"
          },
          "assignee_enabled": {
            "type": "boolean"
          },
          "due_date": {
            "type": "string",
            "format": "date"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "completed",
              "cancelled"
            ]
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "patient_name": {
            "type": "string"
          },
          "mrn": {
            "type": "string"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "can_update": {
            "type": "boolean"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FollowUpEvent"
            },
            "maxItems": 100
          },
          "events_truncated": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "patient_id",
          "visit_id",
          "version",
          "title",
          "instructions",
          "assignee_id",
          "assignee_label",
          "assignee_enabled",
          "due_date",
          "status",
          "created_by",
          "created_at",
          "updated_at",
          "patient_name",
          "mrn",
          "starts_at",
          "can_update",
          "events",
          "events_truncated"
        ]
      },
      "CheckoutDetail": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "visit": {
            "$ref": "#/components/schemas/CheckoutVisitMetadata"
          },
          "preview_snapshot": {
            "$ref": "#/components/schemas/AvsSnapshot"
          },
          "preview_digest": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "Digest returned by checkout GET; recomputed under clinical-list/order serialization before release. No release timestamp participates."
          },
          "current_avs": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/AvsRelease"
              },
              {
                "type": "null"
              }
            ]
          },
          "releases": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AvsRelease"
            },
            "maxItems": 50
          },
          "releases_truncated": {
            "type": "boolean"
          },
          "checkout": {
            "$ref": "#/components/schemas/CheckoutState"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CheckoutEvent"
            },
            "maxItems": 100
          },
          "events_truncated": {
            "type": "boolean"
          },
          "followups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FollowUpTask"
            },
            "maxItems": 100
          },
          "followups_truncated": {
            "type": "boolean"
          }
        },
        "required": [
          "patient_id",
          "visit_id",
          "version",
          "visit",
          "preview_snapshot",
          "preview_digest",
          "current_avs",
          "releases",
          "releases_truncated",
          "checkout",
          "events",
          "events_truncated",
          "followups",
          "followups_truncated"
        ]
      },
      "ReleaseAvsAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "const": "release_avs"
          },
          "instructions": {
            "type": "string",
            "maxLength": 10000,
            "minLength": 1
          },
          "follow_up_instructions": {
            "type": "string",
            "maxLength": 5000,
            "minLength": 0
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          },
          "reviewed": {
            "const": true
          },
          "reviewed_snapshot_digest": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "Digest returned by checkout GET; recomputed under clinical-list/order serialization before release. No release timestamp participates."
          }
        },
        "required": [
          "action",
          "instructions",
          "follow_up_instructions",
          "reason",
          "reviewed",
          "reviewed_snapshot_digest"
        ]
      },
      "RecordAvsDeliveryAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "const": "delivery"
          },
          "method": {
            "type": "string",
            "enum": [
              "print",
              "declined",
              "other"
            ]
          },
          "avs_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "action",
          "method",
          "avs_version",
          "reason"
        ]
      },
      "CompleteCheckoutAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "const": "checkout"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "CheckoutAction": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/ReleaseAvsAction"
          },
          {
            "$ref": "#/components/schemas/RecordAvsDeliveryAction"
          },
          {
            "$ref": "#/components/schemas/CompleteCheckoutAction"
          }
        ],
        "discriminator": {
          "propertyName": "action"
        }
      },
      "CreateFollowUpTask": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1
          },
          "instructions": {
            "type": "string",
            "maxLength": 4000,
            "minLength": 1
          },
          "assignee_id": {
            "type": "string",
            "format": "uuid"
          },
          "due_date": {
            "type": "string",
            "format": "date",
            "description": "Date-only value from 2000-01-01 through 2100-12-31; no UTC conversion."
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "request_id",
          "title",
          "instructions",
          "assignee_id",
          "due_date",
          "reason"
        ]
      },
      "FollowUpTaskAction": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "complete"
              },
              "reason": {
                "type": "string",
                "maxLength": 1000,
                "minLength": 1
              }
            },
            "required": [
              "action",
              "reason"
            ]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "cancel"
              },
              "reason": {
                "type": "string",
                "maxLength": 1000,
                "minLength": 1
              }
            },
            "required": [
              "action",
              "reason"
            ]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "reopen"
              },
              "reason": {
                "type": "string",
                "maxLength": 1000,
                "minLength": 1
              }
            },
            "required": [
              "action",
              "reason"
            ]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "reassign"
              },
              "reason": {
                "type": "string",
                "maxLength": 1000,
                "minLength": 1
              },
              "assignee_id": {
                "type": "string",
                "format": "uuid"
              }
            },
            "required": [
              "action",
              "reason",
              "assignee_id"
            ]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "action": {
                "const": "reschedule"
              },
              "reason": {
                "type": "string",
                "maxLength": 1000,
                "minLength": 1
              },
              "due_date": {
                "type": "string",
                "format": "date"
              }
            },
            "required": [
              "action",
              "reason",
              "due_date"
            ]
          }
        ],
        "discriminator": {
          "propertyName": "action"
        }
      },
      "FollowUpWorklist": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FollowUpTask"
            },
            "maxItems": 100
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "has_more": {
            "type": "boolean"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "completed",
              "cancelled",
              "all"
            ]
          }
        },
        "required": [
          "items",
          "total",
          "has_more",
          "status"
        ]
      },
      "FollowUpAssignees": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "label": {
                  "type": "string"
                },
                "role": {
                  "type": "string",
                  "enum": [
                    "owner",
                    "clinician",
                    "front_desk",
                    "nurse",
                    "medical_assistant"
                  ]
                }
              },
              "required": [
                "id",
                "label",
                "role"
              ]
            },
            "maxItems": 500
          },
          "has_more": {
            "type": "boolean"
          }
        },
        "required": [
          "items",
          "has_more"
        ]
      },
      "PaymentSettingsInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "mode"
        ],
        "properties": {
          "mode": {
            "enum": [
              "own_stripe",
              "suncharts_connect"
            ]
          },
          "api_key": {
            "type": "string",
            "writeOnly": true,
            "description": "Own account test-only sk_test_ or rk_test_ credential; blank preserves saved same-mode credential."
          },
          "webhook_secret": {
            "type": "string",
            "writeOnly": true
          },
          "installation_id": {
            "type": "string",
            "format": "uuid"
          },
          "broker_token": {
            "type": "string",
            "writeOnly": true,
            "pattern": "^scp_inst_[A-Za-z0-9_-]+$"
          }
        }
      },
      "PaymentSettings": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "mode": {
            "enum": [
              "own_stripe",
              "suncharts_connect"
            ]
          },
          "enabled": {
            "type": "boolean"
          },
          "verified": {
            "type": "boolean"
          },
          "provider_account_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          },
          "test_mode": {
            "const": true
          },
          "credentials_configured": {
            "const": true
          },
          "onboarding_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Only verified broker origin + actual owner setup path. Does not grant anonymous financial onboarding."
          },
          "last_test_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_test_result": {
            "type": [
              "string",
              "null"
            ],
            "description": "Includes live_connection_verified when the bound live account was authenticated for display only; this is not live payment activation."
          },
          "charges_enabled": {
            "type": "boolean",
            "description": "Last verified processor account capability evidence; distinct from environment collection availability."
          },
          "payouts_enabled": {
            "type": "boolean",
            "description": "Last verified processor account capability evidence; distinct from environment collection availability."
          },
          "details_submitted": {
            "type": "boolean",
            "description": "Last verified processor account capability evidence; distinct from environment collection availability."
          },
          "requirements_currently_due": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "requirements_past_due": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "card_payments_active": {
            "type": "boolean",
            "description": "True only after a bound provider status explicitly confirms the Stripe card_payments capability is active. General charges_enabled alone is insufficient. Existing settings default false until refreshed."
          }
        }
      },
      "HostedPayment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "amount_cents": {
            "type": "integer"
          },
          "currency": {
            "const": "usd"
          },
          "status": {
            "enum": [
              "creating",
              "open",
              "paid",
              "expired",
              "needs_review",
              "refunded"
            ]
          },
          "checkout_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Null in production even for a historical open test attempt."
          },
          "provider_mode": {
            "enum": [
              "own_stripe",
              "suncharts_connect"
            ]
          },
          "ledger_recorded": {
            "type": "boolean"
          },
          "refunded_cents": {
            "type": "integer"
          },
          "refund_available": {
            "type": "boolean",
            "description": "False in production; historical evidence is preserved."
          },
          "expiry_available": {
            "type": "boolean",
            "description": "False in production; historical evidence is preserved."
          },
          "needs_review": {
            "type": "boolean"
          },
          "test_mode": {
            "const": true
          },
          "version": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "test_payments_available": {
            "type": "boolean",
            "description": "False when ENGINE_ENVIRONMENT=production."
          },
          "collection_unavailable_reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Human-readable environment restriction, or null."
          }
        }
      },
      "HostedPaymentRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "amount_cents"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 50,
            "maximum": 100000000
          }
        }
      },
      "PaymentRefundRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "amount_cents"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000
          }
        }
      },
      "HostedPaymentResult": {
        "type": "object",
        "properties": {
          "payment": {
            "$ref": "#/components/schemas/HostedPayment"
          }
        }
      },
      "RecurringOccurrencePlan": {
        "type": "object",
        "properties": {
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "local_start": {
            "type": "string",
            "description": "Timezone-free local timestamp YYYY-MM-DDTHH:MM:SS, whole-minute."
          },
          "local_end": {
            "type": "string"
          },
          "utc_offset_minutes": {
            "type": "integer",
            "minimum": -840,
            "maximum": 840,
            "description": "UTC offset at start; validated using named timezone."
          }
        },
        "required": [
          "starts_at",
          "ends_at",
          "local_start",
          "local_end",
          "utc_offset_minutes"
        ],
        "additionalProperties": false
      },
      "RecurringAppointmentPlan": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "facility": {
            "type": "string"
          },
          "room": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          },
          "frequency": {
            "type": "string",
            "enum": [
              "daily",
              "weekly",
              "monthly"
            ]
          },
          "interval": {
            "type": "integer",
            "minimum": 1,
            "maximum": 12
          },
          "timezone": {
            "type": "string",
            "maxLength": 100
          },
          "occurrences": {
            "type": "array",
            "minItems": 2,
            "maxItems": 52,
            "items": {
              "$ref": "#/components/schemas/RecurringOccurrencePlan"
            }
          }
        },
        "required": [
          "request_id",
          "patient_id",
          "clinician_id",
          "title",
          "category",
          "facility",
          "room",
          "notes",
          "reason",
          "frequency",
          "interval",
          "timezone",
          "occurrences"
        ],
        "additionalProperties": false,
        "description": "Explicit finite plan. Same local start time and elapsed UTC duration. Daily/weekly/monthly cadence anchored to first date; monthly clamps original day to month end. Last local start within 12 calendar months. Canonical request digest provides exact UUID retry idempotence; changed content with same UUID conflicts."
      },
      "RecurringPreviewOccurrence": {
        "type": "object",
        "properties": {
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "local_start": {
            "type": "string",
            "description": "Timezone-free local timestamp YYYY-MM-DDTHH:MM:SS, whole-minute."
          },
          "local_end": {
            "type": "string"
          },
          "utc_offset_minutes": {
            "type": "integer",
            "minimum": -840,
            "maximum": 840,
            "description": "UTC offset at start; validated using named timezone."
          },
          "position": {
            "type": "integer"
          },
          "available": {
            "type": "boolean"
          },
          "conflict": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "position",
          "available",
          "conflict",
          "starts_at",
          "ends_at",
          "local_start",
          "local_end",
          "utc_offset_minutes"
        ]
      },
      "RecurringAppointmentPreview": {
        "type": "object",
        "properties": {
          "ready_to_create": {
            "type": "boolean"
          },
          "existing_series_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "occurrences": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RecurringPreviewOccurrence"
            }
          },
          "timezone": {
            "type": "string"
          },
          "frequency": {
            "type": "string"
          },
          "interval": {
            "type": "integer"
          },
          "count": {
            "type": "integer"
          },
          "preview_only": {
            "type": "boolean",
            "const": true
          }
        },
        "required": [
          "ready_to_create",
          "existing_series_id",
          "occurrences",
          "timezone",
          "frequency",
          "interval",
          "count",
          "preview_only"
        ],
        "description": "Preview reserves no slots. An exact already-created request returns existing_series_id and no rows."
      },
      "RecurringAppointmentInstance": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "position": {
            "type": "integer"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "type": "string"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "title": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "facility": {
            "type": "string"
          },
          "room": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "planned": {
            "$ref": "#/components/schemas/RecurringOccurrencePlan"
          },
          "changed_from_plan": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "appointment_id",
          "position",
          "version",
          "status",
          "starts_at",
          "ends_at",
          "planned",
          "changed_from_plan"
        ]
      },
      "RecurringAppointmentEvent": {
        "type": "object",
        "properties": {
          "version": {
            "type": "integer"
          },
          "action": {
            "type": "string",
            "enum": [
              "create",
              "cancel_upcoming"
            ]
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "version",
          "action",
          "actor_id",
          "reason",
          "details",
          "created_at"
        ]
      },
      "RecurringAppointmentSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_name": {
            "type": "string"
          },
          "mrn": {
            "type": "string"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "frequency": {
            "type": "string"
          },
          "interval": {
            "type": "integer"
          },
          "timezone": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "cancelled"
            ]
          },
          "version": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "occurrence_count": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "patient_id",
          "patient_name",
          "mrn",
          "clinician_id",
          "title",
          "frequency",
          "interval",
          "timezone",
          "status",
          "version",
          "created_at",
          "occurrence_count"
        ]
      },
      "RecurringAppointmentSeries": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_name": {
            "type": "string"
          },
          "mrn": {
            "type": "string"
          },
          "clinician_id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "frequency": {
            "type": "string"
          },
          "interval": {
            "type": "integer"
          },
          "timezone": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "cancelled"
            ]
          },
          "version": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "provider_label": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "facility": {
            "type": "string"
          },
          "room": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "cancellable_count": {
            "type": "integer"
          },
          "occurrences": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RecurringAppointmentInstance"
            }
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RecurringAppointmentEvent"
            }
          }
        },
        "required": [
          "id",
          "patient_id",
          "patient_name",
          "mrn",
          "clinician_id",
          "title",
          "frequency",
          "interval",
          "timezone",
          "status",
          "version",
          "created_at",
          "provider_label",
          "created_by",
          "updated_at",
          "cancellable_count",
          "occurrences",
          "events"
        ]
      },
      "RecurringAppointmentCancel": {
        "type": "object",
        "properties": {
          "action": {
            "type": "string",
            "const": "cancel_upcoming"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "occurrence_versions": {
            "type": "array",
            "minItems": 2,
            "maxItems": 52,
            "description": "All members in position order, including members that will be preserved. Any stale member conflicts.",
            "items": {
              "type": "object",
              "properties": {
                "appointment_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "version": {
                  "type": "integer",
                  "minimum": 1
                }
              },
              "required": [
                "appointment_id",
                "version"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "action",
          "reason",
          "occurrence_versions"
        ],
        "additionalProperties": false
      },
      "ReminderPreferenceSave": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "channel",
          "destination",
          "consented",
          "verified",
          "automatic_email",
          "reason"
        ],
        "properties": {
          "channel": {
            "type": "string",
            "enum": [
              "email",
              "phone"
            ]
          },
          "destination": {
            "type": "string",
            "maxLength": 254
          },
          "consented": {
            "type": "boolean"
          },
          "verified": {
            "type": "boolean"
          },
          "automatic_email": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "AppointmentReminderCreate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "before_minutes",
          "reason"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "before_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 525600
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "AppointmentReminderAction": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "action",
          "reason"
        ],
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "cancel",
              "manual_contacted",
              "manual_no_answer",
              "manual_failed",
              "retry",
              "refresh_delivery"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "ReminderSenderSave": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "api_key": {
            "type": "string",
            "writeOnly": true,
            "description": "Resend key; omit/blank retains the current key. Never returned."
          },
          "from_email": {
            "type": "string",
            "format": "email"
          },
          "delivery_mode": {
            "type": "string",
            "enum": [
              "suncharts_connect",
              "own_resend"
            ],
            "description": "Managed SunCharts email or own Resend account. Omission preserves existing own-account API compatibility."
          }
        },
        "description": "Own Resend requires from_email and a key on first save. Managed mode requires verified, enabled Connect services. Saving always disables sending."
      },
      "ReminderSenderActivation": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "enabled"
        ],
        "properties": {
          "enabled": {
            "type": "boolean"
          }
        }
      },
      "AppointmentReminder": {
        "type": "object",
        "required": [
          "id",
          "appointment_id",
          "patient_id",
          "version",
          "status",
          "actions"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "needs_contact",
              "sending",
              "accepted",
              "delivered",
              "failed",
              "manual_contacted",
              "manual_no_answer",
              "manual_failed",
              "cancelled",
              "superseded",
              "missed",
              "needs_review"
            ]
          },
          "actions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "due_at": {
            "type": "string",
            "format": "date-time"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "before_minutes": {
            "type": "integer"
          },
          "channel": {
            "type": "string"
          },
          "destination": {
            "type": [
              "string",
              "null"
            ]
          },
          "automatic_email": {
            "type": "boolean"
          },
          "invalidated": {
            "type": "boolean"
          },
          "attempts": {
            "type": "integer"
          },
          "provider_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "last_result": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ConnectServiceSave": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "installation_id"
        ],
        "properties": {
          "installation_id": {
            "type": "string",
            "format": "uuid"
          },
          "installation_token": {
            "type": "string",
            "writeOnly": true,
            "description": "One-time service installation token. Omit only to retain a saved token for the same installation."
          }
        }
      },
      "SupportTicketCreate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "subject",
          "message"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "subject": {
            "type": "string",
            "maxLength": 160
          },
          "message": {
            "type": "string",
            "maxLength": 4000
          },
          "links": {
            "type": "array",
            "maxItems": 10,
            "description": "Records of this practice to attach. The server checks each one and writes its label (medical record number, visit date or claim number; never a patient name).",
            "items": {
              "$ref": "#/components/schemas/SupportLink"
            }
          },
          "attachments": {
            "type": "array",
            "maxItems": 5,
            "description": "Files added through support-files that are not yet on a message.",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      },
      "SupportReply": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "message"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "message": {
            "type": "string",
            "maxLength": 4000
          },
          "links": {
            "type": "array",
            "maxItems": 10,
            "description": "Records of this practice to attach. The server checks each one and writes its label (medical record number, visit date or claim number; never a patient name).",
            "items": {
              "$ref": "#/components/schemas/SupportLink"
            }
          },
          "attachments": {
            "type": "array",
            "maxItems": 5,
            "description": "Files added through support-files that are not yet on a message.",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      },
      "SupportLink": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind",
          "id"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "patient",
              "visit",
              "claim"
            ]
          },
          "id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "SupportFile": {
        "type": "object",
        "required": [
          "id",
          "filename",
          "content_type",
          "size"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "filename": {
            "type": "string",
            "maxLength": 200
          },
          "content_type": {
            "type": "string"
          },
          "size": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10485760
          }
        }
      },
      "PracticeStaffCreate": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "password": {
            "type": "string",
            "writeOnly": true,
            "minLength": 14,
            "maxLength": 1024,
            "description": "Required when staff sign in with a password. Refused when SunCharts Connect handles sign-in."
          },
          "display_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "role": {
            "type": "string",
            "enum": [
              "owner",
              "clinician",
              "nurse",
              "medical_assistant",
              "front_desk",
              "read_only"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "email",
          "display_name",
          "role",
          "reason"
        ]
      },
      "PracticeStaffChange": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254,
            "description": "Optional new sign-in email. Ends that person's sessions. With Connect sign-in a new invitation is sent to the new address and the reply adds invitation; an owner cannot change their own email there."
          },
          "display_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "role": {
            "type": "string",
            "enum": [
              "owner",
              "clinician",
              "nurse",
              "medical_assistant",
              "front_desk",
              "read_only"
            ]
          },
          "disabled": {
            "type": "boolean"
          },
          "password": {
            "type": "string",
            "writeOnly": true,
            "minLength": 14,
            "maxLength": 1024,
            "description": "With Connect sign-in only a practice owner may be given one (emergency sign-in); refused for other roles."
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "display_name",
          "role",
          "disabled",
          "reason"
        ]
      },
      "PracticeProviderChange": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "staff_id": {
            "type": "string",
            "format": "uuid"
          },
          "display_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "npi": {
            "type": "string",
            "pattern": "^([0-9]{10})?$"
          },
          "specialty": {
            "type": "string",
            "maxLength": 200
          },
          "active": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "staff_id",
          "display_name",
          "npi",
          "specialty",
          "active",
          "reason"
        ]
      },
      "PracticeFacilityChange": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "address": {
            "type": "string",
            "maxLength": 1000
          },
          "phone": {
            "type": "string",
            "maxLength": 40
          },
          "active": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "name",
          "address",
          "phone",
          "active",
          "reason"
        ]
      },
      "PracticeRoomChange": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "facility_id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "active": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "facility_id",
          "name",
          "active",
          "reason"
        ]
      },
      "RoomingIntake": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "in_progress",
              "ready"
            ]
          },
          "chief_complaint": {
            "type": "string",
            "maxLength": 2000
          },
          "intake_notes": {
            "type": "string",
            "maxLength": 10000
          },
          "medications_reviewed": {
            "type": "boolean"
          },
          "allergies_reviewed": {
            "type": "boolean"
          }
        },
        "required": [
          "status",
          "chief_complaint",
          "intake_notes",
          "medications_reviewed",
          "allergies_reviewed"
        ]
      },
      "EncounterDiagnosisInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code",
          "display"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "Trimmed and uppercased. Canonical ICD-10-CM syntax is ^[A-Z][A-Z0-9]{2}(\\.[A-Z0-9]{1,4})?$; the second character may be a letter (including FY2027 QA0 codes). Without catalog_release_id, only syntax is validated."
          },
          "display": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000,
            "description": "Nonblank description, at most 2000 UTF-8 bytes after trimming. A selected catalog replaces it with the publisher description."
          },
          "catalog_release_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Optional tenant-owned catalog release. The server resolves the code and requires it to be active and billable for the service date. Must be an ICD-10-CM release."
          }
        }
      },
      "VisitDiagnosesInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "diagnoses",
          "reason"
        ],
        "properties": {
          "diagnoses": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/EncounterDiagnosisInput"
            },
            "description": "Ordered unique canonical codes. First entry is primary; empty array explicitly clears."
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000,
            "description": "Nonblank attributed reason for this revision."
          }
        }
      },
      "EncounterDiagnosis": {
        "type": "object",
        "required": [
          "id",
          "code",
          "display",
          "rank"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Retained while the canonical code remains in the list."
          },
          "code": {
            "type": "string",
            "pattern": "^[A-Z][A-Z0-9]{2}(\\.[A-Z0-9]{1,4})?$"
          },
          "display": {
            "type": "string"
          },
          "rank": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20
          },
          "catalog_release_id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "catalog_snapshot": {
            "$ref": "#/components/schemas/TerminologySelectionSnapshot",
            "readOnly": true
          }
        }
      },
      "VisitDiagnosisRevision": {
        "type": "object",
        "required": [
          "id",
          "visit_version",
          "actor_id",
          "reason",
          "snapshot",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_version": {
            "type": "integer"
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string"
          },
          "snapshot": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EncounterDiagnosis"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "actor_label": {
            "type": [
              "string",
              "null"
            ],
            "description": "Current staff display name or email when available; actor_id retains stable attribution."
          }
        }
      },
      "VisitDiagnoses": {
        "type": "object",
        "required": [
          "visit",
          "version",
          "can_edit",
          "diagnoses",
          "history",
          "history_truncated",
          "code_system",
          "service_date"
        ],
        "properties": {
          "visit": {
            "$ref": "#/components/schemas/Visit"
          },
          "version": {
            "type": "integer"
          },
          "can_edit": {
            "type": "boolean"
          },
          "diagnoses": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/EncounterDiagnosis"
            }
          },
          "history": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/VisitDiagnosisRevision"
            }
          },
          "history_truncated": {
            "type": "boolean"
          },
          "code_system": {
            "type": "string",
            "const": "http://hl7.org/fhir/sid/icd-10-cm"
          },
          "service_date": {
            "type": "string",
            "format": "date",
            "readOnly": true,
            "description": "Encounter service date in the booking timezone, frozen by the earliest catalog selection and retained through immutable revisions."
          }
        }
      },
      "HealthHistoryContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "surgery",
              "dental"
            ]
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "resolved",
              "completed",
              "entered_in_error"
            ]
          },
          "verification": {
            "type": "string",
            "enum": [
              "unconfirmed",
              "confirmed",
              "refuted",
              "entered_in_error"
            ]
          },
          "onset_date": {
            "anyOf": [
              {
                "type": "string",
                "format": "date"
              },
              {
                "type": "null"
              }
            ]
          },
          "end_date": {
            "anyOf": [
              {
                "type": "string",
                "format": "date"
              },
              {
                "type": "null"
              }
            ]
          },
          "code": {
            "anyOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "system": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "code": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "display": {
                    "type": "string",
                    "maxLength": 200,
                    "default": ""
                  }
                },
                "required": [
                  "system",
                  "code"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "notes": {
            "type": "string",
            "maxLength": 10000,
            "default": ""
          }
        },
        "required": [
          "kind",
          "title",
          "status",
          "verification"
        ]
      },
      "HealthHistoryCreate": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/HealthHistoryContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ]
      },
      "HealthHistoryEdit": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "content": {
            "$ref": "#/components/schemas/HealthHistoryContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "content",
          "reason"
        ]
      },
      "HealthHistoryEntry": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "content": {
            "$ref": "#/components/schemas/HealthHistoryContent"
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "updated_by": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "version",
          "content",
          "created_by",
          "updated_by",
          "created_at",
          "updated_at"
        ]
      },
      "HealthHistoryPage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/HealthHistoryEntry"
            }
          },
          "next_cursor": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "items",
          "next_cursor"
        ]
      },
      "FrozenEncounterDiagnosis": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "code": {
            "type": "string",
            "pattern": "^[A-Z][A-Z0-9]{2}(\\.[A-Z0-9]{1,4})?$"
          },
          "display": {
            "type": "string"
          },
          "rank": {
            "type": "integer",
            "minimum": 1
          },
          "catalog_release_id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "catalog_snapshot": {
            "$ref": "#/components/schemas/TerminologySelectionSnapshot",
            "readOnly": true
          }
        },
        "required": [
          "id",
          "code",
          "display",
          "rank"
        ]
      },
      "OrderDiagnosisSnapshot": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_version": {
            "type": "integer",
            "minimum": 1
          },
          "code_system": {
            "type": "string",
            "const": "http://hl7.org/fhir/sid/icd-10-cm"
          },
          "diagnoses": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/FrozenEncounterDiagnosis"
            }
          }
        },
        "required": [
          "visit_id",
          "visit_version",
          "code_system",
          "diagnoses"
        ]
      },
      "AccountDiagnosisSnapshot": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_version": {
            "type": "integer",
            "minimum": 1
          },
          "code_system": {
            "type": "string",
            "const": "http://hl7.org/fhir/sid/icd-10-cm"
          },
          "lines": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "line_index": {
                  "type": "integer",
                  "minimum": 0
                },
                "diagnoses": {
                  "type": "array",
                  "maxItems": 12,
                  "items": {
                    "$ref": "#/components/schemas/FrozenEncounterDiagnosis"
                  }
                }
              },
              "required": [
                "line_index",
                "diagnoses"
              ]
            }
          }
        },
        "required": [
          "visit_id",
          "visit_version",
          "code_system",
          "lines"
        ]
      },
      "OrderDiagnosisSelection": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_version": {
            "type": "integer",
            "minimum": 1
          },
          "diagnosis_ids": {
            "type": "array",
            "maxItems": 20,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "visit_version",
          "diagnosis_ids",
          "reason"
        ]
      },
      "AccountDiagnosisSelection": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_version": {
            "type": "integer",
            "minimum": 1
          },
          "lines": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "line_index": {
                  "type": "integer",
                  "minimum": 0
                },
                "diagnosis_ids": {
                  "type": "array",
                  "maxItems": 12,
                  "uniqueItems": true,
                  "items": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              },
              "required": [
                "line_index",
                "diagnosis_ids"
              ]
            }
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "visit_version",
          "lines",
          "reason"
        ]
      },
      "LabOrder": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "content": {
            "$ref": "#/components/schemas/OrderContent"
          },
          "status": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "diagnosis_snapshot": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/OrderDiagnosisSnapshot"
              },
              {
                "type": "null"
              }
            ]
          },
          "source_history_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "placed_by": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "placed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "visit_id",
          "content",
          "status",
          "version",
          "diagnosis_snapshot"
        ]
      },
      "DocumentContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1
          },
          "category": {
            "type": "string",
            "enum": [
              "identity",
              "insurance",
              "legal",
              "consult",
              "laboratory",
              "imaging",
              "consent",
              "referral",
              "other"
            ],
            "description": "identity: ID/driver license; insurance: insurance card; legal: registration legal document. Front-desk writes are limited to those three categories."
          },
          "document_date": {
            "anyOf": [
              {
                "type": "string",
                "format": "date"
              },
              {
                "type": "null"
              }
            ]
          },
          "visit_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "notes": {
            "type": "string",
            "maxLength": 10000,
            "default": ""
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "archived",
              "entered_in_error"
            ]
          }
        },
        "required": [
          "title",
          "category",
          "status"
        ]
      },
      "DocumentUpload": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "filename": {
            "type": "string",
            "maxLength": 255,
            "minLength": 1
          },
          "content_type": {
            "type": "string",
            "enum": [
              "application/pdf",
              "image/png",
              "image/jpeg",
              "text/plain",
              "audio/mpeg",
              "audio/wav",
              "audio/ogg",
              "audio/webm",
              "audio/mp4",
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            ]
          },
          "content_base64": {
            "type": "string",
            "format": "byte",
            "maxLength": 13981016,
            "description": "Nonempty decoded file up to 10 MiB. text/plain must be valid UTF-8 without unsupported controls and at most 200,000 bytes; all other supported formats are checked by file signature, not complete structure or malware scanning."
          },
          "content": {
            "$ref": "#/components/schemas/DocumentContent"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "request_id",
          "filename",
          "content_type",
          "content_base64",
          "content",
          "reason"
        ]
      },
      "DocumentEdit": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "content": {
            "$ref": "#/components/schemas/DocumentContent"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "content",
          "reason"
        ]
      },
      "PatientDocument": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "content": {
            "$ref": "#/components/schemas/DocumentContent"
          },
          "filename": {
            "type": "string"
          },
          "content_type": {
            "type": "string"
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "size_bytes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10485760
          },
          "uploaded_by": {
            "type": "string",
            "format": "uuid"
          },
          "updated_by": {
            "type": "string",
            "format": "uuid"
          },
          "uploaded_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "uploader_label": {
            "type": [
              "string",
              "null"
            ],
            "description": "Current display name/email when available; uploaded_by preserves stable attribution."
          },
          "file_version": {
            "type": "integer",
            "minimum": 1,
            "description": "Latest immutable working-file version, separate from metadata version. Version 1 is always the original upload."
          }
        },
        "required": [
          "id",
          "patient_id",
          "version",
          "content",
          "filename",
          "content_type",
          "sha256",
          "size_bytes",
          "uploaded_by",
          "updated_by",
          "uploaded_at",
          "updated_at",
          "file_version"
        ]
      },
      "PatientDocumentPage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/PatientDocument"
            }
          },
          "next_cursor": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "items",
          "next_cursor"
        ]
      },
      "DocumentRevision": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "version": {
            "type": "integer"
          },
          "content": {
            "$ref": "#/components/schemas/DocumentContent"
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "actor_label": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "reason": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "version",
          "content",
          "actor_id",
          "actor_label",
          "reason",
          "created_at"
        ]
      },
      "ReferralContent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "requested_service": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1
          },
          "recipient": {
            "type": "string",
            "maxLength": 300,
            "minLength": 1
          },
          "specialty": {
            "type": "string",
            "maxLength": 200,
            "default": ""
          },
          "priority": {
            "type": "string",
            "enum": [
              "routine",
              "urgent"
            ]
          },
          "clinical_reason": {
            "type": "string",
            "maxLength": 2000,
            "minLength": 1
          },
          "clinical_summary": {
            "type": "string",
            "maxLength": 10000,
            "default": ""
          },
          "follow_up_due": {
            "anyOf": [
              {
                "type": "string",
                "format": "date"
              },
              {
                "type": "null"
              }
            ]
          },
          "document_ids": {
            "type": "array",
            "maxItems": 20,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "default": []
          }
        },
        "required": [
          "requested_service",
          "recipient",
          "priority",
          "clinical_reason"
        ]
      },
      "ReferralCreate": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "content": {
            "$ref": "#/components/schemas/ReferralContent"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ]
      },
      "ReferralEdit": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "visit_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "content": {
            "$ref": "#/components/schemas/ReferralContent"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "content",
          "reason"
        ]
      },
      "ReferralAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "draft",
              "ready",
              "sent",
              "accepted",
              "scheduled",
              "completed",
              "cancelled",
              "entered_in_error"
            ]
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          },
          "evidence": {
            "type": "string",
            "maxLength": 4000,
            "default": ""
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "Referral": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "ready",
              "sent",
              "accepted",
              "scheduled",
              "completed",
              "cancelled",
              "entered_in_error"
            ]
          },
          "content": {
            "$ref": "#/components/schemas/ReferralContent"
          },
          "attachment_snapshot": {
            "anyOf": [
              {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "version": {
                      "type": "integer"
                    },
                    "title": {
                      "type": "string"
                    },
                    "filename": {
                      "type": "string"
                    },
                    "content_type": {
                      "type": "string"
                    },
                    "sha256": {
                      "type": "string"
                    },
                    "size_bytes": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "active",
                        "archived",
                        "entered_in_error"
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "version",
                    "title",
                    "filename",
                    "content_type",
                    "sha256",
                    "size_bytes"
                  ]
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "updated_by": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "visit_id",
          "version",
          "status",
          "content",
          "attachment_snapshot",
          "created_by",
          "updated_by",
          "created_at",
          "updated_at"
        ]
      },
      "ReferralPage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/Referral"
            }
          },
          "next_cursor": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "items",
          "next_cursor"
        ]
      },
      "ReferralRevision": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "version": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "ready",
              "sent",
              "accepted",
              "scheduled",
              "completed",
              "cancelled",
              "entered_in_error"
            ]
          },
          "visit_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "content": {
            "$ref": "#/components/schemas/ReferralContent"
          },
          "attachment_snapshot": {
            "anyOf": [
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "version": {
                      "type": "integer"
                    },
                    "title": {
                      "type": "string"
                    },
                    "filename": {
                      "type": "string"
                    },
                    "content_type": {
                      "type": "string"
                    },
                    "sha256": {
                      "type": "string"
                    },
                    "size_bytes": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "active",
                        "archived",
                        "entered_in_error"
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "version",
                    "title",
                    "filename",
                    "content_type",
                    "sha256",
                    "size_bytes"
                  ]
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "author_id": {
            "type": "string",
            "format": "uuid"
          },
          "actor_label": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "reason": {
            "type": "string"
          },
          "evidence": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "version",
          "status",
          "visit_id",
          "content",
          "attachment_snapshot",
          "author_id",
          "actor_label",
          "reason",
          "evidence",
          "created_at"
        ]
      },
      "ReferralWorklistEntry": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "ready",
              "sent",
              "accepted",
              "scheduled",
              "completed",
              "cancelled",
              "entered_in_error"
            ]
          },
          "content": {
            "$ref": "#/components/schemas/ReferralContent"
          },
          "attachment_snapshot": {
            "anyOf": [
              {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "version": {
                      "type": "integer"
                    },
                    "title": {
                      "type": "string"
                    },
                    "filename": {
                      "type": "string"
                    },
                    "content_type": {
                      "type": "string"
                    },
                    "sha256": {
                      "type": "string"
                    },
                    "size_bytes": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "active",
                        "archived",
                        "entered_in_error"
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "version",
                    "title",
                    "filename",
                    "content_type",
                    "sha256",
                    "size_bytes"
                  ]
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "updated_by": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "patient_label": {
            "type": "string"
          },
          "mrn": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "patient_id",
          "visit_id",
          "version",
          "status",
          "content",
          "attachment_snapshot",
          "created_by",
          "updated_by",
          "created_at",
          "updated_at",
          "patient_label",
          "mrn"
        ]
      },
      "PatientIdentitySnapshot": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "mrn": {
            "type": "string",
            "maxLength": 64,
            "minLength": 1,
            "description": "Stable system-assigned or preserved imported identifier. Read-only during identity corrections."
          },
          "given_name": {
            "type": "string",
            "maxLength": 100,
            "minLength": 1
          },
          "family_name": {
            "type": "string",
            "maxLength": 100,
            "minLength": 1
          },
          "birth_date": {
            "type": "string",
            "format": "date"
          }
        },
        "required": [
          "id",
          "mrn",
          "given_name",
          "family_name",
          "birth_date"
        ]
      },
      "PatientIdentityChange": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mrn": {
            "type": "string",
            "maxLength": 64,
            "minLength": 1,
            "description": "Optional compatibility echo of the exact existing MRN. Any different value is rejected; omit this field for identity corrections."
          },
          "given_name": {
            "type": "string",
            "maxLength": 100,
            "minLength": 1
          },
          "family_name": {
            "type": "string",
            "maxLength": 100,
            "minLength": 1
          },
          "birth_date": {
            "type": "string",
            "format": "date"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "given_name",
          "family_name",
          "birth_date",
          "reason"
        ]
      },
      "PatientIdentity": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient": {
            "$ref": "#/components/schemas/PatientIdentitySnapshot"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "can_edit": {
            "type": "boolean"
          },
          "history": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "properties": {
                "version": {
                  "type": "integer"
                },
                "snapshot": {
                  "$ref": "#/components/schemas/PatientIdentitySnapshot"
                },
                "actor_id": {
                  "anyOf": [
                    {
                      "type": "string",
                      "format": "uuid"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "actor_label": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "reason": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "history_truncated": {
            "type": "boolean"
          }
        },
        "required": [
          "patient",
          "version",
          "can_edit",
          "history",
          "history_truncated"
        ]
      },
      "WritableFhirPatient": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "resourceType": {
            "type": "string",
            "const": "Patient"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "meta": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "versionId": {
                "type": "string"
              }
            },
            "required": []
          },
          "identifier": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "system": {
                  "type": "string"
                },
                "value": {
                  "type": "string",
                  "maxLength": 64,
                  "minLength": 1
                },
                "use": {
                  "type": "string",
                  "enum": [
                    "usual",
                    "official"
                  ]
                },
                "type": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "coding": {
                      "type": "array",
                      "minItems": 1,
                      "maxItems": 1,
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "properties": {
                          "system": {
                            "type": "string",
                            "const": "http://terminology.hl7.org/CodeSystem/v2-0203"
                          },
                          "code": {
                            "type": "string",
                            "const": "MR"
                          }
                        },
                        "required": [
                          "system",
                          "code"
                        ]
                      }
                    }
                  },
                  "required": [
                    "coding"
                  ]
                }
              },
              "required": [
                "value"
              ]
            }
          },
          "name": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "use": {
                  "type": "string",
                  "const": "official"
                },
                "family": {
                  "type": "string",
                  "maxLength": 100,
                  "minLength": 1
                },
                "given": {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 1,
                  "items": {
                    "type": "string",
                    "maxLength": 100,
                    "minLength": 1
                  }
                }
              },
              "required": [
                "family",
                "given"
              ]
            }
          },
          "birthDate": {
            "type": "string",
            "format": "date"
          }
        },
        "required": [
          "resourceType",
          "identifier",
          "name",
          "birthDate"
        ],
        "description": "Update subset: the single existing MRN identifier must remain unchanged."
      },
      "ReferralDestinationInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "name": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1
          },
          "endpoint": {
            "type": "string",
            "maxLength": 2000,
            "minLength": 1
          },
          "enabled": {
            "type": "boolean"
          },
          "loopback_test": {
            "type": "boolean",
            "default": false
          },
          "bearer_token": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 16,
                "maxLength": 4096,
                "writeOnly": true
              },
              {
                "type": "null"
              }
            ]
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "name",
          "endpoint",
          "enabled",
          "reason"
        ]
      },
      "ReferralDestination": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "endpoint": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "loopback_test": {
            "type": "boolean"
          },
          "version": {
            "type": "integer"
          },
          "credential_configured": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "name",
          "endpoint",
          "enabled",
          "loopback_test",
          "version",
          "credential_configured"
        ]
      },
      "ReferralDeliveryJob": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "sending",
              "sent",
              "uncertain",
              "not_sent",
              "cancelled"
            ]
          },
          "referral_id": {
            "type": "string",
            "format": "uuid"
          },
          "referral_version": {
            "type": "integer"
          },
          "destination_id": {
            "type": "string",
            "format": "uuid"
          },
          "destination_version": {
            "type": "integer"
          },
          "destination_name": {
            "type": "string"
          },
          "endpoint": {
            "type": "string"
          },
          "manifest": {
            "type": "object"
          },
          "receipt": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "outcome_reason": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "version",
          "status",
          "referral_id",
          "referral_version",
          "destination_id",
          "destination_version",
          "destination_name",
          "endpoint",
          "manifest",
          "receipt",
          "outcome_reason",
          "created_at",
          "updated_at"
        ]
      },
      "ReferralDeliveryQueue": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "destination_id": {
            "type": "string",
            "format": "uuid"
          },
          "destination_version": {
            "type": "integer",
            "minimum": 1
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "review_digest": {
            "type": "string"
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "destination_id",
          "destination_version",
          "request_id",
          "review_digest",
          "reason"
        ]
      },
      "ReferralDeliveryAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "cancel",
              "reconcile_sent",
              "reconcile_not_sent"
            ]
          },
          "receipt": {
            "type": "string",
            "maxLength": 200,
            "default": ""
          },
          "reason": {
            "type": "string",
            "maxLength": 1000,
            "minLength": 1
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "ConnectReplyNotification": {
        "type": "object",
        "required": [
          "id",
          "ticket_id",
          "message_id",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "ticket_id": {
            "type": "string",
            "format": "uuid"
          },
          "message_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ConnectReplyNotifications": {
        "type": "object",
        "required": [
          "items",
          "unread_count",
          "has_more"
        ],
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/ConnectReplyNotification"
            }
          },
          "unread_count": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "has_more": {
            "type": "boolean"
          }
        }
      },
      "ReadConnectReplyNotifications": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "event_ids"
        ],
        "properties": {
          "event_ids": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            }
          }
        }
      },
      "FhirWriteReference": {
        "type": "object",
        "properties": {
          "reference": {
            "type": "string",
            "pattern": "^Patient/[0-9a-fA-F-]{36}$"
          }
        },
        "required": [
          "reference"
        ],
        "additionalProperties": false
      },
      "FhirWriteText": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string"
          }
        },
        "required": [
          "text"
        ],
        "additionalProperties": false
      },
      "FhirWriteMeta": {
        "type": "object",
        "properties": {
          "versionId": {
            "type": "string",
            "pattern": "^[1-9][0-9]*$"
          }
        },
        "required": [],
        "additionalProperties": false
      },
      "FhirWriteCoding": {
        "type": "object",
        "properties": {
          "system": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "display": {
            "type": "string",
            "maxLength": 200
          }
        },
        "required": [
          "system",
          "code"
        ],
        "additionalProperties": false
      },
      "FhirWriteConcept": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "coding": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FhirWriteCoding"
            },
            "minItems": 0,
            "maxItems": 20
          }
        },
        "required": [
          "text"
        ],
        "additionalProperties": false
      },
      "WritableFhirCondition": {
        "type": "object",
        "properties": {
          "resourceType": {
            "type": "string",
            "const": "Condition"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "meta": {
            "$ref": "#/components/schemas/FhirWriteMeta"
          },
          "note": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FhirWriteText"
            },
            "minItems": 1,
            "maxItems": 1
          },
          "subject": {
            "$ref": "#/components/schemas/FhirWriteReference"
          },
          "code": {
            "$ref": "#/components/schemas/FhirWriteConcept"
          },
          "onsetDateTime": {
            "type": "string",
            "format": "date"
          },
          "clinicalStatus": {
            "type": "object",
            "properties": {
              "coding": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "system": {
                      "type": "string",
                      "const": "http://terminology.hl7.org/CodeSystem/condition-clinical"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "active",
                        "inactive",
                        "resolved",
                        "recurrence",
                        "remission"
                      ]
                    }
                  },
                  "required": [
                    "system",
                    "code"
                  ],
                  "additionalProperties": false
                },
                "minItems": 1,
                "maxItems": 1
              }
            },
            "required": [
              "coding"
            ],
            "additionalProperties": false
          },
          "verificationStatus": {
            "type": "object",
            "properties": {
              "coding": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "system": {
                      "type": "string",
                      "const": "http://terminology.hl7.org/CodeSystem/condition-ver-status"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "unconfirmed",
                        "confirmed",
                        "refuted",
                        "entered-in-error"
                      ]
                    }
                  },
                  "required": [
                    "system",
                    "code"
                  ],
                  "additionalProperties": false
                },
                "minItems": 1,
                "maxItems": 1
              }
            },
            "required": [
              "coding"
            ],
            "additionalProperties": false
          },
          "abatementDateTime": {
            "type": "string",
            "format": "date"
          },
          "category": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "coding": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "system": {
                        "type": "string",
                        "const": "http://terminology.hl7.org/CodeSystem/condition-category"
                      },
                      "code": {
                        "type": "string",
                        "enum": [
                          "problem-list-item",
                          "encounter-diagnosis"
                        ]
                      }
                    },
                    "required": [
                      "system",
                      "code"
                    ],
                    "additionalProperties": false
                  },
                  "minItems": 1,
                  "maxItems": 1
                }
              },
              "required": [
                "coding"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "maxItems": 1
          }
        },
        "required": [
          "resourceType",
          "subject",
          "code",
          "verificationStatus"
        ],
        "additionalProperties": false,
        "description": "Strict supported subset; dates have full YYYY-MM-DD precision only. clinicalStatus required except entered-in-error, which omits it. POST forbids id/meta, PUT requires id. No unsupported fields are discarded."
      },
      "WritableFhirAllergyIntolerance": {
        "type": "object",
        "properties": {
          "resourceType": {
            "type": "string",
            "const": "AllergyIntolerance"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "meta": {
            "$ref": "#/components/schemas/FhirWriteMeta"
          },
          "note": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FhirWriteText"
            },
            "minItems": 1,
            "maxItems": 1
          },
          "patient": {
            "$ref": "#/components/schemas/FhirWriteReference"
          },
          "code": {
            "$ref": "#/components/schemas/FhirWriteConcept"
          },
          "onsetDateTime": {
            "type": "string",
            "format": "date"
          },
          "clinicalStatus": {
            "type": "object",
            "properties": {
              "coding": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "system": {
                      "type": "string",
                      "const": "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "active",
                        "inactive",
                        "resolved"
                      ]
                    }
                  },
                  "required": [
                    "system",
                    "code"
                  ],
                  "additionalProperties": false
                },
                "minItems": 1,
                "maxItems": 1
              }
            },
            "required": [
              "coding"
            ],
            "additionalProperties": false
          },
          "verificationStatus": {
            "type": "object",
            "properties": {
              "coding": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "system": {
                      "type": "string",
                      "const": "http://terminology.hl7.org/CodeSystem/allergyintolerance-verification"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "unconfirmed",
                        "confirmed",
                        "refuted",
                        "entered-in-error"
                      ]
                    }
                  },
                  "required": [
                    "system",
                    "code"
                  ],
                  "additionalProperties": false
                },
                "minItems": 1,
                "maxItems": 1
              }
            },
            "required": [
              "coding"
            ],
            "additionalProperties": false
          },
          "category": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "food",
                "medication",
                "environment",
                "biologic"
              ]
            },
            "minItems": 1,
            "maxItems": 1
          },
          "criticality": {
            "type": "string",
            "enum": [
              "low",
              "high",
              "unable-to-assess"
            ]
          },
          "reaction": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "manifestation": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/FhirWriteText"
                  },
                  "minItems": 1,
                  "maxItems": 1
                },
                "severity": {
                  "type": "string",
                  "enum": [
                    "mild",
                    "moderate",
                    "severe"
                  ]
                }
              },
              "required": [
                "manifestation"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "maxItems": 1
          }
        },
        "required": [
          "resourceType",
          "patient",
          "code",
          "verificationStatus"
        ],
        "additionalProperties": false,
        "description": "Strict supported subset; dates have full YYYY-MM-DD precision only. clinicalStatus required except entered-in-error, which omits it. POST forbids id/meta, PUT requires id. No unsupported fields are discarded."
      },
      "WritableFhirMedicationStatement": {
        "type": "object",
        "properties": {
          "resourceType": {
            "type": "string",
            "const": "MedicationStatement"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "meta": {
            "$ref": "#/components/schemas/FhirWriteMeta"
          },
          "note": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FhirWriteText"
            },
            "minItems": 1,
            "maxItems": 1
          },
          "subject": {
            "$ref": "#/components/schemas/FhirWriteReference"
          },
          "medicationCodeableConcept": {
            "$ref": "#/components/schemas/FhirWriteConcept"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "on-hold",
              "stopped",
              "completed",
              "not-taken",
              "intended",
              "entered-in-error"
            ]
          },
          "effectivePeriod": {
            "type": "object",
            "properties": {
              "start": {
                "type": "string",
                "format": "date"
              },
              "end": {
                "type": "string",
                "format": "date"
              }
            },
            "required": [],
            "additionalProperties": false
          },
          "dosage": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FhirWriteText"
            },
            "minItems": 1,
            "maxItems": 1
          }
        },
        "required": [
          "resourceType",
          "subject",
          "medicationCodeableConcept",
          "status"
        ],
        "additionalProperties": false,
        "description": "Strict supported subset; dates have full YYYY-MM-DD precision only. clinicalStatus required except entered-in-error, which omits it. POST forbids id/meta, PUT requires id. No unsupported fields are discarded."
      },
      "WritableFhirServiceRequest": {
        "type": "object",
        "properties": {
          "resourceType": {
            "type": "string",
            "const": "ServiceRequest"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "meta": {
            "$ref": "#/components/schemas/FhirWriteMeta"
          },
          "status": {
            "type": "string",
            "const": "draft"
          },
          "intent": {
            "type": "string",
            "const": "order"
          },
          "subject": {
            "$ref": "#/components/schemas/FhirWriteReference"
          },
          "encounter": {
            "type": "object",
            "properties": {
              "reference": {
                "type": "string",
                "pattern": "^Encounter/[0-9a-fA-F-]{36}$"
              }
            },
            "required": [
              "reference"
            ],
            "additionalProperties": false
          },
          "code": {
            "type": "object",
            "properties": {
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "coding": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/FhirWriteCoding"
                },
                "minItems": 0,
                "maxItems": 1
              }
            },
            "required": [
              "text"
            ],
            "additionalProperties": false
          },
          "category": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FhirWriteText"
            },
            "minItems": 1,
            "maxItems": 1
          },
          "priority": {
            "type": "string",
            "enum": [
              "routine",
              "urgent",
              "stat"
            ]
          },
          "reasonCode": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FhirWriteText"
            },
            "minItems": 1,
            "maxItems": 1
          },
          "performer": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "display": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                }
              },
              "required": [
                "display"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "maxItems": 1
          },
          "note": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FhirWriteText"
            },
            "minItems": 1,
            "maxItems": 1
          }
        },
        "required": [
          "resourceType",
          "status",
          "intent",
          "subject",
          "code",
          "category",
          "priority",
          "reasonCode",
          "performer"
        ],
        "additionalProperties": false,
        "description": "Single-test local draft only. category.text is laboratory, imaging or procedure; reasonCode.text is the clinical reason; performer.display is the recorded destination. No placement or network execution."
      },
      "FhirOperationOutcome": {
        "type": "object",
        "properties": {
          "resourceType": {
            "type": "string",
            "const": "OperationOutcome"
          },
          "issue": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "minItems": 1
          }
        },
        "required": [
          "resourceType",
          "issue"
        ]
      },
      "PrescriptionContent": {
        "type": "object",
        "properties": {
          "medication_name": {
            "type": "string",
            "maxLength": 200
          },
          "rxnorm_code": {
            "type": "string",
            "maxLength": 20,
            "pattern": "^[0-9]*$"
          },
          "strength": {
            "type": "string",
            "maxLength": 120
          },
          "dosage_form": {
            "type": "string",
            "maxLength": 120
          },
          "dose": {
            "type": "string",
            "maxLength": 200
          },
          "route": {
            "type": "string",
            "maxLength": 100
          },
          "frequency": {
            "type": "string",
            "maxLength": 200
          },
          "instructions": {
            "type": "string",
            "maxLength": 4000
          },
          "indication": {
            "type": "string",
            "maxLength": 1000
          },
          "quantity": {
            "type": "string",
            "pattern": "^\\d{1,7}(\\.\\d{1,3})?$"
          },
          "quantity_unit": {
            "type": "string",
            "maxLength": 100
          },
          "refills": {
            "type": "integer",
            "minimum": 0,
            "maximum": 99
          },
          "days_supply": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 3660
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "substitution_allowed": {
            "type": "boolean"
          },
          "controlled_substance": {
            "type": "boolean"
          },
          "pharmacy_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "medication_name",
          "dose",
          "route",
          "frequency",
          "instructions",
          "indication",
          "quantity",
          "quantity_unit",
          "refills",
          "substitution_allowed",
          "controlled_substance"
        ],
        "additionalProperties": false,
        "description": "Positive decimal quantity as a string, numeric RxNorm code when supplied. Local authorization blocks all controlled substances. Optional dates must be ordered."
      },
      "PrescriptionDraft": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/PrescriptionContent"
          },
          "visit_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "prior_prescription_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "relationship": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "renewal",
              "replacement",
              null
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ],
        "additionalProperties": false
      },
      "PrescriptionAction": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "review_token": {
            "type": [
              "string",
              "null"
            ]
          },
          "attest": {
            "type": "boolean",
            "default": false
          }
        },
        "required": [
          "request_id",
          "reason"
        ],
        "additionalProperties": false
      },
      "PharmacyContent": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "address": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "phone": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40
          },
          "ncpdp_id": {
            "type": "string",
            "pattern": "^(\\d{7})?$"
          },
          "npi": {
            "type": "string",
            "pattern": "^(\\d{10})?$"
          }
        },
        "required": [
          "name",
          "address",
          "phone"
        ],
        "additionalProperties": false
      },
      "PharmacyChange": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/PharmacyContent"
          },
          "active": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "active",
          "reason"
        ],
        "additionalProperties": false
      },
      "PharmacyPreferenceChange": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "pharmacy_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "version",
          "reason"
        ],
        "additionalProperties": false
      },
      "PortalActivation": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "minLength": 64,
            "maxLength": 64
          },
          "password": {
            "type": "string",
            "minLength": 15,
            "maxLength": 1024
          }
        },
        "required": [
          "token",
          "password"
        ],
        "additionalProperties": false
      },
      "PortalLogin": {
        "type": "object",
        "properties": {
          "practice_id": {
            "type": "string",
            "format": "uuid"
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "password": {
            "type": "string",
            "maxLength": 1024
          }
        },
        "required": [
          "practice_id",
          "email",
          "password"
        ],
        "additionalProperties": false
      },
      "PortalInvite": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "email",
          "reason"
        ],
        "additionalProperties": false
      },
      "PortalReason": {
        "type": "object",
        "properties": {
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "reason"
        ],
        "additionalProperties": false
      },
      "PortalPublication": {
        "type": "object",
        "properties": {
          "avs_version": {
            "type": "integer",
            "minimum": 1
          },
          "visible": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "avs_version",
          "visible",
          "reason"
        ],
        "additionalProperties": false
      },
      "PortalNewThread": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "message",
              "appointment_change"
            ]
          },
          "appointment_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "body": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          }
        },
        "required": [
          "request_id",
          "kind",
          "subject",
          "body"
        ],
        "additionalProperties": false,
        "description": "appointment_change requires appointment_id belonging to the logged-in patient. message requires no appointment_id. Conversation does not modify a booking."
      },
      "PortalReply": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "body": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          }
        },
        "required": [
          "request_id",
          "body"
        ],
        "additionalProperties": false
      },
      "PortalThreadStatus": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "open",
              "closed"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "status",
          "reason"
        ],
        "additionalProperties": false
      },
      "NativePrescription": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "visit_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "active",
              "cancelled",
              "stopped",
              "completed"
            ]
          },
          "content": {
            "$ref": "#/components/schemas/PrescriptionContent"
          },
          "signed_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "signed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "signed_snapshot": {
            "type": [
              "object",
              "null"
            ],
            "description": "Immutable local authorization snapshot; does not establish transmission or dispensing."
          },
          "fulfillment_status": {
            "type": "string",
            "enum": [
              "not_authorized",
              "local_ready",
              "printed",
              "recorded_local"
            ]
          },
          "authored_by": {
            "type": "string",
            "format": "uuid"
          },
          "updated_by": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "prior_prescription_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "relationship": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "renewal",
              "replacement",
              null
            ]
          }
        },
        "required": [
          "id",
          "patient_id",
          "version",
          "status",
          "content",
          "fulfillment_status"
        ]
      },
      "NativePrescriptionPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/NativePrescription"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "items",
          "next_cursor"
        ]
      },
      "PrescribingPharmacy": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "content": {
            "$ref": "#/components/schemas/PharmacyContent"
          },
          "active": {
            "type": "boolean"
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "updated_by": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "version",
          "content",
          "active"
        ]
      },
      "PrescribingPharmacyPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "$ref": "#/components/schemas/PrescribingPharmacy"
            }
          },
          "truncated": {
            "type": "boolean"
          }
        },
        "required": [
          "items",
          "truncated"
        ]
      },
      "PreferredPharmacy": {
        "type": "object",
        "properties": {
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "pharmacy_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "patient_id",
          "pharmacy_id",
          "version"
        ]
      },
      "PrescribingReview": {
        "type": "object",
        "properties": {
          "review_token": {
            "type": "string"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "lists": {
            "type": "object"
          },
          "active_prescriptions": {
            "type": "array",
            "maxItems": 500,
            "items": {
              "type": "object"
            }
          },
          "active_prescriptions_truncated": {
            "type": "boolean"
          },
          "can_authorize": {
            "type": "boolean"
          },
          "limitations": {
            "type": "string"
          }
        },
        "required": [
          "review_token",
          "patient_id",
          "lists",
          "can_authorize",
          "limitations"
        ]
      },
      "PortalThread": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "subject": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "message",
              "appointment_change"
            ]
          },
          "appointment_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "closed"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "subject",
          "kind",
          "status",
          "version"
        ]
      },
      "PortalThreadPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/PortalThread"
            }
          },
          "has_more": {
            "type": "boolean"
          }
        },
        "required": [
          "items",
          "has_more"
        ]
      },
      "PortalThreadMessages": {
        "type": "object",
        "properties": {
          "thread": {
            "$ref": "#/components/schemas/PortalThread"
          },
          "messages": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "version": {
                  "type": "integer"
                },
                "author": {
                  "type": "string",
                  "enum": [
                    "patient",
                    "staff"
                  ]
                },
                "body": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "required": [
                "id",
                "version",
                "author",
                "body",
                "created_at"
              ]
            }
          },
          "messages_has_more": {
            "type": "boolean"
          }
        },
        "required": [
          "thread",
          "messages",
          "messages_has_more"
        ]
      },
      "PortalAccess": {
        "type": "object",
        "properties": {
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "practice_id": {
            "type": "string",
            "format": "uuid"
          },
          "account": {
            "type": [
              "object",
              "null"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "releases": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object"
            }
          },
          "releases_has_more": {
            "type": "boolean"
          },
          "events": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "object"
            }
          },
          "events_has_more": {
            "type": "boolean"
          }
        },
        "required": [
          "patient_id",
          "practice_id",
          "account",
          "version",
          "releases",
          "releases_has_more",
          "events",
          "events_has_more"
        ]
      },
      "PortalDashboard": {
        "type": "object",
        "properties": {
          "patient": {
            "type": "object",
            "properties": {
              "given_name": {
                "type": "string"
              },
              "family_name": {
                "type": "string"
              }
            },
            "required": [
              "given_name",
              "family_name"
            ]
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "appointments": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object"
            }
          },
          "appointments_has_more": {
            "type": "boolean"
          },
          "releases": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object"
            }
          },
          "releases_has_more": {
            "type": "boolean"
          }
        },
        "required": [
          "patient",
          "account_id",
          "appointments",
          "appointments_has_more",
          "releases",
          "releases_has_more"
        ]
      },
      "PortalInvitation": {
        "type": "object",
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "practice_id": {
            "type": "string",
            "format": "uuid"
          },
          "invitation_url": {
            "type": "string",
            "format": "uri",
            "description": "One-time activation credential; securely hand off without logging."
          },
          "expires_in_seconds": {
            "type": "integer",
            "const": 86400
          },
          "delivery": {
            "type": "string",
            "const": "manual_secure_handoff"
          },
          "email_sent": {
            "type": "boolean",
            "const": false
          }
        },
        "required": [
          "version",
          "practice_id",
          "invitation_url",
          "expires_in_seconds",
          "delivery",
          "email_sent"
        ]
      },
      "ErxCredentialsInput": {
        "type": "object",
        "properties": {
          "username": {
            "type": "string",
            "maxLength": 8192,
            "writeOnly": true
          },
          "password": {
            "type": "string",
            "maxLength": 8192,
            "writeOnly": true
          },
          "api_key": {
            "type": "string",
            "maxLength": 8192,
            "writeOnly": true
          },
          "encryption_key": {
            "type": "string",
            "maxLength": 8192,
            "writeOnly": true
          }
        },
        "required": [],
        "additionalProperties": false,
        "description": "Write only. The entire credential block is replaced when supplied; null retains it unless clear_credentials is true. Never provide EPCS authenticator codes or patient data.",
        "anyOf": [
          {
            "required": [
              "username"
            ],
            "properties": {
              "username": {
                "minLength": 1
              }
            }
          },
          {
            "required": [
              "password"
            ],
            "properties": {
              "password": {
                "minLength": 1
              }
            }
          },
          {
            "required": [
              "api_key"
            ],
            "properties": {
              "api_key": {
                "minLength": 1
              }
            }
          },
          {
            "required": [
              "encryption_key"
            ],
            "properties": {
              "encryption_key": {
                "minLength": 1
              }
            }
          }
        ]
      },
      "ErxCredentialFlags": {
        "type": "object",
        "properties": {
          "stored": {
            "type": "boolean"
          },
          "readable": {
            "type": "boolean"
          },
          "username": {
            "type": "boolean"
          },
          "password": {
            "type": "boolean"
          },
          "api_key": {
            "type": "boolean"
          },
          "encryption_key": {
            "type": "boolean"
          }
        },
        "required": [
          "stored",
          "readable"
        ],
        "additionalProperties": false
      },
      "ErxConnectionPreparation": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "candidate_profile": {
            "type": "string",
            "enum": [
              "none",
              "photon",
              "weno_ez",
              "weno_online",
              "dosespot_full",
              "other"
            ]
          },
          "enrollment_stage": {
            "type": "string",
            "enum": [
              "not_started",
              "contact_planned",
              "awaiting_vendor",
              "agreement_in_progress",
              "test_access_reported"
            ]
          },
          "organization_reference": {
            "type": "string",
            "maxLength": 200
          },
          "requested_capabilities": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "string",
              "enum": [
                "non_controlled",
                "epcs",
                "renewals",
                "cancel",
                "rx_change",
                "medication_history",
                "formulary",
                "prior_authorization"
              ]
            }
          },
          "credentials": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ErxCredentialsInput"
              },
              {
                "type": "null"
              }
            ]
          },
          "clear_credentials": {
            "type": "boolean",
            "default": false
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "version",
          "candidate_profile",
          "enrollment_stage",
          "organization_reference",
          "requested_capabilities",
          "reason"
        ],
        "additionalProperties": false
      },
      "ErxPrescriberPreparation": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "facility_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "vendor_user_id": {
            "type": "string",
            "maxLength": 200
          },
          "vendor_username": {
            "type": "string",
            "maxLength": 200
          },
          "vendor_location_id": {
            "type": "string",
            "maxLength": 200
          },
          "enrollment_reported": {
            "type": "boolean"
          },
          "credentials": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ErxCredentialsInput"
              },
              {
                "type": "null"
              }
            ]
          },
          "clear_credentials": {
            "type": "boolean",
            "default": false
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "version",
          "vendor_user_id",
          "vendor_username",
          "vendor_location_id",
          "enrollment_reported",
          "reason"
        ],
        "additionalProperties": false
      },
      "ErxReadiness": {
        "type": "object",
        "properties": {
          "state": {
            "const": "not_enrolled"
          },
          "ready": {
            "const": false
          },
          "active_provider": {
            "type": "null"
          },
          "launch_available": {
            "const": false
          },
          "transmission_available": {
            "const": false
          },
          "epcs_available": {
            "const": false
          },
          "receipt_sync_available": {
            "const": false
          },
          "vendor_contacted": {
            "const": false
          },
          "missing": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "state",
          "ready",
          "active_provider",
          "launch_available",
          "transmission_available",
          "epcs_available",
          "receipt_sync_available",
          "vendor_contacted",
          "missing",
          "message"
        ],
        "additionalProperties": false
      },
      "ErxConnectionState": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "candidate_profile": {
            "type": "string",
            "enum": [
              "none",
              "photon",
              "weno_ez",
              "weno_online",
              "dosespot_full",
              "other"
            ]
          },
          "profile_revision": {
            "type": "integer",
            "minimum": 0
          },
          "enrollment_stage": {
            "type": "string",
            "enum": [
              "not_started",
              "contact_planned",
              "awaiting_vendor",
              "agreement_in_progress",
              "test_access_reported"
            ]
          },
          "organization_reference": {
            "type": "string",
            "maxLength": 200
          },
          "requested_capabilities": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "non_controlled",
                "epcs",
                "renewals",
                "cancel",
                "rx_change",
                "medication_history",
                "formulary",
                "prior_authorization"
              ]
            }
          },
          "credentials": {
            "$ref": "#/components/schemas/ErxCredentialFlags"
          },
          "active": {
            "const": false
          },
          "vendor_verified": {
            "const": false
          }
        },
        "required": [
          "version",
          "candidate_profile",
          "profile_revision",
          "enrollment_stage",
          "organization_reference",
          "requested_capabilities",
          "credentials",
          "active",
          "vendor_verified"
        ],
        "additionalProperties": false
      },
      "ErxPrescriberState": {
        "type": "object",
        "properties": {
          "user_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "connection_id": {
            "type": "string",
            "format": "uuid"
          },
          "profile_revision": {
            "type": "integer",
            "minimum": 1
          },
          "profile_current": {
            "type": "boolean"
          },
          "facility_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "vendor_user_id": {
            "type": "string",
            "maxLength": 200
          },
          "vendor_username": {
            "type": "string",
            "maxLength": 200
          },
          "vendor_location_id": {
            "type": "string",
            "maxLength": 200
          },
          "enrollment_reported": {
            "type": "boolean"
          },
          "credentials": {
            "$ref": "#/components/schemas/ErxCredentialFlags"
          },
          "vendor_verified": {
            "const": false
          }
        },
        "required": [
          "user_id",
          "version",
          "connection_id",
          "profile_revision",
          "profile_current",
          "facility_id",
          "vendor_user_id",
          "vendor_username",
          "vendor_location_id",
          "enrollment_reported",
          "credentials",
          "vendor_verified"
        ],
        "additionalProperties": false
      },
      "ErxReadinessCheck": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "connection_version": {
            "type": "integer",
            "minimum": 0
          },
          "native_prescription_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "connection_version",
          "reason"
        ],
        "additionalProperties": false
      },
      "ErxReadinessAttempt": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "candidate_profile": {
            "type": "string",
            "enum": [
              "none",
              "photon",
              "weno_ez",
              "weno_online",
              "dosespot_full",
              "other"
            ]
          },
          "connection_version": {
            "type": "integer",
            "minimum": 0
          },
          "prescriber_version": {
            "type": [
              "integer",
              "null"
            ]
          },
          "outcome": {
            "const": "blocked"
          },
          "vendor_contacted": {
            "const": false
          },
          "native_prescription_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "missing": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "actor_id",
          "candidate_profile",
          "connection_version",
          "prescriber_version",
          "outcome",
          "vendor_contacted",
          "native_prescription_id",
          "missing",
          "created_at"
        ],
        "additionalProperties": false
      },
      "ErxSetupStatus": {
        "type": "object",
        "properties": {
          "connection": {
            "$ref": "#/components/schemas/ErxConnectionState"
          },
          "readiness": {
            "$ref": "#/components/schemas/ErxReadiness"
          },
          "credential_storage_ready": {
            "type": "boolean"
          },
          "profiles": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "prescribers": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "type": "object"
            }
          },
          "prescribers_truncated": {
            "type": "boolean"
          },
          "facilities": {
            "type": "array",
            "maxItems": 200,
            "items": {
              "type": "object"
            }
          },
          "facilities_truncated": {
            "type": "boolean"
          },
          "mappings": {
            "type": "array",
            "maxItems": 201,
            "items": {
              "$ref": "#/components/schemas/ErxPrescriberState"
            }
          }
        },
        "required": [
          "connection",
          "readiness",
          "credential_storage_ready",
          "profiles",
          "prescribers",
          "facilities",
          "mappings"
        ]
      },
      "CorrectImmunization": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/ImmunizationContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ],
        "additionalProperties": false
      },
      "CreateImmunization": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "content": {
            "$ref": "#/components/schemas/ImmunizationContent"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "content",
          "reason"
        ],
        "additionalProperties": false
      },
      "ImmunizationContent": {
        "type": "object",
        "properties": {
          "record_type": {
            "type": "string",
            "enum": [
              "administered",
              "historical",
              "not_given"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "completed",
              "not_done",
              "entered_in_error"
            ]
          },
          "vaccine_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "vaccine_code": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/FhirWriteCoding"
              },
              {
                "type": "null"
              }
            ]
          },
          "occurred_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "occurred_on": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "occurrence_text": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "primary_source": {
            "type": "boolean"
          },
          "report_origin": {
            "type": "string",
            "maxLength": 200
          },
          "visit_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "performer_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "manufacturer": {
            "type": "string",
            "maxLength": 200
          },
          "lot_number": {
            "type": "string",
            "maxLength": 100
          },
          "expiration_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "route": {
            "type": "string",
            "maxLength": 100
          },
          "site": {
            "type": "string",
            "maxLength": 100
          },
          "dose": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ImmunizationDose"
              },
              {
                "type": "null"
              }
            ]
          },
          "not_done_reason": {
            "type": "string",
            "maxLength": 1000
          },
          "notes": {
            "type": "string",
            "maxLength": 10000
          }
        },
        "required": [
          "record_type",
          "status",
          "vaccine_name",
          "primary_source"
        ],
        "additionalProperties": false,
        "description": "Exactly one occurrence timestamp/date/nonempty historical description. Administered requires timestamp, active authorized local performer, dose, route and site. Not-given requires reason and excludes dose/lot/performer. Secondary reports require report_origin; primary reports omit it. No future occurrence or occurrence before patient birth. Record type cannot change; status changes only through native entered-in-error action.",
        "oneOf": [
          {
            "properties": {
              "occurred_at": {
                "type": "string"
              },
              "occurred_on": {
                "type": "null"
              },
              "occurrence_text": {
                "type": "null"
              }
            },
            "required": [
              "occurred_at"
            ]
          },
          {
            "properties": {
              "occurred_at": {
                "type": "null"
              },
              "occurred_on": {
                "type": "string"
              },
              "occurrence_text": {
                "type": "null"
              }
            },
            "required": [
              "occurred_on"
            ]
          },
          {
            "properties": {
              "occurred_at": {
                "type": "null"
              },
              "occurred_on": {
                "type": "null"
              },
              "occurrence_text": {
                "type": "string"
              }
            },
            "required": [
              "occurrence_text"
            ]
          }
        ]
      },
      "ImmunizationDose": {
        "type": "object",
        "properties": {
          "value": {
            "type": "string",
            "pattern": "^(?!0+(?:\\.0+)?$)\\d{1,7}(\\.\\d{1,3})?$",
            "description": "Positive decimal; zero rejected; up to three decimal places. Units are recorded text, not validated UCUM."
          },
          "unit": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          }
        },
        "required": [
          "value",
          "unit"
        ],
        "additionalProperties": false
      },
      "ImmunizationError": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "reason"
        ],
        "additionalProperties": false
      },
      "ImmunizationPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/ImmunizationRecord"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "items",
          "next_cursor"
        ],
        "additionalProperties": false
      },
      "ImmunizationRecord": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "content": {
            "$ref": "#/components/schemas/ImmunizationContent"
          },
          "performer_snapshot": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "display": {
                "type": "string"
              }
            }
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "updated_by": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "version",
          "content",
          "created_by",
          "updated_by",
          "created_at",
          "updated_at"
        ]
      },
      "WritableFhirImmunization": {
        "type": "object",
        "properties": {
          "resourceType": {
            "type": "string",
            "const": "Immunization"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "meta": {
            "$ref": "#/components/schemas/FhirWriteMeta"
          },
          "status": {
            "type": "string",
            "enum": [
              "completed",
              "not-done"
            ]
          },
          "vaccineCode": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "coding": {
                "type": "array",
                "maxItems": 1,
                "items": {
                  "$ref": "#/components/schemas/FhirWriteCoding"
                }
              }
            },
            "required": [
              "text"
            ]
          },
          "patient": {
            "$ref": "#/components/schemas/FhirWriteReference"
          },
          "encounter": {
            "type": "object",
            "properties": {
              "reference": {
                "type": "string",
                "pattern": "^Encounter/[0-9a-fA-F-]{36}$"
              }
            },
            "required": [
              "reference"
            ],
            "additionalProperties": false
          },
          "occurrenceDateTime": {
            "type": "string",
            "description": "Exact YYYY-MM-DD date or full RFC3339 timestamp with offset. Administered requires full timestamp."
          },
          "occurrenceString": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "description": "Historical only; no date is inferred from this text."
          },
          "primarySource": {
            "type": "boolean"
          },
          "reportOrigin": {
            "$ref": "#/components/schemas/FhirWriteText"
          },
          "extension": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "description": "Exact installation origin + /StructureDefinition/immunization-record-type"
                },
                "valueCode": {
                  "type": "string",
                  "enum": [
                    "administered",
                    "historical",
                    "not_given"
                  ]
                }
              },
              "required": [
                "url",
                "valueCode"
              ],
              "additionalProperties": false
            }
          },
          "performer": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "items": {
              "type": "object",
              "properties": {
                "actor": {
                  "type": "object",
                  "properties": {
                    "identifier": {
                      "type": "object",
                      "properties": {
                        "system": {
                          "type": "string",
                          "description": "Exact installation origin + /identifier/staff"
                        },
                        "value": {
                          "type": "string",
                          "format": "uuid"
                        }
                      },
                      "required": [
                        "system",
                        "value"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "identifier"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "actor"
              ],
              "additionalProperties": false
            }
          },
          "manufacturer": {
            "type": "object",
            "properties": {
              "display": {
                "type": "string",
                "maxLength": 200
              }
            },
            "required": [
              "display"
            ],
            "additionalProperties": false
          },
          "lotNumber": {
            "type": "string",
            "maxLength": 100
          },
          "expirationDate": {
            "type": "string",
            "format": "date"
          },
          "route": {
            "$ref": "#/components/schemas/FhirWriteText"
          },
          "site": {
            "$ref": "#/components/schemas/FhirWriteText"
          },
          "doseQuantity": {
            "type": "object",
            "properties": {
              "value": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 9999999.999,
                "multipleOf": 0.001
              },
              "unit": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80
              }
            },
            "required": [
              "value",
              "unit"
            ],
            "additionalProperties": false
          },
          "statusReason": {
            "$ref": "#/components/schemas/FhirWriteText"
          },
          "note": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "items": {
              "$ref": "#/components/schemas/FhirWriteText"
            }
          }
        },
        "required": [
          "resourceType",
          "status",
          "vaccineCode",
          "patient",
          "primarySource",
          "extension"
        ],
        "additionalProperties": false,
        "description": "Bounded native vaccine-event subset. Exactly one occurrenceDateTime/occurrenceString. Explicit native record-type extension is required and distinct from primarySource. Performer is a local staff identifier, not an invented Practitioner resource. New entered-in-error records, unsupported fields, recorded timestamps supplied by caller, unknown extensions, and conditional/idempotency headers are rejected. Native entered-in-error action is the reviewed error workflow. POST assigns ID/version; PUT requires matching id, If-Match and X-Change-Reason."
      },
      "ImmunizationRevision": {
        "type": "object",
        "properties": {
          "immunization_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "author_label": {
            "type": [
              "string",
              "null"
            ],
            "description": "Current tenant staff directory label, not a historical identity snapshot; immutable actor_id remains authoritative."
          },
          "reason": {
            "type": "string"
          },
          "snapshot": {
            "$ref": "#/components/schemas/ImmunizationRecord"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "immunization_id",
          "version",
          "actor_id",
          "author_label",
          "reason",
          "snapshot",
          "created_at"
        ]
      },
      "TerminologySystem": {
        "type": "string",
        "enum": [
          "ICD-10-CM",
          "ICD-10-PCS",
          "HCPCS",
          "CPT"
        ]
      },
      "TerminologyRelease": {
        "type": "object",
        "additionalProperties": false,
        "description": "Immutable tenant-owned release metadata. License agreement reference and importing owner identity are not exposed by reference reads.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "system": {
            "$ref": "#/components/schemas/TerminologySystem"
          },
          "edition": {
            "type": "string"
          },
          "source_name": {
            "type": "string"
          },
          "source_url": {
            "type": "string",
            "format": "uri"
          },
          "source_sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "effective_start": {
            "type": "string",
            "format": "date"
          },
          "effective_end": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "rights": {
            "enum": [
              "public_use",
              "licensed"
            ]
          },
          "license_valid_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "code_count": {
            "type": "integer",
            "minimum": 1,
            "maximum": 150000
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "system",
          "edition",
          "source_name",
          "source_url",
          "source_sha256",
          "effective_start",
          "effective_end",
          "rights",
          "license_valid_until",
          "code_count",
          "created_at"
        ]
      },
      "TerminologyCode": {
        "type": "object",
        "description": "Canonical catalog entry. Effective dates are the intersection of release and code dates. Syntax alone does not establish assignment, billability, coverage or licensing. ICD-10-CM permits an alphanumeric second character, including FY2027 QA0 codes; CPT supports numeric, F, T, U and M suffixes.",
        "allOf": [
          {
            "if": {
              "properties": {
                "system": {
                  "const": "ICD-10-CM"
                }
              }
            },
            "then": {
              "properties": {
                "code": {
                  "pattern": "^[A-Z][A-Z0-9]{2}(\\.[A-Z0-9]{1,4})?$"
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "system": {
                  "const": "ICD-10-PCS"
                }
              }
            },
            "then": {
              "properties": {
                "code": {
                  "pattern": "^[A-HJ-NP-Z0-9]{7}$"
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "system": {
                  "const": "HCPCS"
                }
              }
            },
            "then": {
              "properties": {
                "code": {
                  "pattern": "^[A-Z][0-9]{4}$"
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "system": {
                  "const": "CPT"
                }
              }
            },
            "then": {
              "properties": {
                "code": {
                  "pattern": "^[0-9]{4}[0-9FTUM]$"
                }
              }
            }
          }
        ],
        "properties": {
          "release_id": {
            "type": "string",
            "format": "uuid"
          },
          "system": {
            "$ref": "#/components/schemas/TerminologySystem"
          },
          "edition": {
            "type": "string"
          },
          "source_name": {
            "type": "string"
          },
          "source_url": {
            "type": "string",
            "format": "uri"
          },
          "source_sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "effective_start": {
            "type": "string",
            "format": "date"
          },
          "effective_end": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "code": {
            "type": "string",
            "maxLength": 8
          },
          "display": {
            "type": "string",
            "description": "Publisher description, bounded to 10000 UTF-8 bytes."
          },
          "short_display": {
            "type": [
              "string",
              "null"
            ]
          },
          "billable": {
            "type": "boolean"
          },
          "active": {
            "type": "boolean"
          },
          "metadata": {
            "type": "object",
            "description": "Publisher metadata, at most 4096 serialized UTF-8 bytes."
          }
        },
        "required": [
          "release_id",
          "system",
          "edition",
          "source_name",
          "source_url",
          "source_sha256",
          "effective_start",
          "effective_end",
          "code",
          "display",
          "short_display",
          "billable",
          "active",
          "metadata"
        ]
      },
      "TerminologySelectionSnapshot": {
        "allOf": [
          {
            "$ref": "#/components/schemas/TerminologyCode"
          },
          {
            "type": "object",
            "properties": {
              "service_date": {
                "type": "string",
                "format": "date"
              }
            },
            "required": [
              "service_date"
            ]
          }
        ],
        "readOnly": true,
        "description": "Server-resolved immutable selection provenance, including the service date actually validated. Caller-supplied snapshots never establish catalog validity."
      },
      "TerminologyCodeInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string",
            "description": "Trimmed and uppercased. ICD-10-CM: letter plus 2 to 6 alphanumerics; optional decimal only after character 3, canonicalized on import. ICD-10-PCS: 7 alphanumerics excluding I and O. HCPCS: letter plus 4 digits. CPT: 4 digits followed by a digit or F, T, U or M. Duplicate canonical codes are rejected."
          },
          "display": {
            "type": "string",
            "minLength": 1,
            "description": "Required nonblank description; at most 10000 UTF-8 bytes after trimming; control characters rejected."
          },
          "short_display": {
            "type": [
              "string",
              "null"
            ],
            "description": "Optional nonblank description, at most 256 UTF-8 bytes."
          },
          "billable": {
            "type": "boolean"
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "effective_start": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Defaults to release start."
          },
          "effective_end": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Defaults to release end; must not precede code start."
          },
          "metadata": {
            "type": "object",
            "default": {},
            "description": "At most 4096 serialized UTF-8 bytes."
          }
        },
        "required": [
          "code",
          "display",
          "billable"
        ]
      },
      "TerminologyImport": {
        "type": "object",
        "additionalProperties": false,
        "description": "Owner-authorized import, at most 64 MiB. CPT requires rights=licensed and an authorized license reference. No CPT dataset is bundled.",
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "system": {
            "type": "string",
            "description": "Canonical system: ICD-10-CM, ICD-10-PCS, HCPCS or CPT. Matching is case-insensitive; documented system URI and compact ICD aliases are also accepted."
          },
          "edition": {
            "type": "string",
            "minLength": 1,
            "description": "Nonblank, at most 120 UTF-8 bytes after trimming."
          },
          "source_name": {
            "type": "string",
            "minLength": 1,
            "description": "Nonblank, at most 200 UTF-8 bytes after trimming."
          },
          "source_url": {
            "type": "string",
            "format": "uri",
            "description": "HTTPS source URL, at most 2000 UTF-8 bytes; no credentials, query or fragment."
          },
          "source_sha256": {
            "type": "string",
            "description": "64 hexadecimal characters; normalized to lowercase."
          },
          "effective_start": {
            "type": "string",
            "format": "date"
          },
          "effective_end": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Inclusive; must not precede start."
          },
          "rights": {
            "type": "string",
            "enum": [
              "public_use",
              "licensed"
            ]
          },
          "rights_attested": {
            "type": "boolean",
            "const": true
          },
          "license_reference": {
            "type": [
              "string",
              "null"
            ],
            "writeOnly": true,
            "description": "Required for licensed datasets, including CPT; nonblank and at most 500 UTF-8 bytes."
          },
          "license_valid_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Inclusive; cannot be earlier than current UTC date. Expired releases are excluded from subsequent catalog reads and new selections."
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "description": "Attributed import reason, at most 1000 UTF-8 bytes."
          },
          "codes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TerminologyCodeInput"
            },
            "minItems": 1,
            "maxItems": 150000
          }
        },
        "required": [
          "request_id",
          "system",
          "edition",
          "source_name",
          "source_url",
          "source_sha256",
          "effective_start",
          "rights",
          "rights_attested",
          "reason",
          "codes"
        ]
      },
      "AiConnection": {
        "type": "object",
        "additionalProperties": false,
        "description": "Safe staff-visible connection projection. Does not expose provider routing configuration or credentials; model availability is validated on use.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "provider": {
            "enum": [
              "claude",
              "erebine"
            ]
          },
          "label": {
            "type": "string"
          },
          "model": {
            "type": [
              "string",
              "null"
            ]
          },
          "enabled": {
            "const": true
          },
          "status": {
            "type": "string"
          },
          "credential_stored": {
            "const": true
          },
          "capabilities": {
            "type": "array",
            "items": {
              "enum": [
                "document_classification",
                "structured_extraction",
                "draft_summary",
                "draft_response",
                "workflow_design"
              ]
            }
          }
        },
        "required": [
          "id",
          "provider",
          "label",
          "model",
          "enabled",
          "status",
          "credential_stored",
          "capabilities"
        ]
      },
      "ErebineRoutingConfig": {
        "type": "object",
        "additionalProperties": false,
        "description": "Native Erebine SDK routing uses the fixed HTTPS api.erebine.ai origin. Arbitrary origins and unknown configuration keys are rejected.",
        "properties": {
          "project_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "pattern": "^[A-Za-z0-9._-]+$",
            "description": "Required; dot and double-dot identifiers are rejected."
          },
          "workspace_id": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1,
            "maxLength": 200,
            "pattern": "^[A-Za-z0-9._-]+$",
            "description": "Optional; dot and double-dot identifiers are rejected."
          },
          "endpoint_slug": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1,
            "maxLength": 200,
            "pattern": "^[A-Za-z0-9._-]+$",
            "description": "Optional endpoint slug; omit for direct routing. Dot and double-dot identifiers are rejected."
          },
          "model": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 120,
            "description": "Required and nonblank when saving or using a connection. Discovery may omit it, use null or an empty string. Other values must have no surrounding whitespace or control characters; at most 120 UTF-8 bytes."
          }
        },
        "required": [
          "project_id"
        ]
      },
      "ErebineConfig": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ErebineRoutingConfig"
          },
          {
            "required": [
              "model"
            ],
            "properties": {
              "model": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              }
            }
          }
        ]
      },
      "ErebineModels": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "models": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 120
                }
              },
              "required": [
                "id"
              ]
            },
            "maxItems": 2000
          }
        },
        "required": [
          "models"
        ]
      },
      "CarePathwayAiConfiguration": {
        "type": "object",
        "additionalProperties": false,
        "description": "Optional configuration for ai_extract_draft and ai_response_draft nodes only. Both kinds require manual_approval=true. Dispatch approval precedes provider execution; generated output retains its separate human-review gate. The run patient_id supplies optional local identifier context; it cannot be overridden by dispatch input and is not sent as an internal ID to the provider.",
        "properties": {
          "integration_id": {
            "type": "string",
            "format": "uuid",
            "description": "Non-nil clinic AI connection ID; validated against the selected draft purpose at execution."
          },
          "instruction": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000,
            "description": "Nonblank instruction, at most 4000 UTF-8 bytes; NUL rejected."
          },
          "source_field": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "pattern": "^/",
            "description": "Explicit JSON pointer into the workflow context, at most 200 UTF-8 bytes. Only ~0 and ~1 escapes are allowed. Empty pointer, control characters, configuration and credential path segments are rejected."
          },
          "privacy": {
            "$ref": "#/components/schemas/CarePathwayAiPrivacyPolicy",
            "default": {
              "mode": "pseudonymize",
              "preview_required": true,
              "restore_locally": true,
              "retain_clinical_codes": true
            }
          }
        },
        "required": [
          "integration_id",
          "instruction",
          "source_field"
        ]
      },
      "AiDraftMetadata": {
        "type": "object",
        "description": "Shared Claude/Erebine draft metadata. No tenant ID, request digest, source text or credential. List responses omit generated content and exclude requesting drafts.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "integration_id": {
            "type": "string",
            "format": "uuid"
          },
          "provider": {
            "enum": [
              "claude",
              "erebine"
            ]
          },
          "patient_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "pathway_instance_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "step_key": {
            "type": [
              "string",
              "null"
            ]
          },
          "purpose": {
            "enum": [
              "document_classification",
              "structured_extraction",
              "draft_summary",
              "draft_response",
              "workflow_design"
            ]
          },
          "model": {
            "type": "string",
            "maxLength": 120
          },
          "status": {
            "enum": [
              "requesting",
              "draft",
              "failed",
              "approved",
              "rejected"
            ]
          },
          "provider_message_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider_request_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "stop_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "usage": {
            "type": "object"
          },
          "failure_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "reviewed_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "review_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "reviewed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "privacy_preview_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "readOnly": true
          },
          "privacy": {
            "$ref": "#/components/schemas/AiPrivacyApprovalRecord",
            "readOnly": true
          }
        },
        "required": [
          "id",
          "request_id",
          "integration_id",
          "provider",
          "patient_id",
          "pathway_instance_id",
          "step_key",
          "purpose",
          "model",
          "status",
          "provider_message_id",
          "provider_request_id",
          "stop_reason",
          "usage",
          "failure_code",
          "version",
          "created_by",
          "reviewed_by",
          "review_reason",
          "created_at",
          "updated_at",
          "reviewed_at"
        ]
      },
      "AiDraft": {
        "allOf": [
          {
            "$ref": "#/components/schemas/AiDraftMetadata"
          },
          {
            "type": "object",
            "properties": {
              "content": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Generated draft text, bounded to 131072 UTF-8 bytes; null while requesting or failed."
              }
            },
            "required": [
              "content"
            ]
          }
        ]
      },
      "AiDraftEvent": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "sequence": {
            "type": "integer"
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "action": {
            "type": "string"
          },
          "evidence": {
            "type": "object"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "sequence",
          "actor_id",
          "action",
          "evidence",
          "created_at"
        ]
      },
      "CarePathwayAiPrivacyPolicy": {
        "type": "object",
        "additionalProperties": false,
        "description": "Mandatory invariant for every Sun workflow request. Legacy nodes default to this policy. Alternate modes or any disabling value are rejected; local replacement mappings never leave the EHR.",
        "properties": {
          "mode": {
            "const": "pseudonymize"
          },
          "preview_required": {
            "const": true
          },
          "restore_locally": {
            "const": true
          },
          "retain_clinical_codes": {
            "const": true
          }
        },
        "required": [
          "mode",
          "preview_required",
          "restore_locally",
          "retain_clinical_codes"
        ]
      },
      "AiPrivacyPreviewInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "purpose",
          "instruction",
          "source_text"
        ],
        "properties": {
          "integration_id": {
            "type": "string",
            "format": "uuid",
            "description": "Explicit clinic-owned Claude or Erebine connection; omission is allowed only when exactly one eligible connection exists."
          },
          "purpose": {
            "enum": [
              "document_classification",
              "structured_extraction",
              "draft_summary",
              "draft_response",
              "workflow_design"
            ]
          },
          "instruction": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000
          },
          "source_text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 65536
          },
          "pathway_instance_id": {
            "type": "string",
            "format": "uuid"
          },
          "step_key": {
            "type": "string",
            "minLength": 1,
            "maxLength": 63
          },
          "patient_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Optional tenant patient used only for local identifier detection and revision binding. A linked pathway supplies its trusted patient; any explicit patient must match."
          }
        }
      },
      "AiPrivacyPreview": {
        "type": "object",
        "additionalProperties": false,
        "description": "Single-use preview valid for 15 minutes and bound to tenant, reviewer, exact input, selected connection/model, credential configuration, patient revisions and optional workflow revision. Mapping and original input are stored locally in encrypted form and never returned by this preview. Review remains necessary; detection is not a guarantee that all identifying text was found.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "integration_id": {
            "type": "string",
            "format": "uuid"
          },
          "provider": {
            "enum": [
              "claude",
              "erebine"
            ]
          },
          "model": {
            "type": "string"
          },
          "patient_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Local review context only; not part of outbound provider content."
          },
          "purpose": {
            "enum": [
              "document_classification",
              "structured_extraction",
              "draft_summary",
              "draft_response",
              "workflow_design"
            ]
          },
          "instruction": {
            "type": "string",
            "description": "Exact sanitized instruction approved for the provider request."
          },
          "source_text": {
            "type": "string",
            "description": "Exact sanitized source text approved for the provider request. Supported clinical codes remain intact."
          },
          "redaction_count": {
            "type": "integer",
            "minimum": 0
          },
          "identifier_types": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "requires_approval": {
            "const": true
          }
        },
        "required": [
          "id",
          "expires_at",
          "integration_id",
          "provider",
          "model",
          "patient_id",
          "purpose",
          "instruction",
          "source_text",
          "redaction_count",
          "identifier_types",
          "warnings",
          "requires_approval"
        ]
      },
      "AiPrivacyApprovalRecord": {
        "type": "object",
        "description": "Attributed privacy evidence without replacement mappings. Historical drafts may contain an empty object.",
        "properties": {
          "status": {
            "const": "approved"
          },
          "preview_id": {
            "type": "string",
            "format": "uuid"
          },
          "redaction_count": {
            "type": "integer",
            "minimum": 0
          },
          "identifier_types": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "method": {
            "type": "string"
          },
          "limitations": {
            "type": "string",
            "description": "Human-readable limits of local identifier substitution."
          },
          "approved_by": {
            "type": "string",
            "format": "uuid"
          },
          "approved_at": {
            "type": "string",
            "format": "date-time"
          },
          "patient_context_used": {
            "type": "boolean"
          }
        },
        "required": []
      },
      "AccessPolicyPermissions": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "view": {
            "type": "boolean",
            "default": false
          },
          "create": {
            "type": "boolean",
            "default": false
          },
          "edit": {
            "type": "boolean",
            "default": false
          },
          "delete": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "AccessPolicyChange": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "base_role",
          "permissions",
          "reason"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "base_role": {
            "type": "string",
            "enum": [
              "clinician",
              "nurse",
              "medical_assistant",
              "front_desk",
              "read_only"
            ]
          },
          "permissions": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/AccessPolicyPermissions"
            },
            "description": "Resource keys: clinical, scheduling, billing, claims, communications, workflows, ai, integrations, practice, terminology, migration, events. Omitted permissions deny. Native role ceilings still apply; writes require view."
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "PracticeWorkspaceConfiguration": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "module_order",
          "chart_tabs"
        ],
        "properties": {
          "module_order": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string",
              "enum": [
                "practice",
                "clinical",
                "schedule",
                "labs",
                "referrals",
                "followup",
                "portal",
                "specialty",
                "billing",
                "claims",
                "edi",
                "apps",
                "migration",
                "admin",
                "workflows",
                "automation",
                "communications",
                "ai_review"
              ]
            },
            "description": "All supported module keys once. Legacy layouts missing only the four formerly fixed tools are normalized on read/write."
          },
          "hidden_modules": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string",
              "enum": [
                "practice",
                "clinical",
                "schedule",
                "labs",
                "referrals",
                "followup",
                "portal",
                "specialty",
                "billing",
                "claims",
                "edi",
                "apps",
                "migration",
                "admin",
                "workflows",
                "automation",
                "communications",
                "ai_review"
              ]
            }
          },
          "chart_tabs": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string"
            },
            "description": "Native chart area keys; overview required. Omitted areas remain hidden. Functional status and specialty care are independently selectable built-in areas; no specialty bundle is required."
          },
          "specialty_workspaces": {
            "type": "array",
            "deprecated": true,
            "writeOnly": true,
            "description": "Legacy presentation input, accepted for compatibility. An empty array preserves the previously hidden specialty navigation entry by adding specialty to hidden_modules. New requests use hidden_modules and chart_tabs independently. Normalized responses and new revisions omit this field; existing stored revisions remain unchanged.",
            "items": {
              "enum": [
                "spasticity_movement"
              ]
            }
          },
          "module_labels": {
            "type": "object",
            "propertyNames": {
              "enum": [
                "practice",
                "clinical",
                "schedule",
                "labs",
                "referrals",
                "followup",
                "portal",
                "specialty",
                "billing",
                "claims",
                "edi",
                "apps",
                "migration",
                "admin",
                "workflows",
                "automation",
                "communications",
                "ai_review"
              ]
            },
            "additionalProperties": {
              "type": "string",
              "minLength": 1,
              "maxLength": 60
            }
          },
          "module_groups": {
            "type": "object",
            "propertyNames": {
              "enum": [
                "practice",
                "clinical",
                "schedule",
                "labs",
                "referrals",
                "followup",
                "portal",
                "specialty",
                "billing",
                "claims",
                "edi",
                "apps",
                "migration",
                "admin",
                "workflows",
                "automation",
                "communications",
                "ai_review"
              ]
            },
            "additionalProperties": {
              "enum": [
                "today",
                "care",
                "revenue",
                "manage"
              ]
            }
          }
        }
      },
      "CopayReceiptInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          },
          "coverage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000
          },
          "method": {
            "type": "string",
            "enum": [
              "cash",
              "check",
              "external"
            ]
          },
          "reference": {
            "type": "string",
            "maxLength": 200
          },
          "occurred_on": {
            "type": "string",
            "format": "date"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "received_confirmed": {
            "const": true
          }
        },
        "required": [
          "request_id",
          "appointment_id",
          "amount_cents",
          "method",
          "reference",
          "occurred_on",
          "reason",
          "received_confirmed"
        ],
        "description": "Confirmed payment already received. Receipt date cannot be in the future. Nonblank reference is required for check/external. Does not initiate a card or bank transaction."
      },
      "CopayReceipt": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          },
          "coverage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "amount_cents": {
            "type": "integer"
          },
          "method": {
            "enum": [
              "cash",
              "check",
              "external"
            ]
          },
          "reference": {
            "type": "string"
          },
          "occurred_on": {
            "type": "string",
            "format": "date"
          },
          "reason": {
            "type": "string"
          },
          "coverage_snapshot": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Coverage"
              },
              {
                "type": "null"
              }
            ]
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "allocated_cents": {
            "type": "integer",
            "minimum": 0
          },
          "reversed_cents": {
            "type": "integer",
            "minimum": 0
          },
          "voided": {
            "type": "boolean"
          },
          "account_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "hosted_checkout": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "livemode": {
                "type": "boolean"
              },
              "status": {
                "enum": [
                  "creating",
                  "open",
                  "paid",
                  "expired",
                  "needs_review",
                  "refunded"
                ]
              },
              "refunded_cents": {
                "type": "integer",
                "minimum": 0
              },
              "refunded_unapplied_cents": {
                "type": "integer",
                "minimum": 0
              }
            },
            "description": "Present for processor-verified hosted receipts. Manual void/reversal is rejected; verified provider refunds govern their accounting. Test receipts cannot be allocated in production."
          }
        },
        "required": [
          "id",
          "patient_id",
          "appointment_id",
          "amount_cents",
          "method",
          "reference",
          "occurred_on",
          "actor_id",
          "created_at",
          "allocated_cents",
          "reversed_cents",
          "voided",
          "account_ids"
        ],
        "description": "Immutable receipt evidence plus current allocation/void state. Reversing an allocation does not refund funds or make the original receipt reusable."
      },
      "CopayVoidInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "reason"
        ]
      },
      "PatientInvoiceService": {
        "type": "object",
        "properties": {
          "code_system": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "modifiers": {
            "type": "string"
          },
          "units": {
            "type": "integer"
          },
          "line_total_cents": {
            "type": "integer"
          }
        },
        "required": [
          "code_system",
          "code",
          "description",
          "modifiers",
          "units",
          "line_total_cents"
        ],
        "description": "Saved full line total for the quantity; do not multiply line_total_cents by units again."
      },
      "PatientInvoiceActivity": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "enum": [
              "payment",
              "adjustment_credit",
              "adjustment_debit",
              "reversal"
            ]
          },
          "occurred_on": {
            "type": "string",
            "format": "date"
          },
          "method": {
            "type": "string"
          },
          "reference": {
            "type": "string"
          },
          "effect_cents": {
            "type": "integer"
          },
          "reverses_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "description": "Patient-only ledger evidence at issuance. Negative effect reduces balance. Internal staff reason/notes are not copied."
      },
      "PatientInvoiceSnapshot": {
        "type": "object",
        "properties": {
          "format_version": {
            "const": 2
          },
          "practice_name": {
            "type": "string"
          },
          "patient": {
            "type": "object",
            "properties": {
              "given_name": {
                "type": "string"
              },
              "family_name": {
                "type": "string"
              },
              "mrn": {
                "type": "string"
              }
            },
            "required": [
              "given_name",
              "family_name"
            ]
          },
          "service_date": {
            "type": "string",
            "format": "date"
          },
          "services": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PatientInvoiceService"
            }
          },
          "patient_activity": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PatientInvoiceActivity"
            }
          },
          "currency": {
            "const": "USD"
          },
          "reason": {
            "type": "string"
          },
          "test_activity": {
            "type": "boolean"
          },
          "scope": {
            "const": "at_issuance"
          },
          "gross_charges_cents": {
            "type": "integer"
          },
          "responsibility_cents": {
            "type": "integer"
          },
          "patient_credit_cents": {
            "type": "integer"
          },
          "patient_payment_cents": {
            "type": "integer"
          },
          "patient_adjustment_credit_cents": {
            "type": "integer"
          },
          "amount_due_cents": {
            "type": "integer"
          },
          "credit_balance_cents": {
            "type": "integer"
          }
        },
        "required": [
          "patient",
          "service_date",
          "gross_charges_cents",
          "responsibility_cents",
          "patient_credit_cents",
          "amount_due_cents",
          "credit_balance_cents",
          "currency",
          "scope"
        ],
        "description": "Immutable issuance snapshot. Format 2 adds itemized services, patient activity and payment/adjustment subtotals. These fields are absent in older saved snapshots; clients must show original totals with an explicit unavailable-itemization message, never rebuild old invoices from current records."
      },
      "PatientInvoice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_version": {
            "type": "integer"
          },
          "snapshot": {
            "$ref": "#/components/schemas/PatientInvoiceSnapshot"
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "patient_id",
          "account_id",
          "account_version",
          "snapshot",
          "actor_id",
          "created_at"
        ]
      },
      "NewFhirPatient": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "resourceType": {
            "type": "string",
            "const": "Patient"
          },
          "name": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "use": {
                  "type": "string",
                  "const": "official"
                },
                "family": {
                  "type": "string",
                  "maxLength": 100,
                  "minLength": 1
                },
                "given": {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 1,
                  "items": {
                    "type": "string",
                    "maxLength": 100,
                    "minLength": 1
                  }
                }
              },
              "required": [
                "family",
                "given"
              ]
            }
          },
          "birthDate": {
            "type": "string",
            "format": "date"
          }
        },
        "required": [
          "resourceType",
          "name",
          "birthDate"
        ],
        "description": "Creation subset: identifiers are assigned by the server; omit identifier, id and meta."
      },
      "BillingEntryContent": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "payment",
              "adjustment_credit",
              "adjustment_debit",
              "reversal"
            ]
          },
          "amount_cents": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 1000000000
          },
          "reverses_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "party": {
            "type": "string",
            "enum": [
              "patient",
              "insurer",
              "other"
            ]
          },
          "method": {
            "type": "string",
            "enum": [
              "cash",
              "check",
              "external",
              "other",
              "none"
            ]
          },
          "reference": {
            "type": "string",
            "minLength": 0,
            "maxLength": 200
          },
          "occurred_on": {
            "type": "string",
            "format": "date"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "copay_receipt_id": {
            "type": "string",
            "format": "uuid",
            "description": "Server-assigned source receipt for an automatic appointment copay allocation."
          }
        },
        "required": [
          "kind",
          "amount_cents",
          "party",
          "method",
          "reference",
          "occurred_on",
          "reason"
        ],
        "description": "Stored ledger content, including server-attributed receipt or provider evidence. Unlike NewBillingEntry, it is not accepted as a write payload."
      },
      "HostedCopayOperation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 50,
            "maximum": 100000000
          },
          "currency": {
            "const": "USD"
          },
          "livemode": {
            "type": "boolean"
          },
          "status": {
            "enum": [
              "creating",
              "open",
              "paid",
              "expired",
              "needs_review",
              "refunded"
            ]
          },
          "checkout_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Available only for an open attempt permitted in this environment."
          },
          "receipt_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "refunded_cents": {
            "type": "integer",
            "minimum": 0
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "captured_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_result": {
            "type": [
              "string",
              "null"
            ]
          },
          "channel": {
            "type": "string",
            "enum": [
              "hosted",
              "reader"
            ],
            "description": "`hosted` for a Stripe-hosted Checkout link, `reader` for a card payment taken on a reader. For a reader payment `last_result` says where it stands: `reader_waiting`, `reader_offline` or `reader_finishing` while open; `reader_declined`, `reader_cancelled`, `reader_timed_out`, `reader_offline`, `reader_in_use`, `reader_unavailable` or `reader_failed` once closed (`expired`)."
          },
          "reader_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "The card reader for a reader payment."
          }
        },
        "required": [
          "id",
          "patient_id",
          "appointment_id",
          "request_id",
          "amount_cents",
          "currency",
          "livemode",
          "status",
          "checkout_url",
          "receipt_id",
          "refunded_cents",
          "version",
          "created_at",
          "captured_at",
          "last_result",
          "channel",
          "reader_id"
        ],
        "description": "Immutable appointment/payment binding with durable reconciliation state. Receipt creation requires independently retrieved account/mode-bound captured charge evidence. Browser return and Checkout opening never count as payment."
      },
      "HostedCopayInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "coverage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 50,
            "maximum": 100000000
          },
          "livemode": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "reader_id": {
            "type": "string",
            "pattern": "^tmr_[A-Za-z0-9]+$",
            "description": "A card reader from GET /api/v1/billing/payments/readers. When present the payment is taken on that reader instead of a Stripe-hosted Checkout link."
          }
        },
        "required": [
          "request_id",
          "amount_cents",
          "livemode",
          "reason"
        ]
      },
      "ClaimTracking": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "submissions": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "status": {
                  "type": "string"
                },
                "technical_status": {
                  "type": "string"
                },
                "payer_outcome": {
                  "type": "string"
                },
                "created_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                }
              },
              "required": [
                "id",
                "status",
                "technical_status",
                "payer_outcome",
                "created_at"
              ]
            }
          },
          "reports": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "submission_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "received_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "evidence": {
                  "type": "object",
                  "additionalProperties": true,
                  "description": "Canonical allowlisted Claim.MD response fields, including senderid, sender_name, response_time, status and message. Acknowledgment is not payer acceptance or payment."
                }
              },
              "required": [
                "id",
                "submission_id",
                "received_at",
                "evidence"
              ]
            }
          },
          "connections": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "route_key": {
                  "type": "string"
                },
                "paused": {
                  "type": "boolean"
                },
                "last_poll_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "last_success_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "next_poll_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "last_result": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "route_key",
                "paused",
                "last_poll_at",
                "last_success_at",
                "next_poll_at",
                "last_result"
              ]
            }
          },
          "eligibility": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "status": {
                    "type": "string"
                  },
                  "created_at": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "completed_at": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "service_date": {
                    "type": "string",
                    "format": "date"
                  }
                },
                "required": [
                  "status",
                  "created_at",
                  "completed_at",
                  "service_date"
                ]
              }
            ]
          },
          "remittance_posted": {
            "type": "boolean"
          },
          "external_submission_recorded": {
            "type": "boolean"
          }
        },
        "required": [
          "submissions",
          "reports",
          "connections",
          "eligibility",
          "remittance_posted",
          "external_submission_recorded"
        ],
        "description": "Read-only evidence scoped to the exact tenant and claim. Eligibility matches frozen coverage, member, payer and service date. Remittance posting does not imply zero balance. No GET triggers provider calls or accounting changes."
      },
      "OfficeEditorSession": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "session_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "saving",
              "saved",
              "needs_review",
              "closed"
            ]
          },
          "current_version": {
            "type": "integer",
            "minimum": 1
          },
          "save_request_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "last_error": {
            "type": [
              "string",
              "null"
            ]
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "editor_origin": {
            "type": "string"
          },
          "config": {
            "type": "object",
            "additionalProperties": true,
            "description": "Exact server-signed ONLYOFFICE configuration. Token, scoped source URL and callback capability are sensitive and must not be logged."
          }
        },
        "required": [
          "session_id",
          "status",
          "current_version",
          "save_request_id",
          "last_error",
          "expires_at"
        ],
        "description": "Scoped to the current authenticated browser session, patient, document, immutable base file version and document metadata revision. A metadata or encounter-link change requires reopening the editor. Only a matching save_request_id with status saved confirms an EHR save."
      },
      "OfficeEditorSessionCreate": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "base_version": {
            "type": "integer",
            "minimum": 1
          },
          "mode": {
            "type": "string",
            "enum": [
              "view",
              "edit"
            ]
          }
        },
        "required": [
          "request_id",
          "base_version",
          "mode"
        ]
      },
      "OfficeEditorSave": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "request_id",
          "expected_version"
        ]
      },
      "DocumentFileAnnotation": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "page": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000
          },
          "kind": {
            "type": "string",
            "enum": [
              "highlight",
              "rectangle",
              "note"
            ]
          },
          "x": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "y": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "width": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 1
          },
          "height": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 1
          },
          "text": {
            "type": "string",
            "maxLength": 2000,
            "default": ""
          },
          "color": {
            "type": "string",
            "enum": [
              "yellow",
              "blue",
              "red"
            ]
          }
        },
        "required": [
          "id",
          "page",
          "kind",
          "x",
          "y",
          "width",
          "height",
          "color"
        ],
        "description": "Normalized top-left page rectangle; x+width and y+height must not exceed 1. IDs must be unique in the version. PDF page numbers start at 1; images require page 1. Stored overlays are displayed by the file viewer and do not modify or redact the underlying binary."
      },
      "DocumentFileVersionSummary": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "filename": {
            "type": "string"
          },
          "content_type": {
            "type": "string",
            "enum": [
              "application/pdf",
              "image/png",
              "image/jpeg",
              "text/plain",
              "audio/mpeg",
              "audio/wav",
              "audio/ogg",
              "audio/webm",
              "audio/mp4",
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "size_bytes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10485760
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "reason": {
            "type": "string"
          },
          "actor_label": {
            "type": [
              "string",
              "null"
            ]
          },
          "annotation_count": {
            "type": "integer",
            "minimum": 0,
            "maximum": 500
          }
        },
        "required": [
          "version",
          "filename",
          "content_type",
          "sha256",
          "size_bytes",
          "actor_id",
          "created_at",
          "reason",
          "actor_label",
          "annotation_count"
        ]
      },
      "DocumentFileVersion": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "filename": {
            "type": "string"
          },
          "content_type": {
            "type": "string",
            "enum": [
              "application/pdf",
              "image/png",
              "image/jpeg",
              "text/plain",
              "audio/mpeg",
              "audio/wav",
              "audio/ogg",
              "audio/webm",
              "audio/mp4",
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "size_bytes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10485760
          },
          "actor_id": {
            "type": "string",
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "reason": {
            "type": "string"
          },
          "annotations": {
            "type": "array",
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/DocumentFileAnnotation"
            }
          },
          "text_content": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200000,
            "description": "Only populated for text/plain. Other file bytes require the authenticated preview/download endpoints."
          }
        },
        "required": [
          "version",
          "filename",
          "content_type",
          "sha256",
          "size_bytes",
          "actor_id",
          "created_at",
          "reason",
          "annotations",
          "text_content"
        ],
        "description": "Immutable working copy, original version 1, or an appended version. Metadata versioning is independent; actor and reason are retained per saved copy."
      },
      "DocumentFileVersionPage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 101,
            "items": {
              "$ref": "#/components/schemas/DocumentFileVersionSummary"
            }
          },
          "latest_version": {
            "type": "integer",
            "minimum": 1
          },
          "truncated": {
            "type": "boolean"
          }
        },
        "required": [
          "items",
          "latest_version",
          "truncated"
        ],
        "description": "Latest 100 appended versions descending, followed by preserved original version 1. truncated indicates older appended versions were omitted."
      },
      "DocumentFileSave": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "text_content": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1,
            "maxLength": 200000,
            "description": "Only for a text/plain original, limited to 200,000 UTF-8 bytes. Cannot be combined with non-null content_base64."
          },
          "content_base64": {
            "type": [
              "string",
              "null"
            ],
            "format": "byte",
            "maxLength": 13981016,
            "description": "Optional new binary of the same MIME type, 1 byte to 10 MiB. Omit both content fields to retain the chosen base bytes while changing annotations."
          },
          "annotations": {
            "type": "array",
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/DocumentFileAnnotation"
            }
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "request_id",
          "annotations",
          "reason"
        ],
        "description": "Append a working-file version using If-Match of the current FILE version, not metadata version. Original and prior copies are immutable. Exact retries replay their existing version; changed content with the same request ID or a stale file version conflicts. Only active documents accept saves. Annotation overlays are allowed only on PDF/PNG/JPEG."
      },
      "EraPayerIdentity": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "n1_qualifier",
          "n1_identifier",
          "additional_payer_id"
        ],
        "properties": {
          "n1_qualifier": {
            "type": "string",
            "maxLength": 3
          },
          "n1_identifier": {
            "type": "string",
            "maxLength": 100
          },
          "additional_payer_id": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1,
            "maxLength": 100
          }
        },
        "description": "Retained payer-loop source identifiers. Unique REF*2U resolves the payer code; a different XV plan ID is preserved separately. Explicit legacy PI may resolve only when 2U is absent; contradictory PI/2U or multiple different 2U IDs are rejected. Payee/claim REF segments never determine payer identity."
      },
      "EraSupplementalEvidence": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "segment",
          "elements",
          "claim_index",
          "service_index"
        ],
        "properties": {
          "segment": {
            "enum": [
              "AMT",
              "QTY",
              "TS2",
              "TS3",
              "MIA",
              "MOA"
            ]
          },
          "elements": {
            "type": "array",
            "minItems": 1,
            "maxItems": 24,
            "items": {
              "type": "string",
              "maxLength": 200
            }
          },
          "claim_index": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 999
          },
          "service_index": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 99
          }
        },
        "description": "Retained informational elements without segment tag, in original order, scoped to zero-based claim/service or provider summary. Segment-specific shape and numeric values are validated. No extra payment, PR charge or adjustment is generated from these fields. CLP/CAS/SVC/BPR balancing remains mandatory."
      },
      "SecondaryCoordinationRequest": {
        "type": "object",
        "additionalProperties": false,
        "description": "Explicit original secondary preparation on the same posted account. parent_id identifies its adjudicated primary claim. Requires current native delivered primary details and active posted primary ERA (CLP1; CLP19 crossover refused), same services, active effective secondary coverage and reviewed paid units/crossover/payer timing. No ledger mutation. Corrections inherit frozen coordination from the secondary parent.",
        "properties": {
          "coverage_id": {
            "type": "string",
            "format": "uuid"
          },
          "remittance_id": {
            "type": "string",
            "format": "uuid"
          },
          "coverage_version": {
            "type": "integer",
            "minimum": 1
          },
          "primary_claim_version": {
            "type": "integer",
            "minimum": 1
          },
          "remittance_version": {
            "type": "integer",
            "minimum": 1
          },
          "row_index": {
            "type": "integer",
            "minimum": 0
          },
          "not_forwarded_confirmed": {
            "const": true
          },
          "payer_timing_reviewed": {
            "const": true
          },
          "crossover_reference": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "paid_units": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          }
        },
        "required": [
          "coverage_id",
          "remittance_id",
          "coverage_version",
          "primary_claim_version",
          "remittance_version",
          "row_index",
          "not_forwarded_confirmed",
          "payer_timing_reviewed",
          "crossover_reference",
          "paid_units"
        ]
      },
      "PatientLifecycleChange": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "archived",
          "reason"
        ],
        "properties": {
          "archived": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000,
            "description": "Nonblank reason without control characters; recorded with actor and time."
          }
        }
      },
      "PatientLifecycle": {
        "type": "object",
        "required": [
          "patient_id",
          "version",
          "archived",
          "can_manage",
          "history",
          "history_truncated"
        ],
        "properties": {
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1,
            "description": "Starts at 1 for an active chart without lifecycle events."
          },
          "archived": {
            "type": "boolean"
          },
          "can_manage": {
            "type": "boolean"
          },
          "history": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "required": [
                "version",
                "archived",
                "reason",
                "actor_id",
                "created_at"
              ],
              "properties": {
                "version": {
                  "type": "integer",
                  "minimum": 2
                },
                "archived": {
                  "type": "boolean"
                },
                "reason": {
                  "type": "string"
                },
                "actor_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "actor_label": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "history_truncated": {
            "type": "boolean"
          }
        }
      },
      "PracticeFeeContext": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "facility_id": {
            "type": "string",
            "format": "uuid"
          },
          "setting": {
            "type": "string",
            "enum": [
              "facility",
              "nonfacility"
            ]
          }
        },
        "required": [
          "facility_id",
          "setting"
        ]
      },
      "PracticeFeeSource": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "HTTPS source URL; no embedded credentials",
            "maxLength": 2000
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-fA-F0-9]{64}$"
          },
          "published_on": {
            "type": "string",
            "format": "date"
          }
        },
        "required": [
          "id",
          "url",
          "sha256",
          "published_on"
        ]
      },
      "PracticeFeeEntry": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code_system": {
            "type": "string",
            "enum": [
              "CPT",
              "HCPCS"
            ]
          },
          "code": {
            "type": "string",
            "pattern": "^[A-Z0-9]{5}$"
          },
          "modifiers": {
            "type": "string",
            "description": "Exact ordered modifier tokens; normalized uppercase, comma separated, at most four two-character tokens. Blank is a separate key."
          },
          "reference_unit_cents": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000
          },
          "source_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "source_row": {
            "type": "integer",
            "minimum": 1
          },
          "qualification": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000
          }
        },
        "required": [
          "code_system",
          "code",
          "modifiers",
          "reference_unit_cents",
          "source_id",
          "source_row",
          "qualification"
        ]
      },
      "PracticeFeeProposal": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "provider_id": {
            "type": "string",
            "format": "uuid"
          },
          "facility_id": {
            "type": "string",
            "format": "uuid"
          },
          "setting": {
            "type": "string",
            "enum": [
              "facility",
              "nonfacility"
            ]
          },
          "qp_basis": {
            "type": "string",
            "enum": [
              "qp",
              "non_qp",
              "not_applicable"
            ]
          },
          "locality": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "reference_from": {
            "type": "string",
            "format": "date"
          },
          "reference_to": {
            "type": "string",
            "format": "date"
          },
          "effective_from": {
            "type": "string",
            "format": "date"
          },
          "effective_to": {
            "type": "string",
            "format": "date"
          },
          "multiplier_basis_points": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000,
            "description": "Explicit percentage in basis points: 10000 means 100%. Rounded half up to unit cents before multiplying by units."
          },
          "default_for_scope": {
            "type": "boolean",
            "description": "Explicit owner choice allowing this setting as default for the provider/facility/date scope."
          },
          "sources": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/PracticeFeeSource"
            }
          },
          "entries": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20000,
            "items": {
              "$ref": "#/components/schemas/PracticeFeeEntry"
            }
          }
        },
        "required": [
          "name",
          "provider_id",
          "facility_id",
          "setting",
          "qp_basis",
          "locality",
          "reference_from",
          "reference_to",
          "effective_from",
          "effective_to",
          "multiplier_basis_points",
          "default_for_scope",
          "sources",
          "entries"
        ]
      },
      "NewPracticeFeeProposal": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "content": {
            "$ref": "#/components/schemas/PracticeFeeProposal"
          }
        },
        "required": [
          "request_id",
          "reason",
          "content"
        ]
      },
      "PracticeFeeAction": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "approve",
              "retire"
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "reviewed_scope_and_sources": {
            "type": "boolean",
            "default": false,
            "description": "Must be true for approval; never implied by saving a draft."
          }
        },
        "required": [
          "action",
          "reason"
        ]
      },
      "PracticeFeeSchedule": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "approved",
              "retired"
            ]
          },
          "version": {
            "type": "integer"
          },
          "content": {
            "type": "object",
            "description": "Immutable proposal plus server-captured directory_snapshot (provider and facility IDs/names/versions). List responses omit entries and supply entry_count."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "approved_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "PracticeFeeSnapshot": {
        "type": "object",
        "readOnly": true,
        "description": "Server-generated immutable approved fee evidence. Includes schedule_id, entry_key, unit_amount_cents, expected_line_amount_cents, actual_line_amount_cents, units, service_date, context, approved schedule scope/source metadata, source entry, override_reason and recorded_by. Unchanged saved line evidence survives retirement and directory changes. Supplied client snapshots are discarded."
      },
      "CrossoverTrackingRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "coverage_id": {
            "type": "string",
            "format": "uuid"
          },
          "primary_remittance_id": {
            "type": "string",
            "format": "uuid"
          },
          "secondary_remittance_id": {
            "type": "string",
            "format": "uuid"
          },
          "coverage_version": {
            "type": "integer",
            "minimum": 1
          },
          "primary_claim_version": {
            "type": "integer",
            "minimum": 1
          },
          "primary_remittance_version": {
            "type": "integer",
            "minimum": 1
          },
          "secondary_remittance_version": {
            "type": "integer",
            "minimum": 1
          },
          "primary_row_index": {
            "type": "integer",
            "minimum": 0
          },
          "secondary_row_index": {
            "type": "integer",
            "minimum": 0
          },
          "linkage_confirmed": {
            "const": true
          },
          "linkage_reference": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "coverage_id",
          "primary_remittance_id",
          "secondary_remittance_id",
          "coverage_version",
          "primary_claim_version",
          "primary_remittance_version",
          "secondary_remittance_version",
          "primary_row_index",
          "secondary_row_index",
          "linkage_confirmed",
          "linkage_reference"
        ],
        "description": "Reviewed received-secondary835 crossover linkage, mutually exclusive with coordination and source_history_id; frequency original, parent_id exact adjudicated primary. Requires current posted primary CLP19 and delivered primary details, current effective secondary coverage, and a staged/reconciled unbound original835 with exact payer, N1 PE XX billing NPI, original control, payer claim number, DTM472 service date, ordered service controls/codes/modifiers/charges and balanced paid/CAS. Secondary CLP2/20/4 supported. Creates tracking-only submitted record with frozen source evidence and external-control alias, never an outbound submission or ledger posting. Existing active same-payer originals and active source bindings block duplicates."
      },
      "BillingOrganizationChange": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "tax_id_type",
          "active",
          "reason"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "tax_id": {
            "type": "string",
            "pattern": "^[0-9]{9}$",
            "writeOnly": true
          },
          "tax_id_type": {
            "type": "string",
            "enum": [
              "E",
              "S"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "BillingOrganizationCreate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "tax_id_type",
          "active",
          "reason",
          "request_id",
          "tax_id"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "tax_id": {
            "type": "string",
            "pattern": "^[0-9]{9}$",
            "writeOnly": true
          },
          "tax_id_type": {
            "type": "string",
            "enum": [
              "E",
              "S"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        }
      },
      "BillingOrganization": {
        "type": "object",
        "required": [
          "id",
          "name",
          "tax_id_type",
          "tax_id_last4",
          "active",
          "version"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "tax_id_type": {
            "type": "string",
            "enum": [
              "E",
              "S"
            ]
          },
          "tax_id_last4": {
            "type": "string",
            "pattern": "^[0-9]{4}$"
          },
          "active": {
            "type": "boolean"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "ClaimmdEligibilityRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "service_date",
          "insured_given_name",
          "insured_family_name"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "service_date": {
            "type": "string",
            "format": "date"
          },
          "service_codes": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string"
            },
            "default": []
          },
          "procedure_code": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 10
          },
          "insured_given_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "insured_family_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "insured_middle_name": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "insured_birth_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "insured_sex": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "F",
              "M",
              null
            ]
          },
          "patient_sex": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "F",
              "M",
              null
            ]
          },
          "provider_id": {
            "type": "string",
            "format": "uuid"
          },
          "provider_version": {
            "type": "integer",
            "minimum": 1
          },
          "billing_organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "billing_organization_version": {
            "type": "integer",
            "minimum": 1
          },
          "provider_npi": {
            "type": "string",
            "pattern": "^[12][0-9]{9}$"
          },
          "provider_taxid": {
            "type": "string",
            "pattern": "^[0-9]{9}$",
            "writeOnly": true
          },
          "provider_taxid_type": {
            "type": "string",
            "enum": [
              "E",
              "S"
            ]
          },
          "provider_name": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200,
            "description": "Explicitly reviewed provider last name or organization name if needed by the payer. Never inferred from a display name."
          },
          "provider_taxonomy": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 10
          }
        },
        "oneOf": [
          {
            "required": [
              "provider_id",
              "provider_version",
              "billing_organization_id",
              "billing_organization_version"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "provider_npi"
                  ]
                },
                {
                  "required": [
                    "provider_taxid"
                  ]
                },
                {
                  "required": [
                    "provider_taxid_type"
                  ]
                }
              ]
            }
          },
          {
            "required": [
              "provider_npi",
              "provider_taxid",
              "provider_taxid_type"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "provider_id"
                  ]
                },
                {
                  "required": [
                    "provider_version"
                  ]
                },
                {
                  "required": [
                    "billing_organization_id"
                  ]
                },
                {
                  "required": [
                    "billing_organization_version"
                  ]
                }
              ]
            }
          }
        ]
      },
      "BillingOverviewAccount": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_name": {
            "type": "string"
          },
          "mrn": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "service_date": {
            "type": "string"
          },
          "created_at": {
            "type": "string"
          },
          "version": {
            "type": "integer",
            "format": "int64"
          },
          "total_cents": {
            "type": "integer",
            "format": "int64"
          },
          "account_balance_cents": {
            "anyOf": [
              {
                "type": "integer",
                "format": "int64"
              },
              {
                "type": "null"
              }
            ]
          },
          "invoice_due_cents": {
            "anyOf": [
              {
                "type": "integer",
                "format": "int64"
              },
              {
                "type": "null"
              }
            ]
          },
          "reviewed_responsibility_cents": {
            "anyOf": [
              {
                "type": "integer",
                "format": "int64"
              },
              {
                "type": "null"
              }
            ]
          },
          "invoice_credit_cents": {
            "anyOf": [
              {
                "type": "integer",
                "format": "int64"
              },
              {
                "type": "null"
              }
            ]
          },
          "payer_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "invoice_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "invoice_created_at": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "invoice_needs_review": {
            "type": "boolean"
          },
          "test_activity": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "patient_id",
          "patient_name",
          "mrn",
          "status",
          "service_date",
          "created_at",
          "version",
          "total_cents",
          "account_balance_cents",
          "invoice_due_cents",
          "reviewed_responsibility_cents",
          "invoice_credit_cents",
          "payer_name",
          "invoice_id",
          "invoice_created_at",
          "invoice_needs_review",
          "test_activity"
        ]
      },
      "BillingOverviewCopay": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "appointment_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_name": {
            "type": "string"
          },
          "mrn": {
            "type": "string"
          },
          "method": {
            "type": "string"
          },
          "occurred_on": {
            "type": "string"
          },
          "created_at": {
            "type": "string"
          },
          "amount_cents": {
            "type": "integer",
            "format": "int64"
          },
          "refunded_cents": {
            "type": "integer",
            "format": "int64"
          },
          "allocated_cents": {
            "type": "integer",
            "format": "int64"
          },
          "reversed_cents": {
            "type": "integer",
            "format": "int64"
          },
          "refunded_unapplied_cents": {
            "type": "integer",
            "format": "int64"
          },
          "usable_unapplied_cents": {
            "type": "integer",
            "format": "int64"
          },
          "net_received_cents": {
            "type": "integer",
            "format": "int64"
          },
          "voided": {
            "type": "boolean"
          },
          "test_activity": {
            "type": "boolean"
          },
          "needs_review": {
            "type": "boolean"
          },
          "hosted_operation_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "livemode": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ]
          },
          "hosted_status": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "patient_id",
          "appointment_id",
          "patient_name",
          "mrn",
          "method",
          "occurred_on",
          "created_at",
          "amount_cents",
          "refunded_cents",
          "allocated_cents",
          "reversed_cents",
          "refunded_unapplied_cents",
          "usable_unapplied_cents",
          "net_received_cents",
          "voided",
          "test_activity",
          "needs_review",
          "hosted_operation_id",
          "livemode",
          "hosted_status"
        ]
      },
      "BillingOverview": {
        "type": "object",
        "properties": {
          "mode": {
            "enum": [
              "recorded",
              "test"
            ],
            "type": "string"
          },
          "currency": {
            "const": "USD",
            "type": "string"
          },
          "summary": {
            "type": "object",
            "properties": {
              "accounts": {
                "type": "object",
                "properties": {
                  "accounts": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "latest_invoices": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "invoice_review_count": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "open_invoice_count": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "reviewed_patient_due_cents": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "posted_gross_cents": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "posted_account_balance_cents": {
                    "type": "integer",
                    "format": "int64"
                  }
                },
                "required": [
                  "accounts",
                  "latest_invoices",
                  "invoice_review_count",
                  "open_invoice_count",
                  "reviewed_patient_due_cents",
                  "posted_gross_cents",
                  "posted_account_balance_cents"
                ]
              },
              "copays": {
                "type": "object",
                "properties": {
                  "receipts": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "net_received_cents": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "usable_unapplied_cents": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "review_count": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "void_count": {
                    "type": "integer",
                    "format": "int64"
                  }
                },
                "required": [
                  "receipts",
                  "net_received_cents",
                  "usable_unapplied_cents",
                  "review_count",
                  "void_count"
                ]
              }
            },
            "required": [
              "accounts",
              "copays"
            ]
          },
          "accounts": {
            "type": "object",
            "properties": {
              "items": {
                "type": "array",
                "maxItems": 100,
                "items": {
                  "$ref": "#/components/schemas/BillingOverviewAccount"
                }
              },
              "next_cursor": {
                "anyOf": [
                  {
                    "type": "string",
                    "format": "uuid"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "items",
              "next_cursor"
            ]
          },
          "copays": {
            "type": "object",
            "properties": {
              "items": {
                "type": "array",
                "maxItems": 100,
                "items": {
                  "$ref": "#/components/schemas/BillingOverviewCopay"
                }
              },
              "next_cursor": {
                "anyOf": [
                  {
                    "type": "string",
                    "format": "uuid"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "items",
              "next_cursor"
            ]
          },
          "invoice_policy": {
            "type": "string"
          },
          "collection_policy": {
            "type": "string"
          },
          "patient": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/BillingPatient"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "mode",
          "currency",
          "summary",
          "accounts",
          "copays",
          "invoice_policy",
          "collection_policy",
          "patient"
        ]
      },
      "BillingCopayReceiptCopy": {
        "type": "object",
        "properties": {
          "receipt": {
            "$ref": "#/components/schemas/CopayReceipt"
          },
          "context": {
            "type": "object",
            "properties": {
              "patient": {
                "type": "object",
                "properties": {
                  "given_name": {
                    "type": "string"
                  },
                  "family_name": {
                    "type": "string"
                  },
                  "mrn": {
                    "type": "string"
                  }
                },
                "required": [
                  "given_name",
                  "family_name",
                  "mrn"
                ]
              },
              "appointment": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "starts_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "id",
                  "starts_at"
                ]
              },
              "practiceName": {
                "type": "string"
              },
              "printedAt": {
                "type": "string",
                "format": "date-time"
              }
            },
            "required": [
              "patient",
              "appointment",
              "practiceName",
              "printedAt"
            ]
          }
        },
        "required": [
          "receipt",
          "context"
        ]
      },
      "BillingPatient": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "given_name",
          "family_name",
          "mrn",
          "archived"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "given_name": {
            "type": "string"
          },
          "family_name": {
            "type": "string"
          },
          "mrn": {
            "type": "string"
          },
          "archived": {
            "type": "boolean"
          }
        }
      },
      "BillingPatientPage": {
        "type": "object",
        "required": [
          "items",
          "next_cursor"
        ],
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/BillingPatient"
            }
          },
          "next_cursor": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "BillingPatientInvoicePage": {
        "type": "object",
        "required": [
          "items",
          "next_cursor",
          "patient",
          "mode"
        ],
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/PatientInvoice"
                },
                {
                  "type": "object",
                  "properties": {
                    "account_status": {
                      "type": "string"
                    },
                    "needs_review": {
                      "type": "boolean"
                    },
                    "is_latest": {
                      "type": "boolean"
                    },
                    "test_activity": {
                      "type": "boolean"
                    },
                    "patient_name": {
                      "type": "string"
                    },
                    "mrn": {
                      "type": "string"
                    }
                  }
                }
              ]
            }
          },
          "next_cursor": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "patient": {
            "$ref": "#/components/schemas/BillingPatient"
          },
          "mode": {
            "type": "string",
            "enum": [
              "recorded",
              "test"
            ]
          }
        }
      },
      "PatientPaymentSetup": {
        "type": "object",
        "properties": {
          "contract_version": {
            "type": "integer",
            "const": 1
          },
          "installation_id": {
            "type": "string",
            "format": "uuid"
          },
          "remote_tenant_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "creating",
              "open",
              "pending",
              "succeeded",
              "expired",
              "needs_review"
            ]
          },
          "session": {
            "type": [
              "object",
              "null"
            ],
            "description": "Verified hosted Checkout ID/URL, SetupIntent ID/status and payment method ID only. No card credentials."
          },
          "retry_safe_until": {
            "type": "string",
            "format": "date-time"
          },
          "recovery_required": {
            "type": "boolean"
          },
          "retry_allowed": {
            "type": "boolean"
          },
          "provider_status": {
            "type": "string",
            "enum": [
              "not_found"
            ],
            "description": "Local recovery response only: no broker setup reservation found. This is not verified payment-method evidence."
          },
          "error": {
            "type": "string"
          }
        },
        "required": [
          "contract_version",
          "installation_id",
          "remote_tenant_id",
          "patient_id",
          "account_id",
          "livemode",
          "checked_at",
          "request_id",
          "customer_id",
          "status",
          "session",
          "retry_safe_until",
          "recovery_required",
          "retry_allowed"
        ]
      },
      "PatientInstallmentScheduleItem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "due_on",
          "amount_cents"
        ],
        "properties": {
          "due_on": {
            "type": "string",
            "format": "date"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 50,
            "maximum": 100000000
          }
        }
      },
      "PatientInstallmentPreviewRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "invoice_id",
          "livemode",
          "installments"
        ],
        "properties": {
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "livemode": {
            "type": "boolean"
          },
          "installments": {
            "type": "array",
            "minItems": 1,
            "maxItems": 60,
            "items": {
              "$ref": "#/components/schemas/PatientInstallmentScheduleItem"
            }
          }
        }
      },
      "PatientInstallmentCreateRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "invoice_id",
          "livemode",
          "installments",
          "request_id",
          "reason",
          "consent"
        ],
        "properties": {
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "livemode": {
            "type": "boolean"
          },
          "installments": {
            "type": "array",
            "minItems": 1,
            "maxItems": 60,
            "items": {
              "$ref": "#/components/schemas/PatientInstallmentScheduleItem"
            }
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "consent": {
            "type": "boolean",
            "enum": [
              true
            ]
          }
        }
      },
      "PatientInstallmentCheckoutRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "amount_cents",
          "patient_present",
          "reason"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 50,
            "maximum": 100000000
          },
          "patient_present": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "reader_id": {
            "type": "string",
            "pattern": "^tmr_[A-Za-z0-9]+$",
            "description": "A card reader from GET /api/v1/billing/payments/readers. When present the payment is taken on that reader instead of a Stripe-hosted Checkout link."
          }
        }
      },
      "InvoiceCheckoutOperation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "plan_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string"
          },
          "installment_number": {
            "type": "integer"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 0
          },
          "currency": {
            "const": "usd",
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "status": {
            "type": "string",
            "enum": [
              "creating",
              "open",
              "paid",
              "expired",
              "needs_review",
              "refunded"
            ]
          },
          "checkout_url": {
            "anyOf": [
              {
                "type": "string",
                "format": "uri"
              },
              {
                "type": "null"
              }
            ]
          },
          "paid_entry_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "captured_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "refunded_cents": {
            "type": "integer",
            "minimum": 0
          },
          "unapplied_cents": {
            "type": "integer",
            "minimum": 0
          },
          "last_result": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "version": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "channel": {
            "type": "string",
            "enum": [
              "hosted",
              "reader"
            ],
            "description": "`hosted` for a Stripe-hosted Checkout link, `reader` for a card payment taken on a reader. For a reader payment `last_result` says where it stands: `reader_waiting`, `reader_offline` or `reader_finishing` while open; `reader_declined`, `reader_cancelled`, `reader_timed_out`, `reader_offline`, `reader_in_use`, `reader_unavailable` or `reader_failed` once closed (`expired`)."
          },
          "reader_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "The card reader for a reader payment."
          }
        },
        "required": [
          "id",
          "request_id",
          "patient_id",
          "account_id",
          "plan_id",
          "reason",
          "installment_number",
          "amount_cents",
          "currency",
          "livemode",
          "status",
          "checkout_url",
          "paid_entry_id",
          "captured_at",
          "refunded_cents",
          "unapplied_cents",
          "last_result",
          "version",
          "created_at",
          "channel",
          "reader_id"
        ]
      },
      "PatientInstallmentCollectionItem": {
        "type": "object",
        "properties": {
          "number": {
            "type": "integer"
          },
          "due_on": {
            "type": "string",
            "format": "date"
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 0
          },
          "collected_cents": {
            "type": "integer",
            "minimum": 0
          },
          "collectible_cents": {
            "type": "integer",
            "minimum": 0
          },
          "status": {
            "type": "string",
            "enum": [
              "complete",
              "pending"
            ]
          }
        },
        "required": [
          "number",
          "due_on",
          "amount_cents",
          "collected_cents",
          "collectible_cents",
          "status"
        ]
      },
      "PatientInstallmentPlan": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "complete",
              "needs_review"
            ]
          },
          "livemode": {
            "type": "boolean"
          },
          "total_cents": {
            "type": "integer",
            "minimum": 0
          },
          "responsibility_cents": {
            "type": "integer",
            "minimum": 0
          },
          "patient_credit_cents": {
            "type": "integer",
            "minimum": 0
          },
          "remaining_cents": {
            "type": "integer",
            "minimum": 0
          },
          "blocked_reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "installments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PatientInstallmentCollectionItem"
            }
          },
          "attempts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InvoiceCheckoutOperation"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "autopay": {
            "type": "boolean",
            "const": false
          }
        },
        "required": [
          "id",
          "request_id",
          "patient_id",
          "account_id",
          "invoice_id",
          "reason",
          "version",
          "status",
          "livemode",
          "total_cents",
          "responsibility_cents",
          "patient_credit_cents",
          "remaining_cents",
          "blocked_reason",
          "installments",
          "attempts",
          "created_at",
          "autopay"
        ]
      },
      "PatientInstallmentPreview": {
        "type": "object",
        "properties": {
          "invoice_id": {
            "type": "string",
            "format": "uuid"
          },
          "invoice_created_at": {
            "type": "string",
            "format": "date-time"
          },
          "account_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_version": {
            "type": "integer"
          },
          "responsibility_cents": {
            "type": "integer",
            "minimum": 0
          },
          "patient_credit_cents": {
            "type": "integer"
          },
          "remaining_cents": {
            "type": "integer",
            "minimum": 0
          },
          "currency": {
            "type": "string",
            "const": "usd"
          },
          "livemode": {
            "type": "boolean"
          },
          "eligible": {
            "type": "boolean"
          },
          "blocked_reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "installments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "number": {
                  "type": "integer"
                },
                "due_on": {
                  "type": "string",
                  "format": "date"
                },
                "amount_cents": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "required": [
                "number",
                "due_on",
                "amount_cents"
              ]
            }
          },
          "autopay": {
            "type": "boolean",
            "const": false
          }
        },
        "required": [
          "invoice_id",
          "invoice_created_at",
          "account_id",
          "account_version",
          "responsibility_cents",
          "patient_credit_cents",
          "remaining_cents",
          "currency",
          "livemode",
          "eligible",
          "blocked_reason",
          "installments",
          "autopay"
        ]
      },
      "PatientInstallmentPlanList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PatientInstallmentPlan"
            }
          },
          "eligible_invoices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PatientInstallmentPreview"
            }
          },
          "availability": {
            "type": "object",
            "properties": {
              "available": {
                "type": "boolean"
              },
              "livemode": {
                "anyOf": [
                  {
                    "type": "boolean"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "reason": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "available",
              "livemode",
              "reason"
            ]
          }
        },
        "required": [
          "items",
          "eligible_invoices",
          "availability"
        ]
      },
      "PatientInstallmentCheckoutResult": {
        "type": "object",
        "properties": {
          "plan": {
            "$ref": "#/components/schemas/PatientInstallmentPlan"
          },
          "operation": {
            "$ref": "#/components/schemas/InvoiceCheckoutOperation"
          }
        },
        "required": [
          "plan",
          "operation"
        ]
      },
      "InvoiceCheckoutResult": {
        "type": "object",
        "properties": {
          "operation": {
            "$ref": "#/components/schemas/InvoiceCheckoutOperation"
          }
        },
        "required": [
          "operation"
        ]
      },
      "PatientMembershipPrice": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "provider_price_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "amount_cents": {
            "type": "integer",
            "minimum": 50,
            "maximum": 100000000
          },
          "currency": {
            "const": "usd"
          },
          "interval": {
            "enum": [
              "day",
              "week",
              "month",
              "year"
            ]
          },
          "interval_count": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365
          },
          "status": {
            "enum": [
              "creating",
              "active",
              "inactive",
              "approved",
              "needs_review",
              "unavailable"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "request_id",
          "provider_price_id",
          "name",
          "amount_cents",
          "currency",
          "interval",
          "interval_count",
          "status",
          "created_at"
        ]
      },
      "PatientMembership": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "price": {
            "$ref": "#/components/schemas/PatientMembershipPrice"
          },
          "terms": {
            "type": "string"
          },
          "customer_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "enum": [
              "creating",
              "open",
              "active",
              "pending",
              "canceled",
              "expired",
              "needs_review"
            ]
          },
          "session": {
            "anyOf": [
              {
                "type": "object",
                "description": "Verified hosted Checkout id/url/status, explicit authorization_accepted and sanitized subscription. No card data or client secret."
              },
              {
                "type": "null"
              }
            ]
          },
          "subscription_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "subscription_status": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "cancel_at_period_end": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ]
          },
          "current_period_end": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "retry_safe_until": {
            "type": "string",
            "format": "date-time"
          },
          "recovery_required": {
            "type": "boolean"
          },
          "retry_allowed": {
            "type": "boolean"
          },
          "cancellation_available": {
            "type": "boolean",
            "description": "List-only capability: verified local membership mapping and current scheduling/billing-edit permission."
          }
        },
        "required": [
          "request_id",
          "price",
          "terms",
          "customer_id",
          "status",
          "session",
          "subscription_id",
          "subscription_status",
          "cancel_at_period_end",
          "current_period_end",
          "created_at",
          "retry_safe_until",
          "recovery_required",
          "retry_allowed"
        ]
      },
      "PatientMembershipPending": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "enum": [
              "price",
              "membership",
              "cancel"
            ]
          },
          "status": {
            "type": "string"
          },
          "retry_safe_until": {
            "type": "string",
            "format": "date-time"
          },
          "retry_allowed": {
            "type": "boolean"
          },
          "request": {
            "anyOf": [
              {
                "type": "object",
                "description": "Original accepted input for the same currently authorized initiating actor only. No credentials, return URL or account binding."
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "request_id",
          "kind",
          "status",
          "retry_safe_until",
          "retry_allowed",
          "request"
        ]
      },
      "PatientMembershipPriceResponse": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "contract_version": {
            "const": 1
          },
          "installation_id": {
            "type": "string",
            "format": "uuid"
          },
          "remote_tenant_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          },
          "price": {
            "$ref": "#/components/schemas/PatientMembershipPrice"
          },
          "retry_safe_until": {
            "type": "string",
            "format": "date-time"
          },
          "recovery_required": {
            "type": "boolean"
          },
          "retry_allowed": {
            "type": "boolean"
          }
        },
        "required": [
          "contract_version",
          "installation_id",
          "remote_tenant_id",
          "account_id",
          "livemode",
          "checked_at",
          "price",
          "retry_safe_until",
          "recovery_required",
          "retry_allowed"
        ]
      },
      "PatientMembershipResponse": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "contract_version": {
            "const": 1
          },
          "installation_id": {
            "type": "string",
            "format": "uuid"
          },
          "remote_tenant_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "membership": {
            "$ref": "#/components/schemas/PatientMembership"
          }
        },
        "required": [
          "contract_version",
          "installation_id",
          "remote_tenant_id",
          "account_id",
          "livemode",
          "checked_at",
          "patient_id",
          "membership"
        ]
      },
      "PatientMembershipCancellation": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "contract_version": {
            "const": 1
          },
          "installation_id": {
            "type": "string",
            "format": "uuid"
          },
          "remote_tenant_id": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          },
          "patient_id": {
            "type": "string",
            "format": "uuid"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "membership_request_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "enum": [
              "scheduled",
              "canceled",
              "pending",
              "needs_review"
            ]
          },
          "subscription": {
            "type": "object",
            "description": "Sanitized subscription from this verified native membership."
          },
          "retry_safe_until": {
            "type": "string",
            "format": "date-time"
          },
          "recovery_required": {
            "type": "boolean"
          },
          "retry_allowed": {
            "type": "boolean"
          }
        },
        "required": [
          "contract_version",
          "installation_id",
          "remote_tenant_id",
          "account_id",
          "livemode",
          "checked_at",
          "patient_id",
          "request_id",
          "membership_request_id",
          "status",
          "subscription",
          "retry_safe_until",
          "recovery_required",
          "retry_allowed"
        ]
      },
      "CardReader": {
        "type": "object",
        "required": [
          "id",
          "name",
          "model",
          "online",
          "busy"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "description": "The name the practice gave this reader."
          },
          "model": {
            "type": "string"
          },
          "online": {
            "type": "boolean"
          },
          "busy": {
            "type": "boolean",
            "description": "The reader is taking a payment right now."
          }
        }
      },
      "PracticeStaffInvitation": {
        "type": "object",
        "description": "Sign-in status of one staff member on an installation whose sign-in is handled by SunCharts Connect. No invitation link or token is ever returned.",
        "properties": {
          "staff_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "can_sign_in",
              "waiting",
              "expired",
              "cancelled",
              "not_sent",
              "not_invited",
              "access_off",
              "unknown",
              "disabled"
            ],
            "description": "can_sign_in: has accepted or has signed in. waiting: invited, not yet accepted. expired/cancelled: the invitation can no longer be used. not_sent: the last attempt did not go out (see reason). not_invited: no invitation on record. access_off: their Connect membership is inactive. unknown: Connect could not be read. disabled: access is turned off here."
          },
          "reason": {
            "type": "string",
            "enum": [
              "unreachable",
              "email_refused",
              "plan",
              "busy",
              "not_allowed",
              "refused",
              "email_not_delivered",
              "delivery_unknown",
              "partner_delivery"
            ]
          },
          "sent_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "version": {
            "type": "integer",
            "description": "Current staff record version after an invitation attempt was recorded in its history."
          }
        },
        "required": [
          "staff_id",
          "status"
        ]
      },
      "NoteSaved": {
        "type": "object",
        "description": "Who last saved the note, set by the server on every save. Values sent by a client are ignored.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "description": "Display name when saved; empty when the practice has no record of the person. A delegated support session is named Support staff."
          },
          "at": {
            "type": "string",
            "format": "date-time"
          },
          "support": {
            "type": "boolean",
            "description": "Present and true when a delegated support session saved the note."
          }
        },
        "required": [
          "id",
          "name",
          "at"
        ]
      },
      "NoteAuthorship": {
        "type": "object",
        "additionalProperties": false,
        "description": "Who a visit's note belongs to and what the caller may do with it. No note text.",
        "properties": {
          "visit_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "status": {
            "type": "string",
            "enum": [
              "in_progress",
              "signed"
            ]
          },
          "assigned": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string",
                "description": "Provider or staff display name; empty when none is recorded."
              }
            },
            "required": [
              "id",
              "name"
            ]
          },
          "is_assigned": {
            "type": "boolean",
            "description": "The visit is assigned to the caller."
          },
          "last_saved": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/NoteSaved"
              },
              {
                "type": "null"
              }
            ]
          },
          "signed": {
            "anyOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "name": {
                    "type": "string"
                  },
                  "at": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "id",
                  "name",
                  "at"
                ]
              },
              {
                "type": "null"
              }
            ],
            "description": "The person who actually signed. May differ from assigned."
          },
          "amendments": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "author_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "author_name": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "required": [
                "id",
                "author_id",
                "author_name",
                "created_at"
              ]
            }
          },
          "delegated": {
            "type": "boolean",
            "description": "The caller is a delegated support session. It may draft but never sign or amend."
          },
          "can_draft": {
            "type": "boolean"
          },
          "can_sign": {
            "type": "boolean"
          },
          "can_amend": {
            "type": "boolean"
          }
        },
        "required": [
          "visit_id",
          "version",
          "status",
          "assigned",
          "is_assigned",
          "last_saved",
          "signed",
          "amendments",
          "delegated",
          "can_draft",
          "can_sign",
          "can_amend"
        ]
      }
    }
  }
}