---
title: "SQL-001: AuditNote insert (CbpNote)"
summary: Inserts a new CbpNote row when an audit note is created directly rather than attached to a parent bill.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Domain
reference_type: package
---

# SQL-001: AuditNote insert (CbpNote)

The `AuditNote` constructor persists a new audit note by explicitly adding a `CbpNote` entity to the repository. This path is used when a note is created directly rather than attached through a parent `Bill`/`CbpBill` collection.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-001 |
| **Operation type** | Create |
| **Execution method** | ORM (IRepository.Add) |
| **Database** | Oracle* |
| **Schema** | [unqualified]** |
| **Command type** | N/A — ORM (NHibernate generates SQL at runtime from the ClassMaps in `Data/SAIF.Data.NHibernate/Mappings/**`) |
| **Business object** | `AuditNote` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `AuditNote` |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [CBP_NOTE](../database-tables.md#cbp_note) | INSERT | `CBP_NOTE_SEQ_NUM`, `UPDATE_NUM`, `ACTIVE_FLAG`, `CREATE_DATE`, `CREATE_USER`, `UPDATE_DATE`, `UPDATE_USER`, `NOTE_TXT`, `CLAIM_ID`, `NOTE_TYPE_CODE`, `NOTE_CATEGORY_CODE`, `BILL_ID` |

## LINQ statement

Source: `Domain/SAIF.Domain/Model/Claims/Bills/Notes/AuditNote.cs:52`

```csharp
// Domain/SAIF.Domain/Model/Claims/Bills/Notes/AuditNote.cs:37-44
DataItem = new CbpNote
{
    NoteText = noteArguments.NoteText,
    NoteType = type,
    IsActive = noteArguments.IsActive,
    CreateDate = DateTime.Now,
    CreateUser = noteArguments.CurrentUser
};

// Domain/SAIF.Domain/Model/Claims/Bills/Notes/AuditNote.cs:49-53
if (noteArguments.CategoryCode == "C")
{
    DataItem.ClaimId = noteArguments.ClaimId;
    Factory.GetRepository<CbpNote>().Add(DataItem);
}
```

## Sample SQL

> **Inferred SQL:** This SQL was inferred from the LINQ statement above and the NHibernate mappings. It is not concrete SQL from source code; NHibernate generates the executed statement at runtime, so aliases, column order, join syntax, and bind-parameter names may differ.

```sql
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
SELECT CBP_NOTE_SEQ.NEXTVAL
FROM DUAL

INSERT INTO CBP_NOTE (
  CBP_NOTE_SEQ_NUM,
  UPDATE_NUM,
  ACTIVE_FLAG,
  CREATE_DATE,
  CREATE_USER,
  UPDATE_DATE,
  UPDATE_USER,
  NOTE_TXT,
  CLAIM_ID,
  NOTE_TYPE_CODE,
  NOTE_CATEGORY_CODE,
  BILL_ID)
VALUES (
  :Id,
  :UpdateNumber,
  :IsActive,
  :CreateDate,
  :CreateUser,
  :UpdateDate,
  :UpdateUser,
  :NoteText,
  :ClaimId,
  :NoteTypeCode,
  :NoteTypeCategory,
  :Bill)
```

Translation notes:
- `:Id` is the value fetched from `CBP_NOTE_SEQ` (`GeneratedBy.Native("CBP_NOTE_SEQ")` on Oracle).
- `:UpdateNumber` is the initial version value NHibernate seeds on insert (version column mapped with `Version(...)`).
- `:IsActive` is bound as `'Y'`/`'N'` (`YesNoType`).
- `:NoteTypeCode` / `:NoteTypeCategory` are the two composite-key parts of the referenced `CbpNoteTypeCode` (`CbpNoteTypeCodeMap.cs:14-16`: `CODE`, `CBP_NOTE_CATEGORY_CODE`), bound to `NOTE_TYPE_CODE` / `NOTE_CATEGORY_CODE`.
- Path applies only when `noteArguments.CategoryCode == "C"`; `:ClaimId` is set from `noteArguments.ClaimId` and `:Bill` is NULL.
- Reading `NoteType` via `GetNoteTypeCode(...)` (line 33) is a separate query in a query provider, not part of this SQL ID.

## Operations and processes
- OP-DOM-15 AuditNote — attaches the note by category and inserts `CbpNote` (see [Operations and processes](../operations-processes.md))

## Business rules
- [DOM-BR-150](../business-rules.md#dom-br-150-note-create)

> **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
- Domain/SAIF.Domain/Model/Claims/Bills/Notes/AuditNote.cs
