pyhealth.data.Visit#
Another basic data structure in the package. A Visit is a single encounter in hospital. It is a container a sequence of Event for each information aspect, such as diagnosis or medications. It also contains other necessary attributes for supporting healthcare tasks, such as the date of the visit.
- class pyhealth.data.Visit(visit_id, patient_id, encounter_time=None, discharge_time=None, discharge_status=None, **attr)[source]#
Bases:
object
Contains information about a single visit.
A visit is a period of time in which a patient is admitted to a hospital or a specific department. Each visit is associated with a patient and contains a list of different events.
- Parameters:
visit_id (
str
) – unique identifier of the visit.patient_id (
str
) – unique identifier of the patient.encounter_time (
Optional
[datetime
]) – timestamp of visit’s encounter. Default is None.discharge_time (
Optional
[datetime
]) – timestamp of visit’s discharge. Default is None.discharge_status – patient’s status upon discharge. Default is None.
**attr – optional attributes to add to the visit as key=value pairs.
- attr_dict#
Dict, dictionary of visit attributes. Each key is an attribute name and each value is the attribute’s value.
- event_list_dict#
Dict[str, List[Event]], dictionary of event lists. Each key is a table name and each value is a list of events from that table ordered by timestamp.
Examples
>>> from pyhealth.data import Event, Visit >>> event = Event( ... code="00069153041", ... table="PRESCRIPTIONS", ... vocabulary="NDC", ... visit_id="v001", ... patient_id="p001", ... dosage="250mg", ... ) >>> visit = Visit( ... visit_id="v001", ... patient_id="p001", ... ) >>> visit.add_event(event) >>> visit Visit v001 from patient p001 with 1 events from tables ['PRESCRIPTIONS'] >>> visit.available_tables ['PRESCRIPTIONS'] >>> visit.num_events 1 >>> visit.get_event_list('PRESCRIPTIONS') [Event with NDC code 00069153041 from table PRESCRIPTIONS] >>> visit.get_code_list('PRESCRIPTIONS') ['00069153041'] >>> patient.available_tables ['PRESCRIPTIONS'] >>> patient.get_visit_by_index(0) Visit v001 from patient p001 with 1 events from tables ['PRESCRIPTIONS'] >>> patient.get_visit_by_index(0).get_code_list(table="PRESCRIPTIONS") ['00069153041']
- add_event(event)[source]#
Adds an event to the visit.
If the event’s table is not in the visit’s event list dictionary, it is added as a new key. The event is then added to the list of events of that table.
- Parameters:
event (
Event
) – event to add.
Note
- As for now, there is no check on the order of the events. The new event
is simply appended to end of the list.
- Return type:
- get_event_list(table)[source]#
Returns a list of events from a specific table.
If the table is not in the visit’s event list dictionary, an empty list is returned.
- Parameters:
table (
str
) – name of the table.- Return type:
- Returns:
List of events from the specified table.
Note
- As for now, there is no check on the order of the events. The list of
events is simply returned as is.
- get_code_list(table, remove_duplicate=True)[source]#
Returns a list of codes from a specific table.
If the table is not in the visit’s event list dictionary, an empty list is returned.
- Parameters:
- Return type:
- Returns:
List of codes from the specified table.
Note
- As for now, there is no check on the order of the codes. The list of
codes is simply returned as is.
- set_event_list(table, event_list)[source]#
Sets the list of events from a specific table.
This function will overwrite any existing list of events from the specified table.
Note
- As for now, there is no check on the order of the events. The list of
events is simply set as is.
- Return type: