﻿---
title: "PolicyOutputDocumentRepository"
summary: API reference for PolicyOutputDocumentRepository
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data.NHibernate
reference_type: package
---


# PolicyOutputDocumentRepository

`PolicyOutputDocumentRepository` is the `RepositoryBase<PolicyOutputDocument>` implementation behind agency document delivery: it eager-fetches `OutputDocument`/`DocumentType`, `Policy`/`SubmissionPolicies`, and `Policy`/`RelationshipPolicy` for every read, and composes the query-scoping extension methods on `PolicyOutputDocumentExtensions` (documented separately) to answer agency-inbox, released/held/pending, and parent/child document queries. Agency-visibility scoping (`AgencyViewable`, `AgencyInboxViewable`, category/producer/agency filters) restricts results by caller-supplied ids that are not independently validated against the current user at this layer (DLA-SDN-03, [Security and authorization](../../security-authorization.md)).

## Purpose
- Retrieve policy output documents by id, source key text, or image id, and enumerate unreleased documents prior to a release date.
- Serve agency document-inbox queries with an `Unread`/`All`/`Deleted` filter, per [SDN-BR-060](../../business-rules.md#sdn-br-060-agency-inbox%3A-unread-%3D-not-viewed-and-not-agency-deleted).
- Restrict agency-facing queries to released, agency-viewable documents (or held/pending variants for specific views), per [SDN-BR-061](../../business-rules.md#sdn-br-061-agencies-see-only-released%2C-agency-viewable-documents).
- Detect duplicate documents before creation (`CheckDocumentExist`) and return a released parent document's agency-viewable children, enforcing that the parent is released ([SDN-BR-063](../../business-rules.md#sdn-br-063-child-documents-are-returned-only-for-a-released-parent)).

## Context
- Namespace: `SAIF.Data.NHibernate.Repositories.OutputDocuments`
- Assembly/package: `SAIF.Data.NHibernate` (ships inside the `SAIF.SAIFCode.Core` NuGet package)
- Base class: `RepositoryBase<PolicyOutputDocument>` from `SAIF.Framework.Data.NHibernate` (external, resolved via Legends CLI — see Inherited public members below).
- Implements: `IPolicyOutputDocumentRepository`, defined in `SAIF.Data.Interfaces.Repositories.OutputDocuments`.
- Collaborator: this type composes filter methods from [PolicyOutputDocumentExtensions](PolicyOutputDocumentExtensions.md), declared in the same source file.

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| PolicyOutputDocumentRepository(NHibernateUnitOfWork) | `public PolicyOutputDocumentRepository(NHibernateUnitOfWork uow)` | Constructor; passes `uow` to the `RepositoryBase<PolicyOutputDocument>` base and retains it (as `_uow`) to obtain the `Policy` repository in `GetAccountNumber`. |
| GetUnReleasedDocumentsPriorToDate | `public IEnumerable<PolicyOutputDocument> GetUnReleasedDocumentsPriorToDate(DateTime releaseDate)` | Returns eager-loaded documents in `Pending` status whose `OutputDocument.DocumentDate` is before `releaseDate`, ordered by policy number then id ([SQL-036](../../sql/SQL-036-policy-output-document-repository-get-un-released-documents-prior-to-date.md)). |
| GetPolicyOutputDocument | `public PolicyOutputDocument GetPolicyOutputDocument(long documentId)` | Returns the `PolicyOutputDocument` for `documentId` via the inherited `Get(object id)`, or `null` if not found ([SQL-037](../../sql/SQL-037-policy-output-document-repository-get-policy-output-document.md)). |
| GetPolicyOutputDocumentsBySourceKeyText | `public IEnumerable<PolicyOutputDocument> GetPolicyOutputDocumentsBySourceKeyText(string sourceKeyText)` | Returns eager-loaded documents whose `OutputDocument.PolicyOutputDocument.SourceKeyText` equals `sourceKeyText` ([SQL-038](../../sql/SQL-038-policy-output-document-repository-get-policy-output-documents-by-source-key-text.md)). |
| GetPolicyOutputDocumentsByImageId | `public IEnumerable<PolicyOutputDocument> GetPolicyOutputDocumentsByImageId(long imageId)` | Returns eager-loaded documents whose `OutputDocument.ImageId` equals `imageId` ([SQL-039](../../sql/SQL-039-policy-output-document-repository-get-policy-output-documents-by-image-id.md)). |
| GetHeldDocumentsForNotification | `public IEnumerable<PolicyOutputDocument> GetHeldDocumentsForNotification()` | Returns documents in `Held` status where `HoldTaskId` is null and `TaskUser` is not null — i.e. held documents awaiting a notification task to be created ([SQL-040](../../sql/SQL-040-policy-output-document-repository-get-held-documents-for-notification.md)). |
| GetReleasedAgencyViewablePolicyOutputDocuments (long) | `public IEnumerable<PolicyOutputDocument> GetReleasedAgencyViewablePolicyOutputDocuments(long policyNumber)` | Returns eager-loaded, released, agency-viewable documents for the policy number or its account ([SDN-BR-061](../../business-rules.md#sdn-br-061-agencies-see-only-released%2C-agency-viewable-documents), [SQL-041](../../sql/SQL-041-policy-output-document-repository-get-released-agency-viewable-policy-output-documents.md)). |
| GetReleasedAgencyViewablePolicyOutputDocuments (long, string) | `public IEnumerable<PolicyOutputDocument> GetReleasedAgencyViewablePolicyOutputDocuments(long policyNumber, string documentCategory)` | Same as the single-parameter overload, additionally filtered to `documentCategory` via `ForCategory` (blank/"ALL" means no filter, [SDN-BR-062](../../business-rules.md#sdn-br-062-category-%22all%22-or-blank-means-no-filter)) ([SQL-041](../../sql/SQL-041-policy-output-document-repository-get-released-agency-viewable-policy-output-documents.md)). |
| GetHeldAndPendingAgencyViewablePolicyOutputDocuments | `public IEnumerable<PolicyOutputDocument> GetHeldAndPendingAgencyViewablePolicyOutputDocuments(long policyNumber)` | Resolves the policy's account number, then returns eager-loaded, agency-viewable documents in `Held` or `Pending` status for the policy or account ([SQL-042](../../sql/SQL-042-policy-output-document-repository-get-held-and-pending-agency-viewable-policy-output-documents.md)). |
| GetPolicyOutputDocumentsForInbox (4-arg) | `public IEnumerable<PolicyOutputDocument> GetPolicyOutputDocumentsForInbox(ShowOnlyDocuments showOnlyDocuments, DateTime releaseDate, long agencyId)` | Returns agency-inbox-viewable, released-on-or-after, agency-scoped documents, with `showOnlyDocuments` selecting `NonViewed`+`NotAgencyDeleted` (`Unread`, and the default case), `NotAgencyDeleted` only (`All`), or `AgencyDeleted` (`Deleted`) ([SDN-BR-060](../../business-rules.md#sdn-br-060-agency-inbox%3A-unread-%3D-not-viewed-and-not-agency-deleted), [SQL-043](../../sql/SQL-043-policy-output-document-repository-get-policy-output-documents-for-inbox.md)). |
| GetPolicyOutputDocumentsForInbox (5-arg) | `public IEnumerable<PolicyOutputDocument> GetPolicyOutputDocumentsForInbox(ShowOnlyDocuments showOnlyDocuments, DateTime releaseDate, long agencyId, long producerId)` | Same as the 4-argument overload, additionally filtered to `producerId` via `ForProducer` ([SQL-043](../../sql/SQL-043-policy-output-document-repository-get-policy-output-documents-for-inbox.md)). |
| GetPolicyOutputDocuments | `public IEnumerable<PolicyOutputDocument> GetPolicyOutputDocuments(long policyNumber, DateTime documentDate, DateTime releaseDate)` | Returns released, agency-viewable documents for the policy/account matching both `documentDate` and `releaseDate` exactly ([SQL-044](../../sql/SQL-044-policy-output-document-repository-get-policy-output-documents.md)). |
| CheckDocumentExist | `public bool CheckDocumentExist(PolicyOutputDocument document, string documentTypeCode)` | Returns `true` if a released document already exists for the same relationship-policy number, `PolicyPeriodEffectiveDate`, `documentTypeCode`, `ReleaseDate`, and `OutputDocument.DocumentDate` as `document` — used to prevent duplicate document creation ([SQL-045](../../sql/SQL-045-policy-output-document-repository-check-document-exist.md)). |
| GetReleasedAgencyViewableChildOutputDocuments | `public IEnumerable<PolicyOutputDocument> GetReleasedAgencyViewableChildOutputDocuments(PolicyOutputDocument doc)` | Returns agency-viewable, released child documents of `doc`'s relationship-policy, matching `doc`'s release date and document date; throws `Exception("Document does not is released!")` if `doc.ReleaseDate` is null ([SDN-BR-063](../../business-rules.md#sdn-br-063-child-documents-are-returned-only-for-a-released-parent), [SQL-046](../../sql/SQL-046-policy-output-document-repository-get-released-agency-viewable-child-output-documents.md)). |

## Inherited public members

Members in this section are inherited from `RepositoryBase<PolicyOutputDocument>` in `SAIF.Framework.Data.NHibernate`. They are available on this type through inheritance.

| Member | Signature | Purpose | Origin |
| --- | --- | --- | --- |
| Add | `public void Add(PolicyOutputDocument entity)` | Registers a new `PolicyOutputDocument` entity for insertion on the next unit-of-work commit.† | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<PolicyOutputDocument>` |
| Update | `public void Update(PolicyOutputDocument entity)` | Marks an existing `PolicyOutputDocument` entity as modified for the next unit-of-work commit.† | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<PolicyOutputDocument>` |
| Delete | `public void Delete(PolicyOutputDocument entity)` | Registers a `PolicyOutputDocument` entity for deletion on the next unit-of-work commit.† | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<PolicyOutputDocument>` |
| Query | `public IQueryable<PolicyOutputDocument> Query()` | Returns a LINQ-queryable session projection over `PolicyOutputDocument`, used as the basis for `EagerLoadQuery()` and every filtered query above.† | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<PolicyOutputDocument>` |
| Get | `public PolicyOutputDocument Get(object id)` | Loads a `PolicyOutputDocument` by primary key, returning `null` if not found; used directly by `GetPolicyOutputDocument`.† | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<PolicyOutputDocument>` |
| Load | `public PolicyOutputDocument Load(object id)` | Loads a `PolicyOutputDocument` by primary key as a (possibly proxied) reference, throwing if not found.† | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<PolicyOutputDocument>` |
| SystemDate | `public DateTime SystemDate { get; }` | Current system date/time as tracked by the underlying session/unit of work.† | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<PolicyOutputDocument>` |

## Behavioral notes
- All read methods share a common eager-fetch shape (`OutputDocument`â†’`DocumentType`, `Policy`â†’`SubmissionPolicies`, `Policy`â†’`RelationshipPolicy`) via the private `EagerLoadQuery()` helper, so N+1 query patterns are avoided for these navigation paths*.
- Several methods resolve an "account number" for the policy (`GetAccountNumber`, a private helper over the injected `NHibernateUnitOfWork`'s `Policy` repository) so that documents scoped to either the specific policy or its account are both returned ([SQL-047](../../sql/SQL-047-policy-output-document-repository-get-account-number.md)).
- `agencyId`/`producerId`/`policyNumber` parameters are accepted from the caller and used directly to scope the query; there is no check here that the current user is actually authorized for that agency/producer/policy (DLA-SDN-03, [Security and authorization](../../security-authorization.md)).
- `GetReleasedAgencyViewableChildOutputDocuments` throws a bare `Exception` (not a more specific type) when the parent document is not released, which callers must catch by type `Exception` rather than a narrower exception type*.

## Constraints and usage notes
- `GetReleasedAgencyViewableChildOutputDocuments` requires `doc.ReleaseDate.HasValue`; pass only already-released parent documents.
- The agency/producer/category filters composed here duplicate filter logic also present in SAIF.Data's own `PolicyOutputDocumentExtensions` (SD-BR-070/072) — see [SDN-BR-061](../../business-rules.md#sdn-br-061-agencies-see-only-released%2C-agency-viewable-documents) for the duplication note.

> **Note:** Statements marked with `†` are derived from dependency library
> documentation via the Legends CLI. Statements marked with `*` were inferred
> from code structure or contextual evidence. Statements marked with `**` could
> not be confirmed; treat as unknown until verified.

## Related documentation
- [Index](../../index.md)
- [Overview](../../overview.md)
- [Architecture](../../architecture.md)
- [Dependencies](../../dependencies.md)
- [Operations and processes](../../operations-processes.md)
- [Business rules](../../business-rules.md)
- [Database tables](../../database-tables.md)
- [SQL catalog](../../sql/index.md)
- [Procedures](../../procedures/index.md)
- [Security and authorization](../../security-authorization.md)
- [API reference](../index.md)

## Sources
- `Data/SAIF.Data.NHibernate/Repositories/OutputDocuments/PolicyOutputDocumentRepository.cs`
