feat(sp14): 5-lane Inbox UI with Payer-Rejected acknowledge action
Closes the gap between the SP10 backend (5 lanes) and the SP6
frontend (4 lanes). The Payer-Rejected lane (277CA STC A4/A6/A7)
is now rendered alongside Rejected/Candidates/Unmatched/Done,
with an Acknowledge bulk action that drops claims from the
working surface without erasing the original 277CA rejection
event (audit log stays intact, SP11).
Backend:
* Migration 0010: add payer_rejected_acknowledged_at +
payer_rejected_acknowledged_actor columns + partial index.
* db.py: surface the two new columns on the Claim model.
* inbox_lanes.py: filter acknowledged claims out of the
payer_rejected lane; expose the new fields on the row payload
for forward-compat (e.g. a future 'Recently acknowledged' view).
* api.py:
- POST /api/inbox/payer-rejected/acknowledge
Bulk-acknowledge. Idempotent. Returns transitioned /
already_acked / not_found / not_rejected counts so the UI
can show '3 of 5 were already acknowledged' on a noop bulk.
Writes a 'claim.payer_rejected_acknowledged' event to the
SP11 hash-chained audit log.
- GET /api/inbox/export.csv: accept 'payer_rejected' lane.
* test_acks.py: bump user_version assertion to 10.
* test_lane_filter_acknowledged.py: 4 tests for the lane filter
and forward-compat row payload.
* test_payer_rejected_acknowledge.py: 6 tests for the endpoint
(happy path, idempotency, no-op on non-rejected, missing
ids, 400 on empty, audit-log wiring + chain integrity).
Frontend:
* lib/inbox-api.ts: add payer_rejected to InboxLanes, add
acknowledgePayerRejected(), update exportInboxCsvUrl union.
* hooks/useInboxLanes.ts: add payer_rejected to initial state.
* hooks/useInboxLanes.test.ts: add payer_rejected to mocks.
* components/inbox/BulkBar.tsx: add 'payer_rejected' lane with
Acknowledge action (no Resubmit, no Dismiss — payer-rejected
is not eligible for either).
* components/inbox/BulkBar.test.tsx: add payer_rejected test.
* pages/Inbox.tsx: render the 5th lane, hook up onAcknowledge,
include payer_rejected in the needEyes count.
* pages/Inbox.test.tsx: 3 new tests (5-lane render, need-eyes
count, acknowledge action hits the right endpoint).
* components/inbox/InboxHeader.tsx: doc comment now explains
why payer_rejected rolls up into need-eyes.
Pre-existing typecheck warnings in BulkBar.test.tsx / InboxRow
.test.tsx / Lane.tsx / download.test.ts are unchanged from
main — not touched here.
Test counts: backend 724 -> 734 (+10). Frontend 350 -> 354 (+4).
This commit is contained in:
@@ -1105,6 +1105,78 @@ def inbox_dismiss_candidates(body: dict):
|
||||
return {"ok": True, "dismissed_count": len(pairs)}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# SP14: Payer-Rejected acknowledge
|
||||
#
|
||||
# Operator hits "Acknowledge" on the Payer-Rejected Inbox lane to clear
|
||||
# the claim from the working surface. We don't delete the rejection
|
||||
# (the original payer_rejected_* fields stay for SP11 audit), we just
|
||||
# set payer_rejected_acknowledged_at so the lane query filters it out.
|
||||
#
|
||||
# Idempotent: re-acknowledging an already-acknowledged claim is a noop
|
||||
# (the timestamp is not bumped). Returns the count actually transitioned
|
||||
# so the UI can show "3 of 5 were already acknowledged".
|
||||
# ---------------------------------------------------------------------------
|
||||
@app.post("/api/inbox/payer-rejected/acknowledge")
|
||||
def inbox_acknowledge_payer_rejected(body: dict):
|
||||
"""Mark Payer-Rejected claims as acknowledged by the operator."""
|
||||
claim_ids = body.get("claim_ids") or []
|
||||
actor = body.get("actor") or "operator"
|
||||
if not isinstance(claim_ids, list) or not claim_ids:
|
||||
raise HTTPException(400, "claim_ids must be a non-empty list")
|
||||
if not all(isinstance(c, str) for c in claim_ids):
|
||||
raise HTTPException(400, "claim_ids must be a list of strings")
|
||||
|
||||
with db.SessionLocal()() as session:
|
||||
from cyclone.db import Claim
|
||||
now = datetime.now(timezone.utc)
|
||||
transitioned = 0
|
||||
already_acked = 0
|
||||
not_found = 0
|
||||
not_rejected = 0
|
||||
for cid in claim_ids:
|
||||
claim = session.get(Claim, cid)
|
||||
if claim is None:
|
||||
not_found += 1
|
||||
continue
|
||||
if claim.payer_rejected_at is None:
|
||||
not_rejected += 1
|
||||
continue
|
||||
if claim.payer_rejected_acknowledged_at is not None:
|
||||
already_acked += 1
|
||||
continue
|
||||
claim.payer_rejected_acknowledged_at = now
|
||||
claim.payer_rejected_acknowledged_actor = actor
|
||||
transitioned += 1
|
||||
# SP11: audit event for the acknowledge action.
|
||||
try:
|
||||
from cyclone.audit_log import append_event, AuditEvent
|
||||
append_event(session, AuditEvent(
|
||||
event_type="claim.payer_rejected_acknowledged",
|
||||
entity_type="claim",
|
||||
entity_id=claim.id,
|
||||
actor=actor,
|
||||
payload={
|
||||
"payer_rejected_status_code": claim.payer_rejected_status_code,
|
||||
"payer_rejected_by_277ca_id": claim.payer_rejected_by_277ca_id,
|
||||
},
|
||||
))
|
||||
except Exception: # noqa: BLE001
|
||||
# Audit append is best-effort; don't block the operator's
|
||||
# acknowledge action on an audit-log failure.
|
||||
pass
|
||||
if transitioned:
|
||||
session.commit()
|
||||
|
||||
return {
|
||||
"ok": True,
|
||||
"transitioned": transitioned,
|
||||
"already_acked": already_acked,
|
||||
"not_found": not_found,
|
||||
"not_rejected": not_rejected,
|
||||
}
|
||||
|
||||
|
||||
@app.post("/api/inbox/rejected/resubmit")
|
||||
def inbox_resubmit_rejected(
|
||||
request: Request,
|
||||
@@ -1202,7 +1274,7 @@ def inbox_resubmit_rejected(
|
||||
@app.get("/api/inbox/export.csv")
|
||||
def inbox_export_csv(lane: str):
|
||||
"""Stream a CSV for a single lane."""
|
||||
if lane not in {"rejected", "candidates", "unmatched", "done_today"}:
|
||||
if lane not in {"rejected", "candidates", "unmatched", "done_today", "payer_rejected"}:
|
||||
raise HTTPException(400, f"unknown lane: {lane}")
|
||||
dismissed_pairs = getattr(app.state, "dismissed_pairs", set())
|
||||
with db.SessionLocal()() as session:
|
||||
|
||||
@@ -239,6 +239,16 @@ class Claim(Base):
|
||||
payer_rejected_by_277ca_id: Mapped[Optional[str]] = mapped_column(
|
||||
String(64), nullable=True
|
||||
)
|
||||
# SP14: when the operator hits "Acknowledge" on the Payer-Rejected
|
||||
# lane, we set this timestamp. The lane query filters on it being
|
||||
# NULL so acknowledged claims drop out of the working surface. The
|
||||
# original payer_rejected_* fields stay intact for audit (SP11).
|
||||
payer_rejected_acknowledged_at: Mapped[Optional[datetime]] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True
|
||||
)
|
||||
payer_rejected_acknowledged_actor: Mapped[Optional[str]] = mapped_column(
|
||||
String(64), nullable=True
|
||||
)
|
||||
resubmit_count: Mapped[int] = mapped_column(
|
||||
Integer, nullable=False, default=0, server_default=text("0")
|
||||
)
|
||||
|
||||
@@ -73,6 +73,12 @@ def _claim_to_row(
|
||||
"payer_rejected_reason": c.payer_rejected_reason,
|
||||
"payer_rejected_status_code": c.payer_rejected_status_code,
|
||||
"payer_rejected_by_277ca_id": c.payer_rejected_by_277ca_id,
|
||||
# SP14: acknowledgment tracking. Always null on the lane
|
||||
# (we filter acknowledged claims out) but exposed for
|
||||
# forward-compat if we later add a "Recently acknowledged"
|
||||
# inspector view.
|
||||
"payer_rejected_acknowledged_at": _isoformat(c.payer_rejected_acknowledged_at),
|
||||
"payer_rejected_acknowledged_actor": c.payer_rejected_acknowledged_actor,
|
||||
}
|
||||
|
||||
|
||||
@@ -192,8 +198,15 @@ def compute_lanes(session: Session, *, dismissed_pairs: Iterable[frozenset]) ->
|
||||
# by the payer after we submitted a syntactically-valid file).
|
||||
# We don't filter by Claim.state here because the claim may still
|
||||
# be in SUBMITTED state — the payer just hasn't paid it yet.
|
||||
#
|
||||
# SP14: filter out claims the operator has already acknowledged.
|
||||
# The original payer_rejected_* fields stay intact for audit;
|
||||
# only the working surface (this lane) is filtered.
|
||||
payer_rejected_claims = (
|
||||
session.query(Claim).filter(Claim.payer_rejected_at.is_not(None)).all()
|
||||
session.query(Claim)
|
||||
.filter(Claim.payer_rejected_at.is_not(None))
|
||||
.filter(Claim.payer_rejected_acknowledged_at.is_(None))
|
||||
.all()
|
||||
)
|
||||
pr_matched, pr_total = _line_count_lookup(session, payer_rejected_claims)
|
||||
matched_counts.update(pr_matched)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
-- version: 10
|
||||
-- SP14: Payer-Rejected lane acknowledge
|
||||
-- When the operator reviews a payer-rejected claim, they hit the
|
||||
-- "Acknowledge" bulk action. We mark the claim with the timestamp so
|
||||
-- the lane query can filter it out (it stays in the DB for audit but
|
||||
-- doesn't show up in the operator's working surface).
|
||||
--
|
||||
-- Why a separate column instead of clearing payer_rejected_at:
|
||||
-- * Audit trail: SP11's hash-chained audit_log needs the *original*
|
||||
-- rejection event intact. Clearing the timestamp would erase the
|
||||
-- evidence of the payer saying "no" — exactly what auditors want
|
||||
-- to see.
|
||||
-- * Reconciliation: future SPs that match payer-rejected claims
|
||||
-- against appeals (e.g. SP17) can still see the original status
|
||||
-- code and reason.
|
||||
|
||||
ALTER TABLE claims ADD COLUMN payer_rejected_acknowledged_at TEXT;
|
||||
ALTER TABLE claims ADD COLUMN payer_rejected_acknowledged_actor TEXT;
|
||||
|
||||
CREATE INDEX idx_claims_payer_rejected_unack
|
||||
ON claims(payer_rejected_at)
|
||||
WHERE payer_rejected_acknowledged_at IS NULL;
|
||||
Reference in New Issue
Block a user