fix(sp21): drop dead code surfaced by code-quality review
- 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).
This commit is contained in:
@@ -38,30 +38,8 @@ Backward-compat shims for tests:
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
|
||||||
import threading
|
import threading
|
||||||
from datetime import datetime, timezone
|
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:
|
def utcnow() -> datetime:
|
||||||
@@ -112,8 +90,6 @@ from .orm_builders import (
|
|||||||
_remittance_835_row,
|
_remittance_835_row,
|
||||||
)
|
)
|
||||||
from .providers import (
|
from .providers import (
|
||||||
_payer_orm_to_dict,
|
|
||||||
_provider_orm_to_dict,
|
|
||||||
ensure_clearhouse_seeded,
|
ensure_clearhouse_seeded,
|
||||||
get_clearhouse,
|
get_clearhouse,
|
||||||
get_payer_config,
|
get_payer_config,
|
||||||
@@ -125,18 +101,9 @@ from .providers import (
|
|||||||
)
|
)
|
||||||
from .records import BatchKind, BatchRecord, BatchRecord837, BatchRecord835
|
from .records import BatchKind, BatchRecord, BatchRecord837, BatchRecord835
|
||||||
from .ui import (
|
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_detail,
|
||||||
to_ui_claim_from_orm,
|
to_ui_claim_from_orm,
|
||||||
to_ui_provider,
|
to_ui_provider,
|
||||||
to_ui_remittance,
|
|
||||||
to_ui_remittance_from_orm,
|
to_ui_remittance_from_orm,
|
||||||
to_ui_remittance_with_adjustments,
|
to_ui_remittance_with_adjustments,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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:
|
def _persist_835_remit(session, cp: "ClaimPayment", remittance_id: str) -> None:
|
||||||
"""SP7: persist ServiceLinePayment + CAS rows for one CLP composite.
|
"""SP7: persist ServiceLinePayment + CAS rows for one CLP composite.
|
||||||
|
|
||||||
|
|||||||
@@ -529,39 +529,4 @@ def _date_in_bounds(
|
|||||||
return False
|
return False
|
||||||
if date_to is not None and date_part > date_to:
|
if date_to is not None and date_part > date_to:
|
||||||
return False
|
return False
|
||||||
return True
|
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,
|
|
||||||
}
|
|
||||||
@@ -238,13 +238,4 @@ def _sync_publish(event_bus, kind: str, payload: dict) -> None:
|
|||||||
"""
|
"""
|
||||||
event = {**payload, "_kind": kind}
|
event = {**payload, "_kind": kind}
|
||||||
for queue in list(event_bus._subscribers.get(kind, ())):
|
for queue in list(event_bus._subscribers.get(kind, ())):
|
||||||
event_bus._enqueue_or_drop_oldest(queue, event)
|
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()
|
|
||||||
Reference in New Issue
Block a user