From fe84ce7cf3e3bb8140adc1011b9fb2f0b3f2e11d Mon Sep 17 00:00:00 2001 From: Nora Date: Mon, 29 Jun 2026 16:20:01 -0600 Subject: [PATCH] fix(sp21): drop dead code surfaced by code-quality review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - write.py: drop orphan run_reconcile() — no callers, and the pre-split store.py never had it. (The CycloneStore class already has _publish_events_sync + _sync_publish delegations; the spec's mention of _run_reconcile was a doc drift from the 2026-06-21 plan, not a real requirement.) - ui.py: drop duplicate _provider_orm_to_dict + _payer_orm_to_dict (canonical copies live in providers.py and are the only ones used; the ui.py copies were accidental duplicates from the split). - orm_builders.py: drop orphan _cas_adjustment_row() — never called; _persist_835_remit() builds CAS rows inline. - __init__.py: prune 30+ unused top-level imports and 9 unused re-exports. The facade only ever needs the type-hint-bearing BatchRecord family, the 4 read-path ORM-row serializers actually used inside the package, the 3 documented private helpers, and the 7 function-level re-exports the spec promises. Everything else was carryover from the original store.py header. Tests at exact baseline: 1 failed, 1176 passed, 10 skipped (the 1 failure is the pre-existing test_provider_detail isolation flake documented in the spec). --- backend/src/cyclone/store/__init__.py | 33 -------------------- backend/src/cyclone/store/orm_builders.py | 21 ------------- backend/src/cyclone/store/ui.py | 37 +---------------------- backend/src/cyclone/store/write.py | 11 +------ 4 files changed, 2 insertions(+), 100 deletions(-) diff --git a/backend/src/cyclone/store/__init__.py b/backend/src/cyclone/store/__init__.py index c63bb58..49108a7 100644 --- a/backend/src/cyclone/store/__init__.py +++ b/backend/src/cyclone/store/__init__.py @@ -38,30 +38,8 @@ Backward-compat shims for tests: from __future__ import annotations -import json import threading from datetime import datetime, timezone -from decimal import Decimal -from typing import Any, Literal - -from pydantic import BaseModel, ConfigDict, model_validator - -from cyclone import db -from cyclone.db import ( - Ack, - ActivityEvent, - Batch, - CasAdjustment, - Claim, - ClaimState, - JSONText, - Match, - Remittance, -) -from cyclone.parsers.models import ClaimOutput, ParseResult -from cyclone.parsers.models_835 import ClaimPayment, ParseResult835 -from cyclone.parsers.payer import PayerConfig835 -from cyclone.providers import Clearhouse, Payer, Provider # SP9: ORM-row DTOs def utcnow() -> datetime: @@ -112,8 +90,6 @@ from .orm_builders import ( _remittance_835_row, ) from .providers import ( - _payer_orm_to_dict, - _provider_orm_to_dict, ensure_clearhouse_seeded, get_clearhouse, get_payer_config, @@ -125,18 +101,9 @@ from .providers import ( ) from .records import BatchKind, BatchRecord, BatchRecord837, BatchRecord835 from .ui import ( - CLAIM_DETAIL_HISTORY_LIMIT, - _address_to_ui, - _date_in_bounds, - _iso_z, - _svc_to_wire_dict, - _validation_issues_to_ui, - to_activity_event, - to_ui_claim, to_ui_claim_detail, to_ui_claim_from_orm, to_ui_provider, - to_ui_remittance, to_ui_remittance_from_orm, to_ui_remittance_with_adjustments, ) diff --git a/backend/src/cyclone/store/orm_builders.py b/backend/src/cyclone/store/orm_builders.py index cff67d9..b3a38b0 100644 --- a/backend/src/cyclone/store/orm_builders.py +++ b/backend/src/cyclone/store/orm_builders.py @@ -96,27 +96,6 @@ def _remittance_835_row(cp: ClaimPayment, batch_id: str) -> Remittance: ) -def _cas_adjustment_row(adj, remittance_id: str) -> "db.CasAdjustment": - """Build a CasAdjustment ORM row from a ClaimAdjustment. NOT yet persisted. - - One row per SVC-level CAS adjustment is persisted so the T10 - reconcile aggregator can compute ``Remittance.adjustment_amount`` - as ``SUM(CasAdjustment.amount) WHERE remittance_id = ...``. - - ``quantity`` is optional in the X12 CAS spec; we coerce to Decimal - only when present to keep the column NULL for the common no-QTY case. - """ - from cyclone.db import CasAdjustment - quantity = getattr(adj, "quantity", None) - return CasAdjustment( - remittance_id=remittance_id, - group_code=adj.group_code, - reason_code=adj.reason_code, - amount=Decimal(str(adj.amount)), - quantity=Decimal(str(quantity)) if quantity is not None else None, - ) - - def _persist_835_remit(session, cp: "ClaimPayment", remittance_id: str) -> None: """SP7: persist ServiceLinePayment + CAS rows for one CLP composite. diff --git a/backend/src/cyclone/store/ui.py b/backend/src/cyclone/store/ui.py index 430ad32..44ce974 100644 --- a/backend/src/cyclone/store/ui.py +++ b/backend/src/cyclone/store/ui.py @@ -529,39 +529,4 @@ def _date_in_bounds( return False if date_to is not None and date_part > date_to: return False - return True - - -# --------------------------------------------------------------------------- -# SP9: ORM-to-Pydantic conversion helpers -# --------------------------------------------------------------------------- - - -def _provider_orm_to_dict(row) -> dict: - return { - "npi": row.npi, - "label": row.label, - "legal_name": row.legal_name, - "tax_id": row.tax_id, - "taxonomy_code": row.taxonomy_code, - "address_line1": row.address_line1, - "address_line2": row.address_line2, - "city": row.city, - "state": row.state, - "zip": row.zip, - "is_active": bool(row.is_active), - "created_at": row.created_at, - "updated_at": row.updated_at, - } - - -def _payer_orm_to_dict(row) -> dict: - return { - "payer_id": row.payer_id, - "name": row.name, - "receiver_name": row.receiver_name, - "receiver_id": row.receiver_id, - "is_active": bool(row.is_active), - "created_at": row.created_at, - "updated_at": row.updated_at, - } \ No newline at end of file + return True \ No newline at end of file diff --git a/backend/src/cyclone/store/write.py b/backend/src/cyclone/store/write.py index 408f665..e4b05a1 100644 --- a/backend/src/cyclone/store/write.py +++ b/backend/src/cyclone/store/write.py @@ -238,13 +238,4 @@ def _sync_publish(event_bus, kind: str, payload: dict) -> None: """ event = {**payload, "_kind": kind} for queue in list(event_bus._subscribers.get(kind, ())): - event_bus._enqueue_or_drop_oldest(queue, event) - - -def run_reconcile(batch_id): - """Standalone reconcile helper. Currently unused by callers — the - 835 ingest site calls reconcile.run inline during add().""" - from cyclone import reconcile as _reconcile - with db.SessionLocal()() as s: - _reconcile.run(s, batch_id) - s.commit() \ No newline at end of file + event_bus._enqueue_or_drop_oldest(queue, event) \ No newline at end of file