{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-08 Shared Health Record / Health Chart",
    "version": "1.0.0",
    "description": "A policy-filtered, source-attributed longitudinal view assembled from the systems that hold the record. OHN-08 never replaces those systems and never presents a chart as complete. Default deny; bearer authentication; every mutating request needs an Idempotency-Key header. Access is evaluated when a chart is assembled and again on every read. Dependencies (OHN-02, 15, 16, 23, 40, 41, 42) are reached through versioned interfaces that fail closed (503) when unavailable. Reconciled with the observed behaviour of the TypeScript reference (docs/program/java/ohn-08-contract-changes.md)."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/patients/{id}/health-chart": {
      "get": {
        "operationId": "getPatientHealthChart",
        "x-inventory-id": "OHN-08-API-001",
        "summary": "The caller's current chart for the patient, grouped by section",
        "description": "Returns the most recent chart the caller assembled for this patient. Access is re-evaluated; if it was withdrawn the cached projection is purged (W003) and 403 access_revoked is returned. No business state changes; the read is audited.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Chart",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "x-schema": "#/components/schemas/Chart"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/patients/{id}/timeline": {
      "get": {
        "operationId": "getPatientTimeline",
        "x-inventory-id": "OHN-08-API-002",
        "summary": "The same chart as dated entries, most recent first, plus undated statements",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Timeline",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "x-schema": "#/components/schemas/Timeline"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/rebuild": {
      "post": {
        "operationId": "rebuildChart",
        "x-inventory-id": "OHN-08-API-003",
        "summary": "Assemble a chart (F001, workflow W001)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "x-schema": "#/components/schemas/ChartQueryCommand"
              }
            }
          },
          "description": "JSON object validated by the controller against ChartQueryCommand (every bad field is reported together; unknown fields are refused with 422)."
        },
        "responses": {
          "201": {
            "description": "Chart presented, with receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "x-schema": "#/components/schemas/Chart"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/vocabularies": {
      "get": {
        "operationId": "getVocabularies",
        "summary": "Controlled lists, workflow states and the policy configuration in force",
        "responses": {
          "200": {
            "description": "Vocabularies",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": []
      }
    },
    "/health-chart/views": {
      "get": {
        "operationId": "listViews",
        "summary": "The caller's own chart requests (metadata only)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          }
        ],
        "responses": {
          "200": {
            "description": "Page of views",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/views/{id}": {
      "get": {
        "operationId": "getView",
        "summary": "One of the caller's chart requests with sources and workflow history",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "View",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "x-schema": "#/components/schemas/View"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/views/{id}/access-snapshots": {
      "get": {
        "operationId": "listAccessSnapshots",
        "summary": "Access decisions taken for one chart view (audit-access side panel)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Snapshots",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/source-requests": {
      "post": {
        "operationId": "requestSource",
        "summary": "Re-read named sections from one located source and refresh them in the current chart (F003)",
        "description": "201 carries the terminal state: delivered or unavailable (source_not_located, source_unreachable, source_integrity_rejected). 409 chart_required when the caller holds no usable chart for the patient.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "x-schema": "#/components/schemas/SourceRequestCommand"
              }
            }
          },
          "description": "JSON object validated by the controller against SourceRequestCommand (every bad field is reported together; unknown fields are refused with 422)."
        },
        "responses": {
          "201": {
            "description": "Source request with receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      },
      "get": {
        "operationId": "listSourceRequests",
        "summary": "The caller's source requests",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          }
        ],
        "responses": {
          "200": {
            "description": "Page of source requests",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/source-requests/{id}": {
      "get": {
        "operationId": "getSourceRequest",
        "summary": "One source request with its history",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Source request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/discrepancies": {
      "post": {
        "operationId": "openDiscrepancy",
        "summary": "Open a source discrepancy case (F002, workflow W002)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "x-schema": "#/components/schemas/DiscrepancyCaseCommand"
              }
            }
          },
          "description": "JSON object validated by the controller against DiscrepancyCaseCommand (every bad field is reported together; unknown fields are refused with 422)."
        },
        "responses": {
          "201": {
            "description": "Case with receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "x-schema": "#/components/schemas/DiscrepancyCase"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      },
      "get": {
        "operationId": "listDiscrepancies",
        "summary": "Cases in the caller's jurisdiction",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "One of: conflict_detected, evidence_linked, clinical_review, resolved_or_disputed, history_preserved"
          },
          {
            "name": "clinical_risk",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "One of: low, moderate, high, critical"
          },
          {
            "name": "assigned_to_me",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "true | false"
          }
        ],
        "responses": {
          "200": {
            "description": "Page of cases",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/discrepancies/{id}": {
      "get": {
        "operationId": "getDiscrepancy",
        "summary": "One case with its history",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Case",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "x-schema": "#/components/schemas/DiscrepancyCase"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/discrepancies/{id}/transitions": {
      "post": {
        "operationId": "transitionDiscrepancy",
        "summary": "Move a case to the next state",
        "description": "conflict_detected > evidence_linked (needs evidence_refs) > clinical_review (assigned reviewer or steward) > resolved_or_disputed (licensed clinician other than the opener; needs outcome and reason) > history_preserved. 409 stale_version or invalid_transition; 403 not_assignee, clinician_required or independent_review_required. Refusals change nothing and are audited.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "x-schema": "#/components/schemas/DiscrepancyTransitionCommand"
              }
            }
          },
          "description": "JSON object validated by the controller against DiscrepancyTransitionCommand (every bad field is reported together; unknown fields are refused with 422)."
        },
        "responses": {
          "200": {
            "description": "Updated case with history and receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "x-schema": "#/components/schemas/DiscrepancyCase"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/revocation-signals": {
      "post": {
        "operationId": "deliverRevocationSignal",
        "summary": "Deliver a consent revocation (workflow W003); platform service or steward only",
        "description": "Purges every cached chart projection of the patient in the jurisdiction and creates a notice for each affected principal. Redelivery of the same signal_id returns 200 with duplicate=true.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "x-schema": "#/components/schemas/RevocationSignalCommand"
              }
            }
          },
          "description": "JSON object validated by the controller against RevocationSignalCommand (every bad field is reported together; unknown fields are refused with 422)."
        },
        "responses": {
          "200": {
            "description": "Already processed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "Revocation processed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/revocations": {
      "get": {
        "operationId": "listRevocations",
        "summary": "Revocations handled in the jurisdiction, with history (steward only)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          }
        ],
        "responses": {
          "200": {
            "description": "Page of revocations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/revocation-notices": {
      "get": {
        "operationId": "listRevocationNotices",
        "summary": "Notices for charts the caller had open whose access was withdrawn",
        "parameters": [
          {
            "name": "pending",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "true | false"
          }
        ],
        "responses": {
          "200": {
            "description": "Notices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/revocation-notices/{id}/acknowledge": {
      "post": {
        "operationId": "acknowledgeRevocationNotice",
        "summary": "Acknowledge a notice; the revocation reaches user_notified when all are acknowledged",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Acknowledged with receipt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/reports/{reportId}": {
      "get": {
        "operationId": "getReport",
        "summary": "Reports OHN-08-R001 (source completeness), R002 (discrepancy audit), R003 (access and response performance)",
        "parameters": [
          {
            "$ref": "#/components/parameters/ReportId"
          },
          {
            "name": "jurisdiction",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "uuid"
          },
          {
            "name": "provider",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "uuid"
          },
          {
            "name": "facility",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "uuid"
          },
          {
            "name": "severity",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "One of: low, moderate, high, critical"
          },
          {
            "name": "resolution",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "One of: unresolved, all"
          },
          {
            "name": "service",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "One of: assemble, read, source_request"
          },
          {
            "name": "period_from",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "date-time"
          },
          {
            "name": "period_to",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "date-time"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          }
        ],
        "responses": {
          "200": {
            "description": "Report",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "x-schema": "#/components/schemas/Report"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/reports/{reportId}/export": {
      "post": {
        "operationId": "exportReport",
        "summary": "Create a signed, single-use, five-minute CSV or PDF export",
        "parameters": [
          {
            "$ref": "#/components/parameters/ReportId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "x-schema": "#/components/schemas/ExportCommand"
              }
            }
          },
          "description": "JSON object validated by the controller against ExportCommand (every bad field is reported together; unknown fields are refused with 422)."
        },
        "responses": {
          "201": {
            "description": "Export receipt with download_path",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ]
      }
    },
    "/health-chart/exports/{id}/download": {
      "get": {
        "operationId": "downloadExport",
        "summary": "Download an export once (requester only)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "text/csv or application/pdf",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        },
        "tags": [
          "OHN-08"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "description": "200 returns text/csv or application/pdf with Content-Disposition attachment; single use (second download 410 export_consumed), expires after five minutes (410 export_expired), requester only (404 for anyone else)."
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "x-format": "uuid"
        },
        "description": "A path id that is not a UUID is 404 not_found."
      },
      "ReportId": {
        "name": "reportId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "enum": [
            "OHN-08-R001",
            "OHN-08-R002",
            "OHN-08-R003"
          ]
        },
        "description": "Any other value is 404 not_found."
      },
      "Page": {
        "name": "page",
        "in": "query",
        "schema": {
          "type": "string"
        },
        "description": "Integer >= 1. Lists clamp an unreadable value to 1; reports refuse it with 422."
      },
      "PageSize": {
        "name": "page_size",
        "in": "query",
        "schema": {
          "type": "string"
        },
        "description": "Integer 1..100. Lists clamp (default 25); reports default 50 and refuse values outside 1..100 with 422."
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "maxLength": 255
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Typed error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "unauthenticated, denied_by_policy, access_revoked, not_found, chart_expired, chart_required, chart_disabled, stale_version, invalid_transition, not_assignee, clinician_required, independent_review_required, idempotency_conflict, request_in_progress, missing_idempotency_key, domain_validation_failed, rate_limited, dependency_unavailable, export_expired, export_consumed, export_integrity_failed"
          },
          "message": {
            "type": "string"
          },
          "dependency": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "description": "Field problems (field -> code) or extra facts such as dependency, current_state, current_version, next_state"
          }
        }
      },
      "Section": {
        "enum": [
          "allergies",
          "medications",
          "problems",
          "immunizations",
          "results",
          "procedures",
          "encounters"
        ]
      },
      "ClinicalPurpose": {
        "enum": [
          "treatment",
          "emergency_care",
          "care_coordination",
          "clinical_data_stewardship"
        ]
      },
      "ClinicalRisk": {
        "enum": [
          "low",
          "moderate",
          "high",
          "critical"
        ]
      },
      "DiscrepancyState": {
        "enum": [
          "conflict_detected",
          "evidence_linked",
          "clinical_review",
          "resolved_or_disputed",
          "history_preserved"
        ]
      },
      "ChartQueryCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "health_id",
          "facility_id",
          "clinical_purpose",
          "relationship_ref",
          "record_scope"
        ],
        "properties": {
          "health_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "facility_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "clinical_purpose": {
            "$ref": "#/components/schemas/ClinicalPurpose",
            "description": "Must equal the purpose in the bearer token"
          },
          "relationship_ref": {
            "type": "string",
            "x-format": "uuid"
          },
          "record_scope": {
            "enum": [
              "full_chart",
              "allergies",
              "medications",
              "problems",
              "immunizations",
              "results",
              "procedures",
              "encounters"
            ]
          },
          "date_from": {
            "type": "string",
            "x-format": "date"
          },
          "date_to": {
            "type": "string",
            "x-format": "date"
          }
        }
      },
      "DiscrepancyCaseCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "patient_id",
          "source_record_ids",
          "discrepancy_type",
          "clinical_risk",
          "assignee"
        ],
        "properties": {
          "patient_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "source_record_ids": {
            "type": "string",
            "maxLength": 8192,
            "description": "2 to 50 identifiers separated by new lines, commas or semicolons"
          },
          "discrepancy_type": {
            "enum": [
              "conflicting_status",
              "conflicting_value",
              "duplicate_record",
              "wrong_patient_suspected",
              "outdated_information",
              "missing_information",
              "other"
            ]
          },
          "clinical_risk": {
            "$ref": "#/components/schemas/ClinicalRisk"
          },
          "assignee": {
            "type": "string",
            "x-format": "uuid"
          },
          "notes": {
            "type": "string",
            "maxLength": 8192
          }
        }
      },
      "DiscrepancyTransitionCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "expected_version",
          "to_state"
        ],
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "to_state": {
            "$ref": "#/components/schemas/DiscrepancyState"
          },
          "reason": {
            "type": "string",
            "minLength": 3,
            "maxLength": 2048
          },
          "evidence_refs": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "type": "string",
              "maxLength": 128
            }
          },
          "outcome": {
            "enum": [
              "resolved",
              "disputed"
            ]
          }
        }
      },
      "SourceRequestCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "record_locator_ref",
          "source_endpoint_ref",
          "requested_sections",
          "patient_context",
          "purpose"
        ],
        "properties": {
          "record_locator_ref": {
            "type": "string",
            "x-format": "uuid"
          },
          "source_endpoint_ref": {
            "type": "string",
            "x-format": "uuid"
          },
          "requested_sections": {
            "type": "string",
            "maxLength": 8192,
            "description": "Section names separated by commas or spaces"
          },
          "patient_context": {
            "type": "string",
            "x-format": "uuid"
          },
          "purpose": {
            "$ref": "#/components/schemas/ClinicalPurpose"
          }
        }
      },
      "RevocationSignalCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "signal_id",
          "patient_id",
          "consent_ref",
          "revoked_at"
        ],
        "properties": {
          "signal_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "patient_id": {
            "type": "string",
            "x-format": "uuid"
          },
          "consent_ref": {
            "type": "string",
            "x-format": "uuid"
          },
          "revoked_at": {
            "type": "string",
            "x-format": "date-time"
          }
        }
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "format"
        ],
        "properties": {
          "format": {
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "type": "object",
            "additionalProperties": true,
            "description": "Report filters; same rules and strict keys as the report query parameters (string or number values)"
          }
        }
      },
      "Receipt": {
        "type": "object",
        "required": [
          "receipt_id",
          "committed_at",
          "aggregate_id",
          "aggregate_type",
          "version",
          "status",
          "event_delivery",
          "event_id"
        ],
        "properties": {
          "receipt_id": {
            "type": "string",
            "format": "uuid"
          },
          "committed_at": {
            "type": "string",
            "format": "date-time"
          },
          "aggregate_id": {
            "type": "string"
          },
          "aggregate_type": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "status": {
            "const": "committed"
          },
          "event_delivery": {
            "enum": [
              "pending",
              "not_applicable"
            ]
          },
          "event_id": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Source": {
        "type": "object",
        "required": [
          "id",
          "source_system_id",
          "facility_id",
          "availability",
          "freshness",
          "last_updated_at",
          "retrieved_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "view_id": {
            "type": "string",
            "format": "uuid"
          },
          "record_locator_ref": {
            "type": "string",
            "format": "uuid"
          },
          "source_endpoint_ref": {
            "type": "string",
            "format": "uuid"
          },
          "source_system_id": {
            "type": "string",
            "format": "uuid"
          },
          "facility_id": {
            "type": "string",
            "format": "uuid"
          },
          "availability": {
            "enum": [
              "reachable",
              "unreachable",
              "integrity_rejected"
            ]
          },
          "freshness": {
            "enum": [
              "fresh",
              "stale",
              "unknown",
              "threshold_not_configured"
            ]
          },
          "last_updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "retrieved_at": {
            "type": "string",
            "format": "date-time"
          },
          "sections_requested": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Section"
            }
          },
          "fact_count": {
            "type": "integer"
          },
          "rejected_count": {
            "type": "integer"
          }
        }
      },
      "Fact": {
        "type": "object",
        "required": [
          "id",
          "section",
          "source_record_id",
          "concept",
          "status_as_stated",
          "recorded_at",
          "terminology",
          "conflict",
          "open_case_ids",
          "source"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "section": {
            "$ref": "#/components/schemas/Section"
          },
          "source_record_id": {
            "type": "string"
          },
          "concept": {
            "type": "object",
            "required": [
              "system",
              "code",
              "display"
            ],
            "properties": {
              "system": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "display": {
                "type": "string"
              }
            }
          },
          "status_as_stated": {
            "type": [
              "string",
              "null"
            ],
            "description": "As stated by the source at recorded_at; never upgraded to 'current'"
          },
          "value": {
            "type": [
              "string",
              "null"
            ]
          },
          "recorded_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "terminology": {
            "enum": [
              "validated",
              "not_recognised",
              "not_verified"
            ]
          },
          "conflict": {
            "type": "boolean",
            "description": "Another source states a different status for the same concept"
          },
          "open_case_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "source": {
            "type": "object",
            "required": [
              "attribution_id",
              "source_system_id",
              "facility_id",
              "last_updated_at",
              "freshness"
            ],
            "properties": {
              "attribution_id": {
                "type": "string"
              },
              "source_system_id": {
                "type": "string"
              },
              "facility_id": {
                "type": "string"
              },
              "last_updated_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "freshness": {
                "type": "string"
              }
            }
          }
        }
      },
      "View": {
        "type": "object",
        "required": [
          "id",
          "status",
          "outcome",
          "version"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "health_id": {
            "type": "string"
          },
          "facility_id": {
            "type": "string"
          },
          "clinical_purpose": {
            "type": "string"
          },
          "relationship_ref": {
            "type": "string"
          },
          "record_scope": {
            "type": "string"
          },
          "date_from": {
            "type": [
              "string",
              "null"
            ]
          },
          "date_to": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "enum": [
              "patient_resolved",
              "policy_authorized",
              "sources_discovered",
              "records_validated",
              "chart_presented"
            ]
          },
          "outcome": {
            "enum": [
              "in_progress",
              "presented",
              "denied",
              "unavailable"
            ]
          },
          "refusal_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "completeness": {
            "enum": [
              "complete_for_located_sources",
              "partial",
              "no_sources_registered",
              null
            ]
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sections_disclosed": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Section"
            }
          },
          "fact_count": {
            "type": "integer"
          },
          "assembled_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "invalidated_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "invalidation_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          }
        }
      },
      "Chart": {
        "type": "object",
        "required": [
          "view",
          "notices",
          "sections",
          "sources",
          "discrepancies"
        ],
        "properties": {
          "view": {
            "$ref": "#/components/schemas/View"
          },
          "notices": {
            "type": "array",
            "items": {
              "enum": [
                "not_the_complete_record",
                "absence_of_information_is_not_absence_of_condition",
                "status_is_as_stated_by_source"
              ]
            }
          },
          "sections": {
            "type": "array",
            "description": "Only sections the caller may see; a withheld section is not listed at all",
            "items": {
              "type": "object",
              "required": [
                "section",
                "state",
                "facts"
              ],
              "properties": {
                "section": {
                  "$ref": "#/components/schemas/Section"
                },
                "state": {
                  "enum": [
                    "information_available",
                    "no_information_retrieved"
                  ]
                },
                "facts": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Fact"
                  }
                }
              }
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          },
          "discrepancies": {
            "type": "object",
            "properties": {
              "conflicting_statements": {
                "type": "integer"
              },
              "open_cases": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            }
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "Timeline": {
        "type": "object",
        "required": [
          "view",
          "notices",
          "entries",
          "undated",
          "sources"
        ],
        "properties": {
          "view": {
            "$ref": "#/components/schemas/View"
          },
          "notices": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Fact"
            }
          },
          "undated": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Fact"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          }
        }
      },
      "DiscrepancyCase": {
        "type": "object",
        "required": [
          "id",
          "patient_id",
          "source_record_ids",
          "discrepancy_type",
          "clinical_risk",
          "assignee",
          "status",
          "version"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "patient_id": {
            "type": "string"
          },
          "facility_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_record_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "discrepancy_type": {
            "type": "string"
          },
          "clinical_risk": {
            "$ref": "#/components/schemas/ClinicalRisk"
          },
          "assignee": {
            "type": "string"
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "concept": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/DiscrepancyState"
          },
          "next_state": {
            "type": [
              "string",
              "null"
            ]
          },
          "evidence_refs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "outcome": {
            "enum": [
              "resolved",
              "disputed",
              null
            ]
          },
          "outcome_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "decided_by": {
            "type": [
              "string",
              "null"
            ]
          },
          "version": {
            "type": "integer"
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          }
        }
      },
      "Report": {
        "type": "object",
        "required": [
          "report_id",
          "columns",
          "rows",
          "total",
          "state",
          "generated_at"
        ],
        "properties": {
          "report_id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "page_size": {
            "type": "integer"
          },
          "summary": {
            "type": "object"
          },
          "warnings": {
            "type": "array",
            "items": {
              "enum": [
                "small_cohort_suppressed",
                "staleness_threshold_not_configured"
              ]
            }
          },
          "state": {
            "enum": [
              "rendered",
              "no_authorized_data",
              "partial_with_source_warning"
            ]
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
