{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-30 Insurance Coverage and Eligibility Exchange",
    "version": "1.0.1",
    "description": "Base path /api/ohn/v1. Every POST requires Idempotency-Key; mutations use expected_version. Routes default-deny on role AND purpose (coverage_eligibility). Coverage is advisory and never blocks care. Strict bodies: unknown keys are 422 (unrecognized_keys, reported under \"_\"); only the first path segment of a failing field is reported. Policy identifiers are encrypted at rest, masked in views, and never placed in events. The TypeScript-only synthetic sign-in is not served; the gateway issues tokens."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "paths": {
    "/coverage/eligibility-inquiries": {
      "post": {
        "operationId": "createInquiry",
        "summary": "Run an eligibility inquiry (API-001; F001; W001)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Inquiry"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listInquiries",
        "summary": "List inquiries (outcome, status, payer)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/coverage/eligibility-inquiries/{id}": {
      "get": {
        "operationId": "getInquiry",
        "summary": "Inquiry with freshness, disputes and history (API-002)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InquiryView"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/coverage/eligibility-inquiries/{id}/disputes": {
      "post": {
        "operationId": "openDispute",
        "summary": "Dispute a recorded payer response (F003)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Dispute"
              }
            }
          }
        }
      }
    },
    "/coverage/disputes": {
      "get": {
        "operationId": "listDisputes",
        "summary": "Dispute ledger",
        "tags": [
          "OHN-30"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/coverage/disputes/{id}/resolve": {
      "post": {
        "operationId": "resolveDispute",
        "summary": "Resolve a dispute (opener cannot resolve)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DisputeResolve"
              }
            }
          }
        }
      }
    },
    "/coverage/endpoints": {
      "post": {
        "operationId": "configureEndpoint",
        "summary": "Configure an insurer endpoint (F002)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Endpoint"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listEndpoints",
        "summary": "Insurer connection status",
        "tags": [
          "OHN-30"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/coverage/certificates": {
      "get": {
        "operationId": "listCertificates",
        "summary": "Certificates the insurer endpoint form may offer (from OHN-45 /crypto/certificates with the certificate_reader service token; caller organisation only; usable = not expired and not rotation-due). Audited. 503 when OHN-45 is unavailable.",
        "tags": [
          "OHN-30"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "label": {
                            "type": "string"
                          },
                          "key_purpose": {
                            "type": "string"
                          },
                          "expires_at": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "expired": {
                            "type": "boolean"
                          },
                          "rotation_due": {
                            "type": "boolean"
                          },
                          "usable": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied"
          },
          "503": {
            "description": "OHN-45 unavailable"
          }
        }
      }
    },
    "/coverage/endpoints/{id}/verify": {
      "post": {
        "operationId": "verifyEndpoint",
        "summary": "Verify endpoint trust (configurer cannot verify)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EndpointDecision"
              }
            }
          }
        }
      }
    },
    "/coverage/endpoints/{id}/suspend": {
      "post": {
        "operationId": "suspendEndpoint",
        "summary": "Suspend a verified endpoint",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EndpointDecision"
              }
            }
          }
        }
      }
    },
    "/coverage/policy": {
      "get": {
        "operationId": "readPolicy",
        "summary": "Read policy (unset = fail closed)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      },
      "post": {
        "operationId": "writePolicy",
        "summary": "Write policy",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Policy"
              }
            }
          }
        }
      }
    },
    "/coverage/code-lists/{list}": {
      "get": {
        "operationId": "listCodes",
        "summary": "Read code list",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "purpose",
                "supported_standard",
                "resolution_status"
              ]
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      },
      "post": {
        "operationId": "upsertCodes",
        "summary": "Upsert code list entries",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "purpose",
                "supported_standard",
                "resolution_status"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeListUpsert"
              }
            }
          }
        }
      }
    },
    "/coverage/maintenance/retry-sweep": {
      "post": {
        "operationId": "retrySweep",
        "summary": "Retry queued unknown inquiries (needs retry policy)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/coverage/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Drain outbox (no sink => nothing marked delivered)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/coverage/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Report catalog",
        "tags": [
          "OHN-30"
        ],
        "parameters": [],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/coverage/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run report",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-30-R001",
                "OHN-30-R002",
                "OHN-30-R003"
              ]
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Report"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/coverage/reports/{reportId}/export": {
      "post": {
        "operationId": "createExport",
        "summary": "Create signed single-use export",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-30-R001",
                "OHN-30-R002",
                "OHN-30-R003"
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        }
      }
    },
    "/coverage/exports/{token}": {
      "get": {
        "operationId": "fetchExport",
        "summary": "Download export (owner only, single use, 5 min)",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        }
      }
    },
    "/health/ohn-30": {
      "get": {
        "operationId": "health",
        "summary": "Liveness incl. DB and dependency modes",
        "security": [],
        "responses": {
          "200": {
            "description": "ok"
          },
          "503": {
            "description": "unavailable"
          }
        }
      }
    },
    "/coverage/eligibility-inquiries/{id}/answer": {
      "post": {
        "operationId": "answerInquiry",
        "summary": "Insurer answers an in-network eligibility inquiry addressed to it: eligible, ineligible or limited, with validity and benefit notes (F004). Outcomes must be configured in the answer_outcome code list. Role partner_reviewer of the payer organisation.",
        "tags": [
          "OHN-30"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Malformed / missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Role/purpose denied, patient not authorized, or separation of duties"
          },
          "404": {
            "description": "Not found / out of scope"
          },
          "409": {
            "description": "Version conflict, illegal transition or idempotency mismatch",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation or domain refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fails closed)"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PayerAnswer"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {}
        }
      },
      "Inquiry": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "patient_ref",
          "payer_org",
          "policy_identifier",
          "service_code",
          "date_of_service",
          "purpose"
        ],
        "properties": {
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "payer_org": {
            "type": "string",
            "format": "uuid"
          },
          "policy_identifier": {
            "type": "string",
            "maxLength": 512,
            "description": "Sent to the payer; stored encrypted; only a masked form is ever returned"
          },
          "service_code": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:/-]+$",
            "maxLength": 128
          },
          "date_of_service": {
            "type": "string",
            "format": "date"
          },
          "purpose": {
            "type": "string",
            "description": "Must exist in the jurisdiction purpose code list"
          }
        }
      },
      "InquiryView": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "outcome": {
            "enum": [
              "eligible",
              "ineligible",
              "unknown"
            ],
            "description": "unknown means no verdict was obtained; it is never an ineligible result"
          },
          "unknown_reason": {
            "enum": [
              "timeout",
              "endpoint_error",
              null
            ]
          },
          "status": {
            "enum": [
              "recorded",
              "retry_queued",
              "retry_exhausted",
              "resolved"
            ]
          },
          "freshness": {
            "enum": [
              "current",
              "expired",
              "not_applicable"
            ],
            "description": "Expired results must not be presented as current"
          },
          "valid_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "ttl_configured": {
            "type": "boolean"
          },
          "policy_identifier_masked": {
            "type": "string"
          },
          "coverage_is_advisory": {
            "const": true
          },
          "blocks_care": {
            "const": false
          }
        }
      },
      "Endpoint": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "insurer_org",
          "endpoint_url",
          "certificate_ref",
          "supported_standard",
          "timeout_ms"
        ],
        "properties": {
          "insurer_org": {
            "type": "string",
            "format": "uuid"
          },
          "endpoint_url": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048,
            "description": "https only, public host, no credentials, port 443"
          },
          "certificate_ref": {
            "type": "string",
            "format": "uuid"
          },
          "supported_standard": {
            "type": "string"
          },
          "timeout_ms": {
            "type": "integer",
            "minimum": 100,
            "maximum": 120000
          }
        }
      },
      "EndpointDecision": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "expected_version",
          "reason"
        ],
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "Dispute": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "source_response_ref",
          "dispute_reason"
        ],
        "properties": {
          "source_response_ref": {
            "type": "string",
            "format": "uuid"
          },
          "dispute_reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "DisputeResolve": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "resolution_status",
          "reason",
          "expected_version"
        ],
        "properties": {
          "resolution_status": {
            "type": "string"
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Policy": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "eligibility_ttl_minutes",
          "max_retry_attempts",
          "retry_delay_seconds",
          "availability_slo_bp",
          "approval_reference"
        ],
        "properties": {
          "eligibility_ttl_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "max_retry_attempts": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 100
          },
          "retry_delay_seconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "availability_slo_bp": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 10000
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3
          }
        }
      },
      "CodeListUpsert": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "entries"
        ],
        "properties": {
          "entries": {
            "type": "array",
            "minItems": 1,
            "maxItems": 200,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "code",
                "label_en",
                "label_fr"
              ],
              "properties": {
                "code": {
                  "type": "string"
                },
                "label_en": {
                  "type": "string"
                },
                "label_fr": {
                  "type": "string"
                },
                "active": {
                  "type": "boolean",
                  "default": true
                }
              }
            }
          }
        }
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "format"
        ],
        "properties": {
          "format": {
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "type": "object"
          }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "report_id": {
            "enum": [
              "OHN-30-R001",
              "OHN-30-R002",
              "OHN-30-R003"
            ]
          },
          "title": {
            "type": "string"
          },
          "columns": {
            "type": "array"
          },
          "rows": {
            "type": "array"
          },
          "summary": {
            "type": "object"
          },
          "state": {
            "enum": [
              "rendered",
              "no_authorized_data"
            ]
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PayerAnswer": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "result",
          "expected_version"
        ],
        "properties": {
          "result": {
            "type": "string",
            "enum": [
              "eligible",
              "ineligible",
              "limited"
            ]
          },
          "valid_until": {
            "type": "string",
            "format": "date-time"
          },
          "benefit_notes": {
            "type": "string",
            "minLength": 3,
            "maxLength": 2000,
            "description": "Required when result is limited."
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      }
    }
  }
}
