---
title: HlSegment
summary: API reference for HlSegment.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common.Files
reference_type: package
---

# HlSegment

`HlSegment` models the X12 HL hierarchical level segment, used throughout 837 claim transactions to establish parent/child loop relationships (e.g. billing provider → subscriber → patient). Its child-level indicator can be supplied either as an explicit code or derived from a boolean flag, and `Fill()` recomputes that flag strictly from whether the code equals `"1"` ([BR-052](../../business-rules.md#br-052-hl-child-level-indicator)).

## Purpose
- Represents the HL segment identity via `SegmentId` returning the literal `"HL"` ([BR-020](../../business-rules.md#br-020-first-element-is-the-segment-identifier)).
- Carries `IdNumber` and `ParentIdNumber` establishing this level's position in the hierarchy, plus `LevelCode` classifying the level's loop type.
- Reports whether the level has children via element 4: an explicit `ChildCode` when supplied, otherwise `"1"`/`"0"` derived from `ChildExists` ([BR-052](../../business-rules.md#br-052-hl-child-level-indicator)).
- On `Fill()`, sets `ChildExists` to true only when the parsed `ChildCode` equals `"1"` ([BR-052](../../business-rules.md#br-052-hl-child-level-indicator)).

## Context
- Namespace: `SAIF.Common.Files.Edi.Segments`
- Assembly/package: `SAIF.Framework.Common.Files`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| SegmentId | `string SegmentId { get; }` | Returns the literal X12 segment identifier `"HL"`. |
| IdNumber | `int IdNumber { get; set; }` | This hierarchical level's own identifier (HL01), element 1. |
| ParentIdNumber | `int? ParentIdNumber { get; set; }` | The identifier of this level's parent in the hierarchy (HL02), element 2. |
| LevelCode | `string LevelCode { get; set; }` | The code classifying this level's loop type (HL03), element 3. |
| ChildCode | `string ChildCode { get; set; }` | An explicit child-level indicator string (HL04); when set, takes precedence over `ChildExists` on `Build()` ([BR-052](../../business-rules.md#br-052-hl-child-level-indicator)). |
| ChildExists | `bool? ChildExists { get; set; }` | Whether this level has child levels; used to derive `"1"`/`"0"` for element 4 when `ChildCode` is null, and recomputed on `Fill()` as `ChildCode == "1"` ([BR-052](../../business-rules.md#br-052-hl-child-level-indicator)). |
| Build | `IEdiSegment Build()` | Creates a `SegmentBuilder("HL")`, adds `IdNumber`, `ParentIdNumber`, and `LevelCode` at elements 1-3, then adds element 4 as `ChildCode` if set, else as `"1"`/`"0"` from `ChildExists` if set, else omits it, returning the built segment ([BR-052](../../business-rules.md#br-052-hl-child-level-indicator)). |
| Fill | `void Fill(IEdiSegment segment)` | Parses elements 1-2 as `int` via `int.TryParse`, reads `LevelCode` and `ChildCode` at elements 3-4, and sets `ChildExists` to `(ChildCode == "1")` ([BR-052](../../business-rules.md#br-052-hl-child-level-indicator)). |
| Parse | `static HlSegment Parse(IEdiSegment segment)` | Instantiates a new `HlSegment`, calls `Fill(segment)` on it, and returns it. |

## Behavioral notes
- `Fill()` sets `ChildExists` to false (not null) whenever `ChildCode` is anything other than `"1"`, including when the segment carries no element 4 at all, since `GetChildValue` returns an empty string rather than null in that case*.

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts.

## Sources
- Common\SAIF.Common.Files\Edi\Segments\HlSegment.cs
