EbillingService¶
Implements IEbillingService as the orchestration point for the electronic-billing pipeline: reading, validating, and processing inbound EDI 837 bills and 835 acknowledgement files, generating outbound 835/277/837-acknowledgement EDI files, indexing bills to providers/patients/locations, assigning bills to adjusters, extracting explanation-of-benefits (EOB) records, associating imaging API images to e-bill documents, and reconciling clearinghouse invoices. It coordinates persistence through IUnitOfWork, batch/status transitions through SAIF.Domain.Model.Claims.Ebilling.Batch, data access through IEbillingQueryProvider/IClaimQueryProvider/IAuditNoteQueryProvider/ IBillQueryProvider/IWorkerQueryProvider, image retrieval/upload through IImagingClient, and external claim/financial lookups through ICCClaimApiService, IClaimDataApiClient, IFinancialDataApiClient, and IMedicalBillingApiService.
Purpose¶
- Reads and validates inbound EDI 837 (bill submission) and 999/835-acknowledgement transaction sets, checking ISA/GS sender-receiver identifiers, batch numbers, delimiters, and duplicate processing before extraction.
- Extracts 837 bill data into batches (
Process837File), builds outbound 835 EOB files (Create835EobFile), 277 claim-acknowledgement files (Create277ResponseFile), and 837 acknowledgement files (Create837AckFile), driving each batch through its status lifecycle. - Processes EOB acknowledgement (999-style) responses against 835 batches, marking individual or entire-batch EOBs accepted or rejected (
ProcessEOBAcknowledgementFile,ProcessEntireEobBatch,ProcessEobStatus). - Indexes extracted bills to providers, patients, and claim locations (
IndexBatch) and assigns indexed/imaged bills to responsible adjusters (AssignBills). - Polls the imaging API for e-bill document images and associates parent/child images to bill documents and claims, logging failures for documents with no matching image (
AssociateEbillImages,GetBatchImagingResults). - Extracts EOB records from medical billing data (
ExtractEobs,ExtractEobForReject) and generates CBP (compensable-bill-processing) bills for indexed batches (CreateCbpBillsForBatch). - Reconciles a clearinghouse invoice CSV against e-bill records, flagging duplicate, missing, or amount-mismatched bills and persisting an
EbillInvoicewith computed errors (ProcessInvoiceFile).
Context¶
- Namespace:
SAIF.Services.Claims.Ebilling - Assembly/package:
SAIF.Services(packaged inside theSAIF.SAIFCode.CoreNuGet package)
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| EbillingService | public EbillingService(IUnitOfWork uow, IUserProfileService prof, IEbillingQueryProvider qu, IServiceCodeManager svc, IErrorConditionHandler err, IClaimQueryProvider quc, IImagingClient imagingClient, IAuditNoteQueryProvider auditNoteQueryProvider, IBillQueryProvider billQueryProvider, IClaimQueryProvider claimQueryProvider, IWorkerQueryProvider workerQueryProvider, ICCClaimApiService claimApiService, IClaimDataApiClient gwClaimDataApiClient, IFinancialDataApiClient gwFinancialDataApiClient, IMedicalBillingApiService medicalBillingApiService) |
Wires the unit-of-work, query providers, imaging client, and external claim/financial API clients used across all e-billing operations. |
| RetrieveBatch(string, string, long) | public DomainModel.Batch RetrieveBatch(string batchType, string batchStatus, long batchId = 0) |
Loads a batch by type/status (optionally a specific batch ID), defaulting to the current in-progress batch of that type/status when batchId is 0. |
| RetrieveBatch(string, string, EbillClearinghouse, long) | public DomainModel.Batch RetrieveBatch(string batchType, string batchStatus, EbillClearinghouse clearinghouse, long batchId) |
Loads or creates a batch scoped to a specific clearinghouse, type, and status. |
| Process837File | public bool Process837File(IEdiFile file, long batchId, ILogWriter controlLog) |
Extracts an inbound 837 EDI file into the matching batch, transitions the batch to Extracted, and commits or rolls back the transaction based on extraction success. |
| Read999TransactionSet | public IEdiFile Read999TransactionSet(string filepath, ILogWriter controlLog) |
Reads a 999 EDI file from disk and wraps it as an Edi999File. |
| ProcessEOBAcknowledgementFile | public ResultCount ProcessEOBAcknowledgementFile(IEdiFile file, string clearinghouseCode, ILogWriter controlReport, ILogWriter rejectedReport) |
Parses AK9/AK2/IK5 acknowledgement segments to accept or reject an entire 835 batch or individual EOBs within it, creating an 835AK response batch and returning success/failure counts. |
| ProcessEntireEobBatch | public void ProcessEntireEobBatch(EbillBatch batch, string acknowledgmentCode, ResultCount progamResult) |
Applies a single acknowledgement code to every EOB/ebill in a batch, setting bill status to rejected or completed and tallying success/failure counts. |
| ProcessEobStatus | public void ProcessEobStatus(long eobId, string acknowledgmentCode, ResultCount programResult, ILogWriter rejectedReport) |
Applies an acknowledgement code to a single EOB's ebills, updating status, update-user/date, and the success/failure tally. |
| Create835EobFile | public IEdiFile Create835EobFile(long batchId, bool isProductionRun, ILogWriter controlLog, ILogWriter segmentLog, ILogWriter configReport) |
Builds an outbound 835 EOB EDI file for a batch's EOBs (or marks the batch complete with no data to transmit if it has none) and transitions the batch to EobDistributed. |
| Create277ResponseFile | public StatusResponseResults Create277ResponseFile(bool isProductionRun, string path, string outFileName, string clearinghouseCode, ILogWriter controlReport) |
Builds and writes a 277 claim-acknowledgement response file for a clearinghouse's pending response bills, creating a 277CA batch and marking it complete; returns null if there are no bills to respond to. |
| CreateCbpBillsForBatch | public GenerateCBPBillsResults CreateCbpBillsForBatch(long batchId, ILogWriter controlReport) |
Generates CBP bills for every indexed ebill in a batch, one unit-of-work transaction per bill, then resets the batch to Setup. |
| GetBatchImagingResults | public ImageResults GetBatchImagingResults(long batchId, double maxTimeInMinutes, ILogWriter controlReport) |
Polls (sleeping 60 seconds between checks) for up to maxTimeInMinutes until all parent documents for a batch have images, returning counts of imaged/not-yet-imaged documents. |
| AssociateEbillImages | public AssociateImageResults AssociateEbillImages(long batchId, ILogWriter controlReport, ILogWriter noImageReport) |
Retrieves images for all not-yet-imaged bills in a batch and associates parent and secondary document images to each bill, then transitions the batch to Imaged. |
| CreateAffiliateImages | public void CreateAffiliateImages(Ebill ebill, IList<Image> images, ILogWriter noImageReport, AssociateImageResults associateImageResults) |
Associates the parent-document image to an ebill and, if found, associates its secondary (multi-page) document images as cross-references. |
| LogNoMatchingImage | public static void LogNoMatchingImage(EbillDocument billDocument, EbillDocument otherDocument, ILogWriter noImageReport, NoMatchingDataException exception) |
Writes a diagnostic entry describing a document for which the imaging API returned no matching image. |
| LogUnknownException | public static void LogUnknownException(EbillDocument billDocument, EbillDocument otherDocument, ILogWriter noImageReport, Exception exception) |
Writes a diagnostic entry describing an unexpected exception raised while associating a document image. |
| LogUnknownExceptionCrossReference | public static void LogUnknownExceptionCrossReference(EbillDocument billDocument, EbillDocument otherDocument, Image parentImage, ILogWriter noImageReport, Exception exception) |
Writes a diagnostic entry describing an unexpected exception raised while saving a parent/child image cross-reference. |
| IsValidImage | public static bool IsValidImage(EbillDocument document, Image image, ILogWriter noImageReport, AssociateImageResults associateImageResults) |
Reports whether a document has an image sequence number and a corresponding image was found, logging and incrementing the error count otherwise. |
| IndexBatch | public IndexResults IndexBatch(long batchId) |
Runs provider, patient, and bill indexing for an extracted batch in separate transactions, then transitions the batch to Indexed. |
| AssignBills | public AssignResults AssignBills(long batchId) |
Assigns responsibility (adjuster) for every bill in an imaged batch and transitions the batch to Completed, wrapping the batch ID into a failure message if assignment throws. |
| ExtractEobs | public EobResults ExtractEobs(string clearinghouseCode, long rowLimit, ILogWriter errorLogWriter) |
Creates a new 835 batch for a clearinghouse and generates EOB records from medical-billing data (up to rowLimit rows), transitioning the batch to Extracted. |
| ExtractEobForReject | public EobResults ExtractEobForReject(long eobId) |
Regenerates a single rejected EOB into a new 835 batch, throwing if the EOB, its clearinghouse, or the current user cannot be resolved. |
| DataException | public Exception DataException { get; set; } |
Holds the last exception captured for a data-processing operation for later inspection by callers. |
| Read837TransactionSet | public IEdiFile Read837TransactionSet(string filepath, ILogWriter controlLog) |
Reads an inbound 837 EDI file from disk and wraps it as an Edi837File. |
| AreBillsAlreadyProcessed | public bool AreBillsAlreadyProcessed(IEdiFile file, EbillClearinghouse clearinghouse) |
Reports whether a bill with the file's REF*D9 clearinghouse control number already exists for the given clearinghouse. |
| IsClearinghouseRepetitionSeparatorAndElementDelimiterValid | public bool IsClearinghouseRepetitionSeparatorAndElementDelimiterValid(IEdiFile file, EbillClearinghouse clearinghouse) |
Reports whether the file's ISA repetition separator and component-element delimiter match the values configured for the clearinghouse. |
| GetClearinghouse | public EbillClearinghouse GetClearinghouse(IEdiFile file) |
Resolves the sending clearinghouse from the file's GS segment sender tax ID. |
| IsValidFileStructure | public bool IsValidFileStructure(IEdiFile file) |
Reports whether the file begins with an ISA segment and ends with an IEA segment. |
| IsFileAlreadyProcessed | public bool IsFileAlreadyProcessed(IEdiFile file, EbillClearinghouse clearinghouse) |
Reports whether a batch for the file's header batch date and clearinghouse has already been processed. |
| IsValidSenderAndReceiver | public bool IsValidSenderAndReceiver(IEdiFile file) |
Reports whether the file's GS sender/receiver tax IDs match the resolved clearinghouse's configured tax IDs. |
| IsValidFileBatchType | public bool IsValidFileBatchType(IEdiFile file, string batchType) |
Reports whether the file's ST segment transaction-set identifier code matches the expected batch type. |
| IsValidFileBatchNumber | public bool IsValidFileBatchNumber(IEdiFile file, long batchId) |
Reports whether the file's AK1 control number matches the expected batch ID. |
| Create837AckFile | public void Create837AckFile(IEdiFile file, bool isProductionRun, string path, string outFileName, ILogWriter controlReport) |
Builds and writes an 837 acknowledgement EDI file for an inbound 837 batch, creating an 837AK response batch and transitioning both batches (Acknowledged/Completed). |
| CleanEbillingAddress | public DomainModel.Batch CleanEbillingAddress(long batchId) |
Retrieves the INDEX-status 837 batch used as the target for address cleanup processing. |
| WriteEdiFile | public void WriteEdiFile(IEdiFile file, string path) |
Writes an in-memory EDI file to disk at the given path. |
| ProcessInvoiceFile | public void ProcessInvoiceFile(IEnumerable<InvoiceCSVFile> invoiceFile, string invoiceMonth, decimal invoiceTotalAmount, ILogWriter controlLog) |
Reconciles a clearinghouse invoice CSV against ebill records for the invoice month, deleting and reprocessing an existing unbalanced invoice, flagging duplicate/missing/mismatched bills as invoice errors, and persisting the resulting EbillInvoice. |
| CreateInvoiceError | public EbillInvoiceError CreateInvoiceError(string errorText, string clearinghouseControlNumber = null, Ebill ebill = null) |
Builds an EbillInvoiceError record describing a reconciliation discrepancy for an invoice line. |
| CreateInvoiceBill | public EbillInvoiceBill CreateInvoiceBill(InvoiceCSVFile line, Ebill ebill = null) |
Builds an EbillInvoiceBill record capturing the clearinghouse control number and billed amount from an invoice CSV line. |
| ExplodeInvoice | public void ExplodeInvoice(EbillInvoice thisInvoice, ILogWriter log) |
Writes a detailed line-by-line dump of an invoice's bills and errors to the supplied log. |
| IsAddressOverridden | public bool IsAddressOverridden(string ebillAddress, IEnumerable<EbillAddressOverride> overrideAddresses) |
Reports whether an ebill address (case-insensitively) matches any configured address override. |
Behavioral notes¶
- Batch-mutating operations (
Process837File,ProcessEOBAcknowledgementFile,Create835EobFile,Create277ResponseFile,AssociateEbillImages,IndexBatch,AssignBills,ExtractEobs,ExtractEobForReject,Create837AckFile,ProcessInvoiceFile) wrap their work inIUnitOfWork.Begin()/Commit(), rolling back and throwing on extraction failure inProcess837File. GetBatchImagingResultspolls in a blocking loop with a hard-coded 60-secondThread.Sleepbetween checks until the time budget elapses or all documents are imaged.- Image lookups are batched in pages of 300 distinct image IDs per call to
IImagingClient.GetImagesto bound request size. - EDI structural/identity validation (
IsValidFileStructure,IsValidSenderAndReceiver,IsValidFileBatchType,IsValidFileBatchNumber,IsClearinghouseRepetitionSeparatorAndElementDelimiterValid) is performed by parsing raw ISA/GS/ST/AK1 segments rather than through a dedicated validator type. ProcessInvoiceFiledeletes and reprocesses a prior invoice for the same month if it was not already "in balance", then recomputes totals and appends an "Invoice is in balance" marker error when no discrepancies are found.
Sources¶
- Services/SAIF.Services/Claims/EBilling/EBillingService.cs