From 4c7b82f05bca0a0b3a3ab1cc4bb1db9e07b2fbe6 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 20 Jun 2026 19:19:48 -0600 Subject: [PATCH] feat(sp7): ServiceLinePayment ORM model --- backend/src/cyclone/db.py | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/backend/src/cyclone/db.py b/backend/src/cyclone/db.py index 6ab8d67..7a84b63 100644 --- a/backend/src/cyclone/db.py +++ b/backend/src/cyclone/db.py @@ -300,6 +300,48 @@ class CasAdjustment(Base): ) +class ServiceLinePayment(Base): + """One row per 835 SVC composite (loop 2110). + + SP7. Persisted on 835 ingest *before* ``reconcile.run()`` decides + which claim this line applies to. Independent of claim matching. + + See spec ยง3.1. + """ + __tablename__ = "service_line_payments" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + remittance_id: Mapped[str] = mapped_column( + String(64), ForeignKey("remittances.id", ondelete="CASCADE"), nullable=False + ) + line_number: Mapped[int] = mapped_column(Integer, nullable=False) + procedure_qualifier: Mapped[str] = mapped_column(String(4), nullable=False) + procedure_code: Mapped[str] = mapped_column(String(16), nullable=False) + modifiers_json: Mapped[str] = mapped_column( + JSONText, nullable=False, default=lambda: "[]" + ) + charge: Mapped[Decimal] = mapped_column(Numeric(12, 2), nullable=False) + payment: Mapped[Decimal] = mapped_column(Numeric(12, 2), nullable=False) + units: Mapped[Optional[Decimal]] = mapped_column(Numeric(10, 2), nullable=True) + unit_type: Mapped[Optional[str]] = mapped_column(String(8), nullable=True) + service_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True) + ref_benefit_plan: Mapped[Optional[str]] = mapped_column(String(64), nullable=True) + superseded_by_id: Mapped[Optional[int]] = mapped_column( + Integer, + ForeignKey("service_line_payments.id", ondelete="SET NULL"), + nullable=True, + ) + + __table_args__ = ( + Index("ix_service_line_payments_remittance_id", "remittance_id"), + Index( + "ix_service_line_payments_procedure_code_date", + "procedure_code", + "service_date", + ), + ) + + class Match(Base): __tablename__ = "matches"