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

# File837Extractor

`File837Extractor` parses an inbound HIPAA 837 EDI file (version constant `"1.7"`) into e-bill entities through a segment state machine, and is the entry point for operation OP-DOM-10: it validates the ISA date against the batch submission date, walks NM1/N3/N4, PRV, REF, PWK, and LIN segments per bill, applies pharmacy-detection and truncation rules, and persists the resulting `Ebill`/bill/service/document structures through the repository. The class holds its working state (`_queryProvider`, `_profileService`, current provider/address/patient/e-bill/service, and parsed NPIs) in private `static` fields across a single `ProcessFile` call, so it is not safe for concurrent use across overlapping calls*.

## Purpose
- Drives the full 837-to-e-bill extraction for a batch, validating the ISA date against the batch submission date and failing the file when segment ordering or required data is missing or invalid ([DOM-BR-100](../../business-rules.md#dom-br-100-837-parse) through [DOM-BR-108](../../business-rules.md#dom-br-108-837-parse)).
- Applies per-bill parsing rules: NM1/N3/N4 address ordering, PRV "BI" billing-provider defaults, recognized REF qualifiers, required PWK documents, LIN qualifier validation, pharmacy-bill detection, and service-code truncation.
- Exposes segment-container traversal helpers (`GetClaims`, `GetPatients`, `GetProviders`) and drug/segment predicate helpers (`AreAllServicesCompoundDrugs`, `SegmentExists`, `AllServicesArePharmacy`) that the main parse loop and callers use to navigate the parsed 837 structure.

## Context
- Namespace: `SAIF.Domain.Claims.Ebilling`
- Assembly/package: `SAIF.Domain` (`Domain/SAIF.Domain/SAIF.Domain.csproj`, .NET Framework 4.6.2 class library)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| Version | `public const string Version = "1.7"` | Identifies the 837-extraction logic version this class implements. |
| ProcessFile | `public static bool ProcessFile(IEbillingQueryProvider ebillingQueryProvider, IUserProfileService userProfileService, IEdiFile file, Batch batch, ILogWriter controlLog)` | Parses the given 837 file against the batch, validating the ISA date ([DOM-BR-100](../../business-rules.md#dom-br-100-837-parse)) and applying the per-segment rules ([DOM-BR-101](../../business-rules.md#dom-br-101-837-parse)–[DOM-BR-108](../../business-rules.md#dom-br-108-837-parse)) while persisting the resulting e-bill structures*, returning whether the file processed successfully. |
| AreAllServicesCompoundDrugs | `public static bool AreAllServicesCompoundDrugs(IList<EbillService> billServices)` | Reports whether every service in the list is a compound drug, used to decide pharmacy-specific handling. |
| CreateEbillAddress | `public static EbillAddress CreateEbillAddress(string nameType, N3Segment n3Segment, N4Segment n4Segment)` | Builds an `EbillAddress` from a parsed N3/N4 segment pair for the given address role (physical, payment, or facility). |
| SegmentExists | `public static bool SegmentExists(IEnumerable<IEdiSegment> file, IEdiSegment currentSegment, string segmentType)` | Reports whether a segment of the given type exists in the file relative to the current parse position, used to validate expected segment ordering such as N4 following N3 ([DOM-BR-103](../../business-rules.md#dom-br-103-837-parse)). |
| AllServicesArePharmacy | `public static bool AllServicesArePharmacy(IEnumerable<IEdiSegment> file, IEdiSegment billSegment)` | Reports whether every LX service line under the bill has a LIN segment, which for transaction set 005010X222A1 marks the bill as pharmacy ([DOM-BR-107](../../business-rules.md#dom-br-107-837-parse)). |
| ProcessNameSegment | `public static void ProcessNameSegment(Nm1Segment nameSegment, EbillProvider provider, EbillService service, EbillPatient patient)` | Applies an NM1 name segment to the correct target (facility/provider, service, or patient) based on the segment's entity-identifier code*. |
| GetClaims | `public static ISegmentGroupContainer GetClaims(ISegmentGroup patient)` | Returns the claim-level segment group nested under a patient segment group. |
| GetPatients | `public static ISegmentGroupContainer GetPatients(ISegmentGroup provider)` | Returns the patient-level segment group nested under a provider segment group. |
| GetProviders | `public static ISegmentGroupContainer GetProviders(ISegmentGroup transactionSet)` | Returns the provider-level segment group nested under a transaction-set segment group. |

## Behavioral notes
- The class keeps its working state in private `static` fields that are overwritten and read across the whole `ProcessFile` call, so two files must not be processed concurrently on the same process*.
- PRV "BI" provider segments default `TaxId` to `999999999` and truncate taxonomy to 10 characters when the source data does not supply them ([DOM-BR-104](../../business-rules.md#dom-br-104-837-parse)).
- One code path inside `ProcessFile` throws `NotImplementedException` for a case the parser does not yet handle*.
- Persisting the parsed e-bill, bill, service, and document structures through the repository is inferred from the presence of repository calls in `ProcessFile`; the exact insert sequence was not traced line by line*.

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

## Sources
- `Domain/SAIF.Domain/Claims/Ebilling/File837Extractor.cs`
