function get_dbo_treatments_with_references_establishment_dbo_establishment
Queries a Neo4j graph database to retrieve dbo_Establishment nodes that are connected to a specific dbo_Treatments node through a REFERENCES_ESTABLISHMENT relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
2121 - 2128
simple
Purpose
This function is designed to traverse a graph database to find all establishment entities associated with a particular treatment record. It's useful for discovering which medical or research establishments are referenced by a specific treatment, enabling analysis of treatment-establishment relationships in a healthcare or research context. The function supports pagination through a configurable limit parameter.
Source Code
def get_dbo_treatments_with_references_establishment_dbo_establishment(source_id, limit=100):
"""Get dbo_Establishment nodes connected to a dbo_Treatments via REFERENCES_ESTABLISHMENT"""
query = """
MATCH (source:dbo_Treatments {id: $source_id})-[r:REFERENCES_ESTABLISHMENT]->(target:dbo_Establishment)
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 graph traversal. This should be a string or integer value that matches the 'id' property of a dbo_Treatments node in the Neo4j database.
limit: Maximum number of dbo_Establishment nodes to return. Defaults to 100. This parameter controls pagination and prevents overwhelming results. Must be a positive integer.
Return Value
Returns the result of the run_query function, which typically contains a list or collection of dbo_Establishment nodes that match the query criteria. The exact return type depends on the implementation of run_query, but it likely returns a list of dictionaries or Neo4j Record objects containing the properties of each matched dbo_Establishment node. Returns an empty collection if no matching establishments are found.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example 1: Get establishments for a specific treatment
treatment_id = "TREAT_12345"
establishments = get_dbo_treatments_with_references_establishment_dbo_establishment(treatment_id)
# Example 2: Limit results to 50
establishments = get_dbo_treatments_with_references_establishment_dbo_establishment(treatment_id, limit=50)
# Example 3: Process results
for record in establishments:
establishment = record['target']
print(f"Establishment ID: {establishment['id']}")
print(f"Establishment Name: {establishment.get('name', 'N/A')}")
Best Practices
- Always validate that source_id exists in the database before calling this function to avoid empty results
- Use appropriate limit values based on expected result sizes to optimize performance and memory usage
- Consider implementing error handling around this function to catch Neo4j connection errors or query failures
- Ensure the run_query function properly manages database connections and closes them after use
- For large datasets, consider implementing pagination by calling this function multiple times with different offsets
- Verify that the REFERENCES_ESTABLISHMENT relationship exists in your graph schema before using this function
- Consider adding indexes on the 'id' property of dbo_Treatments nodes for better query performance
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_houses_with_references_establishment_dbo_establishment 85.0% similar
-
function get_dbo_tnv_with_references_establishment_dbo_establishment 84.7% similar
-
function get_dbo_establishmentcycles_with_references_establishment_dbo_establishment 84.4% similar
-
function create_references_establishment_relationship_v6 82.9% similar
-
function get_dbo_treatments_with_references_tnv_dbo_tnv 80.5% similar