function get_lims_requests_by_id
Retrieves a single LIMS_Requests node from a Neo4j graph database by matching its unique ID property.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
148 - 155
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_Requests node using its ID. 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.
Source Code
def get_lims_requests_by_id(id):
"""Get a LIMS_Requests node by its ID"""
query = """
MATCH (n:LIMS_Requests {id: $id})
RETURN n
"""
result = run_query(query, {"id": id})
return result[0] if result else None
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
id |
- | - | positional_or_keyword |
Parameter Details
id: The unique identifier of the LIMS_Requests node to retrieve. Expected to be a string or integer that matches the 'id' property of a LIMS_Requests node in the Neo4j database. This parameter is used in a Cypher query to perform an exact match.
Return Value
Returns the first LIMS_Requests node object from the query result if found, or None if no matching node exists. The node object typically contains all properties associated with that LIMS_Requests node in the database. 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 is defined and Neo4j connection 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 get a LIMS request by ID
request_id = "REQ-12345"
lims_request = get_lims_requests_by_id(request_id)
if lims_request:
print(f"Found LIMS request: {lims_request}")
else:
print(f"No LIMS request found with ID: {request_id}")
Best Practices
- Ensure the run_query function is properly defined with error handling for database connection issues
- Validate the id parameter before passing it to prevent injection attacks or invalid queries
- Consider adding type hints to the function signature for better code documentation
- Handle potential None returns appropriately in calling code
- Ensure proper Neo4j driver cleanup in the run_query implementation to avoid connection leaks
- Consider adding logging for debugging database queries
- For production use, implement connection pooling and proper exception handling in run_query
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_requests_by_uid 90.5% similar
-
function get_lims_samples_by_id 86.4% similar
-
function get_lims_tests_by_id 86.3% similar
-
function get_lims_parameters_by_id 85.1% similar
-
function get_all_lims_requests 84.7% similar