Skip to main content

row_utils

Best-effort pd.Series row-value helpers shared across step identity building.

Pure extraction helpers used by criteria_matching (build_subject_identity) and patient_level_eligibility (build_ehr_lookup) to pull identity fields and MRN(s) from a row without each re-implementing the same NaN/list-like coercion. No I/O.

Module​

Functions​

as_str​

def as_str(value: Any | None) ‑> str | None:

Stringify a non-null value, or return None.

Arguments

  • value: The value to stringify.

Returns The string form, or None.

first_present​

def first_present(row: pd.Series[Any], columns: tuple[str, ...]) ‑> Any:

Return the first non-NA value among columns on row, or None.

A list-like value (list/tuple/ndarray/Series — a multi-valued field) is returned whole; pd.isna is only consulted for scalars, since on an array it returns an array whose truth value is ambiguous.

Arguments

  • row: The DataFrame row.
  • columns: Candidate column names in priority order.

Returns The first present value, or None.

mrns_from_row​

def mrns_from_row(row: pd.Series[Any]) ‑> list[str]:

Extract the patient's MRN(s) from a row, best-effort (never NaN).

A list-like value yields one MRN per non-NA element; a scalar becomes a single-item list; NaN/None/missing all yield [].

Arguments

  • row: The DataFrame row.

Returns The MRN(s) found on the row, or [].