function get_lims_requests_by_uid
Retrieves a single LIMS_Requests node from a Neo4j graph database by matching its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
157 - 164
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_Requests 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 laboratory requests by their unique identifier in a graph database context.
Source Code
def get_lims_requests_by_uid(uid):
"""Get a LIMS_Requests node by its UID"""
query = """
MATCH (n:LIMS_Requests {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_Requests 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_Requests node.
Return Value
Returns the first LIMS_Requests node object that matches the provided UID, or None if no matching node is found. The node object contains all properties stored in the Neo4j database for that specific LIMS_Requests node. The return type is either a Neo4j node record/dictionary or None.
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, parameters):
with driver.session() as session:
result = session.run(query, parameters)
return [record['n'] for record in result]
# Using the function
uid_to_search = 'REQ-12345'
request_node = get_lims_requests_by_uid(uid_to_search)
if request_node:
print(f'Found LIMS request: {request_node}')
else:
print('No LIMS request found with that 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 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 when done with database operations
- Consider adding logging for debugging database queries
- UIDs should be unique; if multiple nodes could match, consider the implications of returning only the first result
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_requests_by_id 90.5% similar
-
function get_lims_tests_by_uid 88.3% similar
-
function get_lims_samples_by_uid 88.3% similar
-
function get_lims_parameters_by_uid 88.0% similar
-
function get_lims_sampletestresults_by_uid 86.1% similar