function get_dbo_treatments_with_references_tnv_dbo_tnv
Queries a Neo4j graph database to retrieve dbo_TNV nodes that are connected to a specific dbo_Treatments node through a REFERENCES_TNV relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
2249 - 2256
simple
Purpose
This function is designed to traverse a Neo4j graph database to find Treatment-related TNV (likely Treatment Name Variant or similar medical/pharmaceutical data) references. It's useful for discovering which TNV entities are associated with a particular treatment, enabling analysis of treatment relationships and references in a medical or pharmaceutical knowledge graph.
Source Code
def get_dbo_treatments_with_references_tnv_dbo_tnv(source_id, limit=100):
"""Get dbo_TNV nodes connected to a dbo_Treatments via REFERENCES_TNV"""
query = """
MATCH (source:dbo_Treatments {id: $source_id})-[r:REFERENCES_TNV]->(target:dbo_TNV)
RETURN target
LIMIT $limit
"""
return run_query(query, {"source_id": source_id, "limit": limit})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
source_id |
- | - | positional_or_keyword |
limit |
- | 100 | positional_or_keyword |
Parameter Details
source_id: The unique identifier of the dbo_Treatments node from which to start the traversal. This should be a string or value that matches the 'id' property of a dbo_Treatments node in the Neo4j database.
limit: Maximum number of dbo_TNV target nodes to return. Defaults to 100. This parameter controls query performance and result set size. Must be a positive integer.
Return Value
Returns the result of run_query() function, which typically returns a list of Neo4j records containing the target dbo_TNV nodes. Each record represents a dbo_TNV node with its properties. The exact structure depends on the run_query() implementation, but it likely returns a list of dictionaries or Neo4j Record objects containing the node properties. Returns an empty list if no matching relationships are found.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example run_query implementation:
# def run_query(query, params):
# driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
# with driver.session() as session:
# result = session.run(query, params)
# return [record['target'] for record in result]
# Get TNV nodes referenced by treatment with ID 'TREAT_12345'
results = get_dbo_treatments_with_references_tnv_dbo_tnv('TREAT_12345', limit=50)
# Process results
for tnv_node in results:
print(f"TNV Node: {tnv_node}")
# Get all TNV references (up to default limit of 100)
all_tnv_refs = get_dbo_treatments_with_references_tnv_dbo_tnv('TREAT_67890')
Best Practices
- Ensure the source_id exists in the database before calling to avoid empty results
- Use appropriate limit values to balance between completeness and performance
- Handle the case where run_query() returns an empty list (no matching relationships found)
- Consider implementing error handling for database connection issues
- The run_query() helper function should properly manage Neo4j driver sessions and connections
- For large result sets, consider implementing pagination instead of relying solely on the limit parameter
- Validate that source_id is properly sanitized if it comes from user input (though parameterized queries provide protection against injection)
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_references_tnv_relationship 84.2% similar
-
function get_dbo_treatments_with_references_product_dbo_product 83.6% similar
-
function get_dbo_treatments_with_references_establishment_dbo_establishment 80.5% similar
-
function get_dbo_treatments_with_references_houses_dbo_houses 79.6% similar
-
function get_dbo_tnv_with_references_establishment_dbo_establishment 77.4% similar