This PR implements automated financial reconciliation matching between the medical-claims and financial-records contracts to address revenue cycle leakage and audit failures.
reconcile_claim(): Links payment records from financial-records to specific claims with transactional guaranteesget_unreconciled_claims(): Query function returning claims older than a configurable thresholdmark_claim_disputed(): Allows marking claims with reconciliation discrepanciesset_reconciliation_threshold(): Admin function to configure the reconciliation time threshold
Updated ReconciliationStatus enum with four states:
- Pending: Claim submitted but no payments applied
- PartiallyPaid: Some payments made but not fully reconciled
- FullyReconciled: All expected payments received and matched
- Disputed: Discrepancy between claim and payment amounts
Both InsurerPaymentRecord and PatientPaymentRecord now include:
reconciled: bool- Tracks if payment has been reconciledfinancial_record_owner: Option<Address>- Links to financial record ownerfinancial_record_idx: Option<u32>- Links to specific financial record
ClaimReconciledEvent: Emitted on successful reconciliation with:- claim_id
- payment_amount
- claim_amount
- outstanding_balance
- reconciliation_status
Updated initialize() to include:
financial_records_id: Address- Address of financial-records contractreconciliation_threshold: u64- Time threshold for unreconciled claims (default: 24 hours)
- Claim and payment linking is transactional (both update or neither does)
- Partial payments are tracked with outstanding balance
- Query for unreconciled claims works correctly
- Events include claim amount, payment amount, and outstanding balance
Added comprehensive test coverage:
test_reconcile_insurer_payment- Verifies insurer payment reconciliationtest_reconcile_patient_payment- Verifies patient payment reconciliationtest_reconcile_payment_already_reconciled- Prevents double reconciliationtest_mark_claim_disputed- Tests dispute markingtest_get_unreconciled_claims- Verifies unreconciled claims querytest_set_reconciliation_threshold- Tests threshold configurationtest_unauthorized_cannot_mark_disputed- Verifies authorization
All 18 tests pass successfully.
Added RECONCILIATION.md with:
- Feature overview and key capabilities
- Data model changes
- Usage examples
- Error handling
- Migration notes
- Future enhancement suggestions
initialize() function signature has changed. Existing deployments will need to:
- Redeploy with new initialization parameters
- Update client code to handle new payment record fields
- Subscribe to
ClaimReconciledevents for audit trails
contracts/medical-claims/src/lib.rs- Core reconciliation implementationcontracts/medical-claims/src/types.rs- Updated data structures and error codescontracts/medical-claims/src/test.rs- Comprehensive test coveragecontracts/medical-claims/RECONCILIATION.md- Feature documentation
Closes #392