pyhealth.data.Patient#
Another basic data structure in the package. A Patient is a collection of Visit for the current patients. It contains all necessary attributes of a patient, such as ethnicity, mortality status, gender, etc. It can support various healthcare tasks.
- class pyhealth.data.Patient(patient_id, data_source)[source]#
Bases:
objectPatient class representing a sequence of events.
- data_source#
DataFrame containing all events, sorted by timestamp.
- Type:
pl.DataFrame
- event_type_partitions#
Dictionary mapping event types to their respective DataFrame partitions.
- Type:
Dict[str, pl.DataFrame]
- get_events(event_type=None, start=None, end=None, filters=None, return_df=False)[source]#
Get events with optional type and time filters.
- Parameters:
event_type (Optional[str]) – Type of events to filter.
start (Optional[datetime]) – Start time for filtering events.
end (Optional[datetime]) – End time for filtering events.
return_df (bool) – Whether to return a DataFrame or a list of Event objects.
filters (Optional[List[tuple]]) – Additional filters as [(attr, op, value), …], e.g.: [(“attr1”, “!=”, “abnormal”), (“attr2”, “!=”, 1)]. Filters are applied after type and time filters. The logic is “AND” between different filters.
- Returns:
Filtered events as a DataFrame or a list of Event objects.
- Return type:
Union[pl.DataFrame, List[Event]]