function get_lims_sampletestresults_by_uid
Retrieves a LIMS_SampleTestResults node from a Neo4j graph database by its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
235 - 242
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_SampleTestResults node using its UID. 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_uid(uid):
"""Get a LIMS_SampleTestResults node by its UID"""
query = """
MATCH (n:LIMS_SampleTestResults {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_SampleTestResults node to retrieve. Expected to be a string or value that matches the UID property in the Neo4j database. This should be a valid identifier that exists in the database.
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 UID exists. The exact structure depends on the properties stored in the Neo4j node, but typically includes fields related to sample test results.
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 the function
uid = 'SAMPLE-12345'
result = get_lims_sampletestresults_by_uid(uid)
if result:
print(f"Found sample test results: {result}")
else:
print(f"No sample test results found for UID: {uid}")
Best Practices
- Ensure the run_query function is properly implemented with error handling and connection management
- Validate the uid parameter before passing it to the function to avoid unnecessary database queries
- Handle the None return value appropriately in calling code to avoid NoneType errors
- Consider adding error handling for database connection failures
- Use connection pooling for better performance when making multiple queries
- Close Neo4j driver connections properly when the application terminates
- Consider adding logging for debugging and monitoring database queries
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_sampletestresultdetails_by_uid 95.5% similar
-
function get_lims_samples_by_uid 92.3% similar
-
function get_lims_sampletypetests_by_uid 91.7% similar
-
function get_lims_tests_by_uid 90.9% similar
-
function get_lims_sampletestresults_by_id 89.7% similar