---
title: Batch
summary: API reference for Batch.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Domain
reference_type: package
---

# Batch

`Batch` wraps an `EbillBatch` entity and implements the batch-lifecycle behaviour of [OP-DOM-09](../../operations-processes.md#op-dom-09): new batches are created with status `"NEW"` ([DOM-BR-090](../../business-rules.md#dom-br-090-batch-create)), retrieved batches are validated against an expected status and type (throwing `InvalidBatchException` on a mismatch, [DOM-BR-091](../../business-rules.md#dom-br-091-getbatch)), and a fixed set of status setters (COMP, EXTR, IMAGE, INDEX, EOB, DLOAD, ACK, SETUP) drive the batch through its e-billing pipeline stages ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). It is the unit of work SAIF.Services' e-billing batch jobs track a clearinghouse file's processing state against.

## Purpose
- Creates a new batch record with status `"NEW"` for a given batch type, optionally tied to a clearinghouse, submission date, and file name ([DOM-BR-090](../../business-rules.md#dom-br-090-batch-create)).
- Retrieves an existing batch by ID or by type/status, validating that the retrieved batch actually exists and matches the expected status and type, else throwing `InvalidBatchException` ([DOM-BR-091](../../business-rules.md#dom-br-091-getbatch)).
- Advances a batch through its e-billing pipeline stages via dedicated status setters (COMP, EXTR, IMAGE, INDEX, EOB, DLOAD, ACK, SETUP), each stamping the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)).

## Context
- Namespace: `SAIF.Domain.Model.Claims.Ebilling`
- Assembly/package: `SAIF.Domain` (packaged in `SAIF.SAIFCode.Core`)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| Batch (constructor, create with submission date/file name) | `public Batch(IRepositoryFactory factory, IUserProfileService prof, EbillBatchTypeCode type, IEbillingQueryProvider ebillingQueryProvider, DateTime submissionDate = default(DateTime), string fileName = "")` | Creates a new batch with status `"NEW"` and adds it to the repository ([DOM-BR-090](../../business-rules.md#dom-br-090-batch-create)); defaults the submission date to now when not supplied. |
| Batch (constructor, create with clearinghouse/date/file name) | `public Batch(IRepositoryFactory factory, IUserProfileService prof, EbillBatchTypeCode type, EbillClearinghouse clearinghouse, IEbillingQueryProvider ebillingQueryProvider, DateTime submissionDate, string fileName)` | Creates a new batch tied to `clearinghouse` with status `"NEW"` and adds it to the repository ([DOM-BR-090](../../business-rules.md#dom-br-090-batch-create)). |
| Batch (constructor, create with clearinghouse only) | `public Batch(IRepositoryFactory factory, IUserProfileService prof, EbillBatchTypeCode type, EbillClearinghouse clearinghouse, IEbillingQueryProvider ebillingQueryProvider)` | Creates a new batch tied to `clearinghouse`, defaulting the submission date to now and the file name to `null`, with status `"NEW"` ([DOM-BR-090](../../business-rules.md#dom-br-090-batch-create)). |
| Batch (constructor by id) | `public Batch(IRepositoryFactory factory, IUserProfileService prof, IEbillingQueryProvider ebillingQueryProvider, long batchId)` | Loads an existing batch by `batchId`. |
| Batch (constructor by id and clearinghouse) | `public Batch(IRepositoryFactory factory, IUserProfileService prof, EbillClearinghouse clearinghouse, IEbillingQueryProvider ebillingQueryProvider, long batchId)` | Loads an existing batch by `batchId`, scoped to `clearinghouse`. |
| Batch (constructor by type/status) | `public Batch(IRepositoryFactory factory, IUserProfileService prof, IEbillingQueryProvider ebillingQueryProvider, string batchType, string batchStatus)` | Loads the first batch matching `batchType` and `batchStatus`. |
| Batch (constructor by type/status/clearinghouse) | `public Batch(IRepositoryFactory factory, IUserProfileService prof, string batchType, string batchStatus, EbillClearinghouse clearinghouse, IEbillingQueryProvider ebillingQueryProvider)` | Loads the first batch matching `batchType`/`batchStatus`, scoped to `clearinghouse`. |
| Data | `public EbillBatch Data { get; }` | Exposes the underlying `EbillBatch` entity. |
| GetBatch (IUnitOfWork overload) | `public static Batch GetBatch(IUnitOfWork unitOfWork, IUserProfileService profileService, string batchType, string batchStatus, EbillClearinghouse clearinghouse, IEbillingQueryProvider ebillingQueryProvider, long batchId = 0)` | Retrieves a batch by ID (when `batchId > 0`) or by type/status/clearinghouse otherwise, validating existence and that status/type match, else throwing `InvalidBatchException` ([DOM-BR-091](../../business-rules.md#dom-br-091-getbatch)). |
| GetBatch (IRepositoryFactory overload) | `public static Batch GetBatch(IRepositoryFactory factory, IUserProfileService profileService, IEbillingQueryProvider ebillingQueryProvider, string batchType, string batchStatus, long batchId)` | The same retrieve-and-validate behaviour as the `IUnitOfWork` overload, using an `IRepositoryFactory` and without clearinghouse scoping ([DOM-BR-091](../../business-rules.md#dom-br-091-getbatch)). |
| SetBatchToCompleted | `public void SetBatchToCompleted()` | Sets the batch status to `"COMP"` and stamps the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). |
| SetBatchToExtracted | `public void SetBatchToExtracted()` | Sets the batch status to `"EXTR"` and stamps the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). |
| SetBatchToImaged | `public void SetBatchToImaged()` | Sets the batch status to `"IMAGE"` and stamps the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). |
| SetBatchToIndexed | `public void SetBatchToIndexed()` | Sets the batch status to `"INDEX"` and stamps the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). |
| SetBatchToEobDistributed | `public void SetBatchToEobDistributed()` | Sets the batch status to `"EOB"` and stamps the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). |
| SetBatchToDocumentLoad | `public void SetBatchToDocumentLoad()` | Sets the batch status to `"DLOAD"` and stamps the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). |
| SetBatchToAcknowledged | `public void SetBatchToAcknowledged()` | Sets the batch status to `"ACK"` and stamps the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). |
| SetBatchToSetup | `public void SetBatchToSetup()` | Sets the batch status to `"SETUP"` and stamps the update date/user ([DOM-BR-092](../../business-rules.md#dom-br-092-status-set)). |
| SetResponseBatch | `public void SetResponseBatch(EbillBatch responseBatch)` | Links `responseBatch` as this batch's response batch (used by 277 response processing, [OP-DOM-11](../../operations-processes.md#op-dom-11)) and stamps the update date/user. |

## Inherited public members

Members in this section are inherited from `DomainBase<TItem>` in `SAIF.Domain`. They are available on this type through inheritance (via the intermediate `DomainRepositoryBase<TItem>` base).

| Member | Signature | Purpose | Origin |
| --- | --- | --- | --- |
| HasData | `public virtual bool HasData { get; }` | Reports whether the wrapped `EbillBatch` entity is present, evaluated as `!DataItem.IsNull()`. | `SAIF.Domain` — `DomainBase<TItem>` |

## Behavioral notes
- The class carries a source-code comment about injecting the query provider, indicating the current design of passing `IEbillingQueryProvider` into every constructor is considered a refactor candidate*.
- Both `GetBatch` overloads validate status and type in that order and throw on the first mismatch, so a batch that fails both checks reports only the status mismatch message*.

## Constraints and usage notes
- Every status setter (`SetBatchTo*`) resolves its target `EbillBatchStatusCode` through `_ebillingQueryProvider.BatchQueries.GetBatchStatus`, so an unrecognized status string passed indirectly through configuration would surface as a query-provider failure rather than a compile-time error.

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts.

## Sources
- `Domain/SAIF.Domain/Model/Claims/Ebilling/Batch.cs`
- `Domain/SAIF.Domain/DomainBase.cs`
- `Domain/SAIF.Domain/DomainRepositoryBase.cs`
