Data Layer medium complexity backend
0
Dependencies
4
Dependents
1
Entities
1
Integrations

Description

Data access layer for persisting and querying export run metadata. Each export run record stores the timestamp, triggering user, organization, list of included claim IDs, export format, and status. Provides query methods for history display, audit, and duplicate prevention.

Feature: Accounting System Export and Integration

export-run-repository

Summaries

The Export Run Repository provides the organizational memory for every accounting export that has ever been triggered — who initiated it, when, which claims were included, and whether it succeeded or failed. This audit record is essential for financial compliance, dispute resolution, and regulatory reporting. It also underpins duplicate-payment prevention by giving the system a reliable way to query whether a specific claim has already been exported. Investing in a well-structured export history store reduces the cost of audits and gives finance leadership confidence in the integrity of the reimbursement process.

The Export Run Repository is a medium-complexity data component with no external service dependencies, making it a good early-sprint deliverable that unblocks both the Double-Export Guard and any export history UI. Schema design must be finalized before dependent components begin integration work — changes to the claim ID storage format or run status enum will require coordinated migrations. Testing should cover pagination correctness for large export histories, concurrent write isolation, and the findRunsByClaimId() query performance at scale. Include a migration plan for existing export records if the system is replacing a manual process.

createExportRun() inserts a new record with orgId, triggeredBy, format, and initial 'pending' status, returning the generated runId for downstream use. updateExportRunStatus() performs a single atomic update of status plus the claimIds array — store claim IDs as a serialized array or normalized join table depending on query patterns. getExportHistory() must support keyset or offset pagination; index on orgId + createdAt. findRunsByClaimId() is the hot path for double-export detection — ensure the claim IDs column is indexed or the join table has appropriate indexes.

deleteExportRun() should be soft-delete only in production to preserve audit integrity; expose hard delete only for test/admin contexts.

Responsibilities

  • Create export run records with full metadata on export initiation
  • Update run status and included claim IDs on completion or failure
  • Query export history for a given organization with pagination
  • Support lookup of export run by claim ID for double-export detection

Interfaces

createExportRun(orgId, triggeredBy, format): ExportRun
updateExportRunStatus(runId, status, claimIds)
getExportHistory(orgId, limit, offset): ExportRun[]
getExportRunById(runId): ExportRun
findRunsByClaimId(claimId): ExportRun[]
deleteExportRun(runId)

Related Data Entities (1)

Data entities managed by this component

Used Integrations (1)

External integrations and APIs this component relies on