Actions¶
See Medication actions for how doses are aggregated and binned.
- class ehr2rl.actions.ActionConfig(vasopressor_bins, fluid_bins, timestep='1h', status_include=('FinishedRunning', 'Changed'))¶
Configuration for medication-derived actions.
- Parameters:
vasopressor_bins (
DoseBins) – Bins for norepinephrine-equivalent dose in mcg/kg/min.fluid_bins (
DoseBins) – Bins for IV fluid volume in mL per timestep.timestep (
str) – Aggregation window, as a pandas frequency string.status_include (
tuple[str,...]) –statusdescriptionvalues to keep. Other rows are ignored.
- class ehr2rl.actions.DoseBins(edges, labels=None)¶
Assign continuous dose values to integer bins.
Bin 0 is reserved for exactly zero or lower values. Positive values are assigned with
numpy.searchsorted(..., side="right")so edge values fall into the higher bin.- Parameters:
- Raises:
ValueError – If
edgesis empty or unsorted, orlabelshas the wrong length.
- ehr2rl.actions.build_medication_actions(inputevents, timestamps, *, config)¶
Build
(vasopressor_bin, fluid_bin)actions aligned to state timesteps.Vasopressor exposure is aggregated with max norepinephrine-equivalent dose per timestep so short high-intensity infusion intervals are not diluted. Fluid exposure is allocated by overlap duration when an event spans multiple timesteps, so one recorded amount is not counted in full more than once.
- Parameters:
inputevents (
DataFrame) – Rows withstarttime,endtime,itemid,rate, andamount, and optionallyrateuom,patientweight, andstatusdescription.timestamps (
ndarray) – Shape(T,). State times in Unix seconds.config (
ActionConfig) – Bins and aggregation settings.
- Returns:
Shape
(T, 2)integer array of(vasopressor_bin, fluid_bin).- Return type:
- Raises:
ValueError – If a vasopressor row’s rate unit cannot be converted.
Norepinephrine equivalents¶
- class ehr2rl.actions.VasopressorConversion(name, itemids, factor, rate_unit='mcg/kg/min')¶
Conversion factor for norepinephrine-equivalent dose.
- ehr2rl.actions.DEFAULT_NEE_CONVERSIONS¶
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.
If the argument is a tuple, the return value is the same object.
- ehr2rl.actions.norepinephrine_equivalent(row, conversions=(VasopressorConversion(name='norepinephrine', itemids=(221906,), factor=1.0, rate_unit='mcg/kg/min'), VasopressorConversion(name='epinephrine', itemids=(221289,), factor=1.0, rate_unit='mcg/kg/min'), VasopressorConversion(name='vasopressin', itemids=(222315,), factor=2.5, rate_unit='units/min'), VasopressorConversion(name='phenylephrine', itemids=(221749,), factor=0.1, rate_unit='mcg/kg/min'), VasopressorConversion(name='dopamine', itemids=(221662,), factor=0.01, rate_unit='mcg/kg/min')))¶
Return norepinephrine-equivalent dose for an inputevents row.
The row’s
rateuomis converted to the conversion’srate_unitbeforefactoris applied. Rows withoutrateuomare assumed to already be inrate_unit.- Parameters:
row (
Series) – One inputevents row withitemidandrate, and optionallyrateuomandpatientweight.conversions (
Iterable[VasopressorConversion]) – Conversions to matchitemidagainst.
- Returns:
Dose in norepinephrine mcg/kg/min.
0.0for non-vasopressor rows and rows without a numeric rate.- Return type:
- Raises:
ValueError – If a vasopressor row’s unit cannot be converted, or a per-minute rate has no positive
patientweight. This is raised rather than returning a dose in the wrong unit.