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

# DocumentImageManager

Implements `IDocumentImageManager` as the per-bill orchestrator of the imaging workflow: for every not-yet-imaged bill in a batch it validates the on-disk files, images the primary bill document first, groups and images the remaining documents by type, notifies about new-claim documents by email, and updates bill/document/batch status. It coordinates `IDocumentFileService` for file validation/movement, `IDocumentManagementService` for data access and status transitions, and `IEmailService` for new-claim notifications, all under `IUnitOfWork` transactions.

## Purpose
- Validates that the on-disk document files for a batch match its non-imaged document records before imaging begins (`ImageDocuments`, via `IDocumentFileService.ValidateDocuments`).
- Sends a new-claim notification email and logs a patient note before imaging when a bill's documents indicate a new (unmatched) claim (`ProcessNewClaimDocument`, `CreateNewDocumentNote`, `SendNewClaimEmail`).
- Images the bill's primary ("B"-type) document individually, then images its remaining documents grouped by document type — as a single upload per document if there is only one of that type, or as a merged multi-document upload otherwise (`ImageBillDocument`, `ImageDocumentsByType`, `ImageSingleDocument`).
- Records the resulting image ID against every document imaged in a request (`UpdateDocumentImageSequenceNumber`).
- Fails fast with an `ApplicationException` if the imaging API returns a zero image ID (`ThrowExceptionIfZero`).
- Transitions bill and batch status to document-load after imaging completes (`UpdateBillStatus`, `UpdateBatchStatus`).

## Context
- Namespace: `SAIF.Services.Claims.Ebilling.Imaging`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| DocumentImageManager | `public DocumentImageManager(IUnitOfWork unitOfWork, IDocumentManagementService documentManagementService, IEmailService emailService, IDocumentFileService fileService)` | Wires the unit-of-work, document-management service, email service, and document file service used to drive the imaging workflow. |
| ImageDocuments | `public ImageResults ImageDocuments(ImageDocumentsRequest request, ILogWriter controlReport)` | Validates the batch's document files, then images every not-yet-imaged bill's documents (bill document first, then by type), updating bill status per bill and batch status at the end; wraps per-bill failures in an exception naming the bill ID. |
| UpdateBatchStatus | `public void UpdateBatchStatus(long batchId)` | Transitions the batch to document-load status within a unit-of-work transaction. |
| UpdateBillStatus | `public void UpdateBillStatus(long billId)` | Transitions a bill to document-load status within a unit-of-work transaction. |
| UpdateDocumentImageSequenceNumber | `public void UpdateDocumentImageSequenceNumber(long documentId, long imageId)` | Stamps a document's assigned image ID within a unit-of-work transaction. |
| SendNewClaimEmail | `public void SendNewClaimEmail(long documentId, string fileName, string newClaimEmailAddress)` | Builds and sends the new-claim notification email for an unmatched-claim document via `IEmailService`. |
| CreateNewDocumentNote | `public void CreateNewDocumentNote(long billId)` | Logs a patient error note for a new/unmatched claim document within a unit-of-work transaction. |
| ThrowExceptionIfZero | `public void ThrowExceptionIfZero(long imageId)` | Throws an `ApplicationException` reporting that the imaging API returned zero when the given image ID is `0`. |

## Behavioral notes
- Each status-mutating call (`UpdateBatchStatus`, `UpdateBillStatus`, `UpdateDocumentImageSequenceNumber`, `CreateNewDocumentNote`) opens and commits its own `IUnitOfWork` transaction rather than sharing one transaction across the whole batch.
- `ImageDocuments` treats an exception from any single bill's processing as fatal to the whole run, re-wrapping it with the bill ID and rethrowing rather than continuing with the next bill.
- Documents of a single type are imaged individually; multiple documents of the same type are merged into one combined image via `IDocumentManagementService.ImageDocuments`.

## Sources
- Services/SAIF.Services/Claims/EBilling/Imaging/DocumentManager.cs
