[e988c2]: / docs / includes / generated_docs / language__frames.md

Download this file

268 lines (219 with data), 9.4 kB


class PatientFrame()

Frame containing at most one row per patient.

exists_for_patient() 🔗

Return a boolean patient series which is True for each
patient that has a row in this frame and False otherwise.

Example usage:

pratice_registrations.for_patient_on("2020-01-01").exists_for_patient()
count_for_patient() 🔗

Return an integer patient series giving the number of rows each
patient has in this frame.

Note that if a patient has no rows at all in the frame the result will be zero
rather than NULL.

Example usage:

clinical_events.where(clinical_events.date.year == 2020).count_for_patient()


class EventFrame()

Frame which may contain multiple rows per patient.

where(condition) 🔗

Return a new frame containing only the rows in this frame for which condition
evaluates True.

Note that this excludes any rows for which condition is NULL.

Example usage:

clinical_events.where(clinical_events.date >= "2020-01-01")
except_where(condition) 🔗

Return a new frame containing only the rows in this frame for which condition
evaluates False or NULL i.e. the exact inverse of the rows included by
where().

Example usage:

practice_registrations.except_where(practice_registrations.end_date < "2020-01-01")

Note that except_where() is not the same as where() with an inverted condition,
as the latter would exclude rows where condition is NULL.

sort_by(*sort_values) 🔗

Return a new frame with the rows sorted for each patient, by
each of the supplied sort_values.

Where more than one sort value is supplied then the first (i.e. left-most) value
has highest priority and each subsequent sort value will only be used as a
tie-breaker in case of an exact match among previous values.

Note that NULL is considered smaller than any other value, so you may wish to
filter out NULL values before sorting.

Example usage:

clinical_events.sort_by(clinical_events.date, clinical_events.snomedct_code)
exists_for_patient() 🔗

Return a boolean patient series which is True for each
patient that has a row in this frame and False otherwise.

Example usage:

pratice_registrations.for_patient_on("2020-01-01").exists_for_patient()
count_for_patient() 🔗

Return an integer patient series giving the number of rows each
patient has in this frame.

Note that if a patient has no rows at all in the frame the result will be zero
rather than NULL.

Example usage:

clinical_events.where(clinical_events.date.year == 2020).count_for_patient()


class SortedEventFrame()

Frame which contains multiple rows per patient and has had one or more sort
operations applied.

where(condition) 🔗

Return a new frame containing only the rows in this frame for which condition
evaluates True.

Note that this excludes any rows for which condition is NULL.

Example usage:

clinical_events.where(clinical_events.date >= "2020-01-01")
except_where(condition) 🔗

Return a new frame containing only the rows in this frame for which condition
evaluates False or NULL i.e. the exact inverse of the rows included by
where().

Example usage:

practice_registrations.except_where(practice_registrations.end_date < "2020-01-01")

Note that except_where() is not the same as where() with an inverted condition,
as the latter would exclude rows where condition is NULL.

sort_by(*sort_values) 🔗

Return a new frame with the rows sorted for each patient, by
each of the supplied sort_values.

Where more than one sort value is supplied then the first (i.e. left-most) value
has highest priority and each subsequent sort value will only be used as a
tie-breaker in case of an exact match among previous values.

Note that NULL is considered smaller than any other value, so you may wish to
filter out NULL values before sorting.

Example usage:

clinical_events.sort_by(clinical_events.date, clinical_events.snomedct_code)
exists_for_patient() 🔗

Return a boolean patient series which is True for each
patient that has a row in this frame and False otherwise.

Example usage:

pratice_registrations.for_patient_on("2020-01-01").exists_for_patient()
count_for_patient() 🔗

Return an integer patient series giving the number of rows each
patient has in this frame.

Note that if a patient has no rows at all in the frame the result will be zero
rather than NULL.

Example usage:

clinical_events.where(clinical_events.date.year == 2020).count_for_patient()
first_for_patient() 🔗

Return a PatientFrame containing, for each patient, the first matching row
according to whatever sort order has been applied.

Note that where there are multiple rows tied for first place then the specific
row returned is picked arbitrarily but consistently i.e. you shouldn't depend on
getting any particular result, but the result you do get shouldn't change unless
the data changes.

Example usage:

medications.sort_by(medications.date).first_for_patient()
last_for_patient() 🔗

Return a PatientFrame containing, for each patient, the last matching row
according to whatever sort order has been applied.

Note that where there are multiple rows tied for last place then the specific
row returned is picked arbitrarily but consistently i.e. you shouldn't depend on
getting any particular result, but the result you do get shouldn't change unless
the data changes.

Example usage:

medications.sort_by(medications.date).last_for_patient()