🔍 Code Extractor

function create_lims_testparameters

Maturity: 46

Creates a new LIMS_Testparameters 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:
439 - 448
Complexity:
simple

Purpose

This function is designed to insert a new LIMS_Testparameters 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 store test parameter configurations in a graph database structure.

Source Code

def create_lims_testparameters(properties):
    """Create a new LIMS_Testparameters node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:LIMS_Testparameters)
    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_Testparameters node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, lists, etc.). Example: {'test_name': 'pH Test', 'min_value': 6.5, 'max_value': 7.5, 'unit': 'pH'}

Return Value

Returns the first node from the query result if the creation was successful, which is typically a dictionary-like object representing the created LIMS_Testparameters node with all its properties. Returns None if the query execution fails or returns no results. The returned node object structure depends on the Neo4j driver implementation but typically includes all properties set during creation.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

from neo4j import GraphDatabase

# Assuming run_query is defined elsewhere
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()

# Create test parameters node
test_properties = {
    'test_name': 'Blood Glucose Test',
    'min_value': 70,
    'max_value': 100,
    'unit': 'mg/dL',
    'test_code': 'GLU001',
    'active': True
}

node = create_lims_testparameters(test_properties)
if node:
    print(f'Created node with properties: {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 property names to avoid Cypher injection vulnerabilities, especially if properties come from user input
  • Handle the None return value appropriately to detect creation failures
  • Consider wrapping this function call in try-except blocks to handle potential Neo4j connection or query execution errors
  • Ensure the run_query function properly manages database connections and sessions to avoid connection leaks
  • Use parameterized queries (as this function does) to prevent Cypher injection attacks
  • Consider adding uniqueness constraints or validation logic to prevent duplicate LIMS_Testparameters nodes if needed
  • Document the expected schema/properties for LIMS_Testparameters nodes to maintain consistency across the application

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_lims_parameters 93.1% 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_tests 86.4% 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_tests4pathogens 85.0% similar

    Creates a new LIMS_Tests4Pathogens 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 82.3% 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_sampletypetests 79.7% 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