🔍 Code Extractor

function create_dbo_interventionprotocols

Maturity: 44

Creates a new node of type dbo_InterventionProtocols in a Neo4j graph database with the specified properties.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
985 - 994
Complexity:
simple

Purpose

This function is designed to insert a new intervention protocol record into a Neo4j graph database. It dynamically constructs a Cypher CREATE query based on the provided properties dictionary, executes the query using a run_query helper function, and returns the created node. This is useful for storing medical or research intervention protocol data in a graph database structure.

Source Code

def create_dbo_interventionprotocols(properties):
    """Create a new dbo_InterventionProtocols node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:dbo_InterventionProtocols)
    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 new dbo_InterventionProtocols 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': 'Protocol A', 'version': '1.0', 'approved': True}

Return Value

Returns the created Neo4j node object (first element from the query result) if the creation was successful, or None if the query returned no results or failed. The returned node object typically contains all properties set during creation along with Neo4j metadata like node ID and labels.

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 a new intervention protocol node
protocol_properties = {
    'protocol_id': 'PROTO-001',
    'name': 'Clinical Trial Protocol',
    'version': '2.1',
    'status': 'active',
    'created_date': '2024-01-15'
}

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

Best Practices

  • Ensure the properties dictionary does not contain None values or invalid data types that Neo4j cannot handle
  • Validate property keys to avoid Cypher injection vulnerabilities, especially if properties come from user input
  • The run_query function should handle database connection errors and transaction management properly
  • Consider adding error handling around the function call to catch potential database connection or query execution failures
  • Use parameterized queries (as this function does with ${prop}) to prevent injection attacks
  • Ensure unique constraints or indexes are defined on the database if protocol_id or similar fields should be unique
  • Consider wrapping this function in a try-except block when calling it to handle potential Neo4j driver exceptions

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_dbo_interventionprotocolflocks 82.6% similar

    Creates a new node labeled 'dbo_InterventionProtocolFlocks' in a Neo4j graph database with the specified properties.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocols_by_id 78.2% similar

    Retrieves a single dbo_InterventionProtocols node from a Neo4j graph database by its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_references_interventionprotocols_relationship 76.9% similar

    Creates a directed REFERENCES_INTERVENTIONPROTOCOLS relationship in a Neo4j graph database from a dbo_InterventionProtocolFlocks node to a dbo_InterventionProtocols node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_interventionprotocols 75.1% similar

    Queries a Neo4j graph database to retrieve all nodes labeled as 'dbo_InterventionProtocols' with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocols_by_uid 72.4% similar

    Retrieves a single dbo_InterventionProtocols node from a Neo4j graph database by matching its unique identifier (UID).

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