{
  "schema": "poieti.his.acceptance/1",
  "description": "Acceptance cases a hospital endpoint must pass against the dev Web Service before an institution is switched on in production. Fixtures name example files, optionally changed with an RFC 7386 merge patch; `invalid: true` marks a fixture the contract itself rejects. `expectedPoietiState` is what Poieti records or answers; the hospital's own expectations are in `expectedHospitalAction`.",
  "cases": [
    {
      "id": "push.signature-valid",
      "area": "push",
      "description": "The endpoint accepts a correctly signed request.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": null,
      "expectedHospitalAction": "Verify signature vector `push-delivery` and accept it.",
      "expectedPoietiState": {
        "state": "written"
      }
    },
    {
      "id": "push.signature-replayed",
      "area": "push",
      "description": "A signature replayed on another path is rejected.",
      "fixture": null,
      "injectedFault": {
        "kind": "signature-replayed",
        "detail": "Send verification vector `reject-replayed-path`."
      },
      "expectedHospitalAction": "Reject with 401 and write nothing.",
      "expectedPoietiState": {
        "notes": "Hospital-side check; no Poieti state."
      }
    },
    {
      "id": "push.signature-stale",
      "area": "push",
      "description": "A signature older than 300 s is rejected.",
      "fixture": null,
      "injectedFault": {
        "kind": "stale-signature",
        "detail": "Send verification vector `reject-stale`."
      },
      "expectedHospitalAction": "Reject with 401 and write nothing.",
      "expectedPoietiState": {
        "notes": "Hospital-side check; no Poieti state."
      }
    },
    {
      "id": "push.signature-rotation",
      "area": "push",
      "description": "During a key rotation either key verifies.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "key-rotation",
        "detail": "Send verification vector `accept-rotation-previous-key` to an endpoint that still holds only the previous key."
      },
      "expectedHospitalAction": "Accept when any v1 matches any held key.",
      "expectedPoietiState": {
        "state": "written"
      }
    },
    {
      "id": "push.create-written",
      "area": "push",
      "description": "A create is written synchronously.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": null,
      "expectedHospitalAction": "Write once, store (delivery_id, his_record_id) and answer 201 `{hisRecordId}`.",
      "expectedPoietiState": {
        "state": "written",
        "attempts": 1
      }
    },
    {
      "id": "push.timeout-after-commit",
      "area": "push",
      "description": "A retry after a timed-out request does not write twice.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "timeout-after-commit",
        "detail": "The HIS commits but the response arrives after Poieti's timeout; Poieti retries with the same Idempotency-Key and identical body."
      },
      "expectedHospitalAction": "Answer the retry with 200 and the original hisRecordId (or 409 `DUPLICATE_DELIVERY` with hisRecordId); keep one HIS record.",
      "expectedPoietiState": {
        "state": "written",
        "attempts": 2
      }
    },
    {
      "id": "push.rejection-not-stored",
      "area": "push",
      "description": "A rejection is not cached against the deliveryId.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "rejected-then-fixed",
        "detail": "Answer 422 PATIENT_NOT_FOUND, then fix the HIS; hospital IT retries the delivery from the console."
      },
      "expectedHospitalAction": "Process the retried deliveryId again and answer 201 `{hisRecordId}`.",
      "expectedPoietiState": {
        "state": "written"
      }
    },
    {
      "id": "push.correction-replaces",
      "area": "push",
      "description": "A correction replaces the record named by supersedes.hisRecordId in full.",
      "fixture": {
        "file": "examples/delivery-correction.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": null,
      "expectedHospitalAction": "Find the HIS record NA-20261016-0012 and replace every mapped field with this version, even if its admission is closed; identity comes from the original record. Answer 200 `{hisRecordId}` with the resulting HIS record id (the same id or a new one).",
      "expectedPoietiState": {
        "state": "written",
        "kind": "correction"
      }
    },
    {
      "id": "push.rows-replaced",
      "area": "push",
      "description": "Repeatable rows replace the stored row set as a whole.",
      "fixture": {
        "file": "examples/delivery-correction.json",
        "schema": "DeliveryV1",
        "patch": {
          "fields": {
            "FAMILY": [
              {
                "REL": "02",
                "LIVES_WITH": "true"
              }
            ]
          }
        }
      },
      "injectedFault": {
        "kind": "rows-removed",
        "detail": "Version 1 in the HIS has two FAMILY rows; this correction has one."
      },
      "expectedHospitalAction": "Store exactly one FAMILY row: delete the rows that are not in the delivery. Answer 200 `{hisRecordId}`.",
      "expectedPoietiState": {
        "state": "written",
        "kind": "correction"
      }
    },
    {
      "id": "push.partial-date",
      "area": "push",
      "description": "A partial date is stored as rendered.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": null,
      "expectedHospitalAction": "Store ONSET as `2026-10` (the mapping's text rendering); never invent a day or month. Answer 200 `{hisRecordId}`.",
      "expectedPoietiState": {
        "state": "written"
      }
    },
    {
      "id": "push.attachment-verified",
      "area": "push",
      "description": "Attachment bytes are fetched and verified before writing.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": null,
      "expectedHospitalAction": "GET /his/v1/deliveries/{deliveryId}/attachments/{attachmentId} with a `deliveries` key; check Content-Length = 183204 and SHA-256 = attachments[0].sha256 before writing; answer 200 `{hisRecordId}`.",
      "expectedPoietiState": {
        "state": "written"
      }
    },
    {
      "id": "push.attachment-mismatch",
      "area": "push",
      "description": "Attachment bytes that fail verification are not written.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "attachment-corrupted",
        "detail": "The attachment route serves bytes whose SHA-256 differs from the delivery."
      },
      "expectedHospitalAction": "Do not write. Answer a coded 4xx with `{code: \"ATTACHMENT_MISMATCH\", retryable: true}`.",
      "expectedPoietiState": {
        "state": "pending",
        "errorCode": "ATTACHMENT_MISMATCH",
        "errorRetryable": true,
        "notes": "Poieti posts the same body again after the backoff, with X-Poieti-Attempt: 2."
      }
    },
    {
      "id": "push.missing-required",
      "area": "push",
      "description": "missingRequired lists a hospital-required field without a value.",
      "fixture": {
        "file": "examples/delivery-correction.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": null,
      "expectedHospitalAction": "Apply the hospital's documented policy: write without FOOD_ALG and flag it, or answer 422 with a non-retryable code such as `REQUIRED_FIELD_MISSING`. Never fill in a default. notSent is informational.",
      "expectedPoietiState": {
        "states": [
          "written",
          "failed"
        ]
      }
    },
    {
      "id": "push.identity-rejected",
      "area": "push",
      "description": "The HIS does not know the patient.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1",
        "patch": {
          "patient": {
            "medicalRecordNumber": "DEMO-404"
          }
        }
      },
      "injectedFault": {
        "kind": "unknown-patient",
        "detail": "DEMO-404 does not exist in the test HIS."
      },
      "expectedHospitalAction": "Do not write. Answer 422 `{code: \"PATIENT_NOT_FOUND\", retryable: false}`.",
      "expectedPoietiState": {
        "state": "failed",
        "errorCode": "PATIENT_NOT_FOUND",
        "errorRetryable": false,
        "notes": "Nurses can fix the patient and resend."
      }
    },
    {
      "id": "push.identity-resend",
      "area": "push",
      "description": "After a nurse fixes the patient, the resend arrives as a new generation.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1",
        "patch": {
          "deliveryId": "7c6b5a49-3827-4615-9d4c-3b2a1f0e9d8c",
          "generation": 2
        }
      },
      "injectedFault": {
        "kind": "nurse-resend",
        "detail": "The generation-1 delivery failed with PATIENT_NOT_FOUND and the nurse resent it."
      },
      "expectedHospitalAction": "Treat it as a new deliveryId: look it up, write once, answer 200 `{hisRecordId}`.",
      "expectedPoietiState": {
        "state": "written",
        "generation": 2
      }
    },
    {
      "id": "push.retryable-failure",
      "area": "push",
      "description": "A temporary HIS failure is retried with the same deliveryId and body.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "his-temporarily-unavailable",
        "detail": "The HIS table is locked during attempt 1."
      },
      "expectedHospitalAction": "Answer a coded 4xx such as 423 with `{code: \"HIS_LOCKED\", retryable: true}`. When the delivery returns (X-Poieti-Attempt: 2, identical body), write it and answer 200 `{hisRecordId}`.",
      "expectedPoietiState": {
        "state": "written",
        "attempts": 2,
        "notes": "After the first report the delivery is pending until its backoff ends."
      }
    },
    {
      "id": "push.unencodable-text",
      "area": "push",
      "description": "Text the HIS column cannot hold is reported, never altered.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1",
        "patch": {
          "target": {
            "charset": "utf-8"
          },
          "fields": {
            "CARE_NOTE": "傷口周圍皮膚完整𠀋"
          }
        }
      },
      "injectedFault": {
        "kind": "unencodable-text",
        "detail": "The CARE_NOTE column is Big5 and cannot store U+2000B."
      },
      "expectedHospitalAction": "Do not truncate, drop or replace characters with `?`. Answer 422 `{code: \"VALUE_UNENCODABLE\", retryable: false}` (or `VALUE_TOO_LONG` for an over-long value).",
      "expectedPoietiState": {
        "state": "failed",
        "errorCode": "VALUE_UNENCODABLE",
        "errorRetryable": false
      }
    },
    {
      "id": "push.redeliver",
      "area": "push",
      "description": "After hospital-side data loss a written delivery is redelivered as a new generation.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1",
        "patch": {
          "deliveryId": "1e0d9c8b-7a69-4f58-8e47-3d2c1b0a9f8e",
          "generation": 2
        }
      },
      "injectedFault": {
        "kind": "hospital-data-loss",
        "detail": "The HIS record of generation 1 was lost; hospital IT redelivered it from the console."
      },
      "expectedHospitalAction": "Treat the new deliveryId as new: write once and answer 200 `{hisRecordId}`.",
      "expectedPoietiState": {
        "state": "written",
        "generation": 2
      }
    },
    {
      "id": "push.accepted-202",
      "area": "push",
      "description": "A queued write is followed up by status polling.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "async-import",
        "detail": "Answer 202; the status route answers 202 once, then 200 `{hisRecordId}`."
      },
      "expectedHospitalAction": "Serve GET /deliveries/{deliveryId}: 202 while processing, 200 with hisRecordId when written.",
      "expectedPoietiState": {
        "state": "written"
      }
    },
    {
      "id": "push.accepted-then-failed",
      "area": "push",
      "description": "A queued write is rejected by the import job.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "staging-import-rejected",
        "detail": "Answer 202; the import job then rejects the queued write."
      },
      "expectedHospitalAction": "Answer GET /deliveries/{deliveryId} with a coded 4xx such as 422 `{code: \"IMPORT_REJECTED\"}`.",
      "expectedPoietiState": {
        "state": "failed",
        "errorCode": "IMPORT_REJECTED"
      }
    },
    {
      "id": "push.status-unknown",
      "area": "push",
      "description": "A status 404 makes Poieti post the delivery again.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "status-unknown",
        "detail": "Answer 202, then lose the queued item so GET /deliveries/{deliveryId} answers 404."
      },
      "expectedHospitalAction": "Accept the repeated POST (same key, identical body) and write once.",
      "expectedPoietiState": {
        "state": "written"
      }
    },
    {
      "id": "push.coded-rejection",
      "area": "push",
      "description": "A coded 4xx fails the delivery with that code.",
      "fixture": {
        "file": "examples/delivery-correction.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "coded-rejection",
        "detail": "Answer 422 `{code: \"ENCOUNTER_CLOSED\", retryable: false}`."
      },
      "expectedHospitalAction": "None further.",
      "expectedPoietiState": {
        "state": "failed",
        "errorCode": "ENCOUNTER_CLOSED",
        "errorRetryable": false
      }
    },
    {
      "id": "push.uncoded-rejection",
      "area": "push",
      "description": "An uncoded 4xx with a healthy probe fails only that delivery.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "waf-block",
        "detail": "A gateway answers 400 with an HTML body for this delivery; GET /health answers 200."
      },
      "expectedHospitalAction": "None; hospital IT reviews the gateway rule.",
      "expectedPoietiState": {
        "state": "failed",
        "errorCode": "HIS_REJECTED",
        "circuit": {
          "open": false
        }
      }
    },
    {
      "id": "push.outage",
      "area": "push",
      "description": "An endpoint outage pauses dispatch without failing deliveries.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "outage",
        "detail": "POST /deliveries answers 503 and GET /health fails for an hour."
      },
      "expectedHospitalAction": "None; dispatch resumes after /health recovers.",
      "expectedPoietiState": {
        "state": "pending",
        "circuit": {
          "open": true,
          "reason": "unreachable"
        },
        "notes": "The attempt is not counted; one his.push.paused alert, then his.push.resumed on recovery."
      }
    },
    {
      "id": "push.auth-failure",
      "area": "push",
      "description": "401/403 pause dispatch until the endpoint token changes.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "bad-token",
        "detail": "The endpoint answers 401 to every request."
      },
      "expectedHospitalAction": "Hospital IT and Poieti staff fix the token with set-his-endpoint.",
      "expectedPoietiState": {
        "state": "pending",
        "circuit": {
          "open": true,
          "reason": "auth"
        }
      }
    },
    {
      "id": "push.health",
      "area": "push",
      "description": "The probe route answers a signed GET.",
      "fixture": null,
      "injectedFault": null,
      "expectedHospitalAction": "Verify signature vector `push-health` and answer 200.",
      "expectedPoietiState": {
        "notes": "Used by the gateway before charging suspect responses."
      }
    },
    {
      "id": "push.census-fetch",
      "area": "push",
      "description": "Poieti fetches a ward census.",
      "fixture": {
        "file": "examples/census-snapshot-context.json",
        "schema": "CensusSnapshotV1"
      },
      "injectedFault": null,
      "expectedHospitalAction": "Answer GET /census/wards/8B with the ward's CensusSnapshotV1.",
      "expectedPoietiState": {
        "response": {
          "status": 200
        },
        "notes": "Applied like an upload; context rows replaced per kind."
      }
    },
    {
      "id": "push.patient-search",
      "area": "push",
      "description": "A nurse lookup returns verification data for the requested ward.",
      "fixture": {
        "file": "examples/patient-search-request.json",
        "schema": "PatientSearchRequest"
      },
      "injectedFault": null,
      "expectedHospitalAction": "Answer with patients carrying wardCode and no clinical context, as in patient-search-response.json.",
      "expectedPoietiState": {
        "response": {
          "status": 200
        }
      }
    },
    {
      "id": "push.oversized-response",
      "area": "push",
      "description": "A response body over 64 KB is endpoint-suspect.",
      "fixture": {
        "file": "examples/delivery-create.json",
        "schema": "DeliveryV1"
      },
      "injectedFault": {
        "kind": "oversized-response",
        "detail": "Answer 201 with a 70 KB body."
      },
      "expectedHospitalAction": "Keep delivery responses small.",
      "expectedPoietiState": {
        "states": [
          "pending",
          "failed"
        ],
        "notes": "Probe passes → failed HIS_REJECTED; probe fails → deferred and circuit opens."
      }
    },
    {
      "id": "auth.ip-not-allowed",
      "area": "auth",
      "description": "Requests from an address outside the credential's CIDRs are refused.",
      "fixture": null,
      "injectedFault": {
        "kind": "ip-not-allowed",
        "detail": "Call from an address outside allowed_cidrs."
      },
      "expectedHospitalAction": "Stop and alert hospital IT; do not retry in a tight loop.",
      "expectedPoietiState": {
        "response": {
          "status": 403,
          "code": "HIS_IP_NOT_ALLOWED"
        }
      }
    },
    {
      "id": "auth.revoked",
      "area": "auth",
      "description": "A revoked key stops working on the next request.",
      "fixture": null,
      "injectedFault": {
        "kind": "revoked-credential",
        "detail": "Poieti staff revoke the credential."
      },
      "expectedHospitalAction": "Stop and alert hospital IT; do not retry in a tight loop.",
      "expectedPoietiState": {
        "response": {
          "status": 401,
          "code": "HIS_UNAUTHORIZED"
        }
      }
    },
    {
      "id": "auth.scope-denied",
      "area": "auth",
      "description": "A census-only key cannot download attachments.",
      "fixture": null,
      "injectedFault": {
        "kind": "wrong-scope",
        "detail": "Download an attachment with a credential whose scopes are [census]."
      },
      "expectedHospitalAction": "Use the deliveries credential for delivery routes.",
      "expectedPoietiState": {
        "response": {
          "status": 403,
          "code": "HIS_SCOPE_DENIED"
        }
      }
    },
    {
      "id": "auth.rate-limited",
      "area": "auth",
      "description": "Bursts above 120 requests per minute are limited.",
      "fixture": null,
      "injectedFault": {
        "kind": "rate-limited",
        "detail": "Send 130 requests within a minute."
      },
      "expectedHospitalAction": "Wait for Retry-After seconds before the next request.",
      "expectedPoietiState": {
        "response": {
          "status": 429,
          "code": "HIS_RATE_LIMITED"
        }
      }
    },
    {
      "id": "census.upload",
      "area": "census",
      "description": "A snapshot is applied. Before: DEMO-001 is an HIS patient of 8B, DEMO-003 an active HIS patient, DEMO-009 a manual patient with another name and no matching encounter, DEMO-007 an HIS patient of 8B; DEMO-002 is unknown.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1"
      },
      "injectedFault": null,
      "expectedHospitalAction": "PUT /his/v1/census/wards/8B with the snapshot.",
      "expectedPoietiState": {
        "response": {
          "status": 200,
          "replayed": false
        },
        "census": {
          "created": 1,
          "updated": 1,
          "discharged": 1,
          "missing": 1,
          "rejected": [
            {
              "medicalRecordNumber": "DEMO-009",
              "code": "IDENTITY_CONFLICT"
            }
          ]
        }
      }
    },
    {
      "id": "census.replay",
      "area": "census",
      "description": "The same snapshot uploaded again changes nothing.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1"
      },
      "injectedFault": {
        "kind": "replayed-snapshot",
        "detail": "Upload census.upload's snapshot a second time."
      },
      "expectedHospitalAction": "None.",
      "expectedPoietiState": {
        "response": {
          "status": 200,
          "replayed": true
        },
        "census": {
          "created": 0,
          "updated": 0,
          "discharged": 0,
          "missing": 0
        }
      }
    },
    {
      "id": "census.stale",
      "area": "census",
      "description": "An older snapshot is refused.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1",
        "patch": {
          "asOf": "2026-10-16T14:40:00+08:00"
        }
      },
      "injectedFault": {
        "kind": "stale-snapshot",
        "detail": "Upload after census.upload."
      },
      "expectedHospitalAction": "Discard the old snapshot; send the next one with a newer asOf.",
      "expectedPoietiState": {
        "response": {
          "status": 409,
          "code": "CENSUS_STALE"
        }
      }
    },
    {
      "id": "census.same-asof-changed",
      "area": "census",
      "description": "A changed snapshot must carry a new asOf.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1",
        "patch": {
          "patients": [
            {
              "medicalRecordNumber": "DEMO-001",
              "encounterId": "A2026101601",
              "displayName": "示範病人",
              "bed": "8B-14"
            }
          ]
        }
      },
      "injectedFault": {
        "kind": "same-asof-changed",
        "detail": "Upload after census.upload with the same asOf and different patients."
      },
      "expectedHospitalAction": "Take a fresh snapshot with its own asOf.",
      "expectedPoietiState": {
        "response": {
          "status": 409,
          "code": "CENSUS_STALE"
        }
      }
    },
    {
      "id": "census.missing-offset",
      "area": "census",
      "description": "asOf without an offset is invalid.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1",
        "patch": {
          "asOf": "2026-10-16T15:40:00"
        },
        "invalid": true
      },
      "injectedFault": null,
      "expectedHospitalAction": "Send RFC 3339 times with an offset, for example +08:00.",
      "expectedPoietiState": {
        "response": {
          "status": 422,
          "code": "HIS_CENSUS_INVALID"
        }
      }
    },
    {
      "id": "census.duplicate-chart-number",
      "area": "census",
      "description": "A chart number that appears twice invalidates the snapshot.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1",
        "patch": {
          "patients": [
            {
              "medicalRecordNumber": "DEMO-001",
              "encounterId": "A2026101601",
              "displayName": "示範病人"
            },
            {
              "medicalRecordNumber": "DEMO-001",
              "encounterId": "A2026101699",
              "displayName": "示範病人"
            }
          ]
        }
      },
      "injectedFault": null,
      "expectedHospitalAction": "Fix the HIS query so each patient appears once.",
      "expectedPoietiState": {
        "response": {
          "status": 422,
          "code": "HIS_CENSUS_INVALID"
        }
      }
    },
    {
      "id": "census.unknown-ward",
      "area": "census",
      "description": "An unknown ward code is refused.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1"
      },
      "injectedFault": {
        "kind": "unknown-ward",
        "detail": "PUT to /his/v1/census/wards/ZZ, which no ward uses."
      },
      "expectedHospitalAction": "Ask Poieti staff to set the ward's HIS code.",
      "expectedPoietiState": {
        "response": {
          "status": 404,
          "code": "WARD_NOT_FOUND"
        }
      }
    },
    {
      "id": "census.context-outside-push",
      "area": "census",
      "description": "Clinical context is refused unless the institution is in push mode.",
      "fixture": {
        "file": "examples/census-snapshot-context.json",
        "schema": "CensusSnapshotV1"
      },
      "injectedFault": {
        "kind": "context-outside-push",
        "detail": "Upload to an institution in mode off with census on."
      },
      "expectedHospitalAction": "Send identity and admission data only.",
      "expectedPoietiState": {
        "response": {
          "status": 422,
          "code": "CENSUS_CONTEXT_DISABLED"
        }
      }
    },
    {
      "id": "census.absent-not-discharged",
      "area": "census",
      "description": "A patient missing from a complete snapshot is flagged, not discharged.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1"
      },
      "injectedFault": {
        "kind": "patient-absent",
        "detail": "DEMO-007 is an HIS patient of 8B and is not in the snapshot."
      },
      "expectedHospitalAction": "Send `discharged: true` to discharge a patient.",
      "expectedPoietiState": {
        "census": {
          "missing": 1,
          "discharged": 1
        },
        "notes": "DEMO-007 stays active with census_missing_since set; only DEMO-003 is discharged."
      }
    },
    {
      "id": "census.ward-scope",
      "area": "census",
      "description": "A credential limited to other census wards cannot upload this ward.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1"
      },
      "injectedFault": {
        "kind": "ward-not-allowed",
        "detail": "The credential's census wards are [8A]."
      },
      "expectedHospitalAction": "Use a credential that covers the ward.",
      "expectedPoietiState": {
        "response": {
          "status": 403,
          "code": "HIS_SCOPE_DENIED"
        }
      }
    },
    {
      "id": "census.disabled",
      "area": "census",
      "description": "Uploads are refused while census is off for the institution.",
      "fixture": {
        "file": "examples/census-snapshot.json",
        "schema": "CensusSnapshotV1"
      },
      "injectedFault": {
        "kind": "census-disabled",
        "detail": "The institution's census switch is off."
      },
      "expectedHospitalAction": "Stop uploading until Poieti staff enable census.",
      "expectedPoietiState": {
        "response": {
          "status": 409,
          "code": "HIS_CENSUS_DISABLED"
        }
      }
    }
  ]
}
