{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-31 Patient Health Record Portal",
    "version": "1.1.1",
    "description": "Default-deny: role AND purpose (patient_portal) must both match; the purpose is the token claim. Idempotency-Key (8-128 characters of A-Za-z0-9_.:-) is mandatory on every POST except the public share view. Sensitive actions need a fresh step-up (auth_time within the policy window). A missing policy or code list refuses (fail closed); a dependency that cannot be confirmed (identity, guardian authority, a clinical source) is 503 dependency_unavailable and nothing is shown or stored. Every request body and query is strict: an unknown key, a wrong type or a value outside its limits is 422 domain_validation_failed with details = { <top-level field>: <zod issue code | refinement message> } and \"_\": \"unrecognized_keys\" for unknown keys. Errors are application/problem+json that also carry the legacy {error, message, details} members."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "paths": {
    "/health/ohn-31": {
      "get": {
        "summary": "Liveness and dependency modes",
        "responses": {
          "200": {
            "description": "ok: {status, module: \"OHN-31\", dependencies: {identity, delegation, chart, consent}} with each mode synthetic | unconfigured | live",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "{status: \"unavailable\"} when the database does not answer"
          }
        }
      }
    },
    "/portal/synthetic-token": {
      "post": {
        "summary": "TypeScript development sign-in (not served by the Java service: tokens are gateway tokens)",
        "responses": {
          "200": {
            "description": "token"
          },
          "404": {
            "description": "not found"
          }
        },
        "deprecated": true,
        "x-java": "not ported"
      }
    },
    "/me": {
      "get": {
        "summary": "Sign in and bind identity (W001)",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "x-ohn-operation": "OHN-31-API-001"
      }
    },
    "/me/dashboard": {
      "get": {
        "summary": "Patient dashboard KPIs",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "x-ohn-operation": "OHN-31-API-001"
      }
    },
    "/me/records": {
      "get": {
        "summary": "Records with provenance and freshness",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "session_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "x-ohn-operation": "OHN-31-API-002"
      }
    },
    "/me/critical-info": {
      "get": {
        "summary": "The patient's own critical health information: blood group (LOINC 883-9), Rh (LOINC 10331-7) and configured haemoglobin genotype from verified laboratory results (via OHN-10 / OHN-11), with provenance and conflict warnings; plus allergies and active problems",
        "x-inventory-id": "OHN-31-API-006",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Critical information. items[].status is recorded | not_recorded | conflict | not_configured | needs_review; values are never guessed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "patient_ref",
                    "items",
                    "warnings"
                  ],
                  "properties": {
                    "patient_ref": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "blood_group": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "warnings": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "allergies": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "active_problems": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "receipt": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/me/consents": {
      "get": {
        "summary": "Consents held in OHN-15",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "x-ohn-operation": "OHN-31-API-003"
      }
    },
    "/me/disclosures": {
      "get": {
        "summary": "Disclosure history of this portal",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/me/rights-requests": {
      "post": {
        "summary": "Submit a rights request (F001 correction, F002 consent preference, F003 record access, F004 security update)",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "x-ohn-operation": "OHN-31-API-004",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RightsRequest"
              }
            }
          }
        }
      },
      "get": {
        "summary": "List own rights requests",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "request_type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/me/rights-requests/{id}": {
      "get": {
        "summary": "Rights request detail",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/me/rights-requests/{id}/history": {
      "get": {
        "summary": "Workflow history (W002/W003)",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/me/rights-requests/{id}/prepare": {
      "post": {
        "summary": "Prepare the copy for a record access request (W003), from the OHN-31 chart aggregation",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Prepare"
              }
            }
          }
        },
        "description": "identity_checked -> export_prepared -> available_short_term. Refused with 503 (request unchanged, audited) when a source of a requested section cannot be read: no partial copy. Optional OHN-08 supplement only with OHN31_RECORD_COPY_OHN08=true (ADR-0014)."
      }
    },
    "/me/downloads/{token}": {
      "get": {
        "summary": "Download the copy prepared for a record access request (single use, short-lived, owner only)",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ohn-acting-for",
            "in": "header",
            "required": false,
            "description": "guardian_proxy only: the patient being acted for",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The file. Header X-OHN-Content-SHA256 carries the SHA-256 of the base64 content stored for the integrity check.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "application/pdf"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              },
              "application/fhir+json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (unknown, another person’s, or already used link)"
          },
          "410": {
            "description": "link_expired"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "500": {
            "description": "export_integrity_failed (the stored content failed its hash or signature; nothing is released)"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "description": "ADR-0014: the copy is built from the OHN-31 chart aggregation (GET /me/chart sources) with the jurisdiction chart policy applied (withheld and not-yet-released entries are counted with the reason, never included), restricted to the requested record categories and date range. Format follows the request delivery_format: pdf (application/pdf), json (OHN-31 record copy 1.0.0), fhir_bundle / fhir / fhir_r4 (FHIR R4 document Bundle). The first successful download consumes the link (the request moves to expired and the content is removed); a second use answers 404."
      }
    },
    "/me/chart": {
      "get": {
        "summary": "Own chart (or the represented person's): every section from the clinical modules with site names and dates; withheld items replaced by a reason and a count; sources that cannot be read are marked, never guessed",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/me/chart/documents/{id}/link": {
      "post": {
        "summary": "Issue a short-lived, single-person download link for an own document",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/me/chart/downloads/{token}": {
      "get": {
        "summary": "Download a document through its short-lived link (only the person it was issued to)",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Short-lived signed download token issued by POST /me/chart/documents/{id}/link"
          }
        ],
        "responses": {
          "200": {
            "description": "The document (attachment)",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "410": {
            "description": "link_expired / export_expired / export_consumed"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "500": {
            "description": "export_integrity_failed (the stored content failed its hash or signature; nothing is released)"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/portal/chart-policy": {
      "get": {
        "summary": "Read the jurisdiction chart policy (result release delay, withholding rules)",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      },
      "post": {
        "summary": "Set the jurisdiction chart policy (portal steward only; versioned, with a reason)",
        "x-ohn-roles": [
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "201": {
            "description": "The policy view (configured, basis, version, updated_by, updated_at, reason, policy) and the receipt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChartPolicyCommand"
              }
            }
          }
        }
      }
    },
    "/portal/policy": {
      "get": {
        "summary": "Read portal policy",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      },
      "post": {
        "summary": "Create or change portal policy",
        "x-ohn-roles": [
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "201": {
            "description": "The policy (version 1, or version + 1 with the right expected_version) and the receipt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Policy"
              }
            }
          }
        }
      }
    },
    "/portal/code-lists/{list}": {
      "get": {
        "summary": "Read a code list",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      },
      "post": {
        "summary": "Upsert code list entries",
        "x-ohn-roles": [
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          },
          {
            "name": "list",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CodeListEntries"
              }
            }
          }
        }
      }
    },
    "/portal/accessibility-observations": {
      "post": {
        "summary": "Record an accessibility observation (R003 source)",
        "x-ohn-roles": [
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccessibilityObservation"
              }
            }
          }
        }
      }
    },
    "/portal/maintenance/expire-sweep": {
      "post": {
        "summary": "Expire past-due download links and drop content",
        "x-ohn-roles": [
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/portal/maintenance/reconcile": {
      "post": {
        "summary": "Retry consent preferences committed while OHN-15 was down",
        "x-ohn-roles": [
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/portal/maintenance/drain-outbox": {
      "post": {
        "summary": "Relay the outbox to OHN-24 (nothing is marked delivered without a sink)",
        "x-ohn-roles": [
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/portal/report-catalog": {
      "get": {
        "summary": "Report catalog",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/portal/reports/{reportId}": {
      "get": {
        "summary": "Run OHN-31-R001..R003",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "OHN-31-R001",
                "OHN-31-R002",
                "OHN-31-R003"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "country",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "period_from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "period_to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "patient_scope",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "date_range_from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "date_range_to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "release",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "locale",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "en",
                "fr"
              ]
            }
          },
          {
            "name": "viewport",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "mobile",
                "tablet",
                "desktop"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "description": "R001/R002: a patient role sees only their own bound patient (the identity is re-verified); a portal steward sees organisation aggregates with masked references. R003 is for the portal steward. period_* apply to R001, date_range_* to R002. Any other query key is 422 (details._ = unrecognized_keys; message \"Report filter is not valid.\")."
      }
    },
    "/portal/reports/{reportId}/export": {
      "post": {
        "summary": "Create a signed, single-use, 5-minute CSV/PDF export",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          },
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "409": {
            "description": "version_conflict / idempotency_key_reused / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        }
      }
    },
    "/portal/exports/{token}": {
      "get": {
        "summary": "Download an export once",
        "x-ohn-roles": [
          "patient",
          "guardian_proxy",
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / step_up_required / guardian_* / identity_*"
          },
          "404": {
            "description": "not_found (not a route, not a UUID, or not this person's)"
          },
          "410": {
            "description": "link_expired / export_expired / export_consumed"
          },
          "422": {
            "description": "domain_validation_failed / not_configured"
          },
          "429": {
            "description": "rate_limited"
          },
          "500": {
            "description": "export_integrity_failed (the stored content failed its hash or signature; nothing is released)"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        }
      }
    },
    "/me/exports": {
      "post": {
        "summary": "Generate \"My health summary\" (PDF) or a FHIR R4 IPS Bundle from live sources; returns a single-use short-lived link (ADR-0012)",
        "x-ohn-roles": [
          "patient"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecordExportCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecordExportCreated"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / self_only / identity_*"
          },
          "409": {
            "description": "patient_record_not_found"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / not_configured (portal policy)"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable / not_configured (signing key)"
          }
        }
      }
    },
    "/me/exports/{token}": {
      "get": {
        "summary": "Download an export once (owner only). Headers X-OHN-Content-SHA256 and X-OHN-Signature (HMAC-SHA256)",
        "x-ohn-roles": [
          "patient"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The file",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/fhir+json": {
                "schema": {
                  "type": "object",
                  "description": "FHIR R4 Bundle (type document, IPS profile)"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / self_only / identity_*"
          },
          "404": {
            "description": "not_found (unknown, used, or another patient's)"
          },
          "410": {
            "description": "link_expired"
          },
          "429": {
            "description": "rate_limited"
          },
          "500": {
            "description": "export_integrity_failed (the stored content failed its hash or signature; nothing is released)"
          },
          "503": {
            "description": "dependency_unavailable / not_configured (signing key)"
          }
        }
      }
    },
    "/me/share-options": {
      "get": {
        "summary": "Sections, durations and active OHN-05 facilities a patient can share with",
        "x-ohn-roles": [
          "patient"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / self_only / identity_*"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable / not_configured (signing key)"
          }
        }
      }
    },
    "/me/shares": {
      "get": {
        "summary": "The patient's shares (active, revoked, expired), without tokens",
        "x-ohn-roles": [
          "patient"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / self_only / identity_*"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable / not_configured (signing key)"
          }
        }
      },
      "post": {
        "summary": "Create a time-limited read-only share (link and QR); a named facility is recorded as an OHN-15 consent",
        "x-ohn-roles": [
          "patient"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ShareCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShareCreated"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / self_only / identity_*"
          },
          "409": {
            "description": "idempotency_key_reused / request_in_progress / version_conflict / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "422": {
            "description": "domain_validation_failed / consent_not_recorded"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable / not_configured (signing key)"
          }
        }
      }
    },
    "/me/shares/{id}/revoke": {
      "post": {
        "summary": "Revoke a share at once; the OHN-15 consent is revoked too (or marked revocation_pending while OHN-15 is unreachable)",
        "x-ohn-roles": [
          "patient"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "400": {
            "description": "idempotency_key_required (missing, shorter than 8 or longer than 128 characters, or characters outside A-Za-z0-9_.:-)"
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy / self_only / identity_*"
          },
          "404": {
            "description": "not_found"
          },
          "409": {
            "description": "idempotency_key_reused / request_in_progress / version_conflict / illegal_transition"
          },
          "413": {
            "description": "payload_too_large (a body over 256 KB)"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable / not_configured (signing key)"
          }
        }
      }
    },
    "/portal/shared/view": {
      "post": {
        "summary": "Public read-only view of a share. No OHN-31 sign-in; a facility share needs an OHN-38 session of clinical staff at that facility. Cache-Control no-store, X-Robots-Tag noindex. Rate limited per address and per token.",
        "security": [
          {},
          {
            "bearer": []
          }
        ],
        "x-ohn-roles": [
          "anyone_with_link",
          "facility_clinician"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SharedViewCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SharedView"
                }
              }
            }
          },
          "401": {
            "description": "facility_sign_in_required"
          },
          "403": {
            "description": "not_named_facility / facility_not_active"
          },
          "404": {
            "description": "share_not_found"
          },
          "410": {
            "description": "share_revoked / share_expired / share_unavailable"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable"
          }
        },
        "description": "ADR-0012 public view: no OHN-31 sign-in, the token travels in the body. Rate limited per address and per token (default 30 per minute; 429 with Retry-After). Answers: 200 the shared record; 401 facility_sign_in_required (a facility share needs the viewer's own sign-in; the Java service cannot resolve the viewer, OWNER-BLOCKERS B772, so it always answers 401); 403 not_named_facility / facility_not_active; 404 share_not_found; 410 share_revoked / share_expired / share_unavailable (the patient's identity no longer binds); 503 dependency_unavailable. Responses carry X-Robots-Tag: noindex, nofollow, noarchive and Referrer-Policy: no-referrer."
      }
    },
    "/portal/dashboard": {
      "get": {
        "summary": "Portal dashboard for the portal steward: organisation activity counts, request states and types, 14-day trend, stuck requests (masked references)",
        "x-ohn-roles": [
          "portal_steward"
        ],
        "parameters": [
          {
            "name": "x-ohn-purpose",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "const": "patient_portal"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Object"
                }
              }
            }
          },
          "401": {
            "description": "unauthenticated"
          },
          "403": {
            "description": "denied_by_policy (any role other than portal_steward)"
          },
          "429": {
            "description": "rate_limited"
          },
          "503": {
            "description": "dependency_unavailable / not_configured"
          }
        },
        "x-ohn-operation": "OHN-31-P001-steward"
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Object": {
        "type": "object",
        "additionalProperties": true
      },
      "Prepare": {
        "type": "object",
        "required": [
          "expected_version"
        ],
        "additionalProperties": false,
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "Policy": {
        "type": "object",
        "required": [
          "step_up_max_age_seconds",
          "access_link_ttl_minutes",
          "freshness_days",
          "reason"
        ],
        "additionalProperties": false,
        "properties": {
          "step_up_max_age_seconds": {
            "type": "integer",
            "minimum": 30,
            "maximum": 3600
          },
          "access_link_ttl_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1440
          },
          "freshness_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 3650
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "CodeListEntries": {
        "type": "object",
        "required": [
          "entries"
        ],
        "additionalProperties": false,
        "properties": {
          "entries": {
            "type": "array",
            "minItems": 1,
            "maxItems": 200,
            "items": {
              "type": "object",
              "required": [
                "code",
                "label_en",
                "label_fr"
              ],
              "properties": {
                "code": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,63}$"
                },
                "label_en": {
                  "type": "string"
                },
                "label_fr": {
                  "type": "string"
                },
                "active": {
                  "type": "boolean"
                },
                "critical": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      },
      "AccessibilityObservation": {
        "type": "object",
        "required": [
          "page",
          "release",
          "locale",
          "viewport",
          "keyboard_failures",
          "translation_gaps",
          "error_rate_permille"
        ],
        "additionalProperties": false,
        "properties": {
          "page": {
            "type": "string"
          },
          "release": {
            "type": "string"
          },
          "locale": {
            "enum": [
              "en",
              "fr"
            ]
          },
          "viewport": {
            "enum": [
              "mobile",
              "tablet",
              "desktop"
            ]
          },
          "keyboard_failures": {
            "type": "integer",
            "minimum": 0
          },
          "translation_gaps": {
            "type": "integer",
            "minimum": 0
          },
          "error_rate_permille": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000
          }
        }
      },
      "ExportCommand": {
        "type": "object",
        "required": [
          "format"
        ],
        "additionalProperties": false,
        "properties": {
          "format": {
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "$ref": "#/components/schemas/ReportFilters"
          }
        }
      },
      "ProfileCorrection": {
        "type": "object",
        "required": [
          "request_type",
          "patient_ref",
          "field_name",
          "proposed_value",
          "supporting_evidence",
          "reason"
        ],
        "additionalProperties": false,
        "properties": {
          "request_type": {
            "const": "profile_correction"
          },
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "field_name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "proposed_value": {
            "type": "string",
            "maxLength": 512
          },
          "supporting_evidence": {
            "type": "string",
            "format": "uuid"
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "ConsentPreference": {
        "type": "object",
        "required": [
          "request_type",
          "patient_ref",
          "scope",
          "recipient",
          "action",
          "confirmation"
        ],
        "additionalProperties": false,
        "properties": {
          "request_type": {
            "const": "consent_preference"
          },
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "scope": {
            "type": "string",
            "maxLength": 8192
          },
          "recipient": {
            "type": "string",
            "format": "uuid"
          },
          "action": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "confirmation": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "RecordAccess": {
        "type": "object",
        "required": [
          "request_type",
          "patient_ref",
          "record_categories",
          "delivery_format"
        ],
        "additionalProperties": false,
        "properties": {
          "request_type": {
            "const": "record_access"
          },
          "patient_ref": {
            "type": "string",
            "format": "uuid"
          },
          "record_categories": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            }
          },
          "time_range_start": {
            "type": "string",
            "format": "date"
          },
          "time_range_end": {
            "type": "string",
            "format": "date"
          },
          "delivery_format": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          }
        }
      },
      "SecurityUpdate": {
        "type": "object",
        "required": [
          "request_type",
          "principal_id",
          "authenticator_action",
          "current_proof"
        ],
        "additionalProperties": false,
        "properties": {
          "request_type": {
            "const": "security_update"
          },
          "principal_id": {
            "type": "string",
            "format": "uuid"
          },
          "authenticator_action": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "current_proof": {
            "type": "string",
            "format": "uuid"
          },
          "recovery_option": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          }
        }
      },
      "RightsRequest": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/ProfileCorrection"
          },
          {
            "$ref": "#/components/schemas/ConsentPreference"
          },
          {
            "$ref": "#/components/schemas/RecordAccess"
          },
          {
            "$ref": "#/components/schemas/SecurityUpdate"
          }
        ],
        "discriminator": {
          "propertyName": "request_type"
        }
      },
      "RecordExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "format"
        ],
        "properties": {
          "format": {
            "type": "string",
            "enum": [
              "pdf",
              "fhir_ips"
            ]
          }
        }
      },
      "RecordExportCreated": {
        "type": "object",
        "required": [
          "export",
          "link",
          "notice",
          "receipt"
        ],
        "properties": {
          "export": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "format": {
                "type": "string",
                "enum": [
                  "pdf",
                  "fhir_ips"
                ]
              },
              "state": {
                "type": "string",
                "enum": [
                  "available",
                  "downloaded",
                  "expired"
                ]
              },
              "expires_at": {
                "type": "string",
                "format": "date-time"
              },
              "content_sha256": {
                "type": "string"
              },
              "size_bytes": {
                "type": "integer"
              }
            }
          },
          "link": {
            "type": "object",
            "properties": {
              "download_path": {
                "type": "string",
                "description": "GET with the patient bearer token; works once; at most 15 minutes and never longer than the portal policy link lifetime."
              },
              "expires_at": {
                "type": "string",
                "format": "date-time"
              },
              "single_use": {
                "type": "boolean",
                "const": true
              }
            }
          },
          "notice": {
            "type": "string"
          },
          "receipt": {
            "$ref": "#/components/schemas/Object"
          }
        }
      },
      "ShareCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "scope",
          "duration",
          "recipient"
        ],
        "properties": {
          "scope": {
            "type": "string",
            "enum": [
              "summary",
              "sections"
            ],
            "description": "summary = critical_information, allergies, problems, medications"
          },
          "sections": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "enum": [
                "critical_information",
                "allergies",
                "problems",
                "medications",
                "results",
                "immunizations",
                "encounters"
              ]
            },
            "description": "Required for scope=sections, forbidden for summary."
          },
          "duration": {
            "type": "string",
            "enum": [
              "1h",
              "24h",
              "7d"
            ]
          },
          "recipient": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "kind"
                ],
                "properties": {
                  "kind": {
                    "const": "anyone_with_link"
                  }
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "kind",
                  "facility_id"
                ],
                "properties": {
                  "kind": {
                    "const": "facility"
                  },
                  "facility_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "An active OHN-05 facility. Recorded as an OHN-15 consent directive; no consent, no share."
                  }
                }
              }
            ]
          }
        }
      },
      "Share": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "scope": {
            "type": "string"
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "section_labels": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "recipient": {
            "type": "object"
          },
          "state": {
            "type": "string",
            "enum": [
              "active",
              "revoked",
              "expired"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "views": {
            "type": "integer"
          },
          "last_viewed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "consent": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "ref": {
                "type": "string"
              },
              "sync": {
                "type": "string",
                "enum": [
                  "recorded",
                  "revoked",
                  "revocation_pending"
                ]
              }
            }
          },
          "version": {
            "type": "integer"
          }
        }
      },
      "ShareCreated": {
        "type": "object",
        "properties": {
          "share": {
            "$ref": "#/components/schemas/Share"
          },
          "link": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string",
                "description": "/shared/{token}; the token (256-bit, base64url, 43 chars) is shown once and stored only as SHA-256."
              },
              "expires_at": {
                "type": "string",
                "format": "date-time"
              },
              "shown_once": {
                "type": "boolean"
              }
            }
          },
          "notice": {
            "type": "string"
          },
          "receipt": {
            "$ref": "#/components/schemas/Object"
          }
        }
      },
      "SharedViewCommand": {
        "type": "object",
        "description": "Any other key is ignored; a token that is not 43 characters of A-Za-z0-9_- is 404 share_not_found.",
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          }
        }
      },
      "SharedView": {
        "type": "object",
        "properties": {
          "shared_by_patient": {
            "const": true
          },
          "banner": {
            "type": "string"
          },
          "share": {
            "type": "object"
          },
          "viewer": {
            "type": "object"
          },
          "patient": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "birth_date": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "sex_at_birth": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "health_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "critical": {
            "type": [
              "object",
              "null"
            ]
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "notice": {
            "type": "string"
          },
          "receipt_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "WithholdingRule": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code",
          "label_en",
          "label_fr",
          "basis",
          "sections",
          "match",
          "reason_en",
          "reason_fr"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "label_en": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "label_fr": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "basis": {
            "enum": [
              "legal_requirement",
              "clinical_policy"
            ],
            "description": "legal_requirement fails closed: an entry of a listed section that carries no code to check is withheld."
          },
          "sections": {
            "type": "array",
            "minItems": 1,
            "maxItems": 10,
            "items": {
              "enum": [
                "visits",
                "problems",
                "allergies",
                "medicines",
                "results",
                "vaccinations",
                "documents",
                "referrals",
                "appointments",
                "programmes"
              ]
            }
          },
          "match": {
            "type": "object",
            "additionalProperties": false,
            "minProperties": 1,
            "description": "At least one matcher with at least one entry (else refinement at_least_one_matcher). codes and code_prefixes match \"system|code\".",
            "properties": {
              "codes": {
                "type": "array",
                "maxItems": 200,
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 160
                }
              },
              "code_prefixes": {
                "type": "array",
                "maxItems": 100,
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 160
                }
              },
              "security_labels": {
                "type": "array",
                "maxItems": 10,
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,63}$"
                }
              },
              "document_types": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,63}$"
                }
              },
              "report_types": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,63}$"
                }
              },
              "programme_codes": {
                "type": "array",
                "maxItems": 50,
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 160
                }
              }
            }
          },
          "reason_en": {
            "type": "string",
            "minLength": 10,
            "maxLength": 600
          },
          "reason_fr": {
            "type": "string",
            "minLength": 10,
            "maxLength": 600
          }
        }
      },
      "ChartPolicyCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "result_release_delay_hours",
          "reason"
        ],
        "properties": {
          "result_release_delay_hours": {
            "type": "integer",
            "minimum": 0,
            "maximum": 720
          },
          "delay_report_types": {
            "type": "array",
            "maxItems": 20,
            "default": [],
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,63}$"
            },
            "description": "Empty = every report type."
          },
          "withholding_rules": {
            "type": "array",
            "maxItems": 50,
            "default": [],
            "items": {
              "$ref": "#/components/schemas/WithholdingRule"
            },
            "description": "Each rule needs its own code (else details.withholding_rules = duplicate_code)."
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1,
            "description": "Required to change an existing policy (422 expected_version=required; 409 version_conflict)."
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "ReportFilters": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "country": {
            "type": "string",
            "format": "uuid"
          },
          "period_from": {
            "type": "string",
            "format": "date",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "period_to": {
            "type": "string",
            "format": "date",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "patient_scope": {
            "type": "string",
            "format": "uuid"
          },
          "date_range_from": {
            "type": "string",
            "format": "date",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "date_range_to": {
            "type": "string",
            "format": "date",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "release": {
            "type": "string",
            "maxLength": 64
          },
          "locale": {
            "enum": [
              "en",
              "fr"
            ]
          },
          "viewport": {
            "enum": [
              "mobile",
              "tablet",
              "desktop"
            ]
          }
        }
      }
    }
  },
  "security": [
    {
      "bearer": []
    }
  ]
}
