{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-32 patient-approved access",
    "version": "1.1.0",
    "description": "Scan a patient QR or type a health ID; the patient accepts or refuses; a time-limited grant (an OHN-32 care relationship) follows. ADR: docs/adr/ohn-32-patient-approved-access.md. Paths are under /api/ohn/v1. Every POST needs Idempotency-Key. When the jurisdiction has not switched the capability on, every route except GET options answers 409 patient_access_disabled. Reconciled with the observed TypeScript behaviour (docs/program/java/ohn-32-contract-changes.md): operationIds and a tag added, request bodies named components, query keys closed (422 on unknown). 1.1.0 (owner decisions 2026-11-29): a required note; the requester proposes sections; the patient may narrow sections and duration before accepting; an optional refusal reason kept only in the patient's own log; purpose review; request_ttl_minutes default 15; the request is also announced by SMS (OHN-53 category access_request, generic text, no clinical content). Additive: every new request field is optional in the schema so 1.0.0 clients still parse; the server enforces the note from 1.1.0 (422 note_required)."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/clinician/patient-access/options": {
      "get": {
        "summary": "What this person may ask for (purposes, sections, durations) and whether the capability is on.",
        "x-roles": [
          "licensed_clinician",
          "clinical_supervisor",
          "pharmacist",
          "diagnostic_staff",
          "patient"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.Options"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "operationId": "paOptions",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/identify": {
      "post": {
        "summary": "Identify a patient from scanned QR text, a card code or a health ID. Returns masked identity and an opaque lookup id (5 minutes) only.",
        "x-roles": [
          "licensed_clinician",
          "clinical_supervisor",
          "pharmacist",
          "diagnostic_staff"
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.Lookup"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IdentifyCommand"
              }
            }
          }
        },
        "operationId": "paIdentify",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/requests": {
      "post": {
        "summary": "Ask the patient for access.",
        "x-roles": [
          "licensed_clinician",
          "clinical_supervisor",
          "pharmacist",
          "diagnostic_staff"
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.RequestView"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateRequestCommand"
              }
            }
          }
        },
        "operationId": "paCreateRequest",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "description": "1.1.0: note is required (422 note_required); sections proposes a subset of the purpose's sections. On creation OHN-53 gets event clinician.access-request.created (category access_request: a security notice the patient cannot mute). The in-app notice and the app's modal say who (name, title, facility), the purpose, the sections, the duration and the note; the SMS (only to a verified phone among the patient's OHN-53 contacts, when SMS is on in their preferences) is OHN-53's generic text with no clinical content: a health worker asks to see the record, sign in to answer (opescare.com/m). The patient answers only in the app. Push is not offered until OHN-53 has a push channel."
      },
      "get": {
        "summary": "My recent requests, newest first (50).",
        "x-roles": [
          "licensed_clinician",
          "clinical_supervisor",
          "pharmacist",
          "diagnostic_staff"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Open object; see the description of the operation"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "approved",
                "refused",
                "expired",
                "cancelled"
              ]
            }
          }
        ],
        "operationId": "paListRequests",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/requests/{id}": {
      "get": {
        "summary": "One of my requests (poll while pending). Carries grant id and expiry once accepted.",
        "x-roles": [
          "licensed_clinician",
          "clinical_supervisor",
          "pharmacist",
          "diagnostic_staff"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.RequestView"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "operationId": "paGetRequest",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "description": "1.1.0: shows proposed and granted sections and duration, and the note; never the refusal reason."
      }
    },
    "/clinician/patient-access/requests/{id}/cancel": {
      "post": {
        "summary": "Withdraw a pending request.",
        "x-roles": [
          "licensed_clinician",
          "clinical_supervisor",
          "pharmacist",
          "diagnostic_staff"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.RequestView"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmptyCommand"
              }
            }
          }
        },
        "operationId": "paCancelRequest",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/requests/{id}/use": {
      "post": {
        "summary": "Use the active grant (audited each time). The only answer that carries the patient reference.",
        "x-roles": [
          "licensed_clinician",
          "clinical_supervisor",
          "pharmacist",
          "diagnostic_staff"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Open object; see the description of the operation"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmptyCommand"
              }
            }
          }
        },
        "operationId": "paUseGrant",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/incoming": {
      "get": {
        "summary": "Patient: requests waiting for my answer (poll every few seconds while signed in).",
        "x-roles": [
          "patient"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Open object; see the description of the operation"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "operationId": "paIncoming",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/incoming/{id}/decision": {
      "post": {
        "summary": "Patient (or verified representative): accept or refuse.",
        "x-roles": [
          "patient"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.IncomingView"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DecisionCommand"
              }
            }
          }
        },
        "operationId": "paDecide",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "description": "1.1.0: accept may narrow sections (subset of the proposed ones) and duration_minutes (5 up to the proposed duration); the grant and its OHN-16 care_team assertion (registered lazily at the requester's first opening, as in 1.0.0) cover exactly the granted sections and duration. refuse may carry an optional reason (patient's log only). 1.1.0: the chart of a patient-approved grant is limited to its granted sections: the clinician context's allowed_categories are the OHN-16 decision's categories intersected with the granted sections (empty: 403 denied_by_policy); the summary names the rest as not_permitted_sections."
      }
    },
    "/clinician/patient-access/grants": {
      "get": {
        "summary": "Patient: who can see my record (active and past grants).",
        "x-roles": [
          "patient"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Open object; see the description of the operation"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "operationId": "paGrants",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/grants/{id}/revoke": {
      "post": {
        "summary": "Patient: end an active grant now (id = grant_id).",
        "x-roles": [
          "patient"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.PatientGrant"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmptyCommand"
              }
            }
          }
        },
        "operationId": "paRevoke",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/log": {
      "get": {
        "summary": "Patient: access history (requests, answers, uses, revocations).",
        "x-roles": [
          "patient"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Open object; see the description of the operation"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "operationId": "paLog",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "description": "1.1.0: requested entries carry the note; refused entries carry the patient's own reason."
      }
    },
    "/clinician/patient-access/card": {
      "post": {
        "summary": "Patient: a fresh QR card (short-lived random reference, no clinical data).",
        "x-roles": [
          "patient"
        ],
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.Card"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmptyCommand"
              }
            }
          }
        },
        "operationId": "paNewCard",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/settings": {
      "get": {
        "summary": "Jurisdiction switch and options.",
        "x-roles": [
          "clinical_supervisor"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.Settings"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "operationId": "paReadSettings",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      },
      "post": {
        "summary": "Change the switch and options (audited).",
        "x-roles": [
          "clinical_supervisor"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Shape documented as components.schemas.Settings"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SettingsCommand"
              }
            }
          }
        },
        "operationId": "paWriteSettings",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/clinician/patient-access/audit": {
      "get": {
        "summary": "Staff audit report: every request, decision, use and revocation (JSON, or CSV with format=csv).",
        "x-roles": [
          "clinical_supervisor"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Open object; see the description of the operation"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Error"
          },
          "401": {
            "description": "Error"
          },
          "403": {
            "description": "Error"
          },
          "404": {
            "description": "Error"
          },
          "409": {
            "description": "Error"
          },
          "422": {
            "description": "Error"
          },
          "503": {
            "description": "Error"
          }
        },
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "enum": [
                "json",
                "csv"
              ]
            }
          }
        ],
        "operationId": "paAudit",
        "tags": [
          "OHN-32-patient-access"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "description": "1.1.0: rows record the note, the proposed and granted sections and duration, and whether a refusal reason was given (never its text)."
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "OHN-32 token from the platform gateway (module \"clinician\"). Purposes: clinical_care_access (licensed_clinician, clinical_supervisor), dispensing_access (pharmacist), diagnostics_access (diagnostic_staff), patient_access_requests (patient; subject = the patient record)."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {}
        },
        "required": [
          "error"
        ]
      },
      "Purpose": {
        "enum": [
          "care_visit",
          "prescribing",
          "dispensing",
          "diagnostics",
          "review"
        ],
        "description": "care_visit (consult), prescribing (prescribe), dispensing, diagnostics (lab order and imaging). 1.1.0: review (roles licensed_clinician and clinical_supervisor; owner decision: default sections the same as care_visit, which the patient can untick). A jurisdiction settings row stored before 1.1.0 has no review entry: a request for review there answers 422 purpose_not_configured (fail closed) until settings add it."
      },
      "RequestState": {
        "enum": [
          "pending",
          "approved",
          "refused",
          "expired",
          "cancelled"
        ]
      },
      "Kind": {
        "enum": [
          "clinician",
          "pharmacist",
          "diagnostics"
        ]
      },
      "Masked": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "initials": {
            "type": "string"
          },
          "birth_year": {
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "required": [
          "initials",
          "birth_year"
        ]
      },
      "Options": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "kind": {
            "type": [
              "string",
              "null"
            ]
          },
          "request_ttl_minutes": {
            "type": [
              "integer",
              "null"
            ]
          },
          "durations_minutes": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "purposes": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "code": {
                  "$ref": "#/components/schemas/Purpose"
                },
                "sections": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "code",
                "sections"
              ]
            }
          }
        },
        "required": [
          "enabled",
          "kind",
          "request_ttl_minutes",
          "durations_minutes",
          "purposes"
        ]
      },
      "Lookup": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "lookup_id": {
            "type": "string",
            "format": "uuid"
          },
          "identified_by": {
            "enum": [
              "qr",
              "card_code",
              "health_id"
            ]
          },
          "patient": {
            "$ref": "#/components/schemas/Masked"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "lookup_id",
          "identified_by",
          "patient",
          "expires_at"
        ]
      },
      "Grant": {
        "description": "The grant is an OHN-32 care relationship; grant_id is its id. A /p phone-to-PC hand-off must end at expires_at or as soon as status is not active.",
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "grant_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "enum": [
              "active",
              "ended",
              "expired"
            ]
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "grant_id",
          "status",
          "expires_at"
        ]
      },
      "RequestView": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "state": {
            "$ref": "#/components/schemas/RequestState"
          },
          "purpose": {
            "$ref": "#/components/schemas/Purpose"
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "duration_minutes": {
            "type": "integer"
          },
          "answer_by": {
            "type": "string",
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "decided_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "patient": {
            "$ref": "#/components/schemas/Masked"
          },
          "identified_by": {
            "type": "string"
          },
          "facility_id": {
            "type": "string",
            "format": "uuid"
          },
          "grant": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Grant"
              },
              {
                "type": "null"
              }
            ]
          },
          "version": {
            "type": "integer"
          },
          "note": {
            "type": [
              "string",
              "null"
            ],
            "x-since": "1.1.0",
            "description": "the requester's note (null for requests made before 1.1.0)"
          },
          "proposed_sections": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "x-since": "1.1.0",
            "description": "what the requester asked for (equal to sections, which keeps its 1.0.0 meaning)"
          },
          "proposed_duration_minutes": {
            "type": "integer",
            "x-since": "1.1.0",
            "description": "what the requester asked for (equal to duration_minutes, which keeps its 1.0.0 meaning)"
          },
          "granted_sections": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            },
            "x-since": "1.1.0",
            "description": "what the patient granted (a subset of proposed_sections); null until accepted",
            "nullable": true
          },
          "granted_duration_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "x-since": "1.1.0",
            "description": "what the patient granted (at most proposed_duration_minutes); null until accepted"
          }
        },
        "required": [
          "id",
          "state",
          "purpose",
          "sections",
          "duration_minutes",
          "answer_by",
          "created_at",
          "decided_at",
          "patient",
          "identified_by",
          "facility_id",
          "grant",
          "version"
        ],
        "description": "1.1.0: sections and duration_minutes keep their 1.0.0 meaning (the proposed values); granted_* carry what the patient granted. The refusal reason never appears here."
      },
      "Requester": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "name_attested": {
            "type": "boolean"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          },
          "facility_id": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "name",
          "name_attested",
          "title",
          "kind",
          "facility_id"
        ]
      },
      "IncomingView": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "state": {
            "$ref": "#/components/schemas/RequestState"
          },
          "requester": {
            "$ref": "#/components/schemas/Requester"
          },
          "purpose": {
            "$ref": "#/components/schemas/Purpose"
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "duration_minutes": {
            "type": "integer"
          },
          "answer_by": {
            "type": "string",
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "on_behalf_of": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Masked"
              },
              {
                "type": "null"
              }
            ]
          },
          "grant": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Grant"
              },
              {
                "type": "null"
              }
            ]
          },
          "version": {
            "type": "integer"
          },
          "note": {
            "type": [
              "string",
              "null"
            ],
            "x-since": "1.1.0",
            "description": "the requester's note (null for requests made before 1.1.0)"
          },
          "proposed_sections": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "x-since": "1.1.0",
            "description": "what the requester asked for (equal to sections, which keeps its 1.0.0 meaning)"
          },
          "proposed_duration_minutes": {
            "type": "integer",
            "x-since": "1.1.0",
            "description": "what the requester asked for (equal to duration_minutes, which keeps its 1.0.0 meaning)"
          },
          "granted_sections": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            },
            "x-since": "1.1.0",
            "description": "what the patient granted (a subset of proposed_sections); null until accepted",
            "nullable": true
          },
          "granted_duration_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "x-since": "1.1.0",
            "description": "what the patient granted (at most proposed_duration_minutes); null until accepted"
          }
        },
        "required": [
          "id",
          "state",
          "requester",
          "purpose",
          "sections",
          "duration_minutes",
          "answer_by",
          "created_at",
          "on_behalf_of",
          "grant",
          "version"
        ]
      },
      "PatientGrant": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "grant_id": {
            "type": "string",
            "format": "uuid"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "requester": {
            "$ref": "#/components/schemas/Requester"
          },
          "purpose": {
            "$ref": "#/components/schemas/Purpose"
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "granted_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "enum": [
              "active",
              "ended",
              "expired",
              "revoked"
            ]
          },
          "uses": {
            "type": "integer"
          },
          "last_used_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "proposed_sections": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "x-since": "1.1.0",
            "description": "what the requester asked for (equal to sections, which keeps its 1.0.0 meaning)"
          },
          "proposed_duration_minutes": {
            "type": "integer",
            "x-since": "1.1.0",
            "description": "what the requester asked for (equal to duration_minutes, which keeps its 1.0.0 meaning)"
          },
          "granted_sections": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            },
            "x-since": "1.1.0",
            "description": "what the patient granted (a subset of proposed_sections); null until accepted",
            "nullable": true
          },
          "granted_duration_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "x-since": "1.1.0",
            "description": "what the patient granted (at most proposed_duration_minutes); null until accepted"
          }
        },
        "required": [
          "grant_id",
          "request_id",
          "requester",
          "purpose",
          "sections",
          "granted_at",
          "expires_at",
          "status",
          "uses",
          "last_used_at"
        ],
        "description": "1.1.0: sections is what the grant covers (the granted sections)."
      },
      "LogEntry": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "at": {
            "type": "string",
            "format": "date-time"
          },
          "event": {
            "enum": [
              "identified",
              "requested",
              "accepted",
              "refused",
              "expired",
              "cancelled",
              "used",
              "revoked"
            ]
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "actor": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "kind": {
                "type": "string"
              },
              "facility_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "name",
              "kind",
              "facility_id"
            ]
          },
          "purpose": {
            "$ref": "#/components/schemas/Purpose"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "x-since": "1.1.0",
            "description": "refused entries in the patient's own log only: the patient's refusal reason"
          },
          "note": {
            "type": [
              "string",
              "null"
            ],
            "x-since": "1.1.0",
            "description": "requested entries: the requester's note"
          }
        },
        "required": [
          "at",
          "event",
          "request_id",
          "actor",
          "purpose"
        ]
      },
      "Card": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[0-9A-HJKMNP-TV-Z]{10}$"
          },
          "display": {
            "type": "string"
          },
          "qr_payload": {
            "type": "string",
            "pattern": "^OHN:PA:1:[0-9A-HJKMNP-TV-Z]{10}$"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "code",
          "display",
          "qr_payload",
          "expires_at"
        ]
      },
      "Settings": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "enabled": {
            "type": "boolean"
          },
          "request_ttl_minutes": {
            "type": "integer",
            "description": "unanswered requests expire after this many minutes; 1.1.0: default 15 for a new jurisdiction row (rows already stored keep their value)"
          },
          "card_ttl_minutes": {
            "type": "integer"
          },
          "durations_minutes": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "purpose_sections": {
            "type": "object",
            "description": "sections per purpose (vocabulary: allergies, medications, conditions, results, encounters, orders); 1.1.0: review defaults to the care_visit sections (allergies, medications, conditions, results, encounters) in a new row; a stored row without review refuses it (422 purpose_not_configured)"
          },
          "approval_reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          }
        },
        "required": [
          "configured",
          "enabled",
          "request_ttl_minutes",
          "card_ttl_minutes",
          "durations_minutes",
          "purpose_sections",
          "approval_reference",
          "version"
        ]
      },
      "IdentifyCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "description": "The scanned QR payload (OHN:PA:1:...), the printed card code, or an OHN-02 health ID"
          }
        },
        "required": [
          "code"
        ]
      },
      "CreateRequestCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "lookup_id",
          "purpose",
          "duration_minutes"
        ],
        "properties": {
          "lookup_id": {
            "type": "string",
            "format": "uuid"
          },
          "purpose": {
            "$ref": "#/components/schemas/Purpose"
          },
          "duration_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10080
          },
          "requester_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "requester_title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "note": {
            "type": "string",
            "minLength": 10,
            "maxLength": 1000,
            "x-since": "1.1.0",
            "description": "Why the requester asks; shown to the patient and audited. Required from 1.1.0 (missing or shorter than 10 characters after trimming: 422 note_required); optional in the schema only so 1.0.0 clients still parse."
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "allergies",
                "medications",
                "conditions",
                "results",
                "encounters",
                "orders"
              ]
            },
            "x-since": "1.1.0",
            "description": "Sections the requester proposes, a subset of the purpose's configured sections (another section: 422 section_not_permitted). Absent: all of the purpose's sections, as in 1.0.0. An empty list or duplicates answer 422 domain_validation_failed (checked by the server: no minItems/uniqueItems, because the generated model defaults an absent list to empty and would refuse every request without sections)."
          }
        }
      },
      "DecisionCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "decision",
          "expected_version"
        ],
        "properties": {
          "decision": {
            "type": "string",
            "enum": [
              "accept",
              "refuse"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "sections": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "allergies",
                "medications",
                "conditions",
                "results",
                "encounters",
                "orders"
              ]
            },
            "x-since": "1.1.0",
            "description": "accept only: the sections the patient grants, a subset of the proposed sections (narrowing only; another section: 422 section_not_proposed). Absent: all proposed sections. An empty list or duplicates answer 422 domain_validation_failed (checked by the server: no minItems/uniqueItems, because the generated model defaults an absent list to empty and would refuse every request without sections)."
          },
          "duration_minutes": {
            "type": "integer",
            "minimum": 5,
            "maximum": 10080,
            "x-since": "1.1.0",
            "description": "accept only: the duration the patient grants, any whole number of minutes from 5 to the proposed duration (longer: 422 duration_exceeds_proposed). Absent: the proposed duration."
          },
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500,
            "x-since": "1.1.0",
            "description": "refuse only: an optional reason, kept only in the patient's own log; never shown to the requester and never in the staff audit body (the audit records only that a reason was given)."
          }
        },
        "description": "1.1.0: sections and duration_minutes are allowed only with accept, reason only with refuse (otherwise 422 domain_validation_failed, the module's generic validation code; so are a duration under 5 or not whole, a note over 1000 and duplicate sections)."
      },
      "EmptyCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {}
      },
      "SettingsCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "enabled",
          "request_ttl_minutes",
          "card_ttl_minutes",
          "durations_minutes",
          "purpose_sections",
          "approval_reference"
        ],
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "request_ttl_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 120,
            "description": "unanswered requests expire after this many minutes; 1.1.0: default 15 for a new jurisdiction row (rows already stored keep their value)"
          },
          "card_ttl_minutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1440
          },
          "durations_minutes": {
            "type": "array",
            "minItems": 1,
            "maxItems": 12,
            "items": {
              "type": "integer",
              "minimum": 5,
              "maximum": 10080
            }
          },
          "purpose_sections": {
            "type": "object",
            "description": "sections per purpose (vocabulary: allergies, medications, conditions, results, encounters, orders); 1.1.0: review defaults to the care_visit sections (allergies, medications, conditions, results, encounters) in a new row; a stored row without review refuses it (422 purpose_not_configured)",
            "additionalProperties": {
              "type": "array",
              "minItems": 1,
              "maxItems": 32,
              "items": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              }
            }
          },
          "approval_reference": {
            "type": "string",
            "minLength": 3,
            "maxLength": 256
          }
        }
      }
    }
  }
}
