fix(835): correct SVC04/SVC05 mapping per X12 005010X221A1
X12 835 SVC segment: SVC01 = composite procedure SVC02 = charge SVC03 = payment SVC04 = Unit or Basis for Measurement Code (UN, MJ, DA, ...) SVC05 = Service Unit Count The parser previously read SVC04 as the units count and SVC05 as the unit type — backwards. On real 835s (and the canonical minimal fixture), SVC04 carries the code 'UN' which fails Decimal parsing, so the units always came out as None and the code string was assigned to unit_type. SP7's line-level matcher couldn't compare units on the SVC side against the claim side because of this. - _consume_service_payment: SVC04 → unit_type, SVC05 → units count - Default unit_type to 'UN' when only the count is present - minimal_835.txt + unbalanced_835.txt: swap positions to match spec - Add 2 regression tests (units-and-unit-type, default-unit-type-to-UN)
This commit is contained in:
+2
-2
@@ -12,9 +12,9 @@ N4*Montrose*CO*814014063~
|
||||
LX*1~
|
||||
CLP*CLM001*1*100.00*85.00*15.00*MC*CLM001*12*1~
|
||||
CAS*CO*45*15.00~
|
||||
SVC*HC:S5130:U2*60.00*50.00*7.73*UN*20260602~
|
||||
SVC*HC:S5130:U2*60.00*50.00*UN*7.73*20260602~
|
||||
DTM*472*20260602~
|
||||
SVC*HC:S5130:U2*40.00*35.00*7.73*UN*20260603~
|
||||
SVC*HC:S5130:U2*40.00*35.00*UN*7.73*20260603~
|
||||
DTM*472*20260603~
|
||||
SE*22*991102984~
|
||||
GE*1*991102984~
|
||||
|
||||
+2
-2
@@ -12,9 +12,9 @@ N4*Montrose*CO*814014063~
|
||||
LX*1~
|
||||
CLP*CLM001*1*100.00*85.00*15.00*MC*CLM001*12*1~
|
||||
CAS*CO*45*15.00~
|
||||
SVC*HC:S5130:U2*60.00*50.00*7.73*UN*20260602~
|
||||
SVC*HC:S5130:U2*60.00*50.00*UN*7.73*20260602~
|
||||
DTM*472*20260602~
|
||||
SVC*HC:S5130:U2*40.00*35.00*7.73*UN*20260603~
|
||||
SVC*HC:S5130:U2*40.00*35.00*UN*7.73*20260603~
|
||||
DTM*472*20260603~
|
||||
SE*22*991102985~
|
||||
GE*1*991102985~
|
||||
|
||||
@@ -124,3 +124,57 @@ def test_parse_no_bpr_raises():
|
||||
)
|
||||
with pytest.raises(CycloneParseError, match="No BPR"):
|
||||
parse(text, PayerConfig835.co_medicaid_835())
|
||||
|
||||
|
||||
def test_parse_service_payment_units_and_unit_type():
|
||||
"""X12 005010X221A1: SVC04 = unit-of-measure, SVC05 = service unit count.
|
||||
|
||||
Bug history: the parser previously read SVC04 as ``units`` and SVC05
|
||||
as ``unit_type`` (with the comment stating the opposite of the spec).
|
||||
On real-world 835s — and the canonical minimal fixture — this left
|
||||
``units=None`` because SVC04 carries the string "UN" (which fails
|
||||
``Decimal`` parsing) and SVC05 (a count like "7.73") got assigned to
|
||||
``unit_type``.
|
||||
|
||||
This test pins down the correct mapping so SP7's line-level matcher
|
||||
can compare units on the SVC side against the claim side.
|
||||
"""
|
||||
from decimal import Decimal
|
||||
result = parse(FIXTURE.read_text(), PayerConfig835.co_medicaid_835())
|
||||
c = result.claims[0]
|
||||
s1, s2 = c.service_payments
|
||||
# minimal_835.txt fixture: SVC*HC:S5130:U2*60.00*50.00*UN*7.73*date*
|
||||
assert s1.units == Decimal("7.73"), s1.units
|
||||
assert s1.unit_type == "UN"
|
||||
assert s2.units == Decimal("7.73"), s2.units
|
||||
assert s2.unit_type == "UN"
|
||||
|
||||
|
||||
def test_parse_service_payment_units_default_unit_type_to_un():
|
||||
"""If SVC04 is empty but SVC05 carries a count, default unit_type to UN.
|
||||
|
||||
Some payers omit the unit-of-measure code when the units are obvious
|
||||
(e.g. always "UN"). The parser should still parse the units and
|
||||
surface a reasonable default for ``unit_type`` so downstream
|
||||
consumers (validation, SP7 line matcher) have a non-None value.
|
||||
"""
|
||||
from decimal import Decimal
|
||||
base = FIXTURE.read_text()
|
||||
text = (
|
||||
base
|
||||
.replace(
|
||||
"SVC*HC:S5130:U2*60.00*50.00*UN*7.73*20260602~",
|
||||
"SVC*HC:S5130:U2*60.00*50.00**3*20260602~",
|
||||
)
|
||||
.replace(
|
||||
"SVC*HC:S5130:U2*40.00*35.00*UN*7.73*20260603~",
|
||||
"SVC*HC:S5130:U2*40.00*35.00**4*20260603~",
|
||||
)
|
||||
)
|
||||
result = parse(text, PayerConfig835.co_medicaid_835())
|
||||
s1, s2 = result.claims[0].service_payments
|
||||
assert s1.units == Decimal("3"), s1.units
|
||||
assert s2.units == Decimal("4"), s2.units
|
||||
# Default to UN when SVC04 missing but units present.
|
||||
assert s1.unit_type == "UN", s1.unit_type
|
||||
assert s2.unit_type == "UN", s2.unit_type
|
||||
|
||||
Reference in New Issue
Block a user