🔍 Code Extractor

function get_lims_pathogens_by_uid

Maturity: 39

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
118 - 125
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific pathogen record from the LIMS_Pathogens node collection. It's designed for retrieving individual pathogen entries when the UID is known, typically used in laboratory information management systems (LIMS) for pathogen tracking and data retrieval. The function returns the first matching node or None if no match is found.

Source Code

def get_lims_pathogens_by_uid(uid):
    """Get a LIMS_Pathogens node by its UID"""
    query = """
    MATCH (n:LIMS_Pathogens {UID: $uid})
    RETURN n
    """
    result = run_query(query, {"uid": uid})
    return result[0] if result else None

Parameters

Name Type Default Kind
uid - - positional_or_keyword

Parameter Details

uid: The unique identifier (UID) of the LIMS_Pathogens node to retrieve. Expected to be a string or numeric value that uniquely identifies a pathogen record in the database. This value must match the UID property of a LIMS_Pathogens node exactly.

Return Value

Returns a dictionary-like object representing the LIMS_Pathogens node if found, containing all properties of the matched node. Returns None if no node with the specified UID exists. The returned node object typically contains pathogen-related information such as species, strain, sample data, and other LIMS metadata.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function is defined and Neo4j is 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 get_lims_pathogens_by_uid
pathogen_uid = 'PATH-12345'
pathogen = get_lims_pathogens_by_uid(pathogen_uid)

if pathogen:
    print(f"Found pathogen: {pathogen}")
else:
    print(f"No pathogen found with UID: {pathogen_uid}")

Best Practices

  • Ensure the run_query function is properly implemented with error handling and connection management
  • Validate the uid parameter before calling this function to avoid unnecessary database queries
  • Handle the None return value appropriately in calling code to avoid AttributeError
  • Consider adding input validation to check if uid is not None or empty
  • Use connection pooling in the Neo4j driver for better performance in production environments
  • Consider adding logging for debugging and monitoring database queries
  • Ensure proper database indexes exist on the UID property for optimal query performance

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_lims_tests4pathogens_by_uid 93.6% 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
  • function get_lims_pathogens_by_id 89.6% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_parameters_by_uid 86.5% similar

    Retrieves a LIMS_Parameters node from a Neo4j graph database by searching for a specific UID (unique identifier).

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_lims_testparameters_by_uid 85.3% similar

    Retrieves a LIMS_Testparameters 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_tests4pathogens_by_id 84.7% 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
← Back to Browse