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,
mask: Optional[Mask] = None,
) -> Result
Parses a whole file: indexes every segment, runs the loop engine, the
structure 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. With mask, the
patient data of the tables and diagnostics is hidden.
parse_file ¶
parse_file(
path: Union[str, "os.PathLike[str]"],
spec: Optional[Spec] = None,
delimiters: Optional[Delimiters] = None,
mask: Optional[Mask] = 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,
mask: Optional[Mask] = 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. With mask, the patient data of every batch is hidden.
Mask ¶
Hides the patient data of a parse: the columns the spec flags as patient data are replaced by keyed tokens or shifted dates, and the diagnostics that quote them are masked the same way. The same key always gives the same token, so rows still join on it; without the key the originals cannot be recovered.
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.