🔍 Code Extractor

function get_lims_pathogens_by_id

Maturity: 39

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
109 - 116
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific LIMS_Pathogens node using its ID. It's designed for Laboratory Information Management System (LIMS) applications that track pathogen data in a graph database. The function returns the first matching node or None if no match is found, making it useful for retrieving detailed pathogen information by identifier.

Source Code

def get_lims_pathogens_by_id(id):
    """Get a LIMS_Pathogens node by its ID"""
    query = """
    MATCH (n:LIMS_Pathogens {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_Pathogens node to retrieve. Expected to be a string or integer that matches the 'id' property of a node in the Neo4j database. This should correspond to a valid pathogen record identifier in the LIMS system.

Return Value

Returns a dictionary-like object representing the LIMS_Pathogens node if found, containing all properties of the node (e.g., pathogen name, classification, metadata). Returns None if no node with the specified ID exists. The exact structure depends on the properties stored in the Neo4j node.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j connection is configured
from neo4j import GraphDatabase

# Example usage
pathogen_id = "PATH-12345"
pathogen_node = get_lims_pathogens_by_id(pathogen_id)

if pathogen_node:
    print(f"Found pathogen: {pathogen_node}")
    # Access node properties
    # print(f"Name: {pathogen_node['n']['name']}")
else:
    print(f"No pathogen found with ID: {pathogen_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, even though parameterized queries are used
  • Consider adding type hints to the function signature for better code documentation
  • Handle the None return value appropriately in calling code to avoid AttributeError
  • Implement proper connection pooling and session management in the run_query function
  • Consider adding logging for debugging database queries
  • The function assumes run_query returns a list; ensure this contract is maintained

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_lims_tests4pathogens_by_id 93.3% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_pathogens_by_uid 89.6% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_lims_pathogens 86.6% similar

    Retrieves LIMS_Pathogens nodes from a Neo4j graph database with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_parameters_by_id 85.2% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_tests4pathogens_by_uid 85.0% similar

    Retrieves a LIMS_Tests4Pathogens node from a Neo4j graph database by its unique identifier (UID).

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