🔍 Code Extractor

function create_lims_parameters

Maturity: 44

Creates a new LIMS_Parameters 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:
88 - 97
Complexity:
simple

Purpose

This function is designed to insert a new LIMS_Parameters 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 useful for Laboratory Information Management Systems (LIMS) that need to store parameter configurations in a graph database structure.

Source Code

def create_lims_parameters(properties):
    """Create a new LIMS_Parameters node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:LIMS_Parameters)
    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_Parameters node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, lists, etc.). Example: {'name': 'pH_test', 'value': 7.4, 'unit': 'pH'}

Return Value

Returns the first element from the query result (the created LIMS_Parameters node) if the query execution is successful and returns results. Returns None if the result is empty or the query fails. The returned node is typically a dictionary-like object containing the node's properties and metadata.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

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

properties = {
    'parameter_name': 'temperature',
    'value': 25.5,
    'unit': 'celsius',
    'timestamp': '2024-01-15T10:30:00'
}

node = create_lims_parameters(properties)
if node:
    print(f"Created LIMS_Parameters node: {node}")
else:
    print("Failed to create node")

Best Practices

  • Ensure the properties dictionary does not contain keys with special characters that could break the Cypher query
  • Validate the properties dictionary before passing it to this function to prevent injection attacks
  • The run_query function should handle database connection errors and transaction management appropriately
  • Consider adding error handling for cases where properties is None or empty
  • Be aware that this function uses string formatting to build the Cypher query, which is safe here because property names come from dictionary keys, but values are passed as parameters
  • Ensure the Neo4j database has appropriate indexes on LIMS_Parameters nodes if querying them frequently
  • Consider wrapping this function call in a try-except block to handle potential database connection or query execution errors

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_lims_testparameters 93.1% 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_requests 83.4% similar

    Creates a new LIMS_Requests 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_tests4pathogens 80.6% 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_samples 79.8% similar

    Creates a new LIMS_Samples 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 79.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
← Back to Browse