🔍 Code Extractor

function create_lims_tests

Maturity: 46

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
478 - 487
Complexity:
simple

Purpose

This function is designed to insert a new LIMS_Tests (Laboratory Information Management System Tests) 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 storing test-related information in a graph database structure for laboratory management systems.

Source Code

def create_lims_tests(properties):
    """Create a new LIMS_Tests node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:LIMS_Tests)
    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_Tests 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_id': '12345', 'test_name': 'Blood Test', 'status': 'pending'}

Return Value

Returns the first element from the query result (the created LIMS_Tests node) if the query execution is successful and returns results. Returns None if the query returns an empty result set or fails. The returned node is typically a dictionary-like object containing all the properties set on the node.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function is defined and Neo4j is configured
# 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()

test_properties = {
    'test_id': 'TEST-001',
    'test_name': 'Complete Blood Count',
    'test_type': 'Hematology',
    'status': 'pending',
    'created_date': '2024-01-15'
}

new_test_node = create_lims_tests(test_properties)

if new_test_node:
    print(f"Created test node: {new_test_node}")
else:
    print("Failed to create test 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 in calling code to detect creation failures
  • Consider adding error handling around the function call to catch database connection issues
  • Ensure the run_query function properly manages database connections and sessions to avoid resource leaks
  • Use unique identifiers in properties to prevent duplicate node creation if that's a concern for your use case
  • Consider adding constraints or indexes on LIMS_Tests nodes in Neo4j for better query performance
  • The function assumes run_query is available in scope - ensure proper module organization or imports

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_lims_tests4pathogens 89.7% 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_sampletypetests 89.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
  • function create_lims_sampletestresults 87.5% 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_testparameters 86.4% 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 82.5% 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
← Back to Browse