function get_lims_sampletypetests_by_id
Retrieves a LIMS_SampleTypeTests node from a Neo4j graph database by its unique identifier.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
304 - 311
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_SampleTypeTests node using its ID. It's designed for Laboratory Information Management System (LIMS) data retrieval, specifically for accessing sample type test configurations or records. The function returns the first matching node or None if no match is found.
Source Code
def get_lims_sampletypetests_by_id(id):
"""Get a LIMS_SampleTypeTests node by its ID"""
query = """
MATCH (n:LIMS_SampleTypeTests {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_SampleTypeTests node to retrieve. Expected to be a string or integer that matches the 'id' property of nodes in the Neo4j database. This should correspond to a valid LIMS sample type test identifier.
Return Value
Returns a dictionary representing the LIMS_SampleTypeTests node if found, containing all properties of the node. Returns None if no node with the specified ID exists. The exact structure of the returned dictionary depends on the properties stored in the Neo4j node, but will include at minimum the 'id' field.
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
sample_test = get_lims_sampletypetests_by_id('TEST123')
if sample_test:
print(f"Found sample test: {sample_test}")
else:
print("Sample test not found")
Best Practices
- Ensure the run_query function is properly implemented with error handling and connection management
- 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 Neo4j database connection is properly configured and authenticated
- Consider adding logging for debugging database queries
- The function assumes run_query returns a list; ensure this contract is maintained
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_sampletypetests_by_uid 91.4% similar
-
function get_lims_sampletypes_by_id 90.3% similar
-
function get_lims_tests_by_id 90.0% similar
-
function get_lims_sampletestresults_by_id 89.2% similar
-
function get_all_lims_sampletypetests 88.2% similar