The mcr_data_loader Module

class MedicareDataLoader(context)[source]

MedicareDataLoader is a specialized subclass of DataLoader that handles ingestion of raw Medicare CMS files accompanied by FTS (File Transfer Summary) metadata.

This loader is designed to read data using file specifications included in FTS files provided by ResDAC. It supports fixed-width (.dat) raw data files where metadata is embedded in a parallel .fts file.

Functional Responsibilities: - Resolves (.fts) File Transfer Summary files to their corresponding data (.dat) files - Parses FTS files using MedicareFTS - Creates an FWFReader for reading fixed-width data using inferred column schema - Integrates with the context-configurable data loading pipeline via DataLoader

Attributes:

context (LoaderConfig): Configuration object carrying paths and settings for ingestion.

Example Usage:

loader = MedicareDataLoader(context) loader.run()

See Also:

Initializes a MedicareDataLoader with the given context.

Parameters:

context – A configuration object used by the data loading pipeline.

classmethod dat4fts(fts_path)[source]

Given a path to an FTS metadata file, finds all matching .dat data files.

The .dat files are expected to match the FTS filename prefix.

Parameters:

fts_path – Path to a .fts metadata file.

Returns:

List[str]: List of full paths to .dat files that correspond to the FTS file.

classmethod open(name: str, dat_path: Optional[str] = None) FWFReader[source]

Opens a fixed-width reader for a Medicare file using both the FTS (metadata) and .dat (data) input files.

Given either a .fts or .dat path (or the base file name), this method builds the appropriate pairing of FTS and DAT files, parses the metadata, and returns a FWFReader for iterating over the structured data rows.

Parameters:
  • name – Path to either the .fts or .dat file, or a base file path without extension.

  • dat_path – If provided, explicitly sets .dat file path to use.

Returns:

A reader instance for parsing the structured fixed-width file.

Raises: AssertionError: If provided file has an invalid or unsupported extension. ValueError: If file type cannot be determined from file name.

get_files() List[Tuple[Any, Callable]][source]

Resolves all FTS-to-DAT file pairs from the configured context data path, and returns a list of reader objects paired with file-open functions.

This function provides the loading pipeline with all reader instances needed to load fixed-width Medicare data records.

Returns:

A list of reader/open-function pairs for streaming data.