function get_all_lims_pathogens
Retrieves LIMS_Pathogens nodes from a Neo4j graph database with a configurable limit on the number of results returned.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
100 - 107
simple
Purpose
This function queries a Neo4j database to fetch all nodes labeled as LIMS_Pathogens. It's designed for retrieving pathogen data from a Laboratory Information Management System (LIMS) stored in a graph database. The function uses a parameterized query to allow flexible result limiting, making it suitable for pagination, testing, or controlled data retrieval scenarios.
Source Code
def get_all_lims_pathogens(limit=100):
"""Return LIMS_Pathogens nodes (limited to 25)"""
query = """
MATCH (n:LIMS_Pathogens)
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 LIMS_Pathogens nodes to return from the database. Default is 100. Note: The docstring incorrectly states 'limited to 25', but the actual default is 100. This parameter helps prevent overwhelming queries on large datasets and enables pagination.
Return Value
Returns the result of run_query() function, which typically returns a list of Neo4j Record objects or dictionaries containing the LIMS_Pathogens node data. The exact return type depends on the implementation of run_query(), but it should contain up to 'limit' number of pathogen nodes with all their properties. If no nodes are found, it likely returns an empty list.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is established
# Example 1: Get default 100 pathogens
pathogens = get_all_lims_pathogens()
for pathogen in pathogens:
print(pathogen['n'])
# Example 2: Get only 10 pathogens
pathogens_limited = get_all_lims_pathogens(limit=10)
# Example 3: Get all pathogens (use large limit)
all_pathogens = get_all_lims_pathogens(limit=10000)
Best Practices
- The docstring contains incorrect information (states 'limited to 25' but default is 100) - should be updated for accuracy
- Consider adding type hints for better code documentation: def get_all_lims_pathogens(limit: int = 100) -> list
- Validate that limit is a positive integer to prevent invalid queries
- Consider adding error handling for database connection issues
- For production use, implement proper pagination instead of relying solely on LIMIT
- Be cautious with very large limit values as they may cause performance issues or memory problems
- Ensure the run_query() function properly handles connection pooling and closes connections
- Consider adding logging to track query execution and performance
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_all_lims_tests4pathogens 94.1% similar
-
function get_lims_pathogens_by_id 86.6% similar
-
function get_all_lims_parameters 85.8% similar
-
function get_all_lims_testparameters 84.5% similar
-
function get_lims_tests4pathogens_by_id 82.4% similar