Table Classes¶
Patient¶
clifpy.tables.patient.Patient
¶
Bases: BaseTable
Patient table wrapper inheriting from BaseTable.
This class handles patient-specific data and validations while leveraging the common functionality provided by BaseTable.
Initialize the patient table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_directory
|
str
|
Path to the directory containing data files |
None
|
filetype
|
str
|
Type of data file (csv, parquet, etc.) |
None
|
timezone
|
str
|
Timezone for datetime columns |
'UTC'
|
output_directory
|
str
|
Directory for saving output files and logs |
None
|
data
|
DataFrame
|
Pre-loaded data to use instead of loading from file |
None
|
Source code in clifpy/tables/patient.py
ADT (Admission, Discharge, Transfer)¶
clifpy.tables.adt.Adt
¶
Bases: BaseTable
ADT (Admission/Discharge/Transfer) table wrapper inheriting from BaseTable.
This class handles ADT-specific data and validations while leveraging the common functionality provided by BaseTable.
Initialize the ADT table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_directory
|
str
|
Path to the directory containing data files |
None
|
filetype
|
str
|
Type of data file (csv, parquet, etc.) |
None
|
timezone
|
str
|
Timezone for datetime columns |
'UTC'
|
output_directory
|
str
|
Directory for saving output files and logs |
None
|
data
|
DataFrame
|
Pre-loaded data to use instead of loading from file |
None
|
Source code in clifpy/tables/adt.py
filter_by_date_range
¶
Return records within a specific date range for a given datetime column.
Source code in clifpy/tables/adt.py
filter_by_hospitalization
¶
Return all ADT records for a specific hospitalization.
Source code in clifpy/tables/adt.py
filter_by_location_category
¶
Return all records for a specific location category (e.g., 'icu', 'ward').
Source code in clifpy/tables/adt.py
get_hospital_types
¶
Return unique hospital types in the dataset.
get_location_categories
¶
Return unique location categories in the dataset.
get_summary_stats
¶
Return summary statistics for the ADT data.
Source code in clifpy/tables/adt.py
Hospitalization¶
clifpy.tables.hospitalization.Hospitalization
¶
Hospitalization(
data_directory=None,
filetype=None,
timezone="UTC",
output_directory=None,
data=None,
)
Bases: BaseTable
Hospitalization table wrapper inheriting from BaseTable.
This class handles hospitalization-specific data and validations while leveraging the common functionality provided by BaseTable.
Initialize the hospitalization table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_directory
|
str
|
Path to the directory containing data files |
None
|
filetype
|
str
|
Type of data file (csv, parquet, etc.) |
None
|
timezone
|
str
|
Timezone for datetime columns |
'UTC'
|
output_directory
|
str
|
Directory for saving output files and logs |
None
|
data
|
DataFrame
|
Pre-loaded data to use instead of loading from file |
None
|
Source code in clifpy/tables/hospitalization.py
calculate_length_of_stay
¶
Calculate length of stay for each hospitalization and return DataFrame with LOS column.
Source code in clifpy/tables/hospitalization.py
get_mortality_rate
¶
Calculate in-hospital mortality rate.
Source code in clifpy/tables/hospitalization.py
get_patient_hospitalization_counts
¶
Return DataFrame with hospitalization counts per patient.
Source code in clifpy/tables/hospitalization.py
get_summary_stats
¶
Return comprehensive summary statistics for hospitalization data.
Source code in clifpy/tables/hospitalization.py
Labs¶
clifpy.tables.labs.Labs
¶
Bases: BaseTable
Labs table wrapper inheriting from BaseTable.
This class handles laboratory data and validations including reference unit validation while leveraging the common functionality provided by BaseTable.
Initialize the labs table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_directory
|
str
|
Path to the directory containing data files |
None
|
filetype
|
str
|
Type of data file (csv, parquet, etc.) |
None
|
timezone
|
str
|
Timezone for datetime columns |
'UTC'
|
output_directory
|
str
|
Directory for saving output files and logs |
None
|
data
|
DataFrame
|
Pre-loaded data to use instead of loading from file |
None
|
Source code in clifpy/tables/labs.py
lab_reference_units
property
¶
Get the lab reference units mapping from the schema.
get_lab_category_stats
¶
Return summary statistics for each lab category, including missingness and unique hospitalization_id counts.
Source code in clifpy/tables/labs.py
get_lab_specimen_stats
¶
Return summary statistics for each lab category, including missingness and unique hospitalization_id counts.
Source code in clifpy/tables/labs.py
Vitals¶
clifpy.tables.vitals.Vitals
¶
Bases: BaseTable
Vitals table wrapper inheriting from BaseTable.
This class handles vitals-specific data and validations including range validation for vital signs.
Initialize the vitals table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_directory
|
str
|
Path to the directory containing data files |
None
|
filetype
|
str
|
Type of data file (csv, parquet, etc.) |
None
|
timezone
|
str
|
Timezone for datetime columns |
'UTC'
|
output_directory
|
str
|
Directory for saving output files and logs |
None
|
data
|
DataFrame
|
Pre-loaded data to use instead of loading from file |
None
|
Source code in clifpy/tables/vitals.py
filter_by_vital_category
¶
Return all records for a specific vital category (e.g., 'heart_rate', 'temp_c').
Source code in clifpy/tables/vitals.py
get_vital_summary_stats
¶
Return summary statistics for each vital category.
Source code in clifpy/tables/vitals.py
isvalid
¶
validate_vital_ranges
¶
Validate vital values against expected ranges using grouped data for efficiency.
Source code in clifpy/tables/vitals.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
Respiratory Support¶
clifpy.tables.respiratory_support.RespiratorySupport
¶
RespiratorySupport(
data_directory=None,
filetype=None,
timezone="UTC",
output_directory=None,
data=None,
)
Bases: BaseTable
Respiratory support table wrapper inheriting from BaseTable.
This class handles respiratory support data and validations while leveraging the common functionality provided by BaseTable.
Initialize the respiratory_support table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_directory
|
str
|
Path to the directory containing data files |
None
|
filetype
|
str
|
Type of data file (csv, parquet, etc.) |
None
|
timezone
|
str
|
Timezone for datetime columns |
'UTC'
|
output_directory
|
str
|
Directory for saving output files and logs |
None
|
data
|
DataFrame
|
Pre-loaded data to use instead of loading from file |
None
|
Source code in clifpy/tables/respiratory_support.py
waterfall
¶
Clean + waterfall-fill the respiratory_support table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_col
|
str
|
Encounter-level identifier column (default: hospitalization_id) |
'hospitalization_id'
|
bfill
|
bool
|
If True, numeric setters are back-filled after forward-fill |
False
|
verbose
|
bool
|
Print progress messages |
True
|
return_dataframe
|
bool
|
If True, returns DataFrame instead of RespiratorySupport instance |
False
|
Returns:
Name | Type | Description |
---|---|---|
RespiratorySupport |
Union[RespiratorySupport, DataFrame]
|
New instance with processed data (or DataFrame if return_dataframe=True) |
Note
The waterfall function expects data in UTC timezone. If your data is in a different timezone, it will be converted to UTC for processing. The original object is not modified; a new instance is returned.
Example
processed = resp_support.waterfall() processed.validate() # Can run validation on processed data df = processed.df # Access the DataFrame
Source code in clifpy/tables/respiratory_support.py
Medication Administration (Continuous)¶
clifpy.tables.medication_admin_continuous.MedicationAdminContinuous
¶
MedicationAdminContinuous(
data_directory=None,
filetype=None,
timezone="UTC",
output_directory=None,
data=None,
)
Bases: BaseTable
Medication administration continuous table wrapper inheriting from BaseTable.
This class handles medication administration continuous data and validations while leveraging the common functionality provided by BaseTable.
Initialize the MedicationAdminContinuous table.
This class handles continuous medication administration data, including validation, dose unit standardization, and unit conversion capabilities.
Parameters¶
data_directory : str, optional Path to the directory containing data files. If None and data is provided, defaults to current directory. filetype : str, optional Type of data file (csv, parquet, etc.). If None and data is provided, defaults to 'parquet'. timezone : str, default="UTC" Timezone for datetime columns. Used for proper timestamp handling. output_directory : str, optional Directory for saving output files and logs. If not specified, outputs are saved to the current working directory. data : pd.DataFrame, optional Pre-loaded DataFrame to use instead of loading from file. Supports backward compatibility with direct DataFrame initialization.
Notes¶
The class supports two initialization patterns: 1. Loading from file: provide data_directory and filetype 2. Direct DataFrame: provide data parameter (legacy support)
Upon initialization, the class loads medication schema data including category-to-group mappings from the YAML schema.
Source code in clifpy/tables/medication_admin_continuous.py
med_category_to_group_mapping
property
¶
Get the medication category to group mapping from the schema.
Returns¶
Dict[str, str] A dictionary mapping medication categories to their therapeutic groups. Returns a copy to prevent external modification of the internal mapping. Returns an empty dict if no mappings are loaded.
Examples¶
mac = MedicationAdminContinuous(data) mappings = mac.med_category_to_group_mapping mappings['Antibiotics'] 'Antimicrobials'
convert_dose_to_limited_units
¶
Convert medication doses to standardized units per minute.
This method converts all medication doses to one of three standard units:
- mcg/min for mass-based medications
- ml/min for volume-based medications
- units/min for unit-based medications
The conversion handles different time scales (per hour vs per minute) and weight-based dosing (per kg) by incorporating patient weights from vitals.
Parameters¶
vitals_df : pd.DataFrame DataFrame containing patient vital signs, must include: - hospitalization_id: Patient identifier - recorded_dttm: Timestamp of vital recording - vital_category: Type of vital (looks for 'weight_kg') - vital_value: Numeric value of the vital med_df : pd.DataFrame, optional DataFrame containing medication administration data. If None, uses self.df. Required columns: - hospitalization_id: Patient identifier - admin_dttm: Medication administration timestamp - med_dose_unit: Original dose unit (case-insensitive) - med_dose: Original dose value - med_category: Medication category (used for SQL query) Optional columns: - weight_kg: Patient weight; if absent, pulled from vitals_df
Returns¶
pd.DataFrame Original med_df with additional columns: - med_dose_unit_clean: Standardized unit pattern - weight_kg: Patient weight used for conversion (if applicable) - med_dose_converted: Dose value in standardized units - med_dose_unit_converted: Standardized unit ('mcg/min', 'ml/min', or 'units/min') - Additional calculation columns (time_multiplier, pt_weight_multiplier, amount_multiplier)
Raises¶
ValueError If med_df is None and self.df is also None, or if required columns are missing.
Warnings¶
Logs warnings for unrecognized dose units that cannot be converted.
Notes¶
- Weight-based dosing (/kg) uses the most recent weight prior to administration
- Unrecognized dose units result in NULL converted values
- The conversion preserves the original columns and adds new ones
Examples¶
vitals = pd.DataFrame({ ... 'hospitalization_id': ['H001'], ... 'recorded_dttm': pd.to_datetime(['2023-01-01']), ... 'vital_category': ['weight_kg'], ... 'vital_value': [70.0] ... }) meds = pd.DataFrame({ ... 'hospitalization_id': ['H001'], ... 'admin_dttm': pd.to_datetime(['2023-01-02']), ... 'med_dose': [5.0], ... 'med_dose_unit': ['mcg/kg/hr'], ... 'med_category': ['Vasopressors'] ... }) result = mac.convert_dose_to_limited_units(vitals, meds) result['med_dose_converted'].iloc[0] 5.833333... # 5 * 70 / 60 (mcg/kg/hr to mcg/min with 70kg patient)
Source code in clifpy/tables/medication_admin_continuous.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
Patient Assessments¶
clifpy.tables.patient_assessments.PatientAssessments
¶
PatientAssessments(
data_directory=None,
filetype=None,
timezone="UTC",
output_directory=None,
data=None,
)
Bases: BaseTable
Patient assessments table wrapper inheriting from BaseTable.
This class handles patient assessment data and validations while leveraging the common functionality provided by BaseTable.
Initialize the patient_assessments table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_directory
|
str
|
Path to the directory containing data files |
None
|
filetype
|
str
|
Type of data file (csv, parquet, etc.) |
None
|
timezone
|
str
|
Timezone for datetime columns |
'UTC'
|
output_directory
|
str
|
Directory for saving output files and logs |
None
|
data
|
DataFrame
|
Pre-loaded data to use instead of loading from file |
None
|
Source code in clifpy/tables/patient_assessments.py
assessment_category_to_group_mapping
property
¶
Get the assessment category to group mapping from the schema.
Position¶
clifpy.tables.position.Position
¶
Bases: BaseTable
Position table wrapper inheriting from BaseTable.
This class handles patient position data and validations while leveraging the common functionality provided by BaseTable.
Initialize the position table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_directory
|
str
|
Path to the directory containing data files |
None
|
filetype
|
str
|
Type of data file (csv, parquet, etc.) |
None
|
timezone
|
str
|
Timezone for datetime columns |
'UTC'
|
output_directory
|
str
|
Directory for saving output files and logs |
None
|
data
|
DataFrame
|
Pre-loaded data to use instead of loading from file |
None
|
Source code in clifpy/tables/position.py
get_position_category_stats
¶
Return summary statistics for each position category, including missingness and unique patient counts. Expects columns: 'position_category', 'position_name', and optionally 'hospitalization_id'.