openapi: 3.1.0
info:
  title: OHN-40 Federated Record Locator
  version: 1.0.0
  description: >
    Locates trusted record-holding institutions without exposing record content or permitting patient enumeration.
    Every route except /health/ohn-40 and the synthetic token issuer requires a bearer token whose role and purpose of
    use are checked by a default-deny matrix; refusals are audited. Discovery never reveals whether a patient or a
    pointer exists to a caller who is not authorized and consented (ADR-0001). The inventory paths
    /api/ohn/v1/patients/{id}/record-locations, /api/ohn/v1/record-locator/entries and /api/ohn/v1/record-locator/refresh are
    served under the module's single prefix /api/ohn/v1/record-locator (ADR-0007).
servers:
  - url: https://opeshealthnetwork.com
security:
  - bearerAuth: []
paths:
  /health/ohn-40:
    get:
      operationId: ohn40_health
      summary: Liveness and database reachability
      security: []
      responses:
        '200': { description: Healthy, content: { application/json: { schema: { $ref: '#/components/schemas/Health' } } } }
        '503': { description: Database unavailable }
  /api/ohn/v1/record-locator/synthetic-token:
    post:
      operationId: ohn40_syntheticToken
      summary: TypeScript test harness only - issue a synthetic token (only when NODE_ENV is not production and OHN40_SYNTHETIC_AUTH=true; 404 otherwise). NOT served by the Java service (tokens come from the platform gateway; the route is unmapped and answers 401 without a token, 404 with one)
      x-java-status: not-ported
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/SyntheticToken' } } } }
      responses:
        '200': { description: Token issued }
        '404': { description: Synthetic mode is off }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/context:
    get:
      operationId: ohn40_context
      summary: Caller identity, capabilities, dependency mode and effective locator policy
      responses:
        '200': { description: Context }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
  /api/ohn/v1/record-locator/vocabulary:
    get:
      operationId: ohn40_vocabulary
      summary: Controlled vocabularies, workflows and report catalogue
      responses:
        '200': { description: Vocabulary }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
  /api/ohn/v1/record-locator/entries:
    post:
      operationId: ohn40_registerEntry
      x-inventory-id: OHN-40-API-001
      x-form: OHN-40-F001-SUBMIT
      summary: Index or update a source record pointer (workflow W001)
      description: Creates a pointer (201) or, with the current expected_version, updates it (200). Refuses cross-patient mappings and references that look like personal data (422, raises an incident).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/EntryRegistration' } } } }
      responses:
        '200': { description: Pointer updated, content: { application/json: { schema: { $ref: '#/components/schemas/EntryCommandResult' } } } }
        '201': { description: Pointer created, content: { application/json: { schema: { $ref: '#/components/schemas/EntryCommandResult' } } } }
        '400': { $ref: '#/components/responses/Malformed' }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
    get:
      operationId: ohn40_listEntries
      summary: List pointers in the caller's jurisdiction (patient references masked)
      parameters:
        - { name: status, in: query, schema: { $ref: '#/components/schemas/EntryStatus' } }
        - { name: freshness, in: query, schema: { $ref: '#/components/schemas/Freshness' } }
        - { name: source_org, in: query, schema: { type: string, format: uuid } }
        - { name: cursor, in: query, schema: { type: string, maxLength: 64, format: date-time }, description: The next_cursor of the previous page (an ISO timestamp); anything else is 422 }
      responses:
        '200': { description: Page of pointers }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/entries/{id}:
    get:
      operationId: ohn40_entryDetail
      summary: Pointer detail with source, freshness history, stale reports, resolutions and workflow history (read is audited)
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses:
        '200': { description: Pointer detail }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/record-locator/patients/{id}/locations:
    get:
      operationId: ohn40_patientLocations
      x-inventory-id: OHN-40-API-002
      summary: Authorized record locations for a patient (workflow W002, view channel)
      description: The requesting organization is the caller's own (from the token). The response is identical for an unknown patient, a patient without consent, and a patient whose pointers are all suppressed.
      parameters:
        - { $ref: '#/components/parameters/Id' }
        - { name: purpose, in: query, required: true, schema: { $ref: '#/components/schemas/DiscoveryPurpose' } }
        - { name: policy_evidence_ref, in: query, required: true, schema: { type: string, format: uuid } }
        - { name: resource_types, in: query, schema: { type: string, maxLength: 8192 }, description: Comma or newline separated ResourceType values; all when omitted }
      responses:
        '200': { description: Discovery result, content: { application/json: { schema: { $ref: '#/components/schemas/DiscoveryResult' } } } }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/record-locator/queries:
    post:
      operationId: ohn40_discover
      x-form: OHN-40-F002-SUBMIT
      summary: Locator access query (workflow W002, query channel)
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/DiscoveryQuery' } } } }
      responses:
        '201': { description: Discovery result with receipt, content: { application/json: { schema: { $ref: '#/components/schemas/DiscoveryResult' } } } }
        '400': { $ref: '#/components/responses/Malformed' }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/record-locator/refresh:
    post:
      operationId: ohn40_refresh
      x-inventory-id: OHN-40-API-003
      summary: Freshness sweep against the configured window; newly stale pointers enter the stale-link queue
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Refresh' } } } }
      responses:
        '200': { description: Sweep counts and receipt }
        '400': { $ref: '#/components/responses/Malformed' }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { description: Validation failed, or freshness_policy_not_configured }
  /api/ohn/v1/record-locator/stale-queue:
    get:
      operationId: ohn40_staleQueue
      summary: Server-paginated stale-link queue (20 per page)
      parameters:
        - { name: source_org, in: query, schema: { type: string, format: uuid } }
        - { name: reason_code, in: query, schema: { $ref: '#/components/schemas/StaleReason' } }
        - { name: sort, in: query, schema: { enum: [oldest, newest], default: oldest } }
        - { name: page, in: query, schema: { type: integer, minimum: 1, maximum: 1000, default: 1 } }
      responses:
        '200': { description: Queue page }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/entries/{id}/report-stale:
    post:
      operationId: ohn40_reportStale
      summary: Report a pointer as stale (it stays returned, flagged stale_reported)
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/StaleReport' } } } }
      responses:
        '200': { description: Reported }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/entries/{id}/resolve:
    post:
      operationId: ohn40_resolveStale
      x-form: OHN-40-F003-SUBMIT
      summary: Stale locator resolution (workflow W003); expiring dispositions stop the pointer being returned and emit record-location.expired
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Resolution' } } } }
      responses:
        '200': { description: Resolved, content: { application/json: { schema: { $ref: '#/components/schemas/EntryCommandResult' } } } }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/entries/{id}/verify-expiry:
    post:
      operationId: ohn40_verifyExpiry
      summary: Confirm an expiry once the event bus has acknowledged delivery (downstream_notified -> verified)
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Versioned' } } } }
      responses:
        '200': { description: Verified }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { description: Version conflict or downstream_not_confirmed }
  /api/ohn/v1/record-locator/sources:
    get:
      operationId: ohn40_listSources
      summary: Registered endpoints with live OHN-39 trust evidence (partial data when trust is unavailable)
      responses:
        '200': { description: Sources }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
    post:
      operationId: ohn40_registerSource
      summary: Register a record-holding endpoint; the organization must be accredited
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/SourceRegistration' } } } }
      responses:
        '201': { description: Registered }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/record-locator/sources/{id}/status:
    post:
      operationId: ohn40_setSourceStatus
      summary: Suspend or reactivate an endpoint
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/SourceStatus' } } } }
      responses:
        '200': { description: Updated }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/incidents:
    get:
      operationId: ohn40_listIncidents
      summary: Locator privacy and safety incidents
      parameters: [{ name: state, in: query, schema: { $ref: '#/components/schemas/IncidentState' } }]
      responses:
        '200': { description: Incidents }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
  /api/ohn/v1/record-locator/incidents/{id}:
    get:
      operationId: ohn40_incidentDetail
      summary: Incident with allowed transitions and history
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses:
        '200': { description: Incident }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/record-locator/incidents/{id}/transition:
    post:
      operationId: ohn40_transitionIncident
      summary: Acknowledge or close an incident (privacy officer)
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/IncidentTransition' } } } }
      responses:
        '200': { description: Transitioned }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/simulations:
    get:
      operationId: ohn40_listSimulations
      summary: The caller's recent suppression simulations
      responses:
        '200': { description: Simulations }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
    post:
      operationId: ohn40_simulate
      summary: Evaluate the disclosure policy for a hypothetical pointer (no patient involved)
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Simulation' } } } }
      responses:
        '201': { description: Simulation result }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/workflows/{type}/{id}:
    get:
      operationId: ohn40_workflow
      summary: State graph and history of one workflow instance
      parameters:
        - { name: type, in: path, required: true, schema: { $ref: '#/components/schemas/WorkflowType' } }
        - { $ref: '#/components/parameters/Id' }
      responses:
        '200': { description: Workflow }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
  /api/ohn/v1/record-locator/reports/{reportId}:
    get:
      operationId: ohn40_runReport
      summary: Run report R001, R002 or R003 with its filters
      parameters:
        - { $ref: '#/components/parameters/ReportId' }
        - { name: country, in: query, schema: { type: string, format: uuid } }
        - { name: source, in: query, schema: { type: string, format: uuid } }
        - { name: period_from, in: query, schema: { type: string, format: date-time } }
        - { name: period_to, in: query, schema: { type: string, format: date-time } }
        - { name: role, in: query, schema: { enum: [record_locator_steward, privacy_officer] } }
        - { name: facility, in: query, schema: { type: string, format: uuid } }
        - { name: status, in: query, schema: { enum: [open, resolved] } }
      responses:
        '200': { description: Report, content: { application/json: { schema: { $ref: '#/components/schemas/Report' } } } }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/record-locator/reports/{reportId}/export:
    post:
      operationId: ohn40_exportReport
      summary: Create a signed, five-minute, requester-bound CSV or PDF export (audited)
      parameters: [{ $ref: '#/components/parameters/ReportId' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Export' } } } }
      responses:
        '201': { description: Export receipt with download_path }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { $ref: '#/components/responses/Validation' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/record-locator/exports/{token}:
    get:
      operationId: ohn40_downloadExport
      summary: Download an export (requester only; audited)
      parameters: [{ name: token, in: path, required: true, schema: { type: string, pattern: '^[A-Za-z0-9_-]{20,64}$' } }]
      responses:
        '200': { description: File, content: { text/csv: {}, application/pdf: {} } }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '410': { description: Expired }
  /api/ohn/v1/record-locator/maintenance/drain-outbox:
    post:
      operationId: ohn40_drainOutbox
      summary: Deliver pending events to the configured bus; with no bus nothing is reported delivered (pending counts only, bus not_configured)
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      responses:
        '200': { description: Delivered and pending counts }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { $ref: '#/components/responses/Denied' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/record-locator/synthetic/patients:
    post:
      operationId: ohn40_seedPatient
      summary: Synthetic harness only (404 unless synthetic dependencies are wired) - set an MPI fake status
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      responses: { '201': { description: Seeded }, '404': { $ref: '#/components/responses/NotFound' } }
  /api/ohn/v1/record-locator/synthetic/consents:
    post:
      operationId: ohn40_seedConsent
      summary: Synthetic harness only - set a consent fake decision
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      responses: { '201': { description: Seeded }, '404': { $ref: '#/components/responses/NotFound' } }
  /api/ohn/v1/record-locator/synthetic/trust:
    post:
      operationId: ohn40_seedTrust
      summary: Synthetic harness only - set a trust registry fake status
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      responses: { '201': { description: Seeded }, '404': { $ref: '#/components/responses/NotFound' } }
  /api/ohn/v1/record-locator/synthetic/members:
    post:
      operationId: ohn40_seedMember
      summary: Synthetic harness only - set a membership fake status
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      responses: { '201': { description: Seeded }, '404': { $ref: '#/components/responses/NotFound' } }
components:
  securitySchemes:
    bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT }
  parameters:
    Id: { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    ReportId: { name: reportId, in: path, required: true, schema: { enum: [OHN-40-R001, OHN-40-R002, OHN-40-R003] } }
    IdempotencyKey: { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 8, maxLength: 128, pattern: '^[A-Za-z0-9_.:-]+$' }, description: Same key and payload replays the stored response; same key with a different payload is 409 }
  responses:
    Malformed: { description: Malformed request or missing Idempotency-Key, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Unauthenticated: { description: Missing or invalid bearer token, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Denied: { description: Denied by policy (audited); never depends on the patient, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    NotFound: { description: Not found or non-disclosing refusal, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Conflict: { description: Stale version, duplicate, or idempotency key reused, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Validation: { description: Domain validation failed (details.fieldErrors), content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    RateLimited: { description: Rate limited or discovery budget exceeded (Retry-After), content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Unavailable: { description: A dependency is unavailable; nothing was disclosed or written, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
  schemas:
    ResourceType: { enum: [Encounter, Condition, Observation, DiagnosticReport, MedicationStatement, Immunization, AllergyIntolerance, Procedure, DocumentReference, ImagingStudy] }
    SecurityLabel: { enum: [normal, restricted, sensitive_behavioral_health, sensitive_substance_use, sensitive_sexual_reproductive, sensitive_hiv, sensitive_genetic] }
    DiscoveryPurpose: { enum: [treatment, emergency_care, care_coordination, patient_request] }
    Disposition: { enum: [confirmed_current, relocated, withdrawn_at_source, deleted_at_source, superseded_at_source] }
    StaleReason: { enum: [endpoint_unreachable, source_reported_missing, reference_rejected, patient_reported, freshness_window_exceeded] }
    EntryStatus: { enum: [active, stale_reported, expired] }
    Freshness: { enum: [current, stale, unknown] }
    IncidentState: { enum: [open, acknowledged, closed] }
    IncidentKind: { enum: [cross_patient_mapping_refused, phi_in_locator_refused, enumeration_suspected, untrusted_source_refused] }
    WorkflowType: { enum: [index_source_record, federated_source_discovery, invalidate_stale_reference] }
    Role: { enum: [record_locator_steward, privacy_officer, unauthorized_viewer] }
    CallerPurpose: { enum: [locator_stewardship, privacy_oversight] }
    Error:
      type: object
      required: [error]
      properties:
        error: { type: string }
        message: { type: string }
        details: { type: object }
        dependency: { type: string }
    Health:
      type: object
      properties:
        status: { enum: [ok, unavailable] }
        module: { const: OHN-40 }
        dependencies: { enum: [live, unavailable-fail-closed], description: live only when OHN-03, OHN-07, OHN-15 and OHN-39 are all live clients }
        upstreams: { type: object, description: 'Mode of each upstream: live, unconfigured or (OHN-16 only) local_enforcement_only', additionalProperties: { enum: [live, unconfigured, local_enforcement_only] } }
        event_bus: { enum: [configured, not_configured] }
    SyntheticToken:
      type: object
      additionalProperties: false
      required: [principal_id, role, jurisdiction, organization_id, purpose]
      properties:
        principal_id: { type: string, format: uuid }
        role: { $ref: '#/components/schemas/Role' }
        jurisdiction: { type: string, format: uuid }
        organization_id: { type: string, format: uuid }
        purpose: { $ref: '#/components/schemas/CallerPurpose' }
    EntryRegistration:
      type: object
      additionalProperties: false
      required: [patient_ref, source_org, source_record_ref, resource_type, endpoint_ref, last_observed, security_label]
      properties:
        patient_ref: { type: string, format: uuid, x-classification: restricted }
        source_org: { type: string, format: uuid }
        source_record_ref: { type: string, minLength: 1, maxLength: 512, pattern: '^[A-Za-z0-9._:/#-]+$', x-classification: restricted, description: Opaque reference; refused when it embeds the patient reference, a date, an email or a long identifier }
        resource_type: { $ref: '#/components/schemas/ResourceType' }
        endpoint_ref: { type: string, format: uuid }
        last_observed: { type: string, format: date-time }
        security_label: { $ref: '#/components/schemas/SecurityLabel' }
        expected_version: { type: integer, minimum: 1, description: Required to update an existing pointer }
    RecordLocatorEntry:
      type: object
      properties:
        id: { type: string, format: uuid }
        version: { type: integer }
        patient_ref: { type: string, description: Full in detail views, masked in lists }
        source_org: { type: string, format: uuid }
        source_record_ref: { type: string }
        resource_type: { $ref: '#/components/schemas/ResourceType' }
        endpoint_ref: { type: string, format: uuid }
        last_observed: { type: string, format: date-time }
        security_label: { $ref: '#/components/schemas/SecurityLabel' }
        status: { $ref: '#/components/schemas/EntryStatus' }
        freshness_state: { $ref: '#/components/schemas/Freshness' }
        workflow_state: { type: string }
        expiry_state: { enum: [locator_expired, downstream_notified, verified, null] }
    Receipt:
      type: object
      required: [receipt_id, committed_at, aggregate_id, aggregate_type, version, status]
      properties:
        receipt_id: { type: string, format: uuid }
        committed_at: { type: string, format: date-time }
        aggregate_id: { type: string, format: uuid }
        aggregate_type: { type: string }
        version: { type: integer }
        status: { enum: [committed, denied, pending] }
    EntryCommandResult:
      type: object
      properties:
        entry: { $ref: '#/components/schemas/RecordLocatorEntry' }
        receipt: { $ref: '#/components/schemas/Receipt' }
        event_id: { type: [string, 'null'], format: uuid }
        workflow: { type: [object, 'null'] }
    DiscoveryQuery:
      type: object
      additionalProperties: false
      required: [patient_ref, requesting_org, purpose, resource_types, policy_evidence_ref]
      properties:
        patient_ref: { type: string, format: uuid, x-classification: restricted }
        requesting_org: { type: string, format: uuid, description: Must equal the caller's organization }
        purpose: { $ref: '#/components/schemas/DiscoveryPurpose' }
        resource_types: { type: string, minLength: 1, maxLength: 8192, description: Comma or newline separated ResourceType values }
        policy_evidence_ref: { type: string, format: uuid, x-classification: confidential }
    DiscoveryResult:
      type: object
      required: [query_id, outcome, purpose, resource_types, locations, freshness_policy, provenance, receipt]
      properties:
        query_id: { type: string, format: uuid }
        outcome: { enum: [locations_returned, no_authorized_locations] }
        purpose: { $ref: '#/components/schemas/DiscoveryPurpose' }
        resource_types: { type: array, items: { $ref: '#/components/schemas/ResourceType' } }
        locations:
          type: array
          items:
            type: object
            properties:
              locator_id: { type: string, format: uuid }
              version: { type: integer }
              source_org: { type: string, format: uuid }
              source_name: { type: [string, 'null'] }
              endpoint_ref: { type: string, format: uuid }
              resource_type: { $ref: '#/components/schemas/ResourceType' }
              source_record_ref: { type: string }
              last_observed: { type: string, format: date-time }
              freshness: { $ref: '#/components/schemas/Freshness' }
              stale_reported: { type: boolean }
        freshness_policy: { enum: [configured, not_configured] }
        provenance: { type: object, properties: { source_system_id: { type: string }, evaluated_at: { type: string, format: date-time }, policy_ref: { type: string }, dependency_mode: { type: string }, completeness: { const: not_asserted } } }
        receipt: { $ref: '#/components/schemas/Receipt' }
    Refresh:
      type: object
      additionalProperties: false
      required: [reason]
      properties: { source_org: { type: string, format: uuid }, reason: { type: string, minLength: 3, maxLength: 500 } }
    StaleReport:
      type: object
      additionalProperties: false
      required: [reason_code, expected_version]
      properties: { reason_code: { $ref: '#/components/schemas/StaleReason' }, expected_version: { type: integer, minimum: 1 } }
    Resolution:
      type: object
      additionalProperties: false
      required: [locator_id, source_evidence_ref, disposition, steward_id, expected_version]
      properties:
        locator_id: { type: string, format: uuid }
        source_evidence_ref: { type: string, format: uuid, x-classification: confidential }
        new_locator_ref: { type: string, maxLength: 512, pattern: '^[A-Za-z0-9._:/#-]+$', description: Required when disposition is relocated }
        disposition: { $ref: '#/components/schemas/Disposition' }
        steward_id: { type: string, format: uuid, description: Must equal the signed-in steward }
        expected_version: { type: integer, minimum: 1 }
    Versioned:
      type: object
      additionalProperties: false
      required: [expected_version]
      properties: { expected_version: { type: integer, minimum: 1 } }
    SourceRegistration:
      type: object
      additionalProperties: false
      required: [endpoint_ref, source_org, display_name, sensitive_facility]
      properties:
        endpoint_ref: { type: string, format: uuid }
        source_org: { type: string, format: uuid }
        display_name: { type: string, minLength: 2, maxLength: 160 }
        sensitive_facility: { type: boolean, description: A facility whose mere appearance reveals stigmatizing care; its pointers are suppressed unless configured }
    SourceStatus:
      type: object
      additionalProperties: false
      required: [status, reason, expected_version]
      properties: { status: { enum: [active, suspended] }, reason: { type: string, minLength: 3, maxLength: 500 }, expected_version: { type: integer, minimum: 1 } }
    IncidentTransition:
      type: object
      additionalProperties: false
      required: [to, reason, expected_version]
      properties: { to: { $ref: '#/components/schemas/IncidentState' }, reason: { type: string, minLength: 3, maxLength: 1000 }, expected_version: { type: integer, minimum: 1 } }
    Simulation:
      type: object
      additionalProperties: false
      required: [purpose, security_label, sensitive_facility, consent, source_trusted, last_observed]
      properties:
        purpose: { $ref: '#/components/schemas/DiscoveryPurpose' }
        security_label: { $ref: '#/components/schemas/SecurityLabel' }
        sensitive_facility: { type: boolean }
        consent: { enum: [permit, deny] }
        source_trusted: { type: boolean }
        last_observed: { type: string, format: date-time }
    Export:
      type: object
      additionalProperties: false
      required: [format]
      properties: { format: { enum: [csv, pdf] }, filters: { type: object, additionalProperties: { type: string, maxLength: 128 } } }
    Report:
      type: object
      properties:
        report_id: { enum: [OHN-40-R001, OHN-40-R002, OHN-40-R003] }
        title: { type: string }
        columns: { type: array, items: { type: string } }
        rows: { type: array, items: { type: object } }
        generated_at: { type: string, format: date-time }
        filters: { type: object }
        metric_definitions: { type: object }
        provenance: { type: object, properties: { source: { type: string }, version: { type: string }, period: { type: string }, jurisdiction_id: { type: string } } }
        notes: { type: array, items: { type: string } }
