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

# NoteService

Manages the lifecycle of audit notes attached to claims and bills — retrieval, creation, editing, deletion, and bulk inactivation — validating each write through `IValidationService` and persisting changes via the `AuditNote` domain aggregate inside `IUnitOfWork` transactions. It collaborates with `IUserProfileService` (to stamp the current user on writes), `IBillQueryProvider`, `IAuditNoteQueryProvider`, and `IClaimQueryProvider`, and maps data-model results to `AuditNoteItem`/`NoteTypeCode`/`NoteCategory` contracts via AutoMapper, whose note-related mappings it registers in its static constructor via `BillMappingHelper.MapNoteService()`.

## Purpose
- Retrieves audit notes for a single note, a claim, or a bill, with an option to include inactive notes.
- Determines whether a bill's most recent note activity was performed by a different user than the one specified.
- Validates and creates new audit notes for both general and bill-scoped scenarios, surfacing validation failures to callers.
- Validates and applies edits to existing audit notes.
- Validates and deletes audit notes, individually or via a bulk comma-separated ID list that marks notes inactive instead of removing them.
- Retrieves the catalog of note type and note category codes usable when authoring notes.

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

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| NoteService(uow, uprof, val, query, noteQuery, claimQueryProvider) | `NoteService(IUnitOfWork uow, IUserProfileService uprof, IValidationService val, IBillQueryProvider query, IAuditNoteQueryProvider noteQuery, IClaimQueryProvider claimQueryProvider)` | Guards against null core dependencies (unit of work, user profile service, validation service, bill/note query providers) and stores them for use by all note operations. |
| GetNote | `AuditNoteItem GetNote(long noteId)` | Retrieves the audit note with the given ID and maps it to an `AuditNoteItem` contract. |
| GetClaimNotes | `IEnumerable<AuditNoteItem> GetClaimNotes(long claimId, bool showInactiveToo)` | Retrieves all audit notes for a claim, optionally including inactive ones, mapped to `AuditNoteItem` contracts. |
| GetBillNotes | `IEnumerable<AuditNoteItem> GetBillNotes(long claimId, long billId, bool showInactiveToo)` | Queries `CbpNote` records matching either the claim ID or the bill ID under the requested active/inactive filter, orders them by note-type category description then descending create date, and maps them to `AuditNoteItem` contracts. |
| IsBillNoteByOtherUser | `bool IsBillNoteByOtherUser(long claimId, long billId, string userId, bool showInactiveToo)` | Returns `true` if any matching bill note's last-updating user (or creating user, if never updated) differs from `userId`, restricted to notes matching the requested active/inactive state. |
| GetAuditNoteTypeCodes() | `IEnumerable<NoteTypeCode> GetAuditNoteTypeCodes()` | Retrieves the full set of note type codes, mapped to `NoteTypeCode` contracts. |
| GetAuditNoteTypeCodes(categoryCode) | `IEnumerable<NoteTypeCode> GetAuditNoteTypeCodes(string categoryCode)` | Retrieves the note type codes belonging to a specific note category, mapped to `NoteTypeCode` contracts. |
| CreateNote | `AuditNoteItem CreateNote(long billId, Note note, IMessageContainer messageContainer)` | Builds a bill-scoped `NoteModifyRequest` (forcing the bill note category/type constants), validates it, reports any validation errors to `messageContainer`, and returns the newly created note or an empty `AuditNoteItem` if validation failed. |
| CreateAuditNote | `IValidationResult CreateAuditNote(NoteModifyRequest request)` | Validates the request and, if valid, creates the underlying `AuditNote` aggregate and appends the new note's ID to the validation result's `Messages` collection. |
| UpdateNote | `AuditNoteItem UpdateNote(Note note, IMessageContainer messageContainer)` | Rebuilds a `NoteModifyRequest` from the existing note's current values, validates it, reports errors to `messageContainer`, applies the update if valid, and returns the refreshed note. |
| EditAuditNote | `IValidationResult EditAuditNote(NoteModifyRequest request)` | Validates the request and, if valid, applies the update to the corresponding `AuditNote` aggregate. |
| GetAuditNoteCategoryCodes | `IEnumerable<NoteCategory> GetAuditNoteCategoryCodes()` | Retrieves all `CbpNoteCategoryCode` records and maps them to `NoteCategory` contracts. |
| DeleteNote | `void DeleteNote(long noteId)` | Deletes the `AuditNote` aggregate identified by `noteId` within a unit-of-work transaction. |
| DeleteAuditNote | `IValidationResult DeleteAuditNote(NoteDeleteRequest request)` | Validates the delete request and, if valid, deletes the corresponding `AuditNote` aggregate within a transaction. |
| InactivateNotes | `void InactivateNotes(string ids)` | Splits a comma-separated list of note IDs and, within a single transaction, marks each corresponding note inactive while stamping the current user, update date, and incrementing its update counter. |

## Behavioral notes
- Static constructor calls `BillMappingHelper.MapNoteService()` to register AutoMapper mappings for note-related types before any instance is used.*
- All mutating operations (`CreateNote`/`CreateAuditNote`, `UpdateNote`/`EditAuditNote`, `DeleteNote`/`DeleteAuditNote`, `InactivateNotes`) wrap their changes in `unitOfWork.Begin()`/`unitOfWork.Commit()` transactions.
- Write operations validate their request via `IValidationService` before applying any change; validation failures are surfaced either through the supplied `IMessageContainer` or the returned `IValidationResult`, and no persistence occurs when validation fails.
- The current-user identity used for audit stamping is obtained via `userProfileService.GetCurrentUser().UserId`, upper-cased, on every create/update/inactivate path.
- `CreateNote(billId, note, messageContainer)` hardcodes the note's category/type to `NoteModifyRequest.BILL_NOTE_CATEGORY`/`BILL_NOTE_TYPE` and always sets `UpdateNumber` to `0`, marking it as a bill-note-specific creation path distinct from `CreateAuditNote`.*
- `InactivateNotes` mutates note fields directly on the entities returned by `noteQueryProvider.GetAuditNote(id)` rather than going through the `AuditNote` aggregate used by the other write paths.*

## Constraints and usage notes
- `GetBillNotes`'s active/inactive filter logic is `x.IsActive || x.IsActive != showInactiveToo`, so callers should verify the exact inclusion semantics against a specific `showInactiveToo` value before relying on it.*
- `InactivateNotes` silently skips any ID in the list for which `noteQueryProvider.GetAuditNote(id)` returns `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/NoteService.cs`
