ehrdata.io.omop.setup_obs

Contents

ehrdata.io.omop.setup_obs#

ehrdata.io.omop.setup_obs(backend_handle, observation_table, *, death_table=False)#

Setup the observation table for EHRData object.

For this, a table from the OMOP CDM which represents what a “row” in the EHRData object should represent.

This will be used to set that start timepoint for the time series data in the EHRData object.

Possible choices for the observation_table parameter are:

  • "person": Create one row per person person_id in the person table

  • "person_cohort": Create one row per person subject_id in a cohort in the cohort table

  • "person_observation_period": Create one row per observation_period_id in the observation_period table

  • "person_visit_occurrence": Create one row per visit_occurrence_id in the visit_occurrence table

Data characterizing the rows such as person demographics, and e.g. visit start and end dates are stored in the .obs field of the created EHRData object. Notice a single person_id can have multiple rows for e.g. "person_visit_occurrence" if a person has multiple visit occurrences.

Example: 1000 person_id in the person_table, with 100 people having 1 visit occurrence, 100 people having 2 visit occurrences, and 800 people having no visit occurrences. If observation_table = "person", the created EHRData object will have 1000 rows. If observation_table = "person_visit_occurrence", the created EHRData object will have 300 rows.

The possible choices affect what is taken as the “time 0” in the setup_variables() and setup_interval_variables() functions:

For "person_cohort", the subject_id of the cohort is considered to be the person_id for a join.

Parameters:
backend_handle DuckDBPyConnection

The backend handle to the database.

observation_table Literal['person', 'person_cohort', 'person_observation_period', 'person_visit_occurrence']

The observation table to be used.

death_table bool (default: False)

Whether to include the death table. The observation_table created will be left joined with the death table as the right table.

Returns:

An EHRData object with populated .obs field.

Examples

>>> import ehrdata as ed
>>> import duckdb
>>> con_gi = duckdb.connect(database=":memory:", read_only=False)
>>> ed.dt.gibleed_omop(
...     con_gi,
... )
>>> edata_gi = ed.io.omop.setup_obs(
>>>     con_gi,
>>>     observation_table="person_observation_period",
>>> )
>>> edata_gi