function get_all_lims_sampletypetests
Queries a Neo4j graph database to retrieve LIMS_SampleTypeTests nodes with a configurable limit on the number of results returned.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
295 - 302
simple
Purpose
This function is designed to fetch sample type test records from a Laboratory Information Management System (LIMS) stored in a Neo4j graph database. It provides a simple interface to retrieve all nodes labeled as LIMS_SampleTypeTests, with pagination support through a limit parameter. This is useful for data exploration, reporting, or integration with other systems that need to access LIMS sample type test configurations.
Source Code
def get_all_lims_sampletypetests(limit=100):
"""Return LIMS_SampleTypeTests nodes (limited to 25)"""
query = """
MATCH (n:LIMS_SampleTypeTests)
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_SampleTypeTests nodes to return from the database. Default is 100. Note: The docstring incorrectly states the limit is 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 the run_query function, which typically contains a list or collection of Neo4j node objects representing LIMS_SampleTypeTests records. 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 node. The number of results will not exceed the specified limit parameter.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example run_query implementation:
from neo4j import GraphDatabase
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
def run_query(query, params):
with driver.session() as session:
result = session.run(query, params)
return [record['n'] for record in result]
# Use the function
results = get_all_lims_sampletypetests(limit=50)
print(f'Retrieved {len(results)} sample type tests')
# Iterate through results
for sample_test in results:
print(sample_test)
# Get default limit (100)
all_results = get_all_lims_sampletypetests()
Best Practices
- Be aware of the discrepancy between the docstring (which mentions limit of 25) and the actual default parameter value (100)
- Ensure the run_query function is properly implemented with error handling and connection management
- Consider implementing pagination for large datasets by calling this function multiple times with SKIP clauses
- Always close Neo4j driver connections properly to avoid resource leaks
- Validate that the limit parameter is a positive integer before use
- Consider adding error handling for cases where the database is unavailable or the node label doesn't exist
- For production use, consider adding authentication and authorization checks
- Monitor query performance and adjust the limit parameter based on system resources and requirements
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_all_lims_sampletypes 91.5% similar
-
function get_all_lims_tests 91.1% similar
-
function get_all_lims_sampletestresults 89.7% similar
-
function get_lims_sampletypetests_by_id 88.2% similar
-
function get_all_lims_samples 88.1% similar