feat(backend): add Batch + Claim ORM models + ClaimState enum
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
"""Tests for ORM model definitions and CRUD."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
from datetime import date, datetime, timezone
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from cyclone import db
|
||||
from cyclone.db import Base, Batch, Claim, ClaimState
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _setup(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("CYCLONE_DB_URL", f"sqlite:///{tmp_path}/test.db")
|
||||
db._reset_for_tests()
|
||||
db.init_db()
|
||||
|
||||
|
||||
def test_claim_state_enum_values():
|
||||
assert ClaimState.SUBMITTED.value == "submitted"
|
||||
assert ClaimState.RECEIVED.value == "received"
|
||||
assert ClaimState.PAID.value == "paid"
|
||||
assert ClaimState.PARTIAL.value == "partial"
|
||||
assert ClaimState.DENIED.value == "denied"
|
||||
assert ClaimState.RECONCILED.value == "reconciled"
|
||||
assert ClaimState.REVERSED.value == "reversed"
|
||||
# 7 values total.
|
||||
assert len(list(ClaimState)) == 7
|
||||
|
||||
|
||||
def test_create_and_query_batch():
|
||||
with db.SessionLocal()() as s:
|
||||
b = Batch(
|
||||
id="b1",
|
||||
kind="837p",
|
||||
input_filename="test.txt",
|
||||
parsed_at=datetime(2026, 6, 19, 12, 0, tzinfo=timezone.utc),
|
||||
totals_json={"total_claims": 1},
|
||||
validation_json={"passed": True, "warnings": [], "errors": []},
|
||||
raw_result_json={"_": "stub"},
|
||||
)
|
||||
s.add(b)
|
||||
s.commit()
|
||||
|
||||
with db.SessionLocal()() as s:
|
||||
loaded = s.get(Batch, "b1")
|
||||
assert loaded is not None
|
||||
assert loaded.kind == "837p"
|
||||
assert loaded.totals_json == {"total_claims": 1}
|
||||
|
||||
|
||||
def test_create_and_query_claim_with_default_state():
|
||||
with db.SessionLocal()() as s:
|
||||
s.add(Batch(
|
||||
id="b1", kind="837p", input_filename="x",
|
||||
parsed_at=datetime(2026, 6, 19, tzinfo=timezone.utc),
|
||||
))
|
||||
c = Claim(
|
||||
id="CLM-1",
|
||||
batch_id="b1",
|
||||
patient_control_number="CLM-1",
|
||||
service_date_from=date(2026, 6, 1),
|
||||
service_date_to=date(2026, 6, 1),
|
||||
charge_amount=Decimal("124.00"),
|
||||
provider_npi="1234567890",
|
||||
payer_id="SKCO0",
|
||||
state=ClaimState.SUBMITTED,
|
||||
)
|
||||
s.add(c)
|
||||
s.commit()
|
||||
|
||||
with db.SessionLocal()() as s:
|
||||
loaded = s.get(Claim, "CLM-1")
|
||||
assert loaded is not None
|
||||
assert loaded.state == ClaimState.SUBMITTED
|
||||
assert loaded.charge_amount == Decimal("124.00")
|
||||
assert loaded.service_date_from == date(2026, 6, 1)
|
||||
Reference in New Issue
Block a user