🔍 Code Extractor

function get_lims_samples_by_uid

Maturity: 39

Retrieves a single LIMS_Samples node from a Neo4j graph database by matching its unique identifier (UID).

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
391 - 398
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific LIMS (Laboratory Information Management System) sample record using its UID. It's designed for retrieving individual sample data from a graph database where samples are stored as nodes with the label 'LIMS_Samples'. The function returns the first matching node or None if no match is found.

Source Code

def get_lims_samples_by_uid(uid):
    """Get a LIMS_Samples node by its UID"""
    query = """
    MATCH (n:LIMS_Samples {UID: $uid})
    RETURN n
    """
    result = run_query(query, {"uid": uid})
    return result[0] if result else None

Parameters

Name Type Default Kind
uid - - positional_or_keyword

Parameter Details

uid: The unique identifier (UID) of the LIMS_Samples node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This should be a unique value that identifies a specific sample in the LIMS system.

Return Value

Returns the first LIMS_Samples node that matches the provided UID, or None if no matching node is found. The return type is typically a dictionary-like object representing the Neo4j node with all its properties, or None. The actual structure depends on how the run_query function processes Neo4j results.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j 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]

# Using get_lims_samples_by_uid
sample_uid = 'SAMPLE-12345'
sample = get_lims_samples_by_uid(sample_uid)

if sample:
    print(f'Found sample: {sample}')
else:
    print('Sample not found')

# Clean up
driver.close()

Best Practices

  • Ensure the run_query function is properly implemented with error handling and connection management
  • Validate that the uid parameter is not None or empty before calling this function
  • Consider adding error handling for database connection failures
  • The function assumes UIDs are unique; ensure database constraints enforce this
  • Close Neo4j driver connections properly when done with database operations
  • Consider adding logging for debugging purposes, especially when None is returned
  • For production use, implement proper connection pooling and session management

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_lims_sampletestresults_by_uid 92.3% 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_sampletypes_by_uid 91.1% similar

    Retrieves a single LIMS_SampleTypes node from a Neo4j graph database by matching its unique identifier (UID).

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_samples_by_id 90.4% 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_sampletypetests_by_uid 89.7% similar

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

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

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

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