Build the X12 envelope hierarchy¶
EdiFile.RefreshGroupings and EdiGroupParser convert the flat segment list produced by Parse EDI text into segments and elements into the X12 envelope hierarchy: interchange header/trailer, then functional groups, transaction sets, hierarchical transactions, and hierarchical levels.
| Field | Value |
|---|---|
| Operation ID | OP-08 |
| Trigger | SetSegments, Add of a control segment, or first access to EdiFile.FunctionalGroups. |
| Inputs | Flat segment list. |
| Outputs | IFunctionalGroupContainer tree. |
| Primary components | EdiFile.RefreshGroupings, EdiGroupParser |
| Entry point | Common\SAIF.Common.Files\Edi\EdiFile.cs, Common\SAIF.Common.Files\Edi\Core\Parsers\EdiGroupParser.cs |
Steps¶
RefreshGroupingslocates the firstISAsegment and parses it intoIsaSegment(Header), and the firstIEAintoIeaSegment(Trailer) (BR-029).- Functional groups are (re)built only when
ISA,IEA,GSandGEare all present (BR-030). - If not all present: skip group construction;
EdiFile.FunctionalGroupsremains unbuilt. EdiFile.Add(segment)assignssegment.Index = IndexingSequence.NextValue(delegatedSequence), appends it, and re-runsRefreshGroupingswhen the segment idIsIn("ISA","IEA","GS","GE")(delegated:SAIF.Framework.Common→IEnumerableExtensions.IsIn) (BR-031, BR-032).CreateFunctionalGroupscallsParseSegmentGroup(file.Segments, "GS", 6)— eachGSstarts a group keyed on element 6 (group control number); header = firstGS, trailer = lastGE; memberSegmentsexcludeISA/IEA/GS/GE(BR-033, BR-034).CreateTransactionSetscallsParseSegmentGroup(fg.Segments, "ST", 2)— key is element 2 (transaction set control number); headerST, trailerSE; members excludeST/SE(BR-033).CreateHierarchialTransactionscallsParseSegmentGroup(ts.Segments, "BHT", 1), parses theBHTintoBhtSegment, then partitions the remainder withParseSegmentGroup(htc, "BHT", "HL", 1)and buildsHierarchialLevelobjects from eachHL(key element 1), excludingHL/ST/SEfrom level members (BR-033, BR-035).ParseSegmentGroup(parentGroup, segmentId, keyElement)creates oneSegmentGroupper matching segment, then moves every segment between that segment's index + 1 and the index before the next occurrence (or the last segment index) into the group viaMoveSegmentsToSegmentGroup.- Helper lookups
GetNext,GetFirstInRange,GetLastInRange,FindInRangeall operate onIndexordering and return0when nothing matches (BR-036). EdiFile.FunctionalGroupslazily caches the result ofCreateFunctionalGroupson first access.
Process flow¶
flowchart TD
Start([RefreshGroupings triggered]) --> HeaderTrailer["Locate first ISA (Header)<br>and IEA (Trailer)"]
HeaderTrailer --> Check{"ISA, IEA, GS, GE all present?"}
Check -->|No| Stop([FunctionalGroups left unbuilt])
Check -->|Yes| FG["CreateFunctionalGroups<br>ParseSegmentGroup(GS, element 6)"]
FG --> TS["CreateTransactionSets<br>ParseSegmentGroup(ST, element 2)"]
TS --> HT["CreateHierarchialTransactions<br>ParseSegmentGroup(BHT, element 1)"]
HT --> HL["Partition HL segments into<br>HierarchialLevel objects"]
HL --> EndOk([IFunctionalGroupContainer tree])
Failure and edge-case behavior¶
- Missing any of
ISA/IEA/GS/GE: the interchange still exposes its flatSegmentscollection, butFunctionalGroupsis not built and no exception is raised (BR-030). ParseSegmentGroup'sGetNext/GetFirstInRange/GetLastInRange/FindInRangehelpers return0rather than a sentinel/null when no matching segment exists, so a malformed interchange with unmatched control segments can silently produce an empty or misaligned group rather than an error (BR-036).*EdiGroupParser.ParseSegmentGroup(parentGroup, segmentId, segmentEndId, maxCount, segmentGroupKeyElement)(the 5-parameter overload) is unreachable as implemented: its loop guard compares the group count against a negatedmaxCount, so it always breaks after the first group; the overload has no caller in this library.*
Related documentation¶
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\EdiFile.cs
- Common\SAIF.Common.Files\Edi\Core\Parsers\EdiGroupParser.cs
- Common\SAIF.Common.Files\Edi\Segments\IsaSegment.cs
- Common\SAIF.Common.Files\Edi\Segments\IeaSegment.cs
- Common\SAIF.Common.Files\Edi\Segments\GsSegment.cs
- Common\SAIF.Common.Files\Edi\Segments\GeSegment.cs
- Common\SAIF.Common.Files\Edi\Segments\StSegment.cs
- Common\SAIF.Common.Files\Edi\Segments\SeSegment.cs
- Common\SAIF.Common.Files\Edi\Segments\BhtSegment.cs
- Common\SAIF.Common.Files\Edi\Segments\HlSegment.cs
- Common\SAIF.Common\Extensions\IEnumerableExtensions.cs