🔍 Code Extractor

function get_all_lims_sampletypes

Maturity: 39

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
334 - 341
Complexity:
simple

Purpose

This function is designed to fetch sample type information from a Laboratory Information Management System (LIMS) stored in a Neo4j graph database. It's useful for retrieving metadata about different sample types available in the LIMS, such as for populating dropdown menus, generating reports, or performing data analysis on sample classifications. The function provides a simple interface to query the database without requiring direct knowledge of Cypher query language.

Source Code

def get_all_lims_sampletypes(limit=100):
    """Return LIMS_SampleTypes nodes (limited to 25)"""
    query = """
    MATCH (n:LIMS_SampleTypes)
    RETURN n
    LIMIT $limit
    """
    return run_query(query, {"limit": limit})

Parameters

Name Type Default Kind
limit - 100 positional_or_keyword

Parameter Details

limit: An integer that specifies the maximum number of LIMS_SampleTypes nodes to return from the database. Default value is 100. Note: The docstring incorrectly states the limit is 25, but the actual default is 100. This parameter helps control query performance and result set size.

Return Value

Returns the result of the run_query function, which typically contains a list or collection of Neo4j node objects representing LIMS_SampleTypes. 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 LIMS_SampleTypes 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 is configured
# Example 1: Get default 100 sample types
sample_types = get_all_lims_sampletypes()
for record in sample_types:
    print(record['n'])

# Example 2: Get only 10 sample types
sample_types_limited = get_all_lims_sampletypes(limit=10)

# Example 3: Get all sample types (use a very large limit)
all_sample_types = get_all_lims_sampletypes(limit=10000)

Best Practices

  • The docstring contains an error - it states the limit is 25 but the default parameter is 100. Update the docstring to match the actual default value.
  • Consider adding error handling for database connection issues or query failures.
  • The limit parameter should be validated to ensure it's a positive integer to prevent unexpected query behavior.
  • Consider adding type hints for better code documentation: def get_all_lims_sampletypes(limit: int = 100) -> List[Dict]
  • Ensure the run_query function is properly defined with appropriate connection management and error handling.
  • For production use, consider implementing pagination instead of a simple limit to handle large datasets more efficiently.
  • Document the structure of the returned LIMS_SampleTypes nodes so users know what properties are available.

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_all_lims_sampletypeproperties 92.0% similar

    Queries a Neo4j graph database to retrieve LIMS_SampleTypeProperties 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_sampletypetests 91.5% similar

    Queries a Neo4j graph database to retrieve LIMS_SampleTypeTests 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_samples 90.2% similar

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

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

    Queries a Neo4j graph database to retrieve LIMS_SampleTypes nodes that are connected to a specific LIMS_Samples node through a REFERENCES_SAMPLETYPES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletypes_by_id 88.0% similar

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

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