🔍 Code Extractor

function get_lims_sampletypes_by_id

Maturity: 41

Retrieves a single LIMS_SampleTypes node from a Neo4j graph database by matching its unique ID.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
343 - 350
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific LIMS_SampleTypes node using its ID as the lookup key. It's designed for Laboratory Information Management System (LIMS) data retrieval, specifically for accessing sample type definitions or metadata stored in a graph database. The function returns the first matching node or None if no match is found.

Source Code

def get_lims_sampletypes_by_id(id):
    """Get a LIMS_SampleTypes node by its ID"""
    query = """
    MATCH (n:LIMS_SampleTypes {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 for the LIMS_SampleTypes node to retrieve. Expected to be a string or integer that matches the 'id' property of nodes labeled as LIMS_SampleTypes in the Neo4j database. This should correspond to a valid sample type identifier in the LIMS system.

Return Value

Returns a dictionary-like object representing the LIMS_SampleTypes node if found, containing all properties of the matched node. Returns None if no node with the specified ID exists. The exact structure depends on the properties stored in the Neo4j node, but typically includes fields like id, name, description, and other sample type metadata.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is already defined and 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
sample_type_id = 'ST001'
sample_type = get_lims_sampletypes_by_id(sample_type_id)

if sample_type:
    print(f"Found sample type: {sample_type}")
else:
    print(f"No sample type found with ID: {sample_type_id}")

Best Practices

  • Ensure the run_query function is properly implemented with error handling and connection management
  • Validate the id parameter before calling this function to avoid unnecessary database queries
  • Consider adding type hints to the function signature for better code documentation
  • Handle the None return value appropriately in calling code to avoid AttributeError
  • Use connection pooling in the run_query implementation for better performance
  • Consider adding logging for debugging database queries
  • Ensure proper database indexes exist on the LIMS_SampleTypes.id property for optimal query performance
  • Close Neo4j driver connections properly when the application terminates

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_lims_sampletypes_by_uid 91.3% similar

    Retrieves a single LIMS_SampleTypes node from a Neo4j graph database by matching its unique identifier (UID).

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletypeproperties_by_id 90.4% similar

    Retrieves a LIMS_SampleTypeProperties node from a Neo4j graph database by its unique identifier.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_sampletypetests_by_id 90.3% similar

    Retrieves a LIMS_SampleTypeTests node from a Neo4j graph database by its unique identifier.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_samples_by_id 88.8% similar

    Retrieves a single LIMS_Samples node from a Neo4j graph database by its unique identifier.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_samples_with_references_sampletypes_lims_sampletypes 88.6% similar

    Queries a Neo4j graph database to retrieve LIMS_SampleTypes nodes that are connected to a specific LIMS_Samples node through a REFERENCES_SAMPLETYPES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse