function get_all_dbo_interventionprotocols
Queries a Neo4j graph database to retrieve all nodes labeled as 'dbo_InterventionProtocols' with a configurable limit on the number of results returned.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
958 - 965
simple
Purpose
This function provides a way to fetch intervention protocol data from a Neo4j database. It's designed for retrieving medical or clinical intervention protocol information stored as graph nodes. The function uses Cypher query language to match nodes with the specific label and returns them through a helper function 'run_query'. Despite the docstring mentioning a limit of 25, the default parameter is actually 100, allowing flexible control over result set size.
Source Code
def get_all_dbo_interventionprotocols(limit=100):
"""Return dbo_InterventionProtocols nodes (limited to 25)"""
query = """
MATCH (n:dbo_InterventionProtocols)
RETURN n
LIMIT $limit
"""
return run_query(query, {"limit": limit})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
limit |
- | 100 | positional_or_keyword |
Parameter Details
limit: Integer value that controls the maximum number of dbo_InterventionProtocols nodes to return from the database query. Default is 100. Note: The docstring incorrectly states the limit as 25, but the actual default parameter value is 100. This parameter is passed to the Cypher query's LIMIT clause to prevent overwhelming result sets.
Return Value
Returns the result of the 'run_query' function execution. The exact return type depends on the implementation of 'run_query', but typically would be a list of Neo4j node records or a result object containing the matched dbo_InterventionProtocols nodes. Each node would contain properties associated with intervention protocols stored in the database. If no nodes match, an empty result set would be returned.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
from neo4j import GraphDatabase
# Assuming run_query is defined elsewhere in your module
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['n'] for record in result]
driver.close()
# Get default 100 intervention protocols
protocols = get_all_dbo_interventionprotocols()
# Get only 10 intervention protocols
protocols_limited = get_all_dbo_interventionprotocols(limit=10)
# Process the results
for protocol in protocols:
print(protocol)
Best Practices
- Be aware of the discrepancy between the docstring (mentions limit of 25) and the actual default parameter value (100)
- Consider adjusting the limit parameter based on expected data volume to avoid memory issues with large result sets
- Ensure proper error handling around the run_query function call for database connection failures
- The run_query helper function should handle database connection management and proper resource cleanup
- Consider adding pagination support for very large datasets instead of relying solely on LIMIT
- Validate that the Neo4j database schema includes the 'dbo_InterventionProtocols' label before querying
- Consider adding additional filtering parameters (e.g., by protocol name, date, status) for more targeted queries
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_all_dbo_interventionprotocolflocks 87.1% similar
-
function get_dbo_interventionprotocols_by_id 84.2% similar
-
function get_dbo_interventionprotocolflocks_with_references_interventionprotocols_dbo_interventionprotocols 81.4% similar
-
function get_dbo_interventionprotocols_by_uid 79.3% similar
-
function create_dbo_interventionprotocols 75.1% similar