function get_lims_testparameters_by_uid
Retrieves a LIMS_Testparameters node from a Neo4j graph database by matching its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
430 - 437
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_Testparameters node using its UID property. It's designed for Laboratory Information Management System (LIMS) applications where test parameters need to be retrieved by their unique identifier. The function returns the first matching node or None if no match is found.
Source Code
def get_lims_testparameters_by_uid(uid):
"""Get a LIMS_Testparameters node by its UID"""
query = """
MATCH (n:LIMS_Testparameters {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_Testparameters 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 valid UID in the LIMS_Testparameters nodes.
Return Value
Returns a dictionary-like object representing the LIMS_Testparameters 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_Testparameters node in the database.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j is configured
from neo4j import GraphDatabase
# Define run_query helper function (example implementation)
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 to retrieve a test parameter
uid = 'TEST-PARAM-001'
test_parameter = get_lims_testparameters_by_uid(uid)
if test_parameter:
print(f'Found test parameter: {test_parameter}')
else:
print(f'No test parameter found with UID: {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 input validation for the uid parameter
- Ensure proper Neo4j database connection pooling is configured for production use
- Consider adding logging for debugging database queries
- The function assumes UIDs are unique; ensure database constraints enforce this uniqueness
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_parameters_by_uid 94.5% similar
-
function get_lims_tests_by_uid 90.6% similar
-
function get_lims_testparameters_by_id 88.9% similar
-
function get_lims_tests4pathogens_by_uid 88.7% similar
-
function get_lims_sampletestresults_by_uid 88.7% similar