{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-27 Referral and Care Transition Exchange",
    "version": "1.0.1",
    "description": "Server paths are under /api/ohn/v1/referral-exchange. Default deny: role AND purpose must match. Inventory paths OHN-27-API-001..003 are mapped to this disjoint prefix (see ADR-0001). A referral is visible only to its sending and receiving facility (404 otherwise). Behaviour reconciled with the TypeScript reference and the Java service (docs/program/java/ohn-27-contract-changes.md). Tokens come from the platform gateway (ES256, audience ohn-27); the TypeScript-only synthetic-token endpoint is not part of this contract."
  },
  "servers": [
    {
      "url": "/api/ohn/v1/referral-exchange"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/referrals": {
      "post": {
        "operationId": "createReferral",
        "summary": "Create a draft referral from the acting facility (F001)",
        "x-inventory-id": "OHN-27-API-001",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReferralCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listReferrals",
        "summary": "Referral worklist: inbox, outbox, overdue",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "box",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "inbox",
                "outbox"
              ]
            }
          },
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "priority",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "overdue",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "true"
              ]
            }
          },
          {
            "name": "patient_ref",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralList"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/referrals/{id}": {
      "get": {
        "operationId": "getReferral",
        "summary": "Referral with escalations; visible to the sending and receiving facility only",
        "x-inventory-id": "OHN-27-API-002",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralDetail"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/referrals/{id}/timeline": {
      "get": {
        "operationId": "referralTimeline",
        "summary": "Status timeline from workflow history",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Timeline"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/referrals/{id}/submit": {
      "post": {
        "operationId": "submitReferral",
        "summary": "Send the referral (W001); sets the response deadline when one is configured",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SubmitCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/referrals/{id}/acknowledge": {
      "post": {
        "operationId": "acknowledgeReferral",
        "summary": "Receiving facility: received, accepted, declined or completed (F002)",
        "x-inventory-id": "OHN-27-API-003",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AcknowledgeCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/referrals/{id}/cancellation": {
      "post": {
        "operationId": "cancelReferral",
        "summary": "Cancellation steps request, notify, finalize (W003)",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CancelCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReferralResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/referrals/{id}/escalate": {
      "post": {
        "operationId": "escalateReferral",
        "summary": "Escalate an overdue unanswered referral (append-only levels)",
        "x-roles": [
          "care_coordinator"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EscalateCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EscalationResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/transfers": {
      "post": {
        "operationId": "createTransfer",
        "summary": "Create a care transition handover (F003, W002)",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TransferCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransferResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listTransfers",
        "summary": "Care transitions of the acting facility",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransferList"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/transfers/{id}": {
      "get": {
        "operationId": "getTransfer",
        "summary": "Transfer with its history",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransferDetail"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/transfers/{id}/transitions": {
      "post": {
        "operationId": "stepTransfer",
        "summary": "Confirm, deliver or acknowledge a transfer; acknowledger differs from creator",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TransferStepCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransferResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/destinations": {
      "get": {
        "operationId": "listDestinations",
        "summary": "Referral directory: active OHN-05 sites in the jurisdiction (own site flagged); configured=false without a live registry",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Destinations"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/code-lists/{list}": {
      "get": {
        "operationId": "getCodeList",
        "summary": "Controlled list (priority, requested_service)",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CodeList"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "upsertCodeEntry",
        "summary": "Add or change a code list entry",
        "x-roles": [
          "care_coordinator"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeListEntryCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CodeListWriteResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/sla": {
      "get": {
        "operationId": "getSla",
        "summary": "Response deadlines per priority",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SlaList"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "setSla",
        "summary": "Set a response deadline (approval reference required)",
        "x-roles": [
          "care_coordinator"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SlaCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SlaWriteResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Report pending outbox events (the platform relay publishes them)",
        "x-roles": [
          "care_coordinator"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DrainResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Available reports",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportCatalog"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run report R001..R003",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "facility",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "priority",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            },
            "description": "R002 only: `overdue` keeps the overdue rows; R003: a transfer state"
          },
          {
            "name": "jurisdiction",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Another jurisdiction yields no_authorized_data, never its data"
          },
          {
            "name": "country",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "period_from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "A real calendar date, YYYY-MM-DD"
            }
          },
          {
            "name": "period_to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
              "description": "A real calendar date, YYYY-MM-DD"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/reports/{reportId}/export": {
      "post": {
        "operationId": "exportReport",
        "summary": "Create a signed single-use report export",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExportReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency key reused with a different payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/report-exports/{token}": {
      "get": {
        "operationId": "downloadReportExport",
        "summary": "Download a report export once",
        "x-roles": [
          "care_coordinator",
          "licensed_clinician"
        ],
        "x-purpose": "referral_exchange",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The export, once (text/csv or application/pdf)",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "410": {
            "description": "export_expired (5 minutes) or export_consumed (single use)"
          },
          "400": {
            "description": "Malformed request or missing/invalid Idempotency-Key (8-128 characters of [A-Za-z0-9_.:-])",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "500": {
            "description": "export_integrity_failed (the stored content no longer matches its HMAC tag)"
          }
        }
      }
    },
    "/patients/{id}/patient-view": {
      "get": {
        "operationId": "patientReferralView",
        "summary": "The patient's own referrals (OHN-31 patient chart); own record only",
        "x-roles": [
          "patient"
        ],
        "x-purpose": "patient_access",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The patient's own OHN-03 id (must equal the token subject)"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PatientView"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated (no/invalid token, or claims that are not uuids)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Denied by policy (role AND purpose), wrong facility side, separation of duties",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found / not disclosed (also: any route outside this contract, once authenticated)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Domain validation failed (details: field -> code), unconfigured code list, unmet precondition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable (fail closed)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/health/ohn-27": {
      "get": {
        "operationId": "health",
        "summary": "Public liveness; reports how each dependency is wired",
        "servers": [
          {
            "url": "/"
          }
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Database reachable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          },
          "503": {
            "description": "Database unreachable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 128,
          "pattern": "^[A-Za-z0-9_.:-]+$"
        }
      }
    },
    "schemas": {
      "ReferralCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "source_facility": {
            "type": "string",
            "format": "uuid"
          },
          "destination_facility": {
            "type": "string",
            "format": "uuid"
          },
          "referral_reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4000,
            "description": "Trimmed before the length check"
          },
          "priority": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$",
            "description": "A code of the jurisdiction's active `priority` list"
          },
          "relevant_summary_ref": {
            "type": "string",
            "format": "uuid"
          },
          "requested_service": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$",
            "description": "A code of the jurisdiction's active `requested_service` list"
          }
        },
        "required": [
          "patient_ref",
          "source_facility",
          "destination_facility",
          "referral_reason",
          "priority",
          "relevant_summary_ref",
          "requested_service"
        ]
      },
      "SubmitCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "expected_version"
        ]
      },
      "AcknowledgeCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "received",
              "accepted",
              "declined",
              "completed"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "receiving_clinician": {
            "type": "string",
            "format": "uuid"
          },
          "response_notes": {
            "type": "string",
            "minLength": 5,
            "maxLength": 4000
          },
          "expected_date": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
            "description": "A real calendar date, YYYY-MM-DD"
          }
        },
        "required": [
          "action",
          "expected_version"
        ],
        "description": "accepted and declined need receiving_clinician and response_notes (422 details `required_for_decision`); declined takes no expected_date (`not_for_decline`)."
      },
      "CancelCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "step": {
            "type": "string",
            "enum": [
              "request",
              "notify",
              "finalize"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "step",
          "expected_version",
          "reason"
        ]
      },
      "EscalateCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "expected_version",
          "reason"
        ]
      },
      "TransferCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "referral_id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "source_encounter": {
            "type": "string",
            "format": "uuid"
          },
          "handover_summary": {
            "type": "string",
            "format": "uuid"
          },
          "recipient_org": {
            "type": "string",
            "format": "uuid"
          },
          "handover_time": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "patient_ref",
          "source_encounter",
          "handover_summary",
          "recipient_org",
          "handover_time"
        ]
      },
      "TransferStepCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "to_state": {
            "type": "string",
            "enum": [
              "recipient_confirmed",
              "document_delivered",
              "receipt_acknowledged"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ]
      },
      "CodeListEntryCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "active": {
            "type": "boolean",
            "default": true
          }
        },
        "required": [
          "code",
          "label"
        ]
      },
      "SlaCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "priority": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "response_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 525600
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3,
            "maxLength": 256
          }
        },
        "required": [
          "priority",
          "response_minutes",
          "approval_reference"
        ]
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "format": {
            "type": "string",
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "facility": {
                "type": "string",
                "format": "uuid"
              },
              "priority": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "status": {
                "type": "string",
                "maxLength": 40
              },
              "jurisdiction": {
                "type": "string",
                "format": "uuid"
              },
              "country": {
                "type": "string",
                "format": "uuid"
              },
              "period_from": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                "description": "A real calendar date, YYYY-MM-DD"
              },
              "period_to": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                "description": "A real calendar date, YYYY-MM-DD"
              }
            }
          }
        },
        "required": [
          "format"
        ]
      },
      "Problem": {
        "type": "object",
        "description": "application/problem+json carrying the legacy fields error/message/details; details are `{field: zod-issue-code | custom message}` for 422.",
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "trace_id": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "error"
        ]
      },
      "Receipt": {
        "type": "object",
        "properties": {
          "receipt_id": {
            "type": "string",
            "format": "uuid"
          },
          "committed_at": {
            "type": "string",
            "format": "date-time"
          },
          "aggregate_id": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "committed"
            ]
          }
        },
        "required": [
          "receipt_id",
          "committed_at",
          "aggregate_id",
          "version",
          "status"
        ]
      },
      "Referral": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "source_facility": {
            "type": "string",
            "format": "uuid"
          },
          "destination_facility": {
            "type": "string",
            "format": "uuid"
          },
          "referral_reason": {
            "type": "string"
          },
          "priority": {
            "type": "string"
          },
          "relevant_summary_ref": {
            "type": "string",
            "format": "uuid"
          },
          "requested_service": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "draft",
              "submitted",
              "received",
              "accepted_or_declined",
              "completed_or_cancelled"
            ]
          },
          "outcome": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "accepted",
              "declined",
              "completed",
              "cancelled",
              null
            ]
          },
          "cancellation_state": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "cancellation_requested",
              "recipient_notified",
              "cancelled",
              null
            ]
          },
          "cancellation_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "receiving_clinician": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "response_notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "expected_date": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "submitted_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "received_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "first_response_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "due_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "overdue": {
            "type": "boolean"
          },
          "escalation_count": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          }
        }
      },
      "Transfer": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "referral_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "source_encounter": {
            "type": "string",
            "format": "uuid"
          },
          "handover_summary": {
            "type": "string",
            "format": "uuid"
          },
          "source_org": {
            "type": "string",
            "format": "uuid"
          },
          "recipient_org": {
            "type": "string",
            "format": "uuid"
          },
          "handover_time": {
            "type": "string",
            "format": "date-time"
          },
          "state": {
            "type": "string",
            "enum": [
              "transfer_created",
              "recipient_confirmed",
              "document_delivered",
              "receipt_acknowledged"
            ]
          },
          "created_by": {
            "type": "string",
            "format": "uuid"
          },
          "confirmed_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "delivery_ref": {
            "type": [
              "string",
              "null"
            ]
          },
          "acknowledged_by": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "acknowledged_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "integer"
          }
        }
      },
      "ReferralResult": {
        "type": "object",
        "properties": {
          "referral": {
            "$ref": "#/components/schemas/Referral"
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        },
        "required": [
          "referral",
          "receipt"
        ]
      },
      "EscalationResult": {
        "type": "object",
        "properties": {
          "referral": {
            "$ref": "#/components/schemas/Referral"
          },
          "escalation": {
            "type": "object",
            "properties": {
              "level": {
                "type": "integer"
              },
              "overdue_minutes": {
                "type": "integer"
              }
            }
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "ReferralDetail": {
        "type": "object",
        "properties": {
          "referral": {
            "$ref": "#/components/schemas/Referral"
          },
          "escalations": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "level": {
                  "type": "integer"
                },
                "escalated_by": {
                  "type": "string",
                  "format": "uuid"
                },
                "reason": {
                  "type": "string"
                },
                "overdue_minutes": {
                  "type": "integer"
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "ReferralList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Referral"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Timeline": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "workflow_id": {
                  "type": "string",
                  "enum": [
                    "OHN-27-W001",
                    "OHN-27-W002",
                    "OHN-27-W003"
                  ]
                },
                "from_state": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "to_state": {
                  "type": "string"
                },
                "version": {
                  "type": "integer"
                },
                "actor_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "reason": {
                  "type": "string"
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "TransferResult": {
        "type": "object",
        "properties": {
          "transfer": {
            "$ref": "#/components/schemas/Transfer"
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "TransferList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Transfer"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "TransferDetail": {
        "type": "object",
        "properties": {
          "transfer": {
            "$ref": "#/components/schemas/Transfer"
          },
          "history": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "from_state": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "to_state": {
                  "type": "string"
                },
                "actor_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "reason": {
                  "type": "string"
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "Destinations": {
        "type": "object",
        "description": "configured=false (empty items) while no live OHN-05 registry is wired.",
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "site_type": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "own": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "CodeList": {
        "type": "object",
        "properties": {
          "list": {
            "type": "string",
            "enum": [
              "priority",
              "requested_service"
            ]
          },
          "configured": {
            "type": "boolean"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                },
                "active": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "CodeListWriteResult": {
        "type": "object",
        "properties": {
          "item": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "label": {
                "type": "string"
              },
              "active": {
                "type": "boolean"
              }
            }
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "SlaList": {
        "type": "object",
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "priority": {
                  "type": "string"
                },
                "response_minutes": {
                  "type": "integer"
                },
                "approval_reference": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SlaWriteResult": {
        "type": "object",
        "properties": {
          "item": {
            "type": "object",
            "properties": {
              "priority": {
                "type": "string"
              },
              "response_minutes": {
                "type": "integer"
              },
              "approval_reference": {
                "type": "string"
              }
            }
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "DrainResult": {
        "type": "object",
        "properties": {
          "delivered": {
            "type": "integer"
          },
          "pending": {
            "type": "integer"
          }
        },
        "description": "The platform relay publishes events; this call never claims delivery (delivered is 0) and reports the pending count."
      },
      "ReportCatalog": {
        "type": "object",
        "properties": {
          "reports": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "enum": [
                    "OHN-27-R001",
                    "OHN-27-R002",
                    "OHN-27-R003"
                  ]
                },
                "title": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "report_id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "rows": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "summary": {
            "type": "object",
            "additionalProperties": true
          },
          "state": {
            "type": "string",
            "enum": [
              "rendered",
              "no_authorized_data"
            ]
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ExportReceipt": {
        "type": "object",
        "properties": {
          "export_id": {
            "type": "string",
            "format": "uuid"
          },
          "report_id": {
            "type": "string"
          },
          "format": {
            "type": "string",
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "rows": {
            "type": "integer"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "single_use": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "download_path": {
            "type": "string"
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "PatientView": {
        "type": "object",
        "properties": {
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "as_of": {
            "type": "string",
            "format": "date-time"
          },
          "receipt_id": {
            "type": "string",
            "format": "uuid"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "source_facility": {
                  "type": "string",
                  "format": "uuid"
                },
                "destination_facility": {
                  "type": "string",
                  "format": "uuid"
                },
                "referral_reason": {
                  "type": "string"
                },
                "requested_service": {
                  "type": "string"
                },
                "priority": {
                  "type": "string"
                },
                "state": {
                  "type": "string"
                },
                "outcome": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "expected_date": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "submitted_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "completed_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        },
        "description": "Drafts and the receiving team's response notes are not included."
      },
      "Health": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "module": {
            "type": "string"
          },
          "dependencies": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "enum": [
                "synthetic",
                "unconfigured",
                "live"
              ]
            }
          }
        }
      }
    }
  }
}
