🔍 Code Extractor

function get_lims_tests_by_uid

Maturity: 39

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
469 - 476
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific LIMS_Tests node using its UID property. It's designed for Laboratory Information Management System (LIMS) data retrieval, returning the first matching node or None if no match is found. This is useful for looking up specific test records in a graph database structure.

Source Code

def get_lims_tests_by_uid(uid):
    """Get a LIMS_Tests node by its UID"""
    query = """
    MATCH (n:LIMS_Tests {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_Tests node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This should correspond to a unique test identifier in the LIMS system.

Return Value

Returns a dictionary-like object representing the LIMS_Tests node if found, containing all properties of the matched node. Returns None if no node with the specified UID exists. The exact structure depends on the properties stored in the LIMS_Tests node in the database.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function 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_tests_by_uid
test_uid = 'TEST-12345'
test_node = get_lims_tests_by_uid(test_uid)

if test_node:
    print(f"Found test: {test_node}")
else:
    print(f"No test found with UID: {test_uid}")

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
  • Handle the None return value appropriately in calling code to avoid AttributeError
  • Consider adding type hints for better code documentation (e.g., def get_lims_tests_by_uid(uid: str) -> Optional[Dict])
  • Ensure proper Neo4j database connection pooling and session management in the run_query function
  • Consider adding logging for debugging database queries and results
  • The UID property should be indexed in Neo4j for optimal query performance

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_lims_sampletypetests_by_uid 92.1% 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_tests4pathogens_by_uid 91.1% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletestresults_by_uid 90.9% 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_testparameters_by_uid 90.6% similar

    Retrieves a LIMS_Testparameters 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_tests_by_id 89.4% 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
← Back to Browse