🔍 Code Extractor

function get_dbo_interventionprotocolflocks_with_references_interventionprotocols_dbo_interventionprotocols

Maturity: 43

Queries a Neo4j graph database to retrieve dbo_InterventionProtocols nodes that are connected to a specific dbo_InterventionProtocolFlocks node via a REFERENCES_INTERVENTIONPROTOCOLS relationship.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
2057 - 2064
Complexity:
simple

Purpose

This function is designed to traverse a graph database relationship to find intervention protocols associated with a specific intervention protocol flock. It's useful in scenarios where you need to discover which intervention protocols are referenced by a particular flock, such as in medical or research data management systems. The function uses Cypher query language to perform the graph traversal and returns a limited set of results.

Source Code

def get_dbo_interventionprotocolflocks_with_references_interventionprotocols_dbo_interventionprotocols(source_id, limit=100):
    """Get dbo_InterventionProtocols nodes connected to a dbo_InterventionProtocolFlocks via REFERENCES_INTERVENTIONPROTOCOLS"""
    query = """
    MATCH (source:dbo_InterventionProtocolFlocks {id: $source_id})-[r:REFERENCES_INTERVENTIONPROTOCOLS]->(target:dbo_InterventionProtocols)
    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_InterventionProtocolFlocks node from which to start the relationship traversal. This should be a string or value that matches the 'id' property in the Neo4j database.

limit: Maximum number of target nodes to return from the query. Defaults to 100. This parameter helps control the result set size and prevent overwhelming responses. Must be a positive integer.

Return Value

Returns the result of the run_query function execution, which typically contains a list or collection of dbo_InterventionProtocols 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 the matched target nodes. Returns an empty collection 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
from neo4j import GraphDatabase

# Define or import the run_query function
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]
    driver.close()

# Use the function to get intervention protocols
source_flock_id = 'flock_12345'
protocols = get_dbo_interventionprotocolflocks_with_references_interventionprotocols_dbo_interventionprotocols(source_flock_id, limit=50)

# Process the results
for protocol in protocols:
    print(f"Protocol ID: {protocol['id']}")

Best Practices

  • Ensure the source_id parameter matches the exact format and type stored in the Neo4j database
  • Use appropriate limit values to avoid performance issues with large datasets
  • Handle cases where no results are returned (empty collection)
  • Implement proper error handling around the run_query function call to catch database connection issues
  • Consider adding pagination if working with large result sets beyond the limit parameter
  • Ensure the run_query function properly closes database connections to prevent resource leaks
  • Validate that the source_id exists before querying to provide better error messages
  • Consider adding logging to track query execution and performance

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_dbo_interventionprotocolflocks_with_references_flocks_dbo_flocks 94.5% similar

    Queries a Neo4j graph database to retrieve dbo_Flocks nodes that are connected to a specific dbo_InterventionProtocolFlocks node through a REFERENCES_FLOCKS relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_interventionprotocolflocks 88.9% similar

    Queries a Neo4j graph database to retrieve all nodes labeled as 'dbo_InterventionProtocolFlocks' with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocolflocks_by_id 86.1% similar

    Retrieves a single dbo_InterventionProtocolFlocks node from a Neo4j graph database by its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_references_interventionprotocols_relationship 82.8% similar

    Creates a directed REFERENCES_INTERVENTIONPROTOCOLS relationship in a Neo4j graph database from a dbo_InterventionProtocolFlocks node to a dbo_InterventionProtocols node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocolflocks_by_uid 82.0% similar

    Retrieves a single dbo_InterventionProtocolFlocks node from a Neo4j graph database by matching its unique identifier (UID).

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