function get_dbo_treatments_with_references_houses_dbo_houses
Retrieves dbo_Houses nodes from a Neo4j graph database that are connected to a specific dbo_Treatments node via a REFERENCES_HOUSES relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
2185 - 2192
simple
Purpose
This function queries a Neo4j graph database to find all house records (dbo_Houses) that are referenced by a specific treatment record (dbo_Treatments). It's useful for understanding which houses are associated with a particular treatment, such as in medical, pest control, or property management systems where treatments are linked to physical locations.
Source Code
def get_dbo_treatments_with_references_houses_dbo_houses(source_id, limit=100):
"""Get dbo_Houses nodes connected to a dbo_Treatments via REFERENCES_HOUSES"""
query = """
MATCH (source:dbo_Treatments {id: $source_id})-[r:REFERENCES_HOUSES]->(target:dbo_Houses)
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 dbo_Houses nodes. Expected to be a string or integer that matches the id field in the Neo4j database.
limit: Maximum number of dbo_Houses nodes to return. Defaults to 100. Must be a positive integer. Used to prevent overwhelming results and control query performance.
Return Value
Returns the result of run_query() function, which typically returns a list of Neo4j records containing the target dbo_Houses nodes. Each record represents a house node with all its properties. The exact return type depends on the run_query() implementation, but is likely a list of dictionaries or Neo4j Record objects. Returns an empty list if no connections are found or if the source_id doesn't exist.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example 1: Get houses for a specific treatment
treatment_id = "TREAT_12345"
houses = get_dbo_treatments_with_references_houses_dbo_houses(treatment_id)
for house in houses:
print(house)
# Example 2: Limit results to 10 houses
houses_limited = get_dbo_treatments_with_references_houses_dbo_houses("TREAT_67890", limit=10)
# Example 3: Check if any houses are referenced
if houses:
print(f"Found {len(houses)} houses for this treatment")
else:
print("No houses found for this treatment")
Best Practices
- Always validate that source_id exists before calling this function to avoid unnecessary database queries
- Consider adjusting the limit parameter based on expected result sizes to optimize performance
- Ensure proper error handling around the run_query() call in production code
- Index the 'id' property on dbo_Treatments nodes for better query performance
- Consider pagination for large result sets instead of increasing the limit parameter
- Verify that the Neo4j connection is established before calling this function
- Be aware that this function depends on the run_query() helper function which must handle connection management and error handling
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_concepthouses_with_references_houses_dbo_houses 82.7% similar
-
function create_references_houses_relationship_v3 82.4% similar
-
function get_dbo_treatments_with_references_establishment_dbo_establishment 80.4% similar
-
function get_dbo_treatments_with_references_tnv_dbo_tnv 79.6% similar
-
function get_dbo_houses_with_references_establishment_dbo_establishment 79.4% similar