# Load X12 837 claims into Apache Iceberg and query them from Snowflake

**You can turn raw X12 837 EDI claim files into governed Apache
Iceberg tables that Snowflake queries directly — without a claims
clearinghouse, custom parsers, or your PHI leaving your environment.**
Lakewright detects 837 files by their envelope structure, extracts
claim records with HIPAA-standard segment handling, flags PHI columns,
and lands approved tables in Iceberg that Snowflake reads as external
Iceberg tables.

## What is an X12 837 file?
The HIPAA-mandated EDI format for healthcare claims (837P
professional, 837I institutional, 837D dental). Wire format: ISA/GS
envelopes, segment-delimited records, no column headers — unreadable
to standard ETL tools expecting CSV or JSON.

## How does detection work?
By evidence, not file extensions: the ISA fixed-width envelope, the
GS functional group, and the ST transaction-set code (837) identify
the file; the implementation guide version rides in the envelope.
Claim loops become rows; service lines flatten with their parent
claim keys.

## What about PHI?
Patient identifiers are flagged at scan time and the proposed plan
defaults them to masked or keyed-hash columns. The transformation
happens at load, in your VPC — the raw values never land in the
warehouse, and no third-party processor touches the file (no BAA
required for the pipeline itself).

## The steps
```bash
lakewright scan  s3://claims-drop          # inventory + PHI report
lakewright plan  s3://claims-drop --out plans
lakewright approve plans/claims_837.plan.yaml   # human gate
lakewright load  plans/claims_837.plan.yaml --rest $ICEBERG_CATALOG
```
Snowflake then reads the table via an Iceberg external volume +
catalog integration — no copy, no ingestion job on the Snowflake side.

## FAQ
**Does this replace a clearinghouse?** No — it lands the analytical
copy. Adjudication stays where it is; analytics stops waiting on it.
**835 remittances too?** Yes — same pipeline, and claim/remit tables
share key columns for denial-rate joins.
**Do I need X12 dictionaries/licenses?** No. Detection and extraction
derive from the public envelope/segment structure.
