diff --git a/backend/src/cyclone/store/__init__.py b/backend/src/cyclone/store/__init__.py index 32a1a39..5c6c772 100644 --- a/backend/src/cyclone/store/__init__.py +++ b/backend/src/cyclone/store/__init__.py @@ -325,7 +325,13 @@ class CycloneStore: return _remove_claim_ack(link_id, event_bus=event_bus) def batch_envelope_index(self): - """Return a {envelope.control_number: batch.id} map for D10 Pass 1.""" + """Return a {key: batch.id} map populated from two columns (D10 Pass 1). + + Each 837p batch contributes both ``Batch.raw_result_json.envelope.control_number`` + (ISA13) and ``Batch.transaction_set_control_number`` (ST02); 835 batches + are excluded. Single ``.get(set_control_number)`` lookup resolves + either key — SP37 closes the 999 AK201 → source-batch gap. + """ return _batch_envelope_index() # -- SP17: encrypted DB backups ------------------------------------- diff --git a/backend/src/cyclone/store/claim_acks.py b/backend/src/cyclone/store/claim_acks.py index 94cfaad..2ba9107 100644 --- a/backend/src/cyclone/store/claim_acks.py +++ b/backend/src/cyclone/store/claim_acks.py @@ -11,8 +11,10 @@ Five methods on top of the new ``ClaimAck`` ORM table: ack-orphans lane). * ``remove_claim_ack`` — unlink. Publishes ``claim_ack_dropped``. * ``batch_envelope_index`` — D10 in-memory map of - ``Batch.envelope.control_number → batch.id`` (cheap to rebuild; - re-built once per ingest). + ``{Batch.raw_result_json.envelope.control_number (ISA13) OR + Batch.transaction_set_control_number (ST02)} → batch.id`` + (SP37: populated from two columns; cheap to rebuild, re-built + once per ingest). Each mutating method opens its own ``db.SessionLocal()()`` session so callers don't have to manage session lifecycles. Publishes are diff --git a/backend/tests/test_acks.py b/backend/tests/test_acks.py index cb11a88..8870fcd 100644 --- a/backend/tests/test_acks.py +++ b/backend/tests/test_acks.py @@ -51,7 +51,7 @@ def test_migration_0002_creates_acks_table(): def test_migration_latest_idempotent_on_fresh_db(): """Re-running the migration on the same DB must be a no-op (PRAGMA - user_version already at the latest version — currently 19 after + user_version already at the latest version — currently 20 after 0004-0006 line_reconciliation, 0005 ta1_acks, SP9's 0007 providers/payers/clearhouse, SP10's 0008 payer_rejected, SP11's 0009 audit_log, SP14's 0010 payer_rejected_acknowledged, @@ -61,15 +61,16 @@ def test_migration_latest_idempotent_on_fresh_db(): claims.matched_remittance_id index, SP27-Task 17's 0017 claim.patient_control_number backfill UPDATE, SP28's 0018 claim_acks join table, SP32's 0019 - rendering_provider_npi + service_provider_npi).""" + rendering_provider_npi + service_provider_npi, and SP37's 0020 + transaction_set_control_number).""" with db.engine().begin() as c: v1 = c.exec_driver_sql("PRAGMA user_version").scalar() or 0 - assert v1 == 19 + assert v1 == 20 # A second run should not raise and should not bump the version. db_migrate.run(db.engine()) with db.engine().begin() as c: v2 = c.exec_driver_sql("PRAGMA user_version").scalar() or 0 - assert v2 == 19 + assert v2 == 20 def test_add_ack_persists_row():