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, birth_datetime=None, death_datetime=None, gender=None, ethnicity=None, **attr)#
Contains information about a single patient.
A patient is a person who is admitted at least once to a hospital or a specific department. Each patient is associated with a list of visits.
str) – unique identifier of the patient.
gender – gender of the patient. Default is None.
ethnicity – ethnicity of the patient. Default is None.
**attr – optional attributes to add to the patient as key=value pairs.
Dict, dictionary of patient attributes. Each key is an attribute name and each value is the attribute’s value.
OrderedDict[str, Visit], an ordered dictionary of visits. Each key is a visit_id and each value is a visit.
Dict[int, str], dictionary that maps the index of a visit in the visits list to the corresponding visit_id.
>>> from pyhealth.data import Event, Visit, Patient >>> 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) >>> patient = Patient( ... patient_id="p001", ... ) >>> patient.add_visit(visit) >>> patient Patient p001 with 1 visits
Adds a visit to the patient.
If the visit’s visit_id is already in the patient’s visits dictionary, it will be overwritten by the new visit.
Visit) – visit to add.
- As for now, there is no check on the order of the visits. The new visit
is simply added to the end of the ordered dictionary of visits.
- Return type
Adds an event to the patient.
If the event’s visit_id is not in the patient’s visits dictionary, this function will raise KeyError.
Event) – event to add.
- As for now, there is no check on the order of the events. The new event
is simply appended to the end of the list of events of the corresponding visit.
- Return type
Returns a visit by visit_id.
Returns a visit by its index.