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

# LegalNodeBuilder

Builds a `LegalNode` describing a claim's open legal cases by combining case data from `ILegalService.GetCaseList`, schedule/attorney/firm details from `ILegalQueryProvider`, and directory lookups via `IUserProfileService`. For each non-closed legal case it attaches mediation schedule info, an "Unassigned"/"None" placeholder case number when appropriate, assigned SAIF attorney and legal-assistant/secretary contacts, outside-counsel firm/attorney details, and hearing schedule info depending on the case's most recent schedule type.

## Purpose
- Retrieves the claim's non-closed legal cases and represents each as a `LegalCaseNode` with case number and status.
- Attaches the most recent mediation schedule (type code "MED" or "FMED") to a case when present.
- Normalizes case numbering: uses "None" for pre-litigation cases without a case number, and "Unassigned" when no schedule exists or the case is appellate.
- Resolves and attaches assigned SAIF attorney, their legal-assistant secretary, outside counsel firm/attorney, and secretary-for-outside-counsel details based on the case's most recent schedule.
- Attaches hearing date/time/status when the most recent schedule type is "HEAR".
- Produces a standalone "Legal" alert item (`AlertNode`) when the legal query provider reports an image alert is needed for the claim.

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

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| Node | `public LegalNode Node { get; }` | Exposes the node instance, whose `Cases` collection is initialized as an empty list in the constructor. |
| LegalNodeBuilder(claim, profile, query, legalService) | `public LegalNodeBuilder(Claim claim, IUserProfileService profile, ILegalQueryProvider query, ILegalService legalService)` | Stores dependencies and initializes `Node` with an empty `Cases` list. |
| AddLegalNode() | `public LegalNodeBuilder AddLegalNode()` | Iterates the claim's non-closed legal cases, attaching mediation, case-number placeholders, attorney/secretary, outside-counsel, and hearing details to each resulting `LegalCaseNode`, and appends each to `Node.Cases`. |
| AddLegalAlertItem() | `public AlertNode AddLegalAlertItem()` | Returns an `AlertNode` with `ContactType = "Legal"` and `UserId = "{LEGAL}"` when `ILegalQueryProvider.IsImageAlertNeeded` is true for the claim; otherwise returns `null`. |

## Behavioral notes
- `AddLegalNode()` skips cases whose `CaseStatus` equals `"Closed"` entirely.
- Attorney assignment is only attempted when `AssignedAttorneyEmployeeId` is non-empty, and the corresponding secretary is only attached when the profile's `SecretaryEmployeeId` resolves to a directory user with a last name.
- Outside-firm assignment is only attempted when `AssignedOtherFirmId > 0`.

## Constraints and usage notes
- `AddLegalAlertItem()` can return `null`; callers (e.g. `ClaimInformationApiService.BuildClaimAlertsNode`) must null-check before adding it to a result collection.
- Legal case ordering for "most recent" schedules relies on `Schedules.OrderBy(x => x.Id).LastOrDefault(...)`/`MostRecentSchedule`, so schedule identity ordering must correlate with chronological recency for correct behavior.*

> **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/Information/Api/LegalNodeBuilder.cs
