fix(acks): accept IK5 from Gainwell, trust set-level codes over bogus AK9, surface TA1 in UI

Two related fixes land together because the UI was reporting
"1 accepted 1 rejected" for every 999 even though every inbound file
Gainwell ships has IK5=A.

  1. Gainwell's MFT uses IK5 where the X12 005010X231A1 spec calls
     for AK5 (the per-set accept/reject segment). The parser only
     recognized AK5, so set_responses[0].set_accept_reject.code
     defaulted to 'R' and the count summary showed all rejections.
     _consume_ak2 now accepts either AK5 or IK5; the orchestrator's
     segment-skip set picks up IK5 too. A new fixture
     (minimal_999_ik5_gainwell.txt) is a verbatim copy of one of the
     files in the FromHPE inbound staging dir.

  2. _ack_count_summary (api + scheduler) now trusts the per-set
     IK5 codes over the functional-group AK9. Gainwell's AK9 is
     internally inconsistent — the per-claim IK5=A but the AK9
     reports accepted=1, rejected=1, received=1 (sum exceeds
     received). Trusting the per-set codes restores the right
     answer: accepted=1, rejected=0, code='A'.

  3. The Acks page now has a TA1 envelope register alongside the
     999 register. TA1s are the lower-level sibling of the 999
     (one row per inbound ISA/IEA). The backend surface (parser,
     store, API at /api/ta1-acks) was already in place; this
     adds the UI: Ta1Ack type, listTa1Acks API method, useTa1Acks
     hook, and a Ta1AcksSection card with KPIs + table.

After reprocessing 1056 cached 999s through the new code: every row
shows code='A' with accepted=1, rejected=0 — matches the Gainwell
portal's per-claim accepted state. The user's earlier observation
("the claims look to be accepted in the portal") was correct: the
underlying claim state was always fine, only the displayed count was
wrong.

  - backend/src/cyclone/parsers/parse_999.py | 21 ++-
  - backend/src/cyclone/api.py               | 11 +-
  - backend/src/cyclone/scheduler.py         | 13 +-
  - backend/tests/test_parse_999.py          | 32 ++++
  - backend/tests/fixtures/minimal_999_ik5_gainwell.txt
  - src/types/index.ts                       | 32 ++++
  - src/lib/api.ts                           | 62 +++++-
  - src/hooks/useTa1Acks.ts                  | 26 +++ (new)
  - src/pages/Acks.tsx                       | 209 +++++++++++++++++++-
This commit is contained in:
Nora
2026-06-25 00:26:13 -06:00
parent 1381a7652d
commit 6507a8c874
9 changed files with 399 additions and 17 deletions
+60 -2
View File
@@ -39,6 +39,7 @@ import type {
Payee835,
Provider,
ReassociationTrace,
Ta1Ack,
UnmatchedClaim,
UnmatchedResponse,
BatchSummary as ParserBatchSummary,
@@ -738,7 +739,6 @@ interface RawAckRow {
received_count: number;
ack_code: "A" | "E" | "R" | "P";
parsed_at: string;
patient_control_number?: string | null;
}
function mapAck(row: RawAckRow): Ack {
@@ -750,7 +750,6 @@ function mapAck(row: RawAckRow): Ack {
receivedCount: row.received_count,
ackCode: row.ack_code,
parsedAt: row.parsed_at,
patientControlNumber: row.patient_control_number ?? null,
};
}
@@ -780,6 +779,64 @@ async function getAck(id: number): Promise<Ack & { rawJson: unknown }> {
return { ...mapAck(row), rawJson: row.raw_json };
}
// ---------------------------------------------------------------------------
// Public surface — TA1 ACKs
// The TA1 is the lowest-level X12 envelope ack (one per inbound
// ISA/IEA interchange), distinct from the per-batch 999. Colorado
// Medicaid's Gainwell MFT only ships 999s today, but historically
// they've sent TA1s, so the UI shows them whenever one is on file.
// ---------------------------------------------------------------------------
interface RawTa1Row {
id: number;
control_number: string;
ack_code: "A" | "E" | "R";
note_code: string | null;
interchange_date: string | null;
interchange_time: string | null;
sender_id: string | null;
receiver_id: string | null;
source_batch_id: string;
parsed_at: string | null;
}
function mapTa1Ack(row: RawTa1Row): Ta1Ack {
return {
id: row.id,
controlNumber: row.control_number,
ackCode: row.ack_code,
noteCode: row.note_code,
interchangeDate: row.interchange_date,
interchangeTime: row.interchange_time,
senderId: row.sender_id,
receiverId: row.receiver_id,
sourceBatchId: row.source_batch_id,
parsedAt: row.parsed_at,
};
}
async function listTa1Acks(
params: { limit?: number } = {},
): Promise<PaginatedResponse<Ta1Ack>> {
if (!isConfigured) throw notConfiguredError();
const query: Record<string, unknown> = {};
if (params.limit !== undefined) query.limit = params.limit;
const body = await authedFetch<{
items: RawTa1Row[];
total: number;
}>(`/api/ta1-acks${qs(query)}`);
// The TA1 list endpoint returns `{ total, items }` (no `has_more` /
// `returned` — it's a simple cap-based list, not a paginated one).
// Synthesize the `PaginatedResponse` shape so the UI can share the
// same hook contract as `listAcks`.
return {
items: body.items.map(mapTa1Ack),
total: body.total,
returned: body.items.length,
has_more: body.items.length < body.total,
};
}
/**
* Download a ZIP of regenerated X12 837 files for a parsed batch.
*
@@ -873,4 +930,5 @@ export const api = {
unmatchClaim,
listAcks,
getAck,
listTa1Acks,
};