Features and itemids

See Features and itemid maps for how presets and maps fit into a BigQuery load.

Feature presets

class ehr2rl.data.FeaturePreset(name, concepts, aggregation='1h')

A named set of canonical concepts to use as state features.

Parameters:
  • name (str) – Preset name, recorded in provenance.

  • concepts (tuple[str, ...]) – Canonical concept names. Each must exist in the itemid map.

  • aggregation (str) – Intended time resolution. Not currently applied: BigQuery states use each distinct chart time.

resolve(itemid_map)

Map each concept to its itemid entries.

Parameters:

itemid_map (ItemIdMap) – Map to look the concepts up in.

Returns:

Entries for each concept, in preset order.

Return type:

dict[str, list[ItemIdEntry]]

Raises:

EHRValidationError – If a concept is missing from the map.

ehr2rl.data.get_feature_preset(name)

Return a built-in feature preset by name.

Parameters:

name (str) – "vitals_only", "sepsis3_core", or "full".

Raises:

EHRValidationError – If the name is unknown.

Return type:

FeaturePreset

Itemid maps

class ehr2rl.data.itemid_maps.ItemIdEntry(itemid, source, unit=None, label=None, conversion=None)

One raw MIMIC-IV itemid mapped to a canonical concept.

Parameters:
  • itemid (int) – MIMIC-IV itemid.

  • source (Literal['chartevents', 'labevents', 'inputevents']) – Table the itemid comes from: "chartevents", "labevents", or "inputevents".

  • unit (str | None) – Recorded unit, for reference.

  • label (str | None) – Expected label in d_items or d_labitems, checked by validate_itemid_map when set.

  • conversion (str | None) – Name of an intended unit conversion. Informational only; not applied.

class ehr2rl.data.itemid_maps.ItemIdMap(version, concepts)

A versioned mapping from canonical concepts to raw itemids.

Parameters:
  • version (str) – Map version, such as "v3_1", recorded in provenance.

  • concepts (dict[str, list[ItemIdEntry]]) – Itemid entries for each concept name.

ehr2rl.data.itemid_maps.load_itemid_map(version='v3_1', path=None)

Load a built-in or user-supplied itemid map.

Map files are JSON with a version string and a concepts object that maps each concept name to a list of entries with ItemIdEntry fields.

Parameters:
  • version (str) – Built-in map to load. Only "v3_1" ships with the package.

  • path (str | Path | None) – A map file to load instead. version is ignored when it is given.

Raises:

EHRValidationError – If version names no built-in map.

Return type:

ItemIdMap

ehr2rl.data.itemid_maps.validate_itemid_map(itemid_map, labels)

Check every itemid in a map against live MIMIC-IV labels.

Labels are compared case-insensitively with whitespace collapsed. Entries without an expected label only need to exist.

Parameters:
  • itemid_map (ItemIdMap) – Map to check. Every concept is checked, not only those in a preset.

  • labels (DataFrame) – Rows from d_items and d_labitems with itemid and label columns.

Raises:

EHRValidationError – If labels lacks a required column, an itemid is missing, or a label differs.

Return type:

None