feat(sp41): serialize_837 overload for member-week batches
This commit is contained in:
@@ -73,3 +73,48 @@ def test_override_flag_set_on_past_window_visit_batch():
|
||||
assert out_default[0].member_id == "OLD"
|
||||
assert out_default[0].iso_week == 26
|
||||
assert out_default[0].has_overridden_visits is False
|
||||
|
||||
|
||||
def test_serialize_member_week_batch_emits_one_envelope():
|
||||
"""One 837P envelope per MemberWeekBatch — one CLM + one SV1 + one
|
||||
DTP*472 service date per visit.
|
||||
|
||||
The SP41 plan spec wrote ``DTM*472*`` but the canonical 837P service
|
||||
date segment is ``DTP*472*`` (per :func:`cyclone.parsers.serialize_837.
|
||||
_build_dtp_472` and X12 005010X222A1). This test asserts against the
|
||||
canonical segment name so the batch overload stays consistent with
|
||||
the existing ``serialize_837`` building blocks.
|
||||
"""
|
||||
from cyclone.parsers.serialize_837 import serialize_member_week_batch
|
||||
visits = [
|
||||
_v(date(2026, 6, 23), "J813715", "T1019", "2.32"),
|
||||
_v(date(2026, 6, 25), "J813715", "T1019", "2.32"),
|
||||
]
|
||||
batches = build_pipeline_b_batches(visits, as_of=date(2026, 7, 7), override=False)
|
||||
assert len(batches) == 1
|
||||
body = serialize_member_week_batch(batches[0])
|
||||
text = body.decode("utf-8", errors="ignore") if isinstance(body, bytes) else body
|
||||
# CLM* segment appears twice (once per visit)
|
||||
assert text.count("CLM*") == 2
|
||||
# SV1* appears once per visit (one service line per claim)
|
||||
assert text.count("SV1*") == 2
|
||||
# DTP*472* service-date segment appears twice (canonical 837P segment name)
|
||||
assert text.count("DTP*472*") == 2
|
||||
# Single envelope (single ISA / single IEA), not per-visit envelopes
|
||||
assert text.count("ISA*") == 1
|
||||
assert text.count("IEA*") == 1
|
||||
# Deterministic per-visit claim_id pattern (member_id + date + 1-based idx)
|
||||
assert "MW-J813715-2026-06-23-01" in text
|
||||
assert "MW-J813715-2026-06-25-02" in text
|
||||
|
||||
|
||||
def test_serialize_member_week_batch_return_type_is_bytes():
|
||||
"""Task 14 spec: ``serialize_member_week_batch`` returns ``bytes``
|
||||
(the existing ``serialize_837`` returns ``str``; this overload
|
||||
diverges intentionally so callers can write the file directly)."""
|
||||
from cyclone.parsers.serialize_837 import serialize_member_week_batch
|
||||
visits = [_v(date(2026, 6, 23), "J813715", "T1019", "2.32")]
|
||||
batches = build_pipeline_b_batches(visits, as_of=date(2026, 7, 7), override=False)
|
||||
assert len(batches) == 1
|
||||
body = serialize_member_week_batch(batches[0])
|
||||
assert isinstance(body, bytes)
|
||||
|
||||
Reference in New Issue
Block a user