🔍 Code Extractor

function get_lims_sampletypes_by_uid

Maturity: 39

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
352 - 359
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific LIMS_SampleTypes node using its UID property. It's designed for Laboratory Information Management System (LIMS) data retrieval, allowing users to look up sample type information by a unique identifier. The function returns the first matching node or None if no match is found.

Source Code

def get_lims_sampletypes_by_uid(uid):
    """Get a LIMS_SampleTypes node by its UID"""
    query = """
    MATCH (n:LIMS_SampleTypes {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_SampleTypes node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This should be a valid, existing UID for a LIMS_SampleTypes node.

Return Value

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

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

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

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

# Use the function
sample_uid = 'SAMPLE_001'
sample_type = get_lims_sampletypes_by_uid(sample_uid)

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

Best Practices

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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_lims_sampletypeproperties_by_uid 93.0% similar

    Retrieves a LIMS_SampleTypeProperties 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_uid 92.5% 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_sampletypes_by_id 91.3% 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
  • function get_lims_samples_by_uid 91.1% similar

    Retrieves a single LIMS_Samples 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_sampletestresults_by_uid 87.4% 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
← Back to Browse