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

# GenerateCbpBills

`GenerateCbpBills` builds the internal CBP (`CbpBill`) representation of an indexed e-bill (operation OP-DOM-06): it derives the bill type, statement dates, worker identification, priority/rebill flags, per-service codes/quantities/tooth codes/service locations, and procedure/diagnosis lists, persists the new records through `IRepositoryFactory`/`IUnitOfWork`, and finally marks the e-bill CbpSetup. It resolves service and location codes by delegating to `ServiceCodeManager`/`IServiceCodeManager` rather than duplicating that lookup logic.

## Purpose
- Translates an indexed `Ebill` and its services into a `CbpBill` with associated services, procedures, and diagnoses, applying the bill-type, date, worker, and flag rules used by downstream CBP processing ([DOM-BR-050](../../business-rules.md#dom-br-050-cbp-generation) through [DOM-BR-064](../../business-rules.md#dom-br-064-cbp-generation)).
- Inserts the generated `CbpBill` and its child records via the repository factory, and sets the e-bill status to CbpSetup once generation completes ([DOM-BR-063](../../business-rules.md#dom-br-063-complete)).
- Provides standalone helper methods (service code selection, tooth-number validation, service-type-code derivation, service-location derivation, e-bill type derivation) that the main `Generate` method composes and that other Ebilling code can also call directly.

## Context
- Namespace: `SAIF.Domain.Claims.Ebilling`
- Assembly/package: `SAIF.Domain` (`Domain/SAIF.Domain/SAIF.Domain.csproj`, .NET Framework 4.6.2 class library)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| Generate | `public static GenerateCBPBillsResults Generate(IUnitOfWork uow, Ebill bill, string currentUser, IEbillingQueryProvider ebillingQueryProvider, IErrorConditionHandler errorConditionHandler, ILogWriter controlReport, GenerateCBPBillsResults billResults, IServiceCodeManager serviceCodeManager, ICCClaimApiService ccclaimApiService)` | Builds and inserts the `CbpBill` (type, dates, worker data, priority/rebill flags), its services, procedures, and diagnoses for the given e-bill, then sets the e-bill status to CbpSetup ([DOM-BR-050](../../business-rules.md#dom-br-050-cbp-generation)–[DOM-BR-063](../../business-rules.md#dom-br-063-complete)). |
| GetCbpProviderServiceCode | `public static string GetCbpProviderServiceCode(string natinalDrugCode, string revenueCode, string serviceCode)` | Chooses the code to bill for a non-institutional service: the NDC when present, otherwise the revenue code, otherwise the service code ([DOM-BR-056](../../business-rules.md#dom-br-056-cbp-generation)). |
| GetCbpProviderServiceCodeForInstitutional | `public static string GetCbpProviderServiceCodeForInstitutional(string revenueCode, string serviceCode)` | Chooses the code to bill for an institutional service: the revenue code when present, otherwise the service code ([DOM-BR-056](../../business-rules.md#dom-br-056-cbp-generation)). |
| GetServiceLocationForInstitutionalServiceLine | `public static string GetServiceLocationForInstitutionalServiceLine(CbpBill cbpBill)` | Derives the service-location code for an institutional bill, distinguishing inpatient from outpatient ([DOM-BR-060](../../business-rules.md#dom-br-060-cbp-generation)). |
| DetermineServiceLocationCode | `public static string DetermineServiceLocationCode(Ebill ebill, CbpBill cbpBill)` | Derives the service-location code for a bill, using the institutional inpatient/outpatient rule when applicable and otherwise taking it from `UbBillTypeCode` ([DOM-BR-060](../../business-rules.md#dom-br-060-cbp-generation)). |
| GetToothNumber | `public static decimal? GetToothNumber(string toothCode, string billServiceTypeCode, IErrorConditionHandler errorConditionHandler, EbillService service)` | Validates and returns the tooth number for a dental ("D") service, recording a bill-service error when the tooth code is invalid ([DOM-BR-059](../../business-rules.md#dom-br-059-cbp-generation)). |
| GetCbpBillServiceTypeCode | `public static string GetCbpBillServiceTypeCode(EbillService service, IEbillingQueryProvider ebillingQueryProvider, IErrorConditionHandler errorConditionHandler, string serviceTypeCode)` | Returns the CBP service type code (P/D/R/serviceType/U) for a service and flags an invalid National Drug Code as an error condition ([DOM-BR-064](../../business-rules.md#dom-br-064-cbp-generation)). |
| GetEbillType | `public static string GetEbillType(IEbillingQueryProvider ebillingQueryProvider, Ebill bill)` | Derives the e-bill type code: `I` for an institutional bill with a resolvable place of service, `O` for institutional without one, otherwise `S` ([DOM-BR-050](../../business-rules.md#dom-br-050-cbp-generation)). |

## Behavioral notes
- `Generate` de-duplicates diagnosis codes and only sets diagnosis pointers on Standard-type bills ([DOM-BR-061](../../business-rules.md#dom-br-061-cbp-generation)); other bill types are built without pointers.
- Worker tax IDs equal to `999999999` are nulled and 9-digit tax IDs are reformatted to `xxx-xx-xxxx` as part of `Generate`'s worker-data step ([DOM-BR-053](../../business-rules.md#dom-br-053-cbp-generation)).
- `GetCbpBillServiceTypeCode` and `GetServiceCode`-style resolution ultimately call into `ServiceCodeManager`/`IServiceCodeManager` for code lookups rather than querying `IEbillingQueryProvider` directly for service codes.

## Sources
- `Domain/SAIF.Domain/Claims/Ebilling/GenerateCBPBills.cs`
