function get_lims_tests4pathogens_by_uid
Retrieves a LIMS_Tests4Pathogens node from a Neo4j graph database by its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
508 - 515
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_Tests4Pathogens node using its UID. It's designed for laboratory information management systems (LIMS) to retrieve pathogen test information. The function executes a Cypher query and returns the first matching node or None if no match is found.
Source Code
def get_lims_tests4pathogens_by_uid(uid):
"""Get a LIMS_Tests4Pathogens node by its UID"""
query = """
MATCH (n:LIMS_Tests4Pathogens {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_Tests4Pathogens node to retrieve. Expected to be a string or value that matches the UID property in the Neo4j database. This should correspond to a specific pathogen test record in the LIMS system.
Return Value
Returns the first LIMS_Tests4Pathogens node that matches the provided UID, or None if no matching node is found. The return type is likely a dictionary or Neo4j node object containing all properties of the matched node. Returns None when the result list is empty.
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 = 'TEST-12345'
test_node = get_lims_tests4pathogens_by_uid(uid)
if test_node:
print(f'Found test node: {test_node}')
else:
print('No test node found with that UID')
Best Practices
- Ensure the run_query function is properly defined and handles Neo4j connection errors gracefully
- Validate the uid parameter before passing it to the function to prevent injection attacks
- Consider adding error handling for database connection failures
- The function assumes run_query returns a list; ensure this contract is maintained
- Consider adding type hints for better code documentation (e.g., def get_lims_tests4pathogens_by_uid(uid: str) -> Optional[Dict])
- 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_pathogens_by_uid 93.6% similar
-
function get_lims_tests4pathogens_by_id 91.1% similar
-
function get_lims_tests_by_uid 91.1% similar
-
function get_lims_testparameters_by_uid 88.7% similar
-
function get_lims_sampletestresults_by_uid 86.6% similar