🔍 Code Extractor

function get_dbo_treatments_with_references_tnv_dbo_tnv

Maturity: 40

Queries a Neo4j graph database to retrieve dbo_TNV nodes that are connected to a specific dbo_Treatments node through a REFERENCES_TNV relationship.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
2249 - 2256
Complexity:
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)

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_references_tnv_relationship 84.2% similar

    Creates a REFERENCES_TNV relationship in a Neo4j graph database between a dbo_Treatments node and a dbo_TNV node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_treatments_with_references_product_dbo_product 83.6% similar

    Retrieves dbo_Product nodes from a Neo4j graph database that are connected to a specific dbo_Treatments node via a REFERENCES_PRODUCT relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_treatments_with_references_establishment_dbo_establishment 80.5% similar

    Queries a Neo4j graph database to retrieve dbo_Establishment nodes that are connected to a specific dbo_Treatments node through a REFERENCES_ESTABLISHMENT relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_treatments_with_references_houses_dbo_houses 79.6% similar

    Retrieves dbo_Houses nodes from a Neo4j graph database that are connected to a specific dbo_Treatments node via a REFERENCES_HOUSES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_tnv_with_references_establishment_dbo_establishment 77.4% similar

    Queries a Neo4j graph database to retrieve dbo_Establishment nodes that are connected to a specific dbo_TNV node through a REFERENCES_ESTABLISHMENT relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse