fix(sp31): read NPI and charge from raw_json when ORM attribute missing
This commit is contained in:
@@ -609,3 +609,47 @@ def test_score_fallback_outside_window_excluded(db_session, make_claim, make_rem
|
||||
rendering_provider_npi="1111111111",
|
||||
service_date=remit_date)
|
||||
assert _score_fallback_candidates(db_session, r) is None
|
||||
|
||||
|
||||
# --- SP31 Task 3 fix: Remittance NPI lives in raw_json ----------------------
|
||||
|
||||
|
||||
def test_content_keys_npi_from_remit_raw_json(db_session, make_claim):
|
||||
"""NPI on the Remit is read from ``raw_json`` when the attribute is absent.
|
||||
|
||||
The 835 parser stores rendering_provider_npi on ``Remittance.raw_json``
|
||||
(the ORM has no dedicated column) — reconcile.run() hands a raw
|
||||
``Remittance`` instance to ``_content_keys_match``, so the helper must
|
||||
fall through ``getattr(...rendering_provider_npi...)`` to the raw_json
|
||||
read. This test pins that path with a real ORM row (no transient
|
||||
``setattr`` shadowing the production layout).
|
||||
|
||||
Configuration: PCN mismatched, charge matches, NPI matches via raw_json
|
||||
→ 2 of 3 keys agree → True.
|
||||
"""
|
||||
from decimal import Decimal
|
||||
from datetime import date, datetime, timezone
|
||||
from cyclone.db import Remittance
|
||||
from cyclone.reconcile import _content_keys_match
|
||||
claim = make_claim(
|
||||
patient_control_number="ABC",
|
||||
total_charge=Decimal("100.00"),
|
||||
rendering_provider_npi="1111111111",
|
||||
service_date_from=date(2026, 6, 1),
|
||||
)
|
||||
# Real Remittance ORM instance — NPI lives ONLY in raw_json, not as a
|
||||
# transient attribute. (The 835 parser populates raw_json that way;
|
||||
# the make_remit factory's transient ``rendering_provider_npi`` setattr
|
||||
# would shadow the production read.)
|
||||
remit = Remittance(
|
||||
id="real-remit-1",
|
||||
batch_id="test-batch",
|
||||
payer_claim_control_number="OTHER-PCN", # PCN: won't match "ABC"
|
||||
status_code="1",
|
||||
total_charge=Decimal("100.00"), # charge: matches
|
||||
received_at=datetime(2026, 6, 19, tzinfo=timezone.utc),
|
||||
raw_json={"rendering_provider_npi": "1111111111"}, # NPI: matches
|
||||
)
|
||||
db_session.add(remit)
|
||||
db_session.flush()
|
||||
assert _content_keys_match(remit, claim) is True # charge + NPI = 2 of 3
|
||||
|
||||
Reference in New Issue
Block a user