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

# BillQueryService

Executes bill search, inbox, and explanation-of-benefits queries against `CbpBill` data, applying claim-security filtering via `ClaimUserSecurityAccess` and enriching results with data fetched from Guidewire's `IClaimDataApiClient` and `IFinancialDataApiClient`. It depends on `IUnitOfWork` for repository access, `IUserProfileService` for the acting user's identity and security context, `IDocumentService` to render the EOB PDF, `IClaimInformationService` for security-override checks, and several query providers (`IBillQueryProvider`, `IClaimQueryProvider`, `IAuditNoteQueryProvider`, `IWorkerQueryProvider`) plus `ICCClaimApiService` used when constructing the domain `Bill` for EOB generation.

## Purpose
- Searches bills by flexible criteria (bill ID, check number, claim number, status, type, provider, date ranges), filtering out results the current user is not authorized to see due to claim restriction conflicts.
- Searches "bill entry" queue bills by a distinct set of entry-oriented criteria (provider tax ID, provider location, worker tax ID, received-date ranges), applying the same conflict-based security filter.
- Searches bills by responsible-party mail ID for an inbox view, optionally including items not yet due for review.
- Generates an Explanation of Benefits document as a PDF for a given bill.

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

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| BillQueryService (constructor) | `public BillQueryService(IUnitOfWork unitOfWork, IUserProfileService profileService, IDocumentService document, IClaimInformationService claimInfo, IBillQueryProvider billQueryProvider, IClaimQueryProvider claimQueryProvider, IAuditNoteQueryProvider auditNoteQueryProvider, IWorkerQueryProvider workerQueryProvider, ICCClaimApiService claimApiService, IClaimDataApiClient gwClaimDataApiClient, IFinancialDataApiClient gwFinancialDataApiClient)` | Wires the unit of work, user-profile, document, claim-information, and query-provider/API-client collaborators used by all search and EOB operations. |
| SearchByCriteria | `public SearchResult SearchByCriteria(SearchCriteria criteria)` | Runs a filtered bill search (excluding pending/disallowed statuses), pages results to 300 items, cross-checks each bill's claim against Guidewire claim data, drops claims the caller cannot access due to a restriction conflict, and attaches the associated check number to each result item. |
| GetBillEntryBillsByCriteria | `public SearchResult GetBillEntryBillsByCriteria(BillEntrySearchCriteria criteria)` | Runs a bill-entry-focused search (by provider, worker, claim number, or received-date range), pages results to 300 items, filters out bills tied to a worker-conflicted claim unless the caller has conflict access or a recorded security override, and attaches the associated check number to each result. |
| SearchByResponsiblePartyId | `public InboxResult SearchByResponsiblePartyId(string responsiblePartyId, bool displayAll)` | Returns bills currently assigned to the given responsible-party mail ID, restricted by default to items due for review on or before today (`displayAll` disables that date filter), excluding claims the caller cannot access, and includes the responsible party's display name. |
| GetExplanationOfBenefits | `public MemoryStream GetExplanationOfBenefits(long billId)` | Builds the domain `Bill`'s EOB XML and renders it through `IDocumentService` as a PDF, returning the generated document as an in-memory stream. |

## Behavioral notes
- Applies claim-level security by constructing `ClaimUserSecurityAccess` from the current user and checking `HasConflict` before exposing a claim's bill data, hiding conflicted items and flagging the result as `SecurityFiltered`.
- Calls the Guidewire `IClaimDataApiClient.GetClaims`/`IFinancialDataApiClient.GetPaymentsByInvoiceNumber`/`GetBillDetailsForCheckNumber` synchronously via `.GetAwaiter().GetResult()`, blocking on what are otherwise asynchronous external API calls.*
- Truncates check-number lookups and claim ID batches to prevent exceeding the Oracle `IN`-clause limit (explicitly documented in code as avoiding `ORA-01795`).
- A static constructor calls `BillMappingHelper.MapBillQueryService()`, registering AutoMapper mappings once per process.
- `GetExplanationOfBenefits` constructs a new domain `Bill` object directly (bypassing the query providers used elsewhere for search) to generate EOB XML.*

## Constraints and usage notes
- `SearchByCriteria` and `GetBillEntryBillsByCriteria` cap returned rows at 300/299 respectively and set `MoreItemsExist` when the underlying query exceeds that page size; callers must narrow criteria to retrieve additional results.
- Constructor null-checks are only applied to `unitOfWork`, `profileService`, `document`, and `claimInfo`; the remaining query-provider/API-client parameters are not validated for null.*

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- `Services/SAIF.Services/Claims/Bills/BillQueryService.cs`
