🔍 Code Extractor

function create_lims_sampletypetests

Maturity: 46

Creates a new LIMS_SampleTypeTests 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:
322 - 331
Complexity:
simple

Purpose

This function is designed to insert a new LIMS_SampleTypeTests 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 relationships between sample types and their associated tests.

Source Code

def create_lims_sampletypetests(properties):
    """Create a new LIMS_SampleTypeTests node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:LIMS_SampleTypeTests)
    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_SampleTypeTests 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': '123', 'sample_type': 'blood', 'test_name': 'CBC'}

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_SampleTypeTests node with all its properties. Returns None if the query execution fails or returns an empty result set.

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': 'T001',
    'sample_type': 'blood',
    'test_name': 'Complete Blood Count',
    'required': True,
    'turnaround_time': 24
}

node = create_lims_sampletypetests(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 keys to avoid Cypher injection vulnerabilities, especially if properties come from user input
  • Handle the None return value appropriately to detect creation failures
  • Consider adding error handling around the function call to catch database connection issues
  • Use parameterized queries (as this function does) to prevent injection attacks
  • Ensure the run_query function properly manages database connections and sessions
  • Consider adding uniqueness constraints or validation to prevent duplicate nodes
  • Document the expected schema for LIMS_SampleTypeTests nodes in your application

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_lims_sampletypes 90.7% similar

    Creates a new LIMS_SampleTypes 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 89.5% 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_sampletestresults 87.2% 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_sampletypeproperties 86.6% similar

    Creates a new LIMS_SampleTypeProperties node in a Neo4j graph database with the provided properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_lims_samples 86.1% 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
← Back to Browse