function get_lims_sampletypeproperties_by_id
Retrieves a LIMS_SampleTypeProperties node from a Neo4j graph database by its unique identifier.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
265 - 272
simple
Purpose
This function queries a Neo4j database to fetch a specific LIMS_SampleTypeProperties node using its ID. It's designed for Laboratory Information Management System (LIMS) data retrieval, specifically for accessing sample type property configurations stored in a graph database. The function returns the first matching node or None if no match is found.
Source Code
def get_lims_sampletypeproperties_by_id(id):
"""Get a LIMS_SampleTypeProperties node by its ID"""
query = """
MATCH (n:LIMS_SampleTypeProperties {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_SampleTypeProperties 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 sample type properties identifier in the LIMS system.
Return Value
Returns the first LIMS_SampleTypeProperties node object that matches the provided ID, or None if no matching node is found. The returned object is typically a dictionary-like structure containing all properties of the Neo4j node. The function accesses the first element of the result array (result[0]) when results exist.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j is configured
# Example 1: Retrieve a sample type properties node
sample_props = get_lims_sampletypeproperties_by_id('SAMPLE_TYPE_001')
if sample_props:
print(f"Found sample type properties: {sample_props}")
else:
print("No sample type properties found with that ID")
# Example 2: Using with integer ID
sample_props = get_lims_sampletypeproperties_by_id(12345)
if sample_props:
# Access node properties
node_data = sample_props['n']
print(f"Sample type name: {node_data.get('name')}")
Best Practices
- Always check if the return value is None before accessing node properties to avoid AttributeError
- Ensure the 'run_query' helper function is properly implemented with error handling and connection management
- Consider adding input validation for the 'id' parameter to ensure it's not None or empty
- Use parameterized queries (as done here with $id) to prevent Cypher injection attacks
- Consider adding logging for debugging database queries and tracking failed lookups
- Implement proper connection pooling and session management in the run_query function for production use
- Consider adding type hints to the function signature for better code documentation and IDE support
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_lims_sampletypeproperties_by_uid 90.5% similar
-
function get_lims_sampletypes_by_id 90.4% similar
-
function get_all_lims_sampletypeproperties 87.5% similar
-
function get_lims_sampletypetests_by_id 86.8% similar
-
function get_lims_samples_by_id 85.6% similar