Parsing and results¶
Read a file into a Result: the document, the tables and the diagnostics. See
Reading for the guide.
parse ¶
parse(
data: Buffer,
spec: Optional[Spec] = None,
delimiters: Optional[Delimiters] = None,
) -> Result
Parses a whole file: indexes every segment, runs the loop engine, the
envelope checker and the projector, and returns the document, the
tables and every diagnostic. Without spec, the built-in spec of the
version the file declares is used, else the default one.
parse_file ¶
parse_file(
path: Union[str, "os.PathLike[str]"],
spec: Optional[Spec] = None,
delimiters: Optional[Delimiters] = None,
) -> Result
Reads the file at path in binary mode and parses it.
stream ¶
stream(
data: Buffer,
spec: Optional[Spec] = None,
by: str = "transaction",
delimiters: Optional[Delimiters] = None,
) -> Stream
Walks a file and yields a batch each time an instance of loop by
closes, and one more at the end when anything is left. Without spec,
the built-in spec of the version the file declares is used, else the
default one.
Stream ¶
Iterates the batches of a file. Each step runs with the GIL released.
A stream must be advanced from one thread at a time: a next() that finds
another thread inside a step raises a RuntimeError naming the stream;
unlike a generator, it does not raise ValueError.
Batch ¶
Result ¶
What one parse produced.
spec
property
¶
spec: Spec
The spec that projected the tables: the one given, or the built-in selected from the file's version.
payer
property
¶
payer: dict[str, str | None] | None
The payer organization from the payer_* columns of payments, or
None when the file has none.
payee
property
¶
payee: dict[str, str | None] | None
The payee organization from the payee_* columns of payments, or
None when the file has none.
count_patients ¶
count_patients() -> builtins.int
The distinct non-null values of claims.patient_id. Ids are text:
0123 and 123 are two patients, where edi-835-parser reads both as
the number 123 and counts one.
sum_payments ¶
sum_payments() -> decimal.Decimal
The sum of payments.total_payment_amount, as a Decimal at the
column's scale.
Tables ¶
The tables of one parse or one batch, by name. Shared, never copied.
Table ¶
One projected table. Shares the tables it belongs to.
to_polars ¶
to_polars() -> polars.DataFrame
The table as a polars DataFrame, through the Arrow capsule.
__arrow_c_stream__ ¶
__arrow_c_stream__(
requested_schema: object | None = None,
) -> typing_extensions.CapsuleType
Exports the table as an Arrow stream of one record batch, sharing
the column buffers. requested_schema is ignored, as the protocol
allows: the table keeps its own types.
__arrow_c_array__ ¶
__arrow_c_array__(
requested_schema: object | None = None,
) -> builtins.tuple[
typing_extensions.CapsuleType,
typing_extensions.CapsuleType,
]
Exports the table as one Arrow struct array and its schema, sharing
the column buffers. requested_schema is ignored, as the protocol
allows.
__arrow_c_schema__ ¶
__arrow_c_schema__() -> typing_extensions.CapsuleType
Exports the table's schema.
Document ¶
Segment ¶
One segment of a document, read from the document on access.
elements
property
¶
elements: list[bytes | list[bytes]]
The elements in X12 order (elements[0] is XX01): bytes for a
simple element, a list of bytes for a composite one.
span
property
¶
span: tuple[int, int]
The segment's byte range in the input, (start, end) with end
exclusive: leading trivia, body and terminator, as raw holds them.
Delimiters ¶
The five delimiters of an interchange.
repetition
property
¶
repetition: Optional[bytes]
The repetition separator, or None when the file has none.
__new__ ¶
__new__(
element: bytes = b"*",
component: bytes = b":",
segment: bytes = b"~",
repetition: Optional[bytes] = None,
release: Optional[bytes] = None,
) -> Delimiters
Each delimiter is one byte. element, component and segment default to
*, : and ~; repetition and release default to None (not in use).
Raises ValueError for a value that is not exactly one byte.
ParseError ¶
Bases: ValueError
Input that cannot be indexed: its delimiters cannot be read or it exceeds the size limit; the message says what was found and where.