function get_lims_importerrors_by_uid
Retrieves a LIMS_ImportErrors node from a Neo4j graph database by its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
40 - 47
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_ImportErrors node using its UID. It's designed for Laboratory Information Management System (LIMS) error tracking, allowing retrieval of import error 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_importerrors_by_uid(uid):
"""Get a LIMS_ImportErrors node by its UID"""
query = """
MATCH (n:LIMS_ImportErrors {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_ImportErrors node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This parameter is used in a parameterized query to prevent injection attacks.
Return Value
Returns a dictionary-like object representing the LIMS_ImportErrors 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 LIMS_ImportErrors node in the database.
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
error_uid = 'error-12345'
error_node = get_lims_importerrors_by_uid(error_uid)
if error_node:
print(f'Found error node: {error_node}')
else:
print('No error node found with that UID')
Best Practices
- Ensure the run_query function is properly defined with error handling and connection management
- Always check if the return value is None before accessing node properties
- Use parameterized queries (as done here with $uid) to prevent Cypher injection attacks
- Consider adding error handling for database connection failures
- Ensure proper Neo4j driver cleanup and connection pooling in the run_query implementation
- Validate the uid parameter before passing it to the query if additional constraints exist
- Consider adding logging for debugging database queries and results
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_importerrors_by_id 89.0% similar
-
function get_lims_requests_by_uid 84.7% similar
-
function get_lims_parameters_by_uid 84.1% similar
-
function get_lims_tests_by_uid 82.2% similar
-
function get_lims_sampletestresults_by_uid 82.0% similar