OMOP
Loader
pluginlake.omop.loader
OMOP data loading functions.
load_omop_table(file_path, table_name, *, validate=None, encoding=None)
Load OMOP CSV into validated Polars DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to CSV file. |
required |
table_name
|
str
|
OMOP table name (e.g., 'person', 'condition_occurrence'). |
required |
validate
|
bool | None
|
Run schema validation. Uses config default if None. |
None
|
encoding
|
str | None
|
CSV encoding. Uses config default if None. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with validated schema. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If file doesn't exist. |
ValueError
|
If validation fails and skip_invalid_rows is False. |
Source code in src/pluginlake/omop/loader.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
load_omop_dataset(data_dir=None, table_names=None, *, validate=True)
Load multiple OMOP tables from directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
Path | None
|
Directory containing OMOP CSV files. Uses config default if None. |
None
|
table_names
|
list[str] | None
|
List of table names to load. Loads all CSV files if None. |
None
|
validate
|
bool
|
Whether to validate schemas during loading. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Dictionary mapping table names to DataFrames. |
Source code in src/pluginlake/omop/loader.py
load_vocabulary_table(file_path, table_name, *, validate=None, encoding=None)
Load OMOP vocabulary file into validated Polars DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to vocabulary file (CSV or TSV). |
required |
table_name
|
str
|
Vocabulary table name (e.g., 'concept', 'vocabulary'). |
required |
validate
|
bool | None
|
Run schema validation. Uses config default if None. |
None
|
encoding
|
str | None
|
File encoding. Uses config default if None. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Polars DataFrame with validated schema. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If file doesn't exist. |
ValueError
|
If validation fails and skip_invalid_rows is False. |
Source code in src/pluginlake/omop/loader.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
load_vocabulary_dataset(data_dir=None, table_names=None, *, validate=True)
Load OMOP vocabulary tables from directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
Path | None
|
Directory containing vocabulary files. Uses config default if None. |
None
|
table_names
|
list[str] | None
|
List of vocabulary table names to load. Loads all if None. |
None
|
validate
|
bool
|
Whether to validate schemas during loading. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Dictionary mapping table names to DataFrames. |
Source code in src/pluginlake/omop/loader.py
Queries
pluginlake.omop.queries
High-level query API for OMOP data.
Provides ergonomic Python functions for common OMOP analytical queries.
get_persons(con=None, *, gender_concept_id=None, year_of_birth_min=None, year_of_birth_max=None, race_concept_id=None, ethnicity_concept_id=None, limit=None)
Query person records with optional filters.
Source code in src/pluginlake/omop/queries.py
get_conditions_for_person(person_id, con=None, *, condition_concept_id=None, start_date=None, end_date=None)
Query condition occurrences for a person with optional filters.
Source code in src/pluginlake/omop/queries.py
get_observations_for_person(person_id, con=None, *, observation_concept_id=None, start_date=None, end_date=None)
Query observations for a person with optional filters.
Source code in src/pluginlake/omop/queries.py
get_visits_for_person(person_id, con=None, *, visit_concept_id=None, start_date=None, end_date=None)
Query visit occurrences for a person with optional filters.
Source code in src/pluginlake/omop/queries.py
get_cohort(con=None, *, has_condition_concept_id=None, has_drug_concept_id=None, min_age=None, max_age=None, gender_concept_id=None)
Select a cohort of persons matching the given clinical criteria.
Source code in src/pluginlake/omop/queries.py
get_measurement_values(person_id, measurement_concept_id, con=None, *, start_date=None, end_date=None)
Query measurement values for a person and concept with optional date filters.
Source code in src/pluginlake/omop/queries.py
Schemas
pluginlake.omop.schemas
OMOP CDM table schemas.
Pydantic models for OMOP CDM v5.4 tables. Used for validation and type checking.
Person
Bases: BaseModel
OMOP Person table schema.
Source code in src/pluginlake/omop/schemas.py
ObservationPeriod
Bases: BaseModel
OMOP Observation Period table schema.
Source code in src/pluginlake/omop/schemas.py
VisitOccurrence
Bases: BaseModel
OMOP Visit Occurrence table schema.
Source code in src/pluginlake/omop/schemas.py
VisitDetail
Bases: BaseModel
OMOP Visit Detail table schema.
Source code in src/pluginlake/omop/schemas.py
ConditionOccurrence
Bases: BaseModel
OMOP Condition Occurrence table schema.
Source code in src/pluginlake/omop/schemas.py
DrugExposure
Bases: BaseModel
OMOP Drug Exposure table schema.
Source code in src/pluginlake/omop/schemas.py
ProcedureOccurrence
Bases: BaseModel
OMOP Procedure Occurrence table schema.
Source code in src/pluginlake/omop/schemas.py
DeviceExposure
Bases: BaseModel
OMOP Device Exposure table schema.
Source code in src/pluginlake/omop/schemas.py
Measurement
Bases: BaseModel
OMOP Measurement table schema.
Source code in src/pluginlake/omop/schemas.py
Observation
Bases: BaseModel
OMOP Observation table schema.
Source code in src/pluginlake/omop/schemas.py
Death
Bases: BaseModel
OMOP Death table schema.
Source code in src/pluginlake/omop/schemas.py
Note
Bases: BaseModel
OMOP Note table schema.
Source code in src/pluginlake/omop/schemas.py
NoteNlp
Bases: BaseModel
OMOP Note NLP table schema.
Source code in src/pluginlake/omop/schemas.py
Specimen
Bases: BaseModel
OMOP Specimen table schema.
Source code in src/pluginlake/omop/schemas.py
ConditionEra
Bases: BaseModel
OMOP Condition Era table schema.
Source code in src/pluginlake/omop/schemas.py
DrugEra
Bases: BaseModel
OMOP Drug Era table schema.
Source code in src/pluginlake/omop/schemas.py
FactRelationship
Bases: BaseModel
OMOP Fact Relationship table schema.
Source code in src/pluginlake/omop/schemas.py
get_omop_schema(table_name)
Get Pydantic schema for OMOP table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
OMOP table name (lowercase with underscores). |
required |
Returns:
| Type | Description |
|---|---|
type[BaseModel] | None
|
Pydantic model class or None if not found. |
Source code in src/pluginlake/omop/schemas.py
Validation
pluginlake.omop.validation
OMOP data validation functions.
ValidationError
Represents a validation error.
Source code in src/pluginlake/omop/validation.py
__init__(column, message, row_index=None)
Initialize validation error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Column name where error occurred. |
required |
message
|
str
|
Error description. |
required |
row_index
|
int | None
|
Optional row index where error occurred. |
None
|
Source code in src/pluginlake/omop/validation.py
__repr__()
String representation of validation error.
Source code in src/pluginlake/omop/validation.py
validate_omop_table_schema(df, table_name)
Check DataFrame matches OMOP CDM schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to validate. |
required |
table_name
|
str
|
OMOP table name. |
required |
Returns:
| Type | Description |
|---|---|
list[ValidationError]
|
List of validation errors (empty if valid). |
Source code in src/pluginlake/omop/validation.py
validate_vocabulary_table_schema(df, table_name)
Check DataFrame matches OMOP vocabulary schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to validate. |
required |
table_name
|
str
|
Vocabulary table name. |
required |
Returns:
| Type | Description |
|---|---|
list[ValidationError]
|
List of validation errors (empty if valid). |
Source code in src/pluginlake/omop/validation.py
Vocabulary Queries
pluginlake.omop.vocabulary_queries
Query API for OMOP vocabularies.
Functions for querying OMOP controlled vocabularies.
get_concept(concept_id, con=None, *, schema='ducklake.omop_vocab')
Retrieve a single concept by ID.
Source code in src/pluginlake/omop/vocabulary_queries.py
search_concepts(term, domain_id=None, vocabulary_id=None, *, standard_only=True, limit=100, con=None, schema='ducklake.omop_vocab')
Search concepts by name with optional domain, vocabulary, and standard filters.
Source code in src/pluginlake/omop/vocabulary_queries.py
get_concept_descendants(ancestor_concept_id, max_levels=None, *, con=None, schema='ducklake.omop_vocab')
Return all descendant concepts of an ancestor concept.
Source code in src/pluginlake/omop/vocabulary_queries.py
get_concept_ancestors(descendant_concept_id, max_levels=None, *, con=None, schema='ducklake.omop_vocab')
Return all ancestor concepts of a descendant concept.
Source code in src/pluginlake/omop/vocabulary_queries.py
map_source_code(source_code, source_vocabulary_id, *, con=None, schema='ducklake.omop_vocab')
Map a source code to its standard OMOP concept via the source-to-concept map.
Source code in src/pluginlake/omop/vocabulary_queries.py
get_vocabulary_info(vocabulary_id=None, *, con=None, schema='ducklake.omop_vocab')
Return vocabulary metadata, optionally filtered by vocabulary ID.