function get_dbo_treatments_with_references_product_dbo_product
Retrieves dbo_Product nodes from a Neo4j graph database that are connected to a specific dbo_Treatments node via a REFERENCES_PRODUCT relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
2217 - 2224
simple
Purpose
This function queries a Neo4j graph database to find product references associated with a specific treatment. It's designed for traversing relationships in a medical/pharmaceutical domain model where treatments reference products. The function uses Cypher query language to match patterns and return connected nodes, useful for discovering which products are associated with a given treatment regimen.
Source Code
def get_dbo_treatments_with_references_product_dbo_product(source_id, limit=100):
"""Get dbo_Product nodes connected to a dbo_Treatments via REFERENCES_PRODUCT"""
query = """
MATCH (source:dbo_Treatments {id: $source_id})-[r:REFERENCES_PRODUCT]->(target:dbo_Product)
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 (id property) of the dbo_Treatments node from which to find connected products. 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_Product nodes to return. Defaults to 100. This parameter controls query result size to prevent overwhelming responses or performance issues. Must be a positive integer.
Return Value
Returns the result of run_query() function, which typically contains a list or collection of dbo_Product nodes that match the query criteria. Each node will have properties defined in the Neo4j database schema for dbo_Product. The exact return type depends on the run_query() implementation, but commonly returns a list of dictionaries or Neo4j Record objects containing the 'target' (dbo_Product) node data. Returns empty collection if no matching products 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:
from neo4j import GraphDatabase
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
def run_query(query, params):
with driver.session() as session:
result = session.run(query, params)
return [record['target'] for record in result]
# Use the function
treatment_id = 'TREATMENT_12345'
products = get_dbo_treatments_with_references_product_dbo_product(treatment_id, limit=50)
# Process results
for product in products:
print(f"Product: {product}")
# With default limit
all_products = get_dbo_treatments_with_references_product_dbo_product('TREATMENT_67890')
Best Practices
- Ensure the source_id parameter matches an existing dbo_Treatments node id in the database to avoid empty results
- Adjust the limit parameter based on expected result size and performance requirements
- Handle empty results gracefully when no products are connected to the treatment
- Consider adding error handling around the run_query call for database connection issues
- Ensure proper Neo4j driver cleanup and connection pooling in the run_query implementation
- Validate that the run_query function is properly defined and handles Neo4j session management
- Consider adding indexes on the 'id' property of dbo_Treatments nodes for better query performance
- Be aware that this function depends on the external run_query function which must be available in scope
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_treatments_with_references_tnv_dbo_tnv 83.6% similar
-
function create_references_product_relationship 82.7% similar
-
function get_dbo_treatments_with_references_houses_dbo_houses 78.8% similar
-
function get_dbo_treatments_with_references_establishment_dbo_establishment 78.5% similar
-
function get_dbo_treatments_by_id 75.9% similar