🔍 Code Extractor

function get_lims_sampletestresults_by_id

Maturity: 39

Retrieves a single LIMS_SampleTestResults node from a Neo4j graph database by its unique identifier.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
226 - 233
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific LIMS_SampleTestResults node using its ID. It's designed for Laboratory Information Management System (LIMS) data retrieval, allowing users to access sample test result records stored in a graph database. The function returns the first matching node or None if no match is found.

Source Code

def get_lims_sampletestresults_by_id(id):
    """Get a LIMS_SampleTestResults node by its ID"""
    query = """
    MATCH (n:LIMS_SampleTestResults {id: $id})
    RETURN n
    """
    result = run_query(query, {"id": id})
    return result[0] if result else None

Parameters

Name Type Default Kind
id - - positional_or_keyword

Parameter Details

id: The unique identifier of the LIMS_SampleTestResults node to retrieve. Expected to be a string or integer that matches the 'id' property of nodes in the Neo4j database. This should correspond to a valid sample test result identifier in the LIMS system.

Return Value

Returns a dictionary-like object representing the LIMS_SampleTestResults node if found, containing all properties of the node. Returns None if no node with the specified ID exists. The exact structure depends on the properties stored in the Neo4j node, but typically includes test results, sample information, and metadata.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function is defined and Neo4j connection is configured
from neo4j import GraphDatabase

# Define run_query helper function (example implementation)
def run_query(query, parameters):
    driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
    with driver.session() as session:
        result = session.run(query, parameters)
        return [record['n'] for record in result]
    driver.close()

# Use the function to retrieve a sample test result
sample_id = 'TEST-12345'
result = get_lims_sampletestresults_by_id(sample_id)

if result:
    print(f'Found sample test result: {result}')
else:
    print(f'No sample test result found with ID: {sample_id}')

Best Practices

  • Ensure the run_query function is properly implemented with error handling and connection management
  • Validate the ID parameter before passing it to prevent injection attacks or invalid queries
  • Consider adding error handling for database connection failures or query execution errors
  • The function assumes run_query returns a list; ensure this contract is maintained
  • Close Neo4j driver connections properly to avoid resource leaks
  • Consider adding logging for debugging and monitoring database queries
  • For production use, implement connection pooling and retry logic for database operations

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_lims_sampletestresultdetails_by_id 93.3% similar

    Retrieves a single LIMS_SampleTestResultDetails node from a Neo4j graph database by its unique identifier.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_samples_by_id 91.7% similar

    Retrieves a single LIMS_Samples node from a Neo4j graph database by its unique identifier.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_tests_by_id 89.9% similar

    Retrieves a single LIMS_Tests node from a Neo4j graph database by its unique identifier.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletestresults_by_uid 89.7% similar

    Retrieves a LIMS_SampleTestResults node from a Neo4j graph database by its unique identifier (UID).

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletypetests_by_id 89.2% similar

    Retrieves a LIMS_SampleTypeTests node from a Neo4j graph database by its unique identifier.

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