{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-11 Diagnostics Results Exchange",
    "version": "1.0.0",
    "description": "Server paths are under /api/ohn/v1/diagnostics. Default deny: role AND purpose must match. Inventory paths OHN-11-API-001..003 are mapped to this disjoint prefix (see ADR-0001). Reconciled with the observed behaviour of backend/modules/ohn-11 (docs/program/java/ohn-11-contract-changes.md)."
  },
  "servers": [
    {
      "url": "/api/ohn/v1/diagnostics"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/patients/{id}/observations": {
      "get": {
        "operationId": "listPatientObservations",
        "summary": "Published observation lines for one patient by code (system|code), every version flagged is_current, with source report provenance",
        "x-inventory-id": "OHN-11-API-007",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^(loinc|snomed_ct|local)\\|[A-Za-z0-9._:-]{1,64}$"
              },
              "minItems": 1,
              "maxItems": 20
            },
            "description": "system|code, repeatable or comma separated (1-20)"
          },
          {
            "name": "include_superseded",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/patients/{id}/patient-view": {
      "get": {
        "operationId": "patientResultView",
        "summary": "Own published results of the patient for the OHN-31 patient chart (role patient under purpose patient_access; own record only, otherwise 404; OHN-16 decision; every read audited)",
        "x-roles": [
          "patient"
        ],
        "x-purpose": "patient_access",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/patients/{id}/results": {
      "get": {
        "operationId": "listPatientResults",
        "summary": "Results for one patient (current versions; clinicians see published only)",
        "x-inventory-id": "OHN-11-API-001",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "include_superseded",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "report_type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/results/ingest": {
      "post": {
        "operationId": "ingestResult",
        "summary": "Import a diagnostic report as received",
        "x-inventory-id": "OHN-11-API-002",
        "x-roles": [
          "lab_verifier"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IngestCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/results": {
      "get": {
        "operationId": "listResults",
        "summary": "Results inbox",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "report_type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            }
          },
          {
            "name": "critical",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "patient_ref",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "source_facility",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "current_only",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/results/compare": {
      "get": {
        "operationId": "compareResults",
        "summary": "Compare two reports of one patient",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "left",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "right",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/results/{id}": {
      "get": {
        "operationId": "getResult",
        "summary": "Report with observations, imaging references and critical case",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/results/{id}/provenance": {
      "get": {
        "operationId": "getProvenance",
        "summary": "Source, custody, history and audit of a report",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/results/{id}/versions": {
      "get": {
        "operationId": "getVersions",
        "summary": "All versions of a report",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/results/{id}/transitions": {
      "post": {
        "operationId": "transitionResult",
        "summary": "Advance the publication workflow (W001)",
        "x-roles": [
          "lab_verifier"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TransitionCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/critical-results": {
      "get": {
        "operationId": "listCriticalResults",
        "summary": "Escalation board",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "overdue",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "facility",
            "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": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/critical-results/{id}": {
      "get": {
        "operationId": "getCriticalResult",
        "summary": "Critical result with receipts",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/critical-results/{id}/notify": {
      "post": {
        "operationId": "notifyCriticalResult",
        "summary": "Notify the responsible clinician",
        "x-roles": [
          "lab_verifier"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NotifyCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/critical-results/{id}/ack": {
      "post": {
        "operationId": "acknowledgeCriticalResult",
        "summary": "Acknowledge with read-back",
        "x-inventory-id": "OHN-11-API-003",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AckCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/critical-results/{id}/escalate": {
      "post": {
        "operationId": "escalateCriticalResult",
        "summary": "Escalate an overdue critical result",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EscalateCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/critical-results/{id}/close": {
      "post": {
        "operationId": "closeCriticalResult",
        "summary": "Close an acknowledged critical result",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CloseCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/amendments": {
      "post": {
        "operationId": "submitAmendment",
        "summary": "Submit a report amendment for review (F003)",
        "x-roles": [
          "lab_verifier"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AmendmentCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      },
      "get": {
        "operationId": "listAmendments",
        "summary": "Amendments",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          },
          {
            "name": "report_id",
            "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": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/amendments/{id}/transitions": {
      "post": {
        "operationId": "transitionAmendment",
        "summary": "Advance an amendment (W003)",
        "x-roles": [
          "licensed_clinician"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AmendmentTransitionCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/code-lists/{list}": {
      "get": {
        "operationId": "getCodeList",
        "summary": "Controlled code list",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "report_type",
                "clinical_responsibility",
                "imaging_modality"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      },
      "post": {
        "operationId": "upsertCodeList",
        "summary": "Upsert code list entries",
        "x-roles": [
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "report_type",
                "clinical_responsibility",
                "imaging_modality"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeListCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/policy": {
      "get": {
        "operationId": "getPolicy",
        "summary": "Jurisdiction critical-result policy",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      },
      "post": {
        "operationId": "setPolicy",
        "summary": "Set the jurisdiction critical-result policy",
        "x-roles": [
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PolicyCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/maintenance/drain-outbox": {
      "post": {
        "operationId": "drainOutbox",
        "summary": "Report pending outbox events (no sink configured: nothing is claimed delivered)",
        "x-roles": [
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/report-catalog": {
      "get": {
        "operationId": "reportCatalog",
        "summary": "Available reports",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/reports/{reportId}": {
      "get": {
        "operationId": "runReport",
        "summary": "Run report R001..R003",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician",
          "diagnostics_steward"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "OHN-11-R001",
                "OHN-11-R002",
                "OHN-11-R003"
              ]
            }
          },
          {
            "name": "facility",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "severity",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "critical"
              ]
            }
          },
          {
            "name": "result_type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            }
          },
          {
            "name": "patient_scope",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "jurisdiction",
            "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}$"
            }
          },
          {
            "name": "period_to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/reports/{reportId}/export": {
      "post": {
        "operationId": "exportReport",
        "summary": "Create a signed single-use export",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "OHN-11-R001",
                "OHN-11-R002",
                "OHN-11-R003"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    },
    "/exports/{token}": {
      "get": {
        "operationId": "downloadExport",
        "summary": "Download an export once",
        "x-roles": [
          "lab_verifier",
          "licensed_clinician"
        ],
        "x-purpose": "diagnostic_results_exchange",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{20,64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The export file (single use, five minutes)",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request or missing Idempotency-Key"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "Denied by policy, separation of duties or role not permitted for the step"
          },
          "404": {
            "description": "Not found / not disclosed"
          },
          "409": {
            "description": "version_conflict, invalid_transition, not_overdue, max_escalation_reached, report_not_ready, duplicate_source_report, duplicate_amendment, idempotency_key_reused or request_in_progress"
          },
          "422": {
            "description": "domain_validation_failed (details per field), code_list_not_configured, policy_not_configured, amendment_mismatch, different_patients, report_not_publishable, safety_block"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Dependency unavailable (fail closed): dependency_unavailable with details.dependency"
          },
          "410": {
            "description": "Export expired or already downloaded"
          }
        },
        "tags": [
          "OHN-11"
        ]
      }
    }
  },
  "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": {
      "IngestCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "source_facility": {
            "type": "string",
            "format": "uuid"
          },
          "specimen_ref": {
            "type": "string",
            "format": "uuid"
          },
          "report_type": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "report_status": {
            "type": "string",
            "enum": [
              "registered",
              "partial",
              "preliminary",
              "final",
              "amended",
              "corrected",
              "appended",
              "cancelled",
              "entered_in_error"
            ]
          },
          "issued_at": {
            "type": "string",
            "format": "date-time"
          },
          "file_or_payload": {
            "type": "string",
            "format": "uuid"
          },
          "payload_sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "source_report_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "ordering_org": {
            "type": "string",
            "format": "uuid"
          },
          "replaces_report_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_interpretation": {
            "type": "string",
            "minLength": 1,
            "maxLength": 8000
          },
          "critical_declared": {
            "type": "boolean",
            "default": false
          },
          "observations": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "code_system": {
                  "type": "string",
                  "enum": [
                    "loinc",
                    "snomed_ct",
                    "local"
                  ]
                },
                "code": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "code_display": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "value_number": {
                  "type": "number"
                },
                "value_text": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 1024
                },
                "unit": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64,
                  "pattern": "^[A-Za-z0-9/.%\\[\\]{}^*+_ -]+$"
                },
                "ref_low": {
                  "type": "number"
                },
                "ref_high": {
                  "type": "number"
                },
                "source_flag": {
                  "type": "string",
                  "enum": [
                    "normal",
                    "abnormal",
                    "critical_low",
                    "critical_high",
                    "critical",
                    "unknown"
                  ],
                  "default": "unknown"
                }
              },
              "required": [
                "code_system",
                "code"
              ]
            },
            "maxItems": 500
          },
          "imaging_studies": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "study_instance_uid": {
                  "type": "string",
                  "maxLength": 64,
                  "pattern": "^[0-9]+(\\.[0-9]+){1,31}$"
                },
                "accession_number": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "modality": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,63}$"
                },
                "locator_ref": {
                  "type": "string",
                  "format": "uuid"
                },
                "series_count": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 100000
                }
              },
              "required": [
                "study_instance_uid",
                "modality",
                "locator_ref"
              ]
            },
            "maxItems": 50
          }
        },
        "required": [
          "patient_ref",
          "source_facility",
          "report_type",
          "report_status",
          "issued_at",
          "file_or_payload",
          "source_report_id"
        ]
      },
      "TransitionCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "to_state": {
            "type": "string",
            "enum": [
              "validated",
              "patient_matched",
              "released",
              "available",
              "rejected"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ]
      },
      "NotifyCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "responsible_clinician": {
            "type": "string",
            "format": "uuid"
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "responsible_clinician",
          "expected_version",
          "reason"
        ]
      },
      "AckCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "result_ref": {
            "type": "string",
            "format": "uuid"
          },
          "acknowledged_by": {
            "type": "string",
            "format": "uuid"
          },
          "acknowledged_at": {
            "type": "string",
            "format": "date-time"
          },
          "readback_notes": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4000
          },
          "clinical_responsibility": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "readback_notes",
          "clinical_responsibility",
          "expected_version"
        ]
      },
      "EscalateCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "escalate_to": {
            "type": "string",
            "format": "uuid"
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "escalate_to",
          "expected_version",
          "reason"
        ]
      },
      "CloseCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "expected_version",
          "reason"
        ]
      },
      "AmendmentCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "original_report_id": {
            "type": "string",
            "format": "uuid"
          },
          "replacement_report_id": {
            "type": "string",
            "format": "uuid"
          },
          "amendment_reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          },
          "reviewer": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "original_report_id",
          "replacement_report_id",
          "amendment_reason",
          "reviewer"
        ]
      },
      "AmendmentTransitionCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "to_state": {
            "type": "string",
            "enum": [
              "version_linked",
              "prior_version_marked",
              "notified"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          }
        },
        "required": [
          "to_state",
          "expected_version",
          "reason"
        ]
      },
      "PolicyCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "critical_ack_window_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10080
          },
          "max_escalation_level": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3,
            "maxLength": 256
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "critical_ack_window_minutes",
          "max_escalation_level",
          "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"
              },
              "severity": {
                "type": "string",
                "enum": [
                  "critical"
                ]
              },
              "result_type": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "patient_scope": {
                "type": "string",
                "format": "uuid"
              },
              "jurisdiction": {
                "type": "string",
                "format": "uuid"
              },
              "period_from": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
              },
              "period_to": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
              }
            }
          }
        },
        "required": [
          "format"
        ]
      },
      "CodeListCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "entries": {
            "type": "array",
            "items": {
              "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"
              ]
            },
            "minItems": 1,
            "maxItems": 200
          }
        },
        "required": [
          "entries"
        ]
      }
    }
  }
}