🔍 Code Extractor

function create_lims_tests4pathogens

Maturity: 46

Creates a new LIMS_Tests4Pathogens node in a Neo4j graph database with the specified properties and returns the created node.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
517 - 526
Complexity:
simple

Purpose

This function is designed to insert a new LIMS_Tests4Pathogens node into a Neo4j graph database. It dynamically constructs a Cypher query based on the provided properties dictionary, executes the query using a run_query helper function, and returns the newly created node. This is typically used in Laboratory Information Management Systems (LIMS) to track pathogen testing data.

Source Code

def create_lims_tests4pathogens(properties):
    """Create a new LIMS_Tests4Pathogens node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:LIMS_Tests4Pathogens)
    SET {props_list}
    RETURN n
    """
    result = run_query(query, properties)
    return result[0] if result else None

Parameters

Name Type Default Kind
properties - - positional_or_keyword

Parameter Details

properties: A dictionary containing key-value pairs representing the properties to be set on the LIMS_Tests4Pathogens node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, dates, etc.). Example: {'test_id': '12345', 'pathogen_name': 'E. coli', 'test_date': '2024-01-15'}

Return Value

Returns the created LIMS_Tests4Pathogens node object (typically a Neo4j Record or Node object) if the creation was successful, or None if the query returned no results or failed. The returned node contains all the properties that were set during creation.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function is defined and Neo4j connection is established
# Example run_query implementation:
# 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()

properties = {
    'test_id': 'TEST-2024-001',
    'pathogen_name': 'Salmonella',
    'test_date': '2024-01-15',
    'result': 'positive',
    'lab_technician': 'John Doe'
}

node = create_lims_tests4pathogens(properties)
if node:
    print(f'Successfully created node: {node}')
else:
    print('Failed to create node')

Best Practices

  • Ensure the properties dictionary contains valid data types supported by Neo4j before calling this function
  • Validate and sanitize input properties to prevent injection attacks, even though parameterized queries are used
  • Handle the None return value appropriately to detect creation failures
  • Consider adding error handling around the function call to catch Neo4j connection or query execution errors
  • Ensure the run_query function properly manages database connections (opening and closing sessions)
  • Use unique identifiers in properties to avoid duplicate nodes if business logic requires uniqueness
  • Consider adding constraints or indexes on the LIMS_Tests4Pathogens label in Neo4j for better performance
  • The function assumes run_query is available in scope - ensure it's properly imported or defined

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_lims_tests 89.7% similar

    Creates a new LIMS_Tests node in a Neo4j graph database with specified properties and returns the created node.

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

    Creates a new LIMS_Testparameters node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_sampletestresults 81.6% similar

    Creates a new LIMS_SampleTestResults node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_parameters 80.6% similar

    Creates a new LIMS_Parameters node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_sampletypetests 80.5% similar

    Creates a new LIMS_SampleTypeTests node in a Neo4j graph database with the specified properties and returns the created node.

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