🔍 Code Extractor

function get_all_lims_samples

Maturity: 39

Queries a Neo4j graph database to retrieve LIMS_Samples nodes with a configurable limit on the number of results returned.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
373 - 380
Complexity:
simple

Purpose

This function provides a simple interface to fetch Laboratory Information Management System (LIMS) sample records stored as nodes in a Neo4j graph database. It's designed for retrieving sample data for analysis, reporting, or further processing. The function uses Cypher query language to match all nodes labeled as LIMS_Samples and returns them through a query execution function.

Source Code

def get_all_lims_samples(limit=100):
    """Return LIMS_Samples nodes (limited to 25)"""
    query = """
    MATCH (n:LIMS_Samples)
    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_Samples nodes to return from the database. Default is 100, though the docstring incorrectly states 25. Must be a positive integer. Higher values may impact performance depending on database size and network conditions.

Return Value

Returns the result of run_query() function execution, which typically contains a list or collection of LIMS_Samples node objects from the Neo4j database. The exact return type depends on the implementation of run_query(), but commonly would be a list of dictionaries or Neo4j Record objects containing node properties. Returns up to 'limit' number of nodes. If no nodes exist or the database is unreachable, behavior depends on run_query() implementation (may return empty list or raise exception).

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j connection is configured
# Example 1: Get default 100 samples
samples = get_all_lims_samples()
for sample in samples:
    print(sample)

# Example 2: Get only 10 samples
samples_limited = get_all_lims_samples(limit=10)

# Example 3: Get all samples (use large limit)
all_samples = get_all_lims_samples(limit=10000)

Best Practices

  • Note the discrepancy: docstring says 'limited to 25' but default parameter is 100 - update documentation for consistency
  • Be cautious with large limit values as they may cause performance issues or memory constraints
  • Ensure the run_query() function properly handles database connection errors and query failures
  • Consider adding error handling for invalid limit values (negative numbers, non-integers)
  • For production use, implement pagination instead of relying solely on LIMIT for large datasets
  • Verify that the Neo4j database connection is properly closed after query execution (should be handled by run_query())
  • Consider adding additional parameters for filtering or sorting LIMS_Samples nodes based on properties

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_all_lims_sampletestresults 91.5% similar

    Retrieves LIMS_SampleTestResults nodes from a Neo4j graph database with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_lims_sampletypes 90.2% similar

    Queries a Neo4j graph database to retrieve LIMS_SampleTypes nodes with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_lims_tests 89.3% similar

    Queries a Neo4j graph database to retrieve LIMS_Tests nodes with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_lims_requests 89.1% similar

    Queries a Neo4j graph database to retrieve LIMS_Requests nodes with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_lims_sampletestresultdetails 88.6% similar

    Queries a Neo4j graph database to retrieve LIMS_SampleTestResultDetails nodes with a configurable limit on the number of results returned.

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