LifeTwin Database Connector

General Architecture Diagram

../_images/arch.png

This file provides classes for working with OMOP (Observational Medical Outcomes Partnership) database. It includes a class for database operations, as well as classes for representing person, observation, and measurement objects. The classes allow for reading data from files into pandas DataFrames, iterating through the data, and providing string representations of the objects.

class database.Database

Bases: ABC

This class provides a method to iterate through a collection of person objects.

abstract iterate_person()

Defines a method to iterate through a collection of person objects.

class database.OMOP_DB

Bases: Database

OMOP_DB is a class that initializes the object with paths to person, observation, and measurement data files. It reads the data from the files into pandas DataFrames and raises errors if the files or expected attributes are not found. It also provides a method to iterate through the person data and retrieve corresponding observations and measurements. The method groups the observations and measurements by concept ID and creates OMOP_Observation and OMOP_Measurement objects, yielding the OMOP_Person object along with the associated observations and measurements.

iterate_person()

Iterates through the person data and retrieves corresponding observations and measurements. Groups the observations and measurements by concept ID and creates OMOP_Observation and OMOP_Measurement objects. Yields the OMOP_Person object along with the associated observations and measurements.

class database.OMOP_Measurement(measurement: Series)

Bases: object

OMOP_Measurement is a class that represents a measurement object with specific attributes such as measurement_id, person_id, measurement_concept_id, and others. It initializes the object with a measurement pandas Series and sets the attributes of the object based on the values in the Series. It also provides a string representation of the Measurement object including its id, person id, and concept id.

measurement_concept_id
measurement_date
measurement_datetime
measurement_id
measurement_source_concept_id
measurement_source_value
measurement_type_concept_id
operator_concept_id
person_id
provider_id
range_high
range_low
unit_concept_id
unit_source_value
value_as_concept_id
value_as_number
value_source_value
visit_occurrence_id
class database.OMOP_Obsevation(observation: Series)

Bases: object

OMOP_Observation is a class that represents an observation object with specific attributes such as observation_id, person_id, observation_concept_id, and others. It initializes the object with an observation pandas Series and sets the attributes of the object based on the values in the Series. It also provides a string representation of the Observation object including its id, person id, and concept id.

observation_concept_id
observation_date
observation_datetime
observation_id
observation_source_concept_id
observation_source_value
observation_type_concept_id
person_id
provider_id
qualifier_concept_id
qualifier_source_value
unit_concept_id
unit_source_value
value_as_concept_id
value_as_number
value_as_string
visit_occurrence_id
class database.OMOP_Person(person: Series)

Bases: object

OMOP_Person is a class that represents a person object with specific attributes such as person_id, month_of_birth, day_of_birth, and others. It initializes the object with a person pandas Series and sets the attributes of the object based on the values in the Series. It also provides properties to calculate the age of the person, determine if the person is male or female, and retrieve the sex of the person as an integer. Additionally, it offers a string representation of the Person object including its id.

property age

Returns the age of the person based on the current year and the year of birth.

birth_datetime
care_site_id
day_of_birth
ethnicity_concept_id
ethnicity_source_concept_id
ethnicity_source_value
gender_concept_id
gender_source_concept_id
gender_source_value
property is_female

Returns a boolean indicating whether the person is female based on the gender concept id.

property is_male

Returns a boolean indicating whether the person is male based on the gender concept id.

location_id
month_of_birth
person_id
person_source_value
provider_id
race_concept_id
race_source_concept_id
race_source_value
property sex

Returns the sex of the person as an integer (1 for male, 2 for female) based on the gender concept id. If the gender is not male or female, it raises an exception.

year_of_birth