function get_lims_testparameters_by_id
Retrieves a single LIMS_Testparameters node from a Neo4j graph database by matching its unique ID property.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
421 - 428
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_Testparameters node using its ID. It's designed for Laboratory Information Management System (LIMS) applications where test parameters need to be retrieved individually. The function executes a Cypher query to match nodes with the label 'LIMS_Testparameters' and returns the first matching result or None if no match is found.
Source Code
def get_lims_testparameters_by_id(id):
"""Get a LIMS_Testparameters node by its ID"""
query = """
MATCH (n:LIMS_Testparameters {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_Testparameters node to retrieve. This should be a value that matches the 'id' property of a node in the Neo4j database. The type is not explicitly specified but is typically a string or integer depending on the database schema.
Return Value
Returns the first LIMS_Testparameters node that matches the provided ID, or None if no matching node is found. The return value is a dictionary-like object representing the Neo4j node with all its properties. If the query returns multiple results (which shouldn't happen with unique IDs), only the first result is returned.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j connection is configured
# Example run_query 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()
# Retrieve a test parameter by ID
test_param = get_lims_testparameters_by_id('TP-12345')
if test_param:
print(f"Found test parameter: {test_param}")
# Access properties like: test_param['property_name']
else:
print("Test parameter not found")
Best Practices
- Ensure the 'run_query' helper function is properly implemented with error handling and connection management
- Consider adding input validation to check if the ID parameter is not None or empty
- Add error handling for database connection failures or query execution errors
- Consider adding type hints to the function signature for better code documentation
- If IDs are guaranteed to be unique, consider adding an index on the 'id' property in Neo4j for better query performance
- The function assumes run_query returns a list; ensure this contract is maintained
- Consider logging when None is returned to help with debugging missing nodes
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_parameters_by_id 92.4% similar
-
function get_lims_testparameters_by_uid 88.9% similar
-
function get_all_lims_testparameters 86.6% similar
-
function get_lims_tests_by_id 86.3% similar
-
function get_lims_sampletestresults_by_id 84.1% similar