fix(backend): make 835 summary counts consistent with total_claims

This commit is contained in:
Tyler
2026-06-19 17:07:54 -06:00
parent 8ea951f436
commit 12ac72f915
4 changed files with 47 additions and 8 deletions
+13 -3
View File
@@ -292,12 +292,22 @@ async def parse_835_endpoint(
# Always run the validator; attach the report so the JSON path can
# surface it and the NDJSON path can fold the counts into the summary.
# 835 validation is batch-level, so pass/fail applies uniformly to every
# claim payment in the batch (passed=N or 0, failed=0 or N).
report = validate_835(result, config)
passed = 1 if report.passed else 0
failed = 1 if not report.passed else 0
n = len(result.claims)
claim_ids = [c.payer_claim_control_number for c in result.claims]
if report.passed:
passed, failed, failed_claim_ids = n, 0, []
else:
passed, failed, failed_claim_ids = 0, n, claim_ids
result = result.model_copy(update={
"validation": report,
"summary": result.summary.model_copy(update={"passed": passed, "failed": failed}),
"summary": result.summary.model_copy(update={
"passed": passed,
"failed": failed,
"failed_claim_ids": failed_claim_ids,
}),
})
if strict:
+11 -2
View File
@@ -148,17 +148,26 @@ def parse_835(
raise click.UsageError("No claim payments found in file") from None
# Run validation; populate summary.passed/failed from the report.
# 835 validation is batch-level (BPR/CLP/SVC balancing is cross-cutting),
# so pass/fail applies uniformly to every claim payment in the batch:
# when the batch passes, all N claims "passed" (passed=N, failed=0);
# when the batch fails, all N claims "failed" (passed=0, failed=N).
report = validate_835(result, config)
if strict:
promoted = [i.model_copy(update={"severity": "error"}) for i in report.warnings]
new_errors = report.errors + promoted
report = report.model_copy(update={"errors": new_errors, "passed": not new_errors})
passed = 1 if report.passed else 0
failed = 1 if not report.passed else 0
n = len(result.claims)
claim_ids = [c.payer_claim_control_number for c in result.claims]
if report.passed:
passed, failed, failed_claim_ids = n, 0, []
else:
passed, failed, failed_claim_ids = 0, n, claim_ids
result = result.model_copy(update={"validation": report})
result.summary = result.summary.model_copy(update={
"passed": passed,
"failed": failed,
"failed_claim_ids": failed_claim_ids,
"issues_by_rule": _count_issues(report),
})