Edges
omop_graph.graph.edges
Definitions for graph edges and predicates.
This module defines the lightweight data structures representing the relationships (edges) between concepts in the OMOP Knowledge Graph.
It focuses on data definitions and classification logic, not graph traversal algorithms.
Supported Relationships
- Mapping: Semantic equivalence (e.g., source code to standard concept).
- Versioning: Lifecycle tracking (e.g., 'replaced by', 'is a').
- Ontological: Hierarchical structure (e.g., 'is a', 'subsumes').
- Attribute: Descriptive properties (e.g., 'has dose form').
- Metadata: Administrative or low-semantic value connections.
EdgeView
dataclass
A lightweight, immutable view of an edge in the Knowledge Graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_id
|
int
|
The OMOP Concept ID of the source. |
required |
predicate_id
|
str
|
The relationship ID (e.g., 'is a', 'mapped from'). |
required |
object_id
|
int
|
The OMOP Concept ID of the target. |
required |
valid_start_date
|
date
|
The date the relationship became valid. |
required |
valid_end_date
|
date
|
The date the relationship became invalid. |
required |
invalid_reason
|
str
|
The reason for invalidation (e.g., 'D' for deleted), if applicable. |
required |
pretty(kg)
Return a human-readable string representation of the edge using concept names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kg
|
KnowledgeGraph
|
The graph instance used to look up concept names. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string in the format 'Subject Name -[predicate]-> Object Name'. |
Predicate
dataclass
Definition of a Relationship Type in the OMOP CDM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relationship_id
|
str
|
The unique string identifier (e.g. |
required |
name
|
str
|
The human-readable label (e.g. |
required |
reverse_id
|
str
|
The relationship_id of the inverse relationship (e.g. |
required |
is_hierarchical
|
bool
|
Whether OMOP defines this as a hierarchical relationship. |
required |
anc_up
|
bool
|
Whether this relationship defines 'defines_ancestry' upwards (deprecated logic). |
required |
anc_down
|
bool
|
Whether this relationship defines 'defines_ancestry' downwards (deprecated logic). |
required |
defines_ancestry
property
Check if this predicate is involved in defining ancestry.
is_active(start, end, invalid_reason, *, on=None)
Check if a relationship is active on a given date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
date
|
The start date of the relationship. |
required |
end
|
date
|
The end date of the relationship. |
required |
invalid_reason
|
str
|
The invalid reason code (e.g. 'D', 'U'). None implies valid. |
required |
on
|
date
|
The reference date to check against. If None, only checks |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the relationship is active, False otherwise. |